20 #define GETTEXT_DOMAIN "wesnoth-editor"
40 #ifdef EDITOR_DEBUG_ACTION_LIFETIME
41 LOG_ED <<
"Action " << std::setw(2) <<
id_ <<
" ctor " <<
this <<
" (count is " << instance_count;
49 #ifdef EDITOR_DEBUG_ACTION_LIFETIME
50 LOG_ED <<
"Action " << std::setw(2) <<
id_ <<
" dtor " <<
this <<
" (count is " << instance_count;
61 return "Unknown action";
66 auto undo = std::make_unique<editor_action_whole_map>(mc.
map());
82 for(
const auto& a : other.
actions_) {
95 for(
const auto& a : other.
actions_) {
107 for(
const auto& a : actions_) {
137 auto last = std::move(
actions_.back());
148 auto first = std::move(
actions_.front());
155 auto undo = std::make_unique<editor_action_chain>();
158 undo->append_action(a->perform(mc));
162 std::reverse(undo->actions_.begin(), undo->actions_.end());
169 a->perform_without_undo(mc);
176 area_.insert(locs.begin(), locs.end());
183 paste_.add_tiles(map, locs);
189 auto undo = std::make_unique<editor_action_paste>(mf);
207 auto undo = std::make_unique<editor_action_paste>(mf);
209 perform_without_undo(mc);
223 std::set<map_location> to_fill = mc.map().get_contiguous_terrain_tiles(
loc_);
224 auto undo = std::make_unique<editor_action_paint_area>(to_fill, mc.map().get_terrain(
loc_));
226 mc.draw_terrain(t_, to_fill, one_layer_);
227 mc.set_needs_terrain_rebuild();
243 std::unique_ptr<editor_action> undo;
245 const std::string* old_loc_id = mc.map().is_special_location(
loc_);
246 map_location old_loc = mc.map().special_location(loc_id_);
248 if(old_loc_id !=
nullptr) {
251 auto undo_chain = std::make_unique<editor_action_chain>();
253 undo_chain->append_action(std::make_unique<editor_action_starting_position>(
loc_, *old_loc_id));
254 undo_chain->append_action(std::make_unique<editor_action_starting_position>(old_loc, loc_id_));
256 undo = std::move(undo_chain);
260 mc.map().set_special_location(*old_loc_id,
map_location());
262 undo = std::make_unique<editor_action_starting_position>(old_loc, loc_id_);
265 LOG_ED <<
"ssp actual: " << loc_id_ <<
" to " <<
loc_;
267 mc.map().set_special_location(loc_id_,
loc_);
268 mc.set_needs_labels_reset();
276 if(old_id !=
nullptr) {
288 mc.map().resize(x_size_, y_size_, x_offset_, y_offset_, fill_);
289 mc.set_needs_reload();
296 mc.map().overlay(mask_, {0, 0,
wml_loc()});
297 mc.set_needs_terrain_rebuild();
304 mc.set_map(
editor_map(mc.map().mask_to(target_)));
305 mc.set_needs_terrain_rebuild();
313 auto undo = std::make_unique<editor_action_paste>(mf);
314 perform_without_undo(mc);
320 std::vector<map_location>
shuffle;
325 std::vector<map_location>::const_iterator shuffle_it =
shuffle.begin();
326 std::set<map_location>::const_iterator orig_it =
area_.begin();
328 while(orig_it !=
area_.end()) {
#define IMPLEMENT_ACTION(id)
Helper macro to implement common action methods.
void extend(const editor_map &map, const std::set< map_location > &locs) override
The crux of the extendable contract.
std::set< map_location > area_
Container action wrapping several actions into one.
std::unique_ptr< editor_action > pop_last_action()
Remove the last added action and return it, transferring ownership to the caller.
editor_action_chain()
Create an empty action chain.
void perform_without_undo(map_context &m) const override
Perform all the actions in order.
std::unique_ptr< editor_action > pop_first_action()
Remove the first added action and return it, transferring ownership to the caller.
editor_action_chain & operator=(const editor_action_chain &other)
void append_action(std::unique_ptr< editor_action > a)
Add an action at the end of the chain.
int action_count() const override
Go through the chain and add up all the action counts.
std::deque< std::unique_ptr< editor_action > > actions_
The action pointers owned by this action chain.
void prepend_action(std::unique_ptr< editor_action > a)
Add an action at the beginning of the chain.
std::unique_ptr< editor_action > perform(map_context &m) const override
Perform all the actions in order and create a undo action chain.
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
t_translation::terrain_code t_
Paint the same terrain on a number of locations on the map.
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
t_translation::terrain_code t_
Paste a map fragment into the map.
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
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 ...
Randomize terrain in an area.
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
Set starting position action, sets location ids (both for starting locations and for non-starting loc...
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
Replace contents of the entire map, Useful as a fallback undo method when something else would be imp...
Base class for all editor actions.
static int instance_count_
virtual void perform_without_undo(map_context &) const =0
Perform the action without creating an undo action.
virtual std::unique_ptr< editor_action > perform(map_context &) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
virtual std::string get_description() const
A textual description of the action.
virtual int action_count() const
This class adds extra editor-specific functionality to a normal gamemap.
std::set< map_location > get_contiguous_terrain_tiles(const map_location &start) const
Get a contiguous set of tiles having the same terrain as the starting location.
This class wraps around a map to provide a concise interface for the editor to work with.
void set_needs_labels_reset(bool value=true)
Setter for the labels reset flag.
void draw_terrain(const t_translation::terrain_code &terrain, const map_location &loc, bool one_layer_only=false)
Draw a terrain on a single location on the map.
virtual const editor_map & map() const override
Const map accessor.
void set_needs_terrain_rebuild(bool value=true)
Setter for the terrain rebuild flag.
void add_changed_location(const map_location &loc)
A map fragment – a collection of locations and information abut them.
std::set< map_location > get_offset_area(const map_location &offset) const
Get the area covered by this map fragment, shifted by an offset.
void paste_into(gamemap &map, const map_location &loc) const
Paste the map fragment into the map, treating loc as the (0,0) point (offset).
terrain_code get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
void set_special_location(const std::string &id, const map_location &loc)
const std::string * is_special_location(const map_location &loc) const
returns the name of the special location at position loc, null if no such location exists.
static rng & default_instance()
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
void fill(const SDL_Rect &rect, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Fill an area with the given colour.
Manage the empty-palette in the editor.
std::vector< game_tip > shuffle(const std::vector< game_tip > &tips)
Shuffles the tips.
Encapsulates the map of the game.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...