The Battle for Wesnoth  1.19.0+dev
mouse_action_item.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2024
3  by Fabian Mueller <fabianmueller5@gmx.de>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #define GETTEXT_DOMAIN "wesnoth-editor"
17 
20 
22 #include "gettext.hpp"
23 
24 #include "map/location.hpp"
25 
26 namespace editor {
27 
28 
30 {
31  if (hex == previous_move_hex_) {
32  return;
33  }
34 
35  update_brush_highlights(disp, hex);
36 
37  std::set<map_location> adjacent_set;
39  adjacent_set.insert(adj);
40  }
41 
42  disp.invalidate(adjacent_set);
43  previous_move_hex_ = hex;
44 }
45 
46 std::unique_ptr<editor_action> mouse_action_item::click_left(editor_display& disp, int x, int y)
47 {
48  start_hex_ = disp.hex_clicked_on(x, y);
49  if (!disp.get_map().on_board(start_hex_)) {
50  return nullptr;
51  }
52 
54  disp.add_overlay(start_hex_, item.image, item.halo, "", "", item.visible_in_fog, item.submerge);
55 
56  click_ = true;
57  return nullptr;
58 }
59 
60 std::unique_ptr<editor_action> mouse_action_item::drag_left(editor_display& disp, int x, int y, bool& /*partial*/, editor_action* /*last_undo*/)
61 {
62  map_location hex = disp.hex_clicked_on(x, y);
63  click_ = (hex == start_hex_);
64  return nullptr;
65 }
66 
67 std::unique_ptr<editor_action> mouse_action_item::up_left(editor_display& disp, int x, int y)
68 {
69  if (!click_) return nullptr;
70  click_ = false;
71  map_location hex = disp.hex_clicked_on(x, y);
72  if (!disp.get_map().on_board(hex)) {
73  return nullptr;
74  }
75 
76 // item_type type = item_palette_.selected_fg_item();
77 //
78 // // Does this serve a purpose other than making sure the type is built?
79 // // (Calling item_types.build_item_type(type) would now accomplish that
80 // // with less overhead.)
81 // const std::string& type_id = type.id();
82 // const item_type *new_item_type = item_types.find(type_id);
83 // if (!new_item_type) {
84 // //TODO rewrite the error message.
85 // ERR_ED << "create item dialog returned inexistent or unusable item_type id '" << type_id << "'";
86 // return nullptr;
87 // }
88 //
89 // const item_type &ut = *new_item_type;
90 // item_race::GENDER gender = ut.genders().front();
91 //
92 // item new_item(ut, disp.viewing_side(), true, gender);
93 // editor_action* action = new editor_action_item(hex, new_item);
94 // return action;
95 
96 // \todo in #5070: there's a load of commented-out code in this file, it should probably
97 // all be deleted. For the function that this comment is in, I've left the commented-out
98 // code in because it seems the not-commented code should also be reviewed. AFAICS, the
99 // entire function (including the not-commented code) could be deleted, and fall back to
100 // the parent class' implementation of just returning nullptr.
101 
102  return nullptr;
103 }
104 
105 std::unique_ptr<editor_action> mouse_action_item::drag_end_left(editor_display& disp, int x, int y)
106 {
107  if (click_) return nullptr;
108 
109  map_location hex = disp.hex_clicked_on(x, y);
110  if (!disp.get_map().on_board(hex))
111  return nullptr;
112 
113 // const item_map& items = disp.get_items();
114 // const item_map::const_item_iterator item_it = items.find(start_hex_);
115 // if (item_it == items.end())
116 // return nullptr;
117 
118  return std::make_unique<editor_action_item_replace>(start_hex_, hex);
119 }
120 
122 {
125 }
126 
128 {
130 }
131 
132 
133 } //end namespace editor
Editor action classes.
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:557
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
Definition: display.cpp:3145
const gamemap & get_map() const
Definition: display.hpp:106
void add_overlay(const map_location &loc, const std::string &image, const std::string &halo="", const std::string &team_name="", const std::string &item_id="", bool visible_under_fog=true, float submerge=0.0f, float z_order=0)
Functions to add and remove overlays from locations.
Definition: display.cpp:114
Base class for all editor actions.
Definition: action_base.hpp:42
void set_mouseover_hex_overlay(const texture &image)
Sets texture to be drawn in hex under the mouse's location.
const Item & selected_fg_item() const
Return the currently selected foreground/background item.
std::unique_ptr< editor_action > drag_left(editor_display &disp, int x, int y, bool &partial, editor_action *last_undo) override
Drag operation.
void set_item_mouse_overlay(editor_display &disp, const overlay &u)
std::unique_ptr< editor_action > click_left(editor_display &disp, int x, int y) override
TODO.
std::unique_ptr< editor_action > drag_end_left(editor_display &disp, int x, int y) override
Drag end replaces the item when clicked left, or adjusts the facing when clicked right.
virtual void set_mouse_overlay(editor_display &disp) override
Set the mouse overlay for this action.
std::unique_ptr< editor_action > up_left(editor_display &disp, int x, int y) override
TODO.
void move(editor_display &disp, const map_location &hex) override
Mouse move (not a drag).
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.
map_location previous_move_hex_
The hex previously used in move operations.
bool on_board(const map_location &loc) const
Tell if a location is on the map.
Definition: map.cpp:384
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
Definition: location.cpp:474
Manage the empty-palette in the editor.
Definition: action.cpp:31
std::pair< std::string, unsigned > item
Definition: help_impl.hpp:410
texture get_texture(const image::locator &i_locator, TYPE type, bool skip_cache)
Returns an image texture suitable for hardware-accelerated rendering.
Definition: picture.cpp:960
Encapsulates the map of the game.
Definition: location.hpp:38
std::string image
Definition: overlay.hpp:55