The Battle for Wesnoth  1.17.21+dev
mouse_action_map_label.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2023
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 
24 
26 
27 #include "font/standard_colors.hpp"
28 #include "color.hpp"
29 
30 namespace editor {
31 
32 std::unique_ptr<editor_action> mouse_action_map_label::click_left(editor_display& disp, int x, int y)
33 {
34  click_ = true;
35  map_location hex = disp.hex_clicked_on(x, y);
36  clicked_on_ = hex;
37  return nullptr;
38 }
39 
40 std::unique_ptr<editor_action> mouse_action_map_label::drag_left(editor_display& disp, int x, int y
41  , bool& /*partial*/, editor_action* /*last_undo*/)
42 {
43  map_location hex = disp.hex_clicked_on(x, y);
44  click_ = (hex == clicked_on_);
45  return nullptr;
46 }
47 
48 std::unique_ptr<editor_action> mouse_action_map_label::up_left(editor_display& disp, int x, int y)
49 {
50  if (!click_) return nullptr;
51  click_ = false;
52 
53  const map_location hex = disp.hex_clicked_on(x, y);
54  if (!disp.get_map().on_board(hex)) {
55  return nullptr;
56  }
57 
58  const terrain_label* old_label = disp.get_controller().get_current_map_context().get_labels().get_label(hex);
59  std::string label = old_label ? old_label->text() : "";
60  std::string team_name = old_label ? old_label->team_name() : "";
61  std::string category = old_label ? old_label->category() : "";
62  bool visible_shroud = old_label ? old_label->visible_in_shroud() : false;
63  bool visible_fog = old_label ? old_label->visible_in_fog() : true;
64  bool immutable = old_label ? old_label->immutable() : true;
65  color_t color = old_label ? old_label->color() : font::NORMAL_COLOR;
66 
67  gui2::dialogs::editor_edit_label d(label, immutable, visible_fog, visible_shroud, color, category);
68 
69  std::unique_ptr<editor_action> a;
70  if(d.show()) {
71  a = std::make_unique<editor_action_label>(hex, label, team_name, color
72  , visible_fog, visible_shroud, immutable, category);
73  update_brush_highlights(disp, hex);
74  }
75  return a;
76 }
77 
78 std::unique_ptr<editor_action> mouse_action_map_label::click_right(editor_display& /*disp*/, int /*x*/, int /*y*/)
79 {
80  return nullptr;
81 }
82 
83 std::unique_ptr<editor_action> mouse_action_map_label::up_right(editor_display& disp, int x, int y)
84 {
85  map_location hex = disp.hex_clicked_on(x, y);
86 
87  //TODO
88 // const terrain_label* clicked_label = disp.map().get_map_labels().get_label(hex);
89  //if (!clicked_label)
90  // return nullptr;
91 
92  return std::make_unique<editor_action_label_delete>(hex);
93 }
94 
95 std::unique_ptr<editor_action> mouse_action_map_label::drag_end_left(editor_display& disp, int x, int y)
96 {
97  if (click_) return nullptr;
98 
99  map_location hex = disp.hex_clicked_on(x, y);
100  if (!disp.get_map().on_board(hex))
101  return nullptr;
102 
103  const terrain_label* dragged_label = disp
104  .get_controller()
106  .get_labels()
108 
109  // Return nullptr if the dragged label doesn't exist
110  if (!dragged_label) {
111  return nullptr;
112  }
113 
114  // Create action chain to:
115  // 1. Delete label in initial hex
116  // 2. Delete label in target hex if it exists, otherwise will no-op
117  // 3. Create label in target hex
118  auto chain = std::make_unique<editor_action_chain>();
119  chain->append_action(std::make_unique<editor_action_label_delete>(clicked_on_));
120  chain->append_action(std::make_unique<editor_action_label_delete>(hex));
121  chain->append_action(
122  std::make_unique<editor_action_label>(
123  hex,
124  dragged_label->text(),
125  dragged_label->team_name(),
126  dragged_label->color(),
127  dragged_label->visible_in_fog(),
128  dragged_label->visible_in_shroud(),
129  dragged_label->immutable(),
130  dragged_label->category()
131  )
132  );
133 
134  return chain;
135 }
136 
138 {
141  // center 60px icon on blank hex template
143  "misc/blank-hex.png",
144  "~BLIT(icons/action/editor-tool-label_60.png,6,6)"
145  )
146  )
147  );
148 }
149 
150 
151 } //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:562
const gamemap & get_map() const
Definition: display.hpp:105
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:385
Dialog for editing gamemap labels.
Definition: edit_label.hpp:35
Generic locator abstracting the location of an image.
Definition: picture.hpp:64
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:217
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:985
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