editor2: slight map_context cleanup, clear undo and stacks on map load
This commit is contained in:
parent
6326aa4ec4
commit
702df82a37
3 changed files with 28 additions and 11 deletions
|
@ -441,6 +441,7 @@ void editor_controller::set_map(const editor_map& map)
|
|||
{
|
||||
get_map_context().clear_starting_position_labels(gui());
|
||||
get_map() = map;
|
||||
get_map_context().clear_undo_redo();
|
||||
gui().reload_map();
|
||||
get_map_context().set_starting_position_labels(gui());
|
||||
refresh_all();
|
||||
|
|
|
@ -57,6 +57,15 @@ void map_context::draw_terrain(t_translation::t_terrain terrain,
|
|||
if (!one_layer_only) {
|
||||
terrain = map_.get_terrain_info(terrain).terrain_with_default_base();
|
||||
}
|
||||
draw_terrain_actual(terrain, loc, one_layer_only);
|
||||
}
|
||||
|
||||
void map_context::draw_terrain_actual(t_translation::t_terrain terrain,
|
||||
const gamemap::location& loc, bool one_layer_only)
|
||||
{
|
||||
if (!map_.on_board_with_border(loc)) {
|
||||
throw editor_action_exception("Attempted to draw terrain off the map");
|
||||
}
|
||||
t_translation::t_terrain old_terrain = map_.get_terrain(loc);
|
||||
if (terrain != old_terrain) {
|
||||
if (terrain.base == t_translation::NO_LAYER) {
|
||||
|
@ -77,17 +86,7 @@ void map_context::draw_terrain(t_translation::t_terrain terrain,
|
|||
terrain = map_.get_terrain_info(terrain).terrain_with_default_base();
|
||||
}
|
||||
foreach (const gamemap::location& loc, locs) {
|
||||
t_translation::t_terrain old_terrain = map_.get_terrain(loc);
|
||||
if (terrain != old_terrain) {
|
||||
if (terrain.base == t_translation::NO_LAYER) {
|
||||
map_.set_terrain(loc, terrain, gamemap::OVERLAY);
|
||||
} else if (one_layer_only) {
|
||||
map_.set_terrain(loc, terrain, gamemap::BASE);
|
||||
} else {
|
||||
map_.set_terrain(loc, terrain);
|
||||
}
|
||||
add_changed_location(loc);
|
||||
}
|
||||
draw_terrain_actual(terrain, loc, one_layer_only);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -252,6 +251,12 @@ void map_context::partial_undo()
|
|||
//actions_since_save_ -= last_redo_action()->action_count();
|
||||
}
|
||||
|
||||
void map_context::clear_undo_redo()
|
||||
{
|
||||
clear_stack(undo_stack_);
|
||||
clear_stack(redo_stack_);
|
||||
}
|
||||
|
||||
void map_context::trim_stack(action_stack& stack)
|
||||
{
|
||||
if (stack.size() > max_action_stack_size_) {
|
||||
|
|
|
@ -57,6 +57,12 @@ public:
|
|||
*/
|
||||
void draw_terrain(t_translation::t_terrain terrain, const gamemap::location& loc,
|
||||
bool one_layer_only = false);
|
||||
|
||||
/**
|
||||
* Actual drawing function used by both overloaded variants of draw_terrain.
|
||||
*/
|
||||
void draw_terrain_actual(t_translation::t_terrain terrain, const gamemap::location& loc,
|
||||
bool one_layer_only = false);
|
||||
|
||||
/**
|
||||
* Draw a terrain on a set of locations on the map.
|
||||
|
@ -166,6 +172,11 @@ public:
|
|||
*/
|
||||
void partial_undo();
|
||||
|
||||
/**
|
||||
* Clear the undo and redo stacks
|
||||
*/
|
||||
void clear_undo_redo();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* The map object of this map_context.
|
||||
|
|
Loading…
Add table
Reference in a new issue