The Battle for Wesnoth
1.21.0-dev
Loading...
Searching...
No Matches
editor
action
action_item.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2008 - 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 item action class
19
*/
20
21
#define GETTEXT_DOMAIN "wesnoth-editor"
22
23
#include "
editor/action/action_item.hpp
"
24
#include "
editor/map/map_context.hpp
"
25
26
27
namespace
editor
28
{
29
IMPLEMENT_ACTION
(item)
30
31
std
::unique_ptr<
editor_action
>
editor_action_item
::perform(
map_context
& mc)
const
32
{
33
auto
undo = std::make_unique<editor_action_item_delete>(loc_);
34
perform_without_undo(mc);
35
return
undo;
36
}
37
38
void
editor_action_item::perform_without_undo
(
map_context
&
/*mc*/
)
const
39
{
40
//
41
// mc.get_items().add(loc_,u_);
42
// mc.get_items().find(loc_)->set_location(loc_);
43
// mc.add_changed_location(loc_);
44
}
45
46
IMPLEMENT_ACTION
(item_delete)
47
48
std
::unique_ptr<
editor_action
>
editor_action_item_delete
::perform(
map_context
&
/*mc*/
)
const
49
{
50
// item_map& items = mc.get_items();
51
// item_map::const_item_iterator item_it = items.find(loc_);
52
//
53
// editor_action_ptr undo;
54
// if (item_it != items.end()) {
55
// undo.reset(new editor_action_item(loc_, *item_it));
56
// perform_without_undo(mc);
57
// return undo.release();
58
// }
59
return
nullptr
;
60
}
61
62
void
editor_action_item_delete::perform_without_undo
(
map_context
&
/*mc*/
)
const
63
{
64
// item_map& items = mc.get_items();
65
// if (!items.erase(loc_)) {
66
// ERR_ED << "Could not delete item on " << loc_.x << "/" << loc_.y;
67
// } else {
68
// mc.add_changed_location(loc_);
69
// }
70
}
71
72
IMPLEMENT_ACTION
(item_replace)
73
74
std
::unique_ptr<
editor_action
>
editor_action_item_replace
::perform(
map_context
& mc)
const
75
{
76
auto
undo = std::make_unique<editor_action_item_replace>(new_loc_, loc_);
77
78
perform_without_undo(mc);
79
return
undo;
80
}
81
82
void
editor_action_item_replace::perform_without_undo
(
map_context
&
/*mc*/
)
const
83
{
84
// item_map& items = mc.get_items();
85
// items.move(loc_, new_loc_);
86
// item::clear_status_caches();
87
//
88
// item& u = *items.find(new_loc_);
89
// //TODO do we still need set_standing?
90
// u.anim_comp().set_standing();
91
//
92
// mc.add_changed_location(loc_);
93
// mc.add_changed_location(new_loc_);
94
//
95
// /* @todo
96
// if (mc.map().is_village(new_loc_)) {
97
// (*(resources::gameboard->teams()))[u.side()].get_village(new_loc_);
98
// }
99
// */
100
//
101
// TODO: check if that is useful
102
// game_display::get_singleton()->invalidate_item_after_move(loc_, new_loc_);
103
// display::get_singleton()->draw();
104
}
105
106
IMPLEMENT_ACTION
(item_move_all)
107
108
std
::unique_ptr<
editor_action
>
editor_action_item_move_all
::perform(
map_context
& mc)
const
109
{
110
auto
undo = std::make_unique<editor_action_item_move_all>(-x_offset_, -y_offset_);
111
perform_without_undo(mc);
112
return
undo;
113
}
114
115
void
editor_action_item_move_all::perform_without_undo
(
map_context
& mc)
const
116
{
117
auto
ovls = mc.
get_overlays
();
118
decltype
(ovls) new_overlays_map;
119
for
(
auto
ov: ovls) {
120
map_location
new_loc{ov.first.
x
-
x_offset_
, ov.first.y -
y_offset_
};
121
new_overlays_map.emplace(new_loc, ov.second);
122
}
123
mc.
set_overlays
(new_overlays_map);
124
}
125
126
IMPLEMENT_ACTION
(item_facing)
127
128
std
::unique_ptr<
editor_action
>
editor_action_item_facing
::perform(
map_context
& mc)
const
129
{
130
auto
undo = std::make_unique<editor_action_item_facing>(loc_, old_direction_, new_direction_);
131
perform_without_undo(mc);
132
return
undo;
133
}
134
135
void
editor_action_item_facing::perform_without_undo
(
map_context
&
/*mc*/
)
const
136
{
137
// item_map& items = mc.get_items();
138
// item_map::item_iterator item_it = items.find(loc_);
139
//
140
// if (item_it != items.end()) {
141
// item_it->set_facing(new_direction_);
142
// item_it->set_standing();
143
// }
144
}
145
146
}
// end namespace editor
IMPLEMENT_ACTION
#define IMPLEMENT_ACTION(id)
Helper macro to implement common action methods.
Definition
action_base.hpp:125
action_item.hpp
Editor action classes.
editor::editor_action_item_delete
Remove a item from the map.
Definition
action_item.hpp:66
editor::editor_action_item_delete::perform_without_undo
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
Definition
action_item.cpp:62
editor::editor_action_item_facing
Definition
action_item.hpp:116
editor::editor_action_item_facing::perform_without_undo
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
Definition
action_item.cpp:135
editor::editor_action_item_move_all
Definition
action_item.hpp:98
editor::editor_action_item_move_all::x_offset_
int x_offset_
Definition
action_item.hpp:112
editor::editor_action_item_move_all::perform_without_undo
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
Definition
action_item.cpp:115
editor::editor_action_item_move_all::y_offset_
int y_offset_
Definition
action_item.hpp:112
editor::editor_action_item_replace
Definition
action_item.hpp:80
editor::editor_action_item_replace::perform_without_undo
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
Definition
action_item.cpp:82
editor::editor_action_item
place a new item on the map
Definition
action_item.hpp:45
editor::editor_action_item::perform_without_undo
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
Definition
action_item.cpp:38
editor::editor_action
Base class for all editor actions.
Definition
action_base.hpp:42
editor::map_context
This class wraps around a map to provide a concise interface for the editor to work with.
Definition
map_context.hpp:64
editor::map_context::set_overlays
void set_overlays(overlay_map overlays)
Definition
map_context.hpp:532
editor::map_context::get_overlays
overlay_map & get_overlays()
Definition
map_context.hpp:531
map_context.hpp
editor
Manage the empty-palette in the editor.
Definition
action.cpp:31
std
STL namespace.
map_location
Encapsulates the map of the game.
Definition
location.hpp:46
map_location::x
int x
Definition
location.hpp:196
Generated by
1.9.8