save current gui location in savegames (#1886)

This commit is contained in:
gfgtdf 2017-08-08 15:43:18 +02:00 committed by GitHub
parent 48c6c630a1
commit 22a2d6f380
5 changed files with 20 additions and 1 deletions

View file

@ -3147,12 +3147,19 @@ void display::update_arrow(arrow & arrow)
}
}
map_location display::get_middle_location() const
{
const SDL_Rect& rect = map_area();
return pixel_position_to_hex(rect.x + rect.w / 2 , rect.y + rect.h / 2 );
}
void display::write(config& cfg) const
{
cfg["view_locked"] = view_locked_;
cfg["color_adjust_red"] = color_adjust_.r;
cfg["color_adjust_green"] = color_adjust_.g;
cfg["color_adjust_blue"] = color_adjust_.b;
get_middle_location().write(cfg.add_child("location"));
}
void display::read(const config& cfg)

View file

@ -638,6 +638,7 @@ protected:
/// map of hexes where only one unit should be drawn, the one identified by the associated id string
exclusive_unit_draw_requests_t exclusive_unit_draw_requests_;
map_location get_middle_location() const;
/**
* Called near the beginning of each draw() call.
* Derived classes can use this to add extra actions before redrawing

View file

@ -158,6 +158,7 @@ play_controller::play_controller(const config& level, saved_game& state_of_game,
, skip_replay_(skip_replay)
, linger_(false)
, init_side_done_now_(false)
, map_start_()
, victory_when_enemies_defeated_(level["victory_when_enemies_defeated"].to_bool(true))
, remove_from_carryover_on_defeat_(level["remove_from_carryover_on_defeat"].to_bool(true))
, victory_music_()
@ -238,6 +239,7 @@ void play_controller::init(CVideo& video, const config& level)
LOG_NG << "building terrain rules... " << (SDL_GetTicks() - ticks()) << std::endl;
gui2::dialogs::loading_screen::progress("build terrain");
gui_.reset(new game_display(gamestate().board_, video, whiteboard_manager_, *gamestate().reports_, gamestate().tod_manager_, theme_cfg, level));
map_start_ = map_location(level.child_or_empty("display").child_or_empty("location"));
if (!gui_->video().faked()) {
if (saved_game_.mp_settings().mp_countdown)
gui_->get_theme().modify_label("time-icon", _ ("time left for current turn"));
@ -503,9 +505,10 @@ void play_controller::init_side_end()
gui_->invalidate_all();
}
if (!is_skipping_replay() && current_team().get_scroll_to_leader()){
if (!is_skipping_replay() && current_team().get_scroll_to_leader() && !map_start_.valid()){
gui_->scroll_to_leader(current_side(), game_display::ONSCREEN,false);
}
map_start_ = map_location();
whiteboard_manager_->on_init_side();
}
@ -1070,6 +1073,7 @@ void play_controller::start_game()
if(!gamestate().start_event_fired_)
{
gamestate().start_event_fired_ = true;
map_start_ = map_location();
resources::recorder->add_start_if_not_there_yet();
resources::recorder->get_next_action();

View file

@ -343,6 +343,8 @@ protected:
* (false = we did init sides before we reloaded the game).
*/
bool init_side_done_now_;
//the displayed location when we load a game.
map_location map_start_;
const std::string& select_music(bool victory) const;
void reset_gamestate(const config& level, int replay_pos);

View file

@ -125,6 +125,11 @@ void playsingle_controller::init_gui(){
// does not necessarily define the starting positions. While usually
// best to use the map, the scenarion may explicitly set the positions,
// overriding those found in the map (if any).
if(map_start_.valid())
{
gui_->scroll_to_tile(map_start_, game_display::WARP);
}
else
{
int scroll_team = gamestate().first_human_team_ + 1;
if (scroll_team == 0) {