The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
editor_toolkit.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 - 2016 by Fabian Mueller <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #include "editor_toolkit.hpp"
16 #include "config.hpp"
17 
24 
25 namespace editor {
26 
28  const config& game_config, context_manager& c_manager)
29  : gui_(gui)
30  , key_(key)
31  , palette_manager_()
32  , mouse_action_(nullptr)
33  , mouse_actions_()
34  , brush_(nullptr)
35  , brushes_()
36 {
37  init_brushes(game_config);
38  init_sidebar(game_config);
39  init_mouse_actions(c_manager);
40 }
41 
43 {
44  //TODO ask someone about that
45  //for (const mouse_action_map::value_type a : mouse_actions_) {
46  // delete a.second;
47  //}
48  //delete palette_manager_.get();
49 }
50 
52 {
53  for (const config &i : game_config.child_range("brush")) {
54  brushes_.push_back(brush(i));
55  }
56  if (brushes_.empty()) {
57  ERR_ED << "No brushes defined!";
58  brushes_.push_back(brush());
59  brushes_[0].add_relative_location(0, 0);
60  }
61  brush_ = &brushes_[0];
62 }
63 
65 {
66  palette_manager_.reset(new palette_manager(gui_, game_config, &mouse_action_));
67 }
68 
70 {
72  new mouse_action_paint(&brush_, key_, *palette_manager_->terrain_palette_.get())));
73  mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_FILL,
74  new mouse_action_fill(key_, *palette_manager_->terrain_palette_.get())));
76  new mouse_action_select(&brush_, key_, *palette_manager_->empty_palette_.get())));
78  new mouse_action_starting_position(key_, *palette_manager_->location_palette_.get())));
80  new mouse_action_map_label(key_, *palette_manager_->empty_palette_.get())));
81  mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_UNIT,
82  new mouse_action_unit(key_, *palette_manager_->unit_palette_.get())));
84  new mouse_action_village(key_, *palette_manager_->empty_palette_.get())));
86  new mouse_action_paste(cmanager.get_clipboard(), key_, *palette_manager_->empty_palette_.get())));
87  mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_ITEM,
88  new mouse_action_item(key_, *palette_manager_->item_palette_.get())));
89 
90  for (const theme::menu& menu : gui_.get_theme().menus()) {
91  if (menu.items().size() == 1) {
92  hotkey::HOTKEY_COMMAND hk = hotkey::get_id(menu.items().front());
94  if (i != mouse_actions_.end()) {
95  i->second->set_toolbar_button(&menu);
96  }
97  }
98  }
99 
102 }
103 
104 
106 {
108  if (i != mouse_actions_.end()) {
109  palette_manager_->active_palette().hide(true);
110  mouse_action_ = i->second;
111  palette_manager_->adjust_size();
112 
115  palette_manager_->active_palette().hide(false);
116  } else {
117  ERR_ED << "Invalid hotkey command ("
118  << static_cast<int>(command) << ") passed to set_mouse_action\n";
119  }
120 
121 }
122 
124 {
125  std::map<hotkey::HOTKEY_COMMAND, mouse_action*>::const_iterator i = mouse_actions_.find(command);
126  return (i != mouse_actions_.end()) && (i->second == mouse_action_);
127 }
128 
130 {
131  DBG_ED << __func__ << "\n";
132  int x, y;
133  SDL_GetMouseState(&x, &y);
134  map_location hex_clicked = gui_.hex_clicked_on(x,y);
136 }
137 
139 {
141 }
142 
144 {
146 }
147 
149 
150  for (brush& i : brushes_) {
151  if (i.id() == id) {
152  brush_ = &i;
153  }
154  }
155 }
156 
158 {
159  if (brush_ == &brushes_.back()) {
160  brush_ = &brushes_.front();
161  } else {
162  ++brush_;
163  }
164 
166 }
167 
169 {
170  palette_manager_->adjust_size();
171 }
172 
173 
174 } //Namespace editor
Brush paint mouse action.
child_itors child_range(const std::string &key)
Definition: config.cpp:613
editor_display & gui_
void invalidate_game_status()
Function to invalidate the game status displayed on the sidebar.
Definition: display.hpp:299
theme & get_theme()
Definition: display.hpp:385
void hotkey_set_mouse_action(hotkey::HOTKEY_COMMAND command)
Set the current mouse action based on a hotkey id.
mouse_action_map mouse_actions_
bool is_mouse_action_set(hotkey::HOTKEY_COMMAND command) const
void cycle_brush()
Cycle to the next brush.
void init_sidebar(const config &game_config)
init the sidebar objects
General purpose widgets.
const map_location hex_clicked_on(int x, int y) const
given x,y co-ordinates of an onscreen pixel, will return the location of the hex that this pixel corr...
Definition: display.cpp:577
const std::vector< menu > & menus() const
Definition: theme.hpp:263
void clear_mouseover_hex_overlay()
Definition: display.hpp:461
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
Definitions for the interface to Wesnoth Markup Language (WML).
brush * brush_
The current brush.
Select (and deselect) action, by brush or "magic wand" (via keyboard modifier)
void set_brush(std::string id)
TODO.
expression_ptr key_
Definition: formula.cpp:435
editor_toolkit(editor_display &gui, const CKey &key, const config &game_config, context_manager &c_manager)
item placement action class
GLuint id
Definition: glew.h:1647
std::vector< brush > brushes_
All available brushes.
void update_brush_highlights(editor_display &disp, const map_location &hex)
Unconditionally update the brush highlights for the current tool when hex is the center location...
The brush class represents a single brush – a set of relative locations around a "hotspot"...
Definition: brush.hpp:26
boost::scoped_ptr< palette_manager > palette_manager_
Manage the empty-palette in the editor.
Definition: action.cpp:28
map_fragment & get_clipboard()
mouse_action * get_mouse_action()
Get the current mouse action.
Encapsulates the map of the game.
Definition: location.hpp:38
Unit placement action class.
void init_mouse_actions(context_manager &c_manager)
init the mouse actions (tools)
void init_brushes(const config &game_config)
init the brushes
mouse_action * mouse_action_
The current mouse action.
Game configuration data as global variables.
Definition: build_info.cpp:38
size_t i
Definition: function.cpp:1057
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
virtual void set_mouse_overlay(editor_display &disp)
Set the mouse overlay for this action.
#define ERR_ED
Set starting position action.
Editor mouse action class.
#define DBG_ED
std::string::const_iterator iterator
Definition: tokenizer.hpp:21
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
Class that keeps track of all the keys on the keyboard.
Definition: key.hpp:27
GLsizei const GLcharARB ** string
Definition: glew.h:4503
HOTKEY_COMMAND get_id(const std::string &command)
returns get_hotkey_command(command).id