The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
action_label.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2010 - 2025
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
26namespace editor
27{
29
30std::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
59
60IMPLEMENT_ACTION(label_delete)
61
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
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.
This class wraps around a map to provide a concise interface for the editor to work with.
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:148
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
const std::string & team_name() const
Definition label.hpp:154
const color_t & color() const
Definition label.hpp:184
bool visible_in_fog() const
Definition label.hpp:164
const t_string & text() const
Definition label.hpp:139
const std::string & category() const
Definition label.hpp:159
std::string label
What to show in the filter's drop-down list.
Definition manager.cpp:201
Manage the empty-palette in the editor.
Definition action.cpp:31
STL namespace.