The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
action_label.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2017 by Fabian Mueller <fabianmueller5@gmx.de>
3  Part of the Battle for Wesnoth Project http://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 
30 {
31  editor_action_ptr undo;
32 
33  const terrain_label* old_label = mc.get_labels().get_label(loc_);
34  if(old_label) {
35  undo.reset(new 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.reset(new editor_action_label_delete(loc_));
47  }
48 
49  perform_without_undo(mc);
50  return undo.release();
51 }
52 
54 {
55  mc.get_labels().set_label(
57 }
58 
59 IMPLEMENT_ACTION(label_delete)
60 
62 {
63  editor_action_ptr undo;
64 
65  const terrain_label* deleted = mc.get_labels().get_label(loc_);
66 
67  if(!deleted) {
68  return nullptr;
69  }
70 
71  undo.reset(new editor_action_label(
72  loc_,
73  deleted->text(),
74  deleted->team_name(),
75  deleted->color(),
76  deleted->visible_in_fog(),
77  deleted->visible_in_shroud(),
78  deleted->immutable(),
79  deleted->category())
80  );
81 
82  perform_without_undo(mc);
83  return undo.release();
84 }
85 
87 {
88  mc.get_labels().set_label(loc_, "");
89 }
90 
91 } // end namespace editor
const std::string team_name_
Editor action classes.
const std::string & category() const
Definition: label.hpp:156
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
std::unique_ptr< editor_action > editor_action_ptr
Action pointer typedef.
map_labels & get_labels()
bool immutable() const
Definition: label.hpp:171
map_location loc_
const t_string & text() const
Definition: label.hpp:136
const color_t & color() const
Definition: label.hpp:181
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
const std::string category_
Manage the empty-palette in the editor.
Definition: action.cpp:29
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
const std::string & team_name() const
Definition: label.hpp:151
bool visible_in_shroud() const
Definition: label.hpp:166
Base class for all editor actions.
Definition: action_base.hpp:40
bool visible_in_fog() const
Definition: label.hpp:161
This class wraps around a map to provide a concise interface for the editor to work with...
Definition: map_context.hpp:55
To store label data Class implements logic for rendering.
Definition: label.hpp:107
#define IMPLEMENT_ACTION(id)
Helper macro to implement common action methods.