The Battle for Wesnoth  1.13.10+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 - 2017 by Fabian Mueller <fabianmueller5@gmx.de>
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 
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) // Will be set before this constructor ends.
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 
45 {
46  for (const config &i : game_config.child_range("brush")) {
47  brushes_.emplace_back(i);
48  }
49  if (brushes_.empty()) {
50  ERR_ED << "No brushes defined!";
51  brushes_.emplace_back();
52  brushes_[0].add_relative_location(0, 0);
53  }
54  brush_ = &brushes_[0];
55 }
56 
58 {
59  palette_manager_.reset(new palette_manager(gui_, game_config, *this));
60 }
61 
63 {
65  std::make_shared<mouse_action_paint>(&brush_, key_, *palette_manager_->terrain_palette_.get()));
67  std::make_shared<mouse_action_fill>(key_, *palette_manager_->terrain_palette_.get()));
69  std::make_shared<mouse_action_select>(&brush_, key_, *palette_manager_->empty_palette_.get()));
71  std::make_shared<mouse_action_starting_position>(key_, *palette_manager_->location_palette_.get()));
73  std::make_shared<mouse_action_map_label>(key_, *palette_manager_->empty_palette_.get()));
75  std::make_shared<mouse_action_unit>(key_, *palette_manager_->unit_palette_.get()));
77  std::make_shared<mouse_action_village>(key_, *palette_manager_->empty_palette_.get()));
79  std::make_shared<mouse_action_paste>(cmanager.get_clipboard(), key_, *palette_manager_->empty_palette_.get()));
81  std::make_shared<mouse_action_item>(key_, *palette_manager_->item_palette_.get()));
82 
83  for (const theme::menu& menu : gui_.get_theme().menus()) {
84  if (menu.items().size() == 1) {
85  hotkey::HOTKEY_COMMAND hk = hotkey::get_id(menu.items().front()["id"]);
87  if (i != mouse_actions_.end()) {
88  i->second->set_toolbar_button(&menu);
89  }
90  }
91  }
92 
95 }
96 
97 
99 {
101  if (i != mouse_actions_.end()) {
102  palette_manager_->active_palette().hide(true);
103  mouse_action_ = i->second;
104  palette_manager_->adjust_size();
105 
108  palette_manager_->active_palette().hide(false);
109  } else {
110  ERR_ED << "Invalid hotkey command ("
111  << static_cast<int>(command) << ") passed to set_mouse_action\n";
112  }
113 
114 }
115 
117 {
118  mouse_action_map::const_iterator i = mouse_actions_.find(command);
119  return (i != mouse_actions_.end()) && (i->second == mouse_action_);
120 }
121 
123 {
124  return get_mouse_action().get_palette();
125 }
126 
128 {
129  DBG_ED << __func__ << "\n";
130  int x, y;
131  SDL_GetMouseState(&x, &y);
132  map_location hex_clicked = gui_.hex_clicked_on(x,y);
134 }
135 
137 {
139 }
140 
142 {
144 }
145 
147 
148  for (brush& i : brushes_) {
149  if (i.id() == id) {
150  brush_ = &i;
151  }
152  }
153 }
154 
156 {
157  if (brush_ == &brushes_.back()) {
158  brush_ = &brushes_.front();
159  } else {
160  ++brush_;
161  }
162 
164 }
165 
167 {
168  palette_manager_->adjust_size();
169 }
170 
171 
172 } //Namespace editor
editor_display & gui_
std::vector< char_t > string
void invalidate_game_status()
Function to invalidate the game status displayed on the sidebar.
Definition: display.hpp:287
theme & get_theme()
Definition: display.hpp:375
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.
std::shared_ptr< mouse_action > mouse_action_
The current mouse action.
child_itors child_range(config_key_type key)
Definition: config.cpp:343
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:589
const std::vector< menu > & menus() const
Definition: theme.hpp:244
void clear_mouseover_hex_overlay()
Definition: display.hpp:440
Definitions for the interface to Wesnoth Markup Language (WML).
brush * brush_
The current brush.
void set_brush(std::string id)
TODO.
editor_toolkit(editor_display &gui, const CKey &key, const config &game_config, context_manager &c_manager)
common_palette & get_palette()
Get the current palette.
std::vector< brush > brushes_
All available brushes.
common_palette & get_palette()
Getter for the associated palette.
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:25
std::unique_ptr< palette_manager > palette_manager_
Manage the empty-palette in the editor.
Definition: action.cpp:29
map_fragment & get_clipboard()
Encapsulates the map of the game.
Definition: location.hpp:40
void init_mouse_actions(context_manager &c_manager)
init the mouse actions (tools)
void init_brushes(const config &game_config)
init the brushes
Game configuration data as global variables.
Definition: build_info.cpp:53
size_t i
Definition: function.cpp:933
mouse_action & get_mouse_action()
Get the current mouse action.
virtual void set_mouse_overlay(editor_display &disp)
Set the mouse overlay for this action.
#define ERR_ED
#define DBG_ED
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
Class that keeps track of all the keys on the keyboard.
Definition: key.hpp:27
std::string::const_iterator iterator
Definition: tokenizer.hpp:24
HOTKEY_COMMAND get_id(const std::string &command)
returns get_hotkey_command(command).id