The Battle for Wesnoth  1.19.1+dev
mouse_action_map_label.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 
23 
25 
26 #include "font/standard_colors.hpp"
27 #include "color.hpp"
28 
29 namespace editor {
30 
31 std::unique_ptr<editor_action> mouse_action_map_label::click_left(editor_display& disp, int x, int y)
32 {
33  click_ = true;
34  map_location hex = disp.hex_clicked_on(x, y);
35  clicked_on_ = hex;
36  return nullptr;
37 }
38 
39 std::unique_ptr<editor_action> mouse_action_map_label::drag_left(editor_display& disp, int x, int y
40  , bool& /*partial*/, editor_action* /*last_undo*/)
41 {
42  map_location hex = disp.hex_clicked_on(x, y);
43  click_ = (hex == clicked_on_);
44  return nullptr;
45 }
46 
47 std::unique_ptr<editor_action> mouse_action_map_label::up_left(editor_display& disp, int x, int y)
48 {
49  if (!click_) return nullptr;
50  click_ = false;
51 
52  const map_location hex = disp.hex_clicked_on(x, y);
53  if (!disp.get_map().on_board(hex)) {
54  return nullptr;
55  }
56 
57  const terrain_label* old_label = disp.get_controller().get_current_map_context().get_labels().get_label(hex);
58  std::string label = old_label ? old_label->text() : "";
59  std::string team_name = old_label ? old_label->team_name() : "";
60  std::string category = old_label ? old_label->category() : "";
61  bool visible_shroud = old_label ? old_label->visible_in_shroud() : false;
62  bool visible_fog = old_label ? old_label->visible_in_fog() : true;
63  bool immutable = old_label ? old_label->immutable() : true;
64  color_t color = old_label ? old_label->color() : font::NORMAL_COLOR;
65 
66  gui2::dialogs::editor_edit_label d(label, immutable, visible_fog, visible_shroud, color, category);
67 
68  std::unique_ptr<editor_action> a;
69  if(d.show()) {
70  a = std::make_unique<editor_action_label>(hex, label, team_name, color
71  , visible_fog, visible_shroud, immutable, category);
72  update_brush_highlights(disp, hex);
73  }
74  return a;
75 }
76 
77 std::unique_ptr<editor_action> mouse_action_map_label::click_right(editor_display& /*disp*/, int /*x*/, int /*y*/)
78 {
79  return nullptr;
80 }
81 
82 std::unique_ptr<editor_action> mouse_action_map_label::up_right(editor_display& disp, int x, int y)
83 {
84  map_location hex = disp.hex_clicked_on(x, y);
85 
86  //TODO
87 // const terrain_label* clicked_label = disp.map().get_map_labels().get_label(hex);
88  //if (!clicked_label)
89  // return nullptr;
90 
91  return std::make_unique<editor_action_label_delete>(hex);
92 }
93 
94 std::unique_ptr<editor_action> mouse_action_map_label::drag_end_left(editor_display& disp, int x, int y)
95 {
96  if (click_) return nullptr;
97 
98  map_location hex = disp.hex_clicked_on(x, y);
99  if (!disp.get_map().on_board(hex))
100  return nullptr;
101 
102  const terrain_label* dragged_label = disp
103  .get_controller()
105  .get_labels()
107 
108  // Return nullptr if the dragged label doesn't exist
109  if (!dragged_label) {
110  return nullptr;
111  }
112 
113  // Create action chain to:
114  // 1. Delete label in initial hex
115  // 2. Delete label in target hex if it exists, otherwise will no-op
116  // 3. Create label in target hex
117  auto chain = std::make_unique<editor_action_chain>();
118  chain->append_action(std::make_unique<editor_action_label_delete>(clicked_on_));
119  chain->append_action(std::make_unique<editor_action_label_delete>(hex));
120  chain->append_action(
121  std::make_unique<editor_action_label>(
122  hex,
123  dragged_label->text(),
124  dragged_label->team_name(),
125  dragged_label->color(),
126  dragged_label->visible_in_fog(),
127  dragged_label->visible_in_shroud(),
128  dragged_label->immutable(),
129  dragged_label->category()
130  )
131  );
132 
133  return chain;
134 }
135 
137 {
140  // center 60px icon on blank hex template
142  "misc/blank-hex.png",
143  "~BLIT(icons/action/editor-tool-label_60.png,6,6)"
144  )
145  )
146  );
147 }
148 
149 
150 } //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
const gamemap & get_map() const
Definition: display.hpp:106
Base class for all editor actions.
Definition: action_base.hpp:42
map_context & get_current_map_context() const
void set_mouseover_hex_overlay(const texture &image)
Sets texture to be drawn in hex under the mouse's location.
editor_controller & get_controller()
map_labels & get_labels()
std::unique_ptr< editor_action > drag_left(editor_display &disp, int x, int y, bool &partial, editor_action *last_undo) override
Drags a label.
std::unique_ptr< editor_action > up_right(editor_display &disp, int x, int y) override
Right click erases the label under the mouse.
std::unique_ptr< editor_action > drag_end_left(editor_display &disp, int x, int y) override
Replaces the label under the mouse with the dragged label.
std::unique_ptr< editor_action > click_left(editor_display &disp, int x, int y) override
A click, possibly the beginning of a drag.
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
Left click displays a dialog that is used for entering the label string.
std::unique_ptr< editor_action > click_right(editor_display &disp, int x, int y) override
A click, possibly the beginning of 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.
bool on_board(const map_location &loc) const
Tell if a location is on the map.
Definition: map.cpp:384
Generic locator abstracting the location of an image.
Definition: picture.hpp:63
const terrain_label * get_label(const map_location &loc, const std::string &team_name) const
Definition: label.hpp:48
To store label data Class implements logic for rendering.
Definition: label.hpp:111
bool visible_in_shroud() const
Definition: label.hpp:169
bool immutable() const
Definition: label.hpp:174
bool visible_in_fog() const
Definition: label.hpp:164
const color_t & color() const
Definition: label.hpp:184
const std::string & category() const
Definition: label.hpp:159
const t_string & text() const
Definition: label.hpp:139
const std::string & team_name() const
Definition: label.hpp:154
std::string label
What to show in the filter's drop-down list.
Definition: manager.cpp:207
Manage the empty-palette in the editor.
Definition: action.cpp:31
const color_t NORMAL_COLOR
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
The basic class for representing 8-bit RGB or RGBA colour values.
Definition: color.hpp:59
Encapsulates the map of the game.
Definition: location.hpp:38
#define d
#define a