The Battle for Wesnoth  1.17.10+dev
mouse_action_item.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2022
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 "tooltips.hpp"
23 #include "gettext.hpp"
24 
25 #include "map/location.hpp"
26 
27 namespace editor {
28 
29 
31 {
32  if (hex == previous_move_hex_) {
33  return;
34  }
35 
36  update_brush_highlights(disp, hex);
37 
38  std::set<map_location> adjacent_set;
40  adjacent_set.insert(adj);
41  }
42 
43  disp.invalidate(adjacent_set);
44  previous_move_hex_ = hex;
45 }
46 
47 std::unique_ptr<editor_action> mouse_action_item::click_left(editor_display& disp, int x, int y)
48 {
49  start_hex_ = disp.hex_clicked_on(x, y);
50  if (!disp.get_map().on_board(start_hex_)) {
51  return nullptr;
52  }
53 
55  disp.add_overlay(start_hex_, item.image, item.halo, "", "", item.visible_in_fog, item.submerge);
56 
57  click_ = true;
58  return nullptr;
59 }
60 
61 std::unique_ptr<editor_action> mouse_action_item::drag_left(editor_display& disp, int x, int y, bool& /*partial*/, editor_action* /*last_undo*/)
62 {
63  map_location hex = disp.hex_clicked_on(x, y);
64  click_ = (hex == start_hex_);
65  return nullptr;
66 }
67 
68 std::unique_ptr<editor_action> mouse_action_item::up_left(editor_display& disp, int x, int y)
69 {
70  if (!click_) return nullptr;
71  click_ = false;
72  map_location hex = disp.hex_clicked_on(x, y);
73  if (!disp.get_map().on_board(hex)) {
74  return nullptr;
75  }
76 
77 // item_type type = item_palette_.selected_fg_item();
78 //
79 // // Does this serve a purpose other than making sure the type is built?
80 // // (Calling item_types.build_item_type(type) would now accomplish that
81 // // with less overhead.)
82 // const std::string& type_id = type.id();
83 // const item_type *new_item_type = item_types.find(type_id);
84 // if (!new_item_type) {
85 // //TODO rewrite the error message.
86 // ERR_ED << "create item dialog returned inexistent or unusable item_type id '" << type_id << "'";
87 // return nullptr;
88 // }
89 //
90 // const item_type &ut = *new_item_type;
91 // item_race::GENDER gender = ut.genders().front();
92 //
93 // item new_item(ut, disp.viewing_side(), true, gender);
94 // editor_action* action = new editor_action_item(hex, new_item);
95 // return action;
96 
97 // \todo in #5070: there's a load of commented-out code in this file, it should probably
98 // all be deleted. For the function that this comment is in, I've left the commented-out
99 // code in because it seems the not-commented code should also be reviewed. AFAICS, the
100 // entire function (including the not-commented code) could be deleted, and fall back to
101 // the parent class' implementation of just returning nullptr.
102 
103  return nullptr;
104 }
105 
106 std::unique_ptr<editor_action> mouse_action_item::drag_end_left(editor_display& disp, int x, int y)
107 {
108  if (click_) return nullptr;
109 
110  map_location hex = disp.hex_clicked_on(x, y);
111  if (!disp.get_map().on_board(hex))
112  return nullptr;
113 
114 // const item_map& items = disp.get_items();
115 // const item_map::const_item_iterator item_it = items.find(start_hex_);
116 // if (item_it == items.end())
117 // return nullptr;
118 
119  return std::make_unique<editor_action_item_replace>(start_hex_, hex);
120 }
121 
123 {
125  set_item_mouse_overlay(disp, item);
126 }
127 
129 {
131 }
132 
133 
134 } //end namespace editor
map_location previous_move_hex_
The hex previously used in move operations.
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:475
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
Definition: display.cpp:3141
bool visible_in_fog
Definition: overlay.hpp:62
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:581
void move(editor_display &disp, const map_location &hex) override
Mouse move (not a drag).
std::unique_ptr< editor_action > up_left(editor_display &disp, int x, int y) override
TODO.
float submerge
Definition: overlay.hpp:63
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.
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...
std::unique_ptr< editor_action > drag_left(editor_display &disp, int x, int y, bool &partial, editor_action *last_undo) override
Drag operation.
Manage the empty-palette in the editor.
Definition: action.cpp:30
Encapsulates the map of the game.
Definition: location.hpp:38
void set_item_mouse_overlay(editor_display &disp, const overlay &u)
Base class for all editor actions.
Definition: action_base.hpp:41
bool on_board(const map_location &loc) const
Tell if a location is on the map.
Definition: map.cpp:385
std::string halo
Definition: overlay.hpp:56
const gamemap & get_map() const
Definition: display.hpp:102
const Item & selected_fg_item() const
Return the currently selected foreground/background item.
virtual void set_mouse_overlay(editor_display &disp) override
Set the mouse overlay for this action.
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:1128
void set_mouseover_hex_overlay(const texture &image)
Sets texture to be drawn in hex under the mouse&#39;s location.
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:138
Editor action classes.
std::unique_ptr< editor_action > click_left(editor_display &disp, int x, int y) override
TODO.
std::pair< std::string, unsigned > item
Definition: help_impl.hpp:414
std::string image
Definition: overlay.hpp:55