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());
109 count +=
a->action_count();
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);
197 paste_.paste_into(mc.
map(), offset_);
207 auto undo = std::make_unique<editor_action_paste>(mf);
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);
320 std::vector<map_location>
shuffle;
322 std::copy(area_.begin(), area_.end(), std::inserter(shuffle, shuffle.begin()));
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()) {
void add_changed_location(const map_location &loc)
Randomize terrain in an area.
std::unique_ptr< editor_action > pop_last_action()
Remove the last added action and return it, transferring ownership to the caller. ...
A map fragment – a collection of locations and information abut them.
void perform_without_undo(map_context &m) const override
Perform all the actions in order.
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
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...
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
std::unique_ptr< editor_action > pop_first_action()
Remove the first added action and return it, transferring ownership to the caller.
void extend(const editor_map &map, const std::set< map_location > &locs) override
The crux of the extendable contract.
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.
editor_action_chain & operator=(const editor_action_chain &other)
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Paste a map fragment into the map.
Container action wrapping several actions into one.
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...
Set starting position action, sets location ids (both for starting locations and for non-starting loc...
void append_action(std::unique_ptr< editor_action > a)
Add an action at the end of the chain.
void set_special_location(const std::string &id, const map_location &loc)
std::deque< std::unique_ptr< editor_action > > actions_
The action pointers owned by this action chain.
terrain_code get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
void prepend_action(std::unique_ptr< editor_action > a)
Add an action at the beginning of the chain.
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.
int action_count() const override
Go through the chain and add up all the action counts.
std::unique_ptr< editor_action > perform(map_context &m) const override
Perform all the actions in order and create a undo action chain.
Manage the empty-palette in the editor.
Paint the same terrain on a number of locations on the map.
void set_needs_terrain_rebuild(bool value=true)
Setter for the terrain rebuild flag.
Encapsulates the map of the game.
virtual int action_count() const
This class adds extra editor-specific functionality to a normal gamemap.
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
static int instance_count_
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
Base class for all editor actions.
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 ...
This class wraps around a map to provide a concise interface for the editor to work with...
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 const editor_map & map() const override
Const map accessor.
void set_needs_labels_reset(bool value=true)
Setter for the labels reset flag.
#define IMPLEMENT_ACTION(id)
Helper macro to implement common action methods.
editor_action_chain()
Create an empty action chain.
virtual void perform_without_undo(map_context &) const =0
Perform the action without creating an undo action.
virtual std::string get_description() const
A textual description of the action.
std::vector< game_tip > shuffle(const std::vector< game_tip > &tips)
Shuffles the tips.
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.
static rng & default_instance()
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.