The Battle for Wesnoth  1.19.0-dev
action_label.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 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 /**
17  * @file
18  * Editor label action classes
19  */
20 #define GETTEXT_DOMAIN "wesnoth-editor"
21 
23 
25 
26 namespace editor
27 {
29 
30 std::unique_ptr<editor_action> editor_action_label::perform(map_context& mc) const
31 {
32  std::unique_ptr<editor_action> undo;
33 
34  const terrain_label* old_label = mc.get_labels().get_label(loc_);
35  if(old_label) {
36  undo = std::make_unique<editor_action_label>(
37  loc_,
38  old_label->text(),
39  old_label->team_name(),
40  old_label->color(),
41  old_label->visible_in_fog(),
42  old_label->visible_in_shroud(),
43  old_label->immutable(),
44  old_label->category()
45  );
46  } else {
47  undo = std::make_unique<editor_action_label_delete>(loc_);
48  }
49 
50  perform_without_undo(mc);
51  return undo;
52 }
53 
55 {
56  mc.get_labels().set_label(
58 }
59 
60 IMPLEMENT_ACTION(label_delete)
61 
62 std::unique_ptr<editor_action> editor_action_label_delete::perform(map_context& mc) const
63 {
64  const terrain_label* deleted = mc.get_labels().get_label(loc_);
65 
66  if(!deleted) {
67  return nullptr;
68  }
69 
70  auto undo = std::make_unique<editor_action_label>(
71  loc_,
72  deleted->text(),
73  deleted->team_name(),
74  deleted->color(),
75  deleted->visible_in_fog(),
76  deleted->visible_in_shroud(),
77  deleted->immutable(),
78  deleted->category()
79  );
80 
81  perform_without_undo(mc);
82  return undo;
83 }
84 
86 {
87  mc.get_labels().set_label(loc_, "");
88 }
89 
90 } // end namespace editor
#define IMPLEMENT_ACTION(id)
Helper macro to implement common action methods.
Editor action classes.
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
const std::string category_
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
const std::string team_name_
Base class for all editor actions.
Definition: action_base.hpp:42
This class wraps around a map to provide a concise interface for the editor to work with.
Definition: map_context.hpp:63
map_labels & get_labels()
const terrain_label * set_label(const map_location &loc, const t_string &text, const int creator=-1, const std::string &team="", const color_t color=font::NORMAL_COLOR, const bool visible_in_fog=true, const bool visible_in_shroud=false, const bool immutable=false, const std::string &category="", const t_string &tooltip="")
Definition: label.cpp:147
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
map_location loc_
std::string label
What to show in the filter's drop-down list.
Definition: manager.cpp:209
Manage the empty-palette in the editor.
Definition: action.cpp:31