16 #define GETTEXT_DOMAIN "wesnoth-editor" 51 std::set<map_location> res;
95 if (!
has_alt_modifier() && (event.key.keysym.sym >=
'1' && event.key.keysym.sym <=
'9')) {
96 int side =
event.key.keysym.sym -
'0';
108 std::unique_ptr<editor_action>
a;
109 if ((
has_alt_modifier() && (event.key.keysym.sym >=
'1' && event.key.keysym.sym <=
'9'))
110 ||
event.key.keysym.sym == SDLK_DELETE) {
111 int res =
event.key.keysym.sym -
'0';
114 if (res == 0 && old_id !=
nullptr) {
115 a = std::make_unique<editor_action_starting_position>(
map_location(), *old_id);
116 }
else if (res > 0 && (old_id ==
nullptr || *old_id == std::to_string(res))) {
117 a = std::make_unique<editor_action_starting_position>(
previous_move_hex_, std::to_string(res));
130 return key_[SDLK_RALT] ||
key_[SDLK_LALT];
135 return key_[SDLK_RSHIFT] ||
key_[SDLK_LSHIFT];
141 return key_[SDLK_RGUI] ||
key_[SDLK_LGUI];
143 return key_[SDLK_RCTRL] ||
key_[SDLK_LCTRL];
154 const std::string blank_hex =
"misc/blank-hex.png";
157 ERR_ED <<
"Missing terrain icon";
169 static const int half_size = size / 2;
170 static const int quarter_size = size / 4;
171 static const int offset = 2;
172 static const int new_size = half_size - 2;
175 std::stringstream
path;
178 <<
"~BLIT(" << fg_path <<
"~SCALE(" << new_size <<
"," << new_size
179 <<
")," << offset <<
"," << quarter_size <<
")" 180 <<
"~BLIT(" << bg_path <<
"~SCALE(" << new_size <<
"," << new_size
181 <<
")," << half_size <<
"," << quarter_size <<
")";
190 return get_brush().project(hex);
196 previous_drag_hex_ = hex;
203 previous_drag_hex_ = hex;
210 return drag_generic<&brush_drag_mouse_action::click_perform_left>(disp, x, y, partial, last_undo);
216 return drag_generic<&brush_drag_mouse_action::click_perform_right>(disp, x, y, partial, last_undo);
225 template <std::unique_ptr<editor_action> (brush_drag_mouse_action::*perform_func)(editor_display&, const std::set<map_location>&)>
230 if (hex != previous_drag_hex_) {
232 LOG_ED <<
"Last undo is " << last_undo <<
" and as x " << last_undo_x;
235 previous_drag_hex_ = hex;
278 auto chain = std::make_unique<editor_action_chain>();
279 chain->append_action(std::make_unique<editor_action_paint_area>(
289 auto chain = std::make_unique<editor_action_chain>();
290 chain->append_action(std::make_unique<editor_action_paint_area>(
298 terrain_palette_.selected_bg_item());
313 return paste_.get_offset_area(hex);
319 return std::make_unique<editor_action_paste>(paste_, hex);
333 "misc/blank-hex.png",
334 "~BLIT(icons/action/editor-paste_60.png,6,6)" 355 return std::make_unique<editor_action_fill>(hex, terrain_palette_.selected_fg_item(),
369 return std::make_unique<editor_action_fill>(hex, terrain_palette_.selected_bg_item(),
377 terrain_palette_.selected_bg_item());
382 if (!click_)
return nullptr;
391 if (player_starting_at_hex) {
392 location_palette_.add_item(*player_starting_at_hex);
397 std::string new_player_at_hex = location_palette_.selected_item();
398 std::unique_ptr<editor_action>
a;
400 if(!player_starting_at_hex || new_player_at_hex != *player_starting_at_hex) {
402 a = std::make_unique<editor_action_starting_position>(hex, new_player_at_hex);
406 a = std::make_unique<editor_action_starting_position>(
map_location(), *player_starting_at_hex);
424 if (player_starting_at_hex !=
nullptr) {
425 return std::make_unique<editor_action_starting_position>(
map_location(), *player_starting_at_hex);
442 "misc/blank-hex.png",
443 "~BLIT(icons/action/editor-tool-starting-position_60.png,6,6)" const editor_map & map() const
virtual std::unique_ptr< editor_action > drag_end_left(editor_display &disp, int x, int y)
The end of dragging.
std::unique_ptr< editor_action > click_right(editor_display &disp, int x, int y) override
Right click does nothing for now.
const CKey & key_
Key presses, used for modifiers (alt, shift) in some operations.
std::unique_ptr< editor_action > click_left(editor_display &disp, int x, int y) override
Return a paste with offset action.
const brush & get_brush()
Brush accessor.
map_location previous_move_hex_
The hex previously used in move operations.
const std::string * is_special_location(const map_location &loc) const
returns the name of the special location at position loc, null if no such location exists...
map_location starting_position(int side) const
std::unique_ptr< editor_action > click_left(editor_display &disp, int x, int y) override
Handle terrain sampling before calling generic handler.
std::unique_ptr< editor_action > click_left(editor_display &disp, int x, int y) override
Left / right click fills with the respective terrain.
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...
void set_mouse_overlay(editor_display &disp) override
Set the mouse overlay for this action.
void set_brush_locs(const std::set< map_location > &hexes)
std::unique_ptr< editor_action > click_right(editor_display &disp, int x, int y) override
A click, possibly the beginning of a drag.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
const terrain_type & get_terrain_info(const t_translation::terrain_code &terrain) const
void set_terrain_mouse_overlay(editor_display &disp, const t_translation::terrain_code &fg, const t_translation::terrain_code &bg)
Helper function for derived classes that need a active-terrain mouse overlay.
const std::string & editor_image() const
point get_size(const locator &i_locator, bool skip_cache)
Returns the width and height of an image.
std::unique_ptr< editor_action > up_right(editor_display &disp, int x, int y) override
Right click only erases the starting position if there is one.
virtual std::unique_ptr< editor_action > up_right(editor_display &disp, int x, int y)
std::unique_ptr< editor_action > click_right(editor_display &disp, int x, int y) override
Handle terrain sampling before calling generic handler.
virtual std::unique_ptr< editor_action > drag_end_right(editor_display &disp, int x, int y)
static const int MAX_PLAYERS
Maximum number of players supported.
std::unique_ptr< editor_action > drag_left(editor_display &disp, int x, int y, bool &partial, editor_action *last_undo)
Calls click_perform() for every new hex the mouse is dragged into.
bool exists(const image::locator &i_locator)
Returns true if the given image actually exists, without loading it.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
virtual std::unique_ptr< editor_action > key_event(editor_display &disp, const SDL_Event &e)
Function called by the controller on a key event for the current mouse action.
virtual bool has_context_menu() const
terrain_code get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
virtual void set_mouse_overlay(editor_display &disp) override
Set the mouse overlay for this action.
bool has_shift_modifier() const
virtual void set_mouse_overlay(editor_display &disp) override
Set the mouse overlay for this action.
std::set< map_location > get_contiguous_terrain_tiles(const map_location &start) const
Get a contiguous set of tiles having the same terrain as the starting location.
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"...
Manage the empty-palette in the editor.
Generic locator abstracting the location of an image.
std::unique_ptr< editor_action > click_left(editor_display &disp, int x, int y) override
A click, possibly the beginning of a drag.
Encapsulates the map of the game.
virtual bool has_context_menu() const override
std::set< map_location > affected_hexes(editor_display &disp, const map_location &hex) override
Tiles that will be painted to, possibly use modifier keys here.
void scroll_to_tile(const map_location &loc, SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true, bool force=true)
Scroll such that location loc is on-screen.
virtual void set_mouse_overlay(editor_display &disp) override
Set the mouse overlay for this action.
void clear_mouseover_hex_overlay()
Base class for all editor actions.
std::unique_ptr< editor_action > drag_generic(editor_display &disp, int x, int y, bool &partial, editor_action *last_undo)
Template helper gathering actions common for both drag_right and drag_left.
std::unique_ptr< editor_action > click_right(editor_display &disp, int x, int y) override
Left / right click fills with the respective terrain.
Base class for actions that: 1) operate on an area 2) can be used as undo for a click-drag operation ...
bool on_board(const map_location &loc) const
Tell if a location is on the map.
std::unique_ptr< editor_action > click_left(editor_display &disp, int x, int y)
Calls click_perform_left()
virtual std::unique_ptr< editor_action > up_left(editor_display &disp, int x, int y)
virtual void set_mouse_overlay(editor_display &disp)
Set the mouse overlay for this action.
std::unique_ptr< editor_action > up_left(editor_display &disp, int x, int y) override
Left click displays a player-number-selector dialog and then creates an action or returns nullptr if ...
const gamemap & get_map() const
virtual void move(editor_display &disp, const map_location &hex)
Mouse move (not a drag).
std::unique_ptr< editor_action > click_perform_right(editor_display &disp, const std::set< map_location > &hexes) override
Create an appropriate editor_action and return it.
bool has_ctrl_modifier() const
virtual std::unique_ptr< editor_action > drag_left(editor_display &disp, int x, int y, bool &partial, editor_action *last_undo)
Drag operation.
std::set< map_location > affected_hexes(editor_display &disp, const map_location &hex) override
Show an outline of where the paste will go.
std::unique_ptr< editor_action > click_perform_left(editor_display &disp, const std::set< map_location > &hexes) override
Create an appropriate editor_action and return it.
std::unique_ptr< editor_action > click_right(editor_display &disp, int x, int y)
Calls click_perform_right()
virtual std::set< map_location > affected_hexes(editor_display &disp, const map_location &hex)
Locations that would be affected by a click, used by move to update highlights.
std::unique_ptr< editor_action > drag_right(editor_display &disp, int x, int y, bool &partial, editor_action *last_undo)
Calls click_perform for every new hex the mouse is dragged into.
texture get_texture(const image::locator &i_locator, TYPE type, bool skip_cache)
Returns an image texture suitable for hardware-accelerated rendering.
virtual std::unique_ptr< editor_action > drag_right(editor_display &disp, int x, int y, bool &partial, editor_action *last_undo)
Drag operation.
void set_mouseover_hex_overlay(const texture &image)
Sets texture to be drawn in hex under the mouse's location.
std::unique_ptr< editor_action > drag_end(editor_display &disp, int x, int y)
End of dragging.
std::set< map_location > affected_hexes(editor_display &disp, const map_location &hex)
The affected hexes of a brush action are the result of projecting the current brush on the mouseover ...
bool has_alt_modifier() const