The Battle for Wesnoth  1.15.12+dev
action_label.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2018 by Fabian Mueller <fabianmueller5@gmx.de>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * @file
17  * Editor label action classes
18  */
19 #define GETTEXT_DOMAIN "wesnoth-editor"
20 
22 
24 
25 namespace editor
26 {
27 IMPLEMENT_ACTION(label)
28 
29 std::unique_ptr<editor_action> editor_action_label::perform(map_context& mc) const
30 {
31  std::unique_ptr<editor_action> undo;
32 
33  const terrain_label* old_label = mc.get_labels().get_label(loc_);
34  if(old_label) {
35  undo = std::make_unique<editor_action_label>(
36  loc_,
37  old_label->text(),
38  old_label->team_name(),
39  old_label->color(),
40  old_label->visible_in_fog(),
41  old_label->visible_in_shroud(),
42  old_label->immutable(),
43  old_label->category()
44  );
45  } else {
46  undo = std::make_unique<editor_action_label_delete>(loc_);
47  }
48 
49  perform_without_undo(mc);
50  return undo;
51 }
52 
54 {
55  mc.get_labels().set_label(
57 }
58 
59 IMPLEMENT_ACTION(label_delete)
60 
62 {
63  const terrain_label* deleted = mc.get_labels().get_label(loc_);
64 
65  if(!deleted) {
66  return nullptr;
67  }
68 
69  auto undo = std::make_unique<editor_action_label>(
70  loc_,
71  deleted->text(),
72  deleted->team_name(),
73  deleted->color(),
74  deleted->visible_in_fog(),
75  deleted->visible_in_shroud(),
76  deleted->immutable(),
77  deleted->category()
78  );
79 
81  return undo;
82 }
83 
85 {
86  mc.get_labels().set_label(loc_, "");
87 }
88 
89 } // end namespace editor
std::unique_ptr< editor_action > perform(map_context &mc) const override
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
const std::string team_name_
Editor action classes.
const color_t & color() const
Definition: label.hpp:183
const std::string & category() const
Definition: label.hpp:158
const t_string & text() const
Definition: label.hpp:138
map_labels & get_labels()
const std::string & team_name() const
Definition: label.hpp:153
STL namespace.
bool visible_in_shroud() const
Definition: label.hpp:168
map_location loc_
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:146
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
const std::string category_
Manage the empty-palette in the editor.
Definition: action.cpp:29
bool visible_in_fog() const
Definition: label.hpp:163
Base class for all editor actions.
Definition: action_base.hpp:40
This class wraps around a map to provide a concise interface for the editor to work with...
Definition: map_context.hpp:59
To store label data Class implements logic for rendering.
Definition: label.hpp:109
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
#define IMPLEMENT_ACTION(id)
Helper macro to implement common action methods.
bool immutable() const
Definition: label.hpp:173