The Battle for Wesnoth  1.17.0-dev
action_item.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2021
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 item action class
19  */
20 
21 // TODO is a textdomain needed?
22 #define GETTEXT_DOMAIN "wesnoth-editor"
23 
25 
27 
28 namespace editor
29 {
31 
32 std::unique_ptr<editor_action> editor_action_item::perform(map_context& mc) const
33 {
34  auto undo = std::make_unique<editor_action_item_delete>(loc_);
35  perform_without_undo(mc);
36  return undo;
37 }
38 
40 {
41  //
42  // mc.get_items().add(loc_,u_);
43  // mc.get_items().find(loc_)->set_location(loc_);
44  // mc.add_changed_location(loc_);
45 }
46 
47 IMPLEMENT_ACTION(item_delete)
48 
50 {
51  // item_map& items = mc.get_items();
52  // item_map::const_item_iterator item_it = items.find(loc_);
53  //
54  // editor_action_ptr undo;
55  // if (item_it != items.end()) {
56  // undo.reset(new editor_action_item(loc_, *item_it));
57  // perform_without_undo(mc);
58  // return undo.release();
59  // }
60  return nullptr;
61 }
62 
64 {
65  // item_map& items = mc.get_items();
66  // if (!items.erase(loc_)) {
67  // ERR_ED << "Could not delete item on " << loc_.x << "/" << loc_.y << std::endl;
68  // } else {
69  // mc.add_changed_location(loc_);
70  // }
71 }
72 
73 IMPLEMENT_ACTION(item_replace)
74 
76 {
77  auto undo = std::make_unique<editor_action_item_replace>(new_loc_, loc_);
78 
80  return undo;
81 }
82 
84 {
85  // item_map& items = mc.get_items();
86  // items.move(loc_, new_loc_);
87  // item::clear_status_caches();
88  //
89  // item& u = *items.find(new_loc_);
90  // //TODO do we still need set_standing?
91  // u.anim_comp().set_standing();
92  //
93  // mc.add_changed_location(loc_);
94  // mc.add_changed_location(new_loc_);
95  //
96  // /* @todo
97  // if (mc.map().is_village(new_loc_)) {
98  // (*(resources::gameboard->teams()))[u.side()].get_village(new_loc_);
99  // }
100  // */
101  //
102  // TODO: check if that is useful
103  // game_display::get_singleton()->invalidate_item_after_move(loc_, new_loc_);
104  // display::get_singleton()->draw();
105 }
106 
107 IMPLEMENT_ACTION(item_facing)
108 
110 {
111  auto undo = std::make_unique<editor_action_item_facing>(loc_, old_direction_, new_direction_);
113  return undo;
114 }
115 
117 {
118  // item_map& items = mc.get_items();
119  // item_map::item_iterator item_it = items.find(loc_);
120  //
121  // if (item_it != items.end()) {
122  // item_it->set_facing(new_direction_);
123  // item_it->set_standing();
124  // }
125 }
126 
127 } // end namespace editor
place a new item on the map
Definition: action_item.hpp:44
STL namespace.
map_location loc_
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 ...
Definition: action_item.cpp:32
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
Definition: action_item.cpp:39
Remove a item from the map.
Definition: action_item.hpp:65
Manage the empty-palette in the editor.
Definition: action.cpp:30
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
Definition: action_item.cpp:83
Base class for all editor actions.
Definition: action_base.hpp:41
This class wraps around a map to provide a concise interface for the editor to work with...
Definition: map_context.hpp:60
#define IMPLEMENT_ACTION(id)
Helper macro to implement common action methods.
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
Definition: action_item.cpp:63
Editor action classes.
std::pair< std::string, unsigned > item
Definition: help_impl.hpp:410