diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cheat_gui.cpp | 8 | ||||
-rw-r--r-- | src/linkgraph/linkgraphschedule.cpp | 13 | ||||
-rw-r--r-- | src/linkgraph/linkgraphschedule.h | 1 | ||||
-rw-r--r-- | src/toolbar_gui.cpp | 22 |
4 files changed, 32 insertions, 12 deletions
diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp index 87288279e..9eb405d2a 100644 --- a/src/cheat_gui.cpp +++ b/src/cheat_gui.cpp @@ -24,8 +24,7 @@ #include "rail_gui.h" #include "settings_gui.h" #include "company_gui.h" -#include "linkgraph/linkgraph.h" -#include "linkgraph/linkgraphjob.h" +#include "linkgraph/linkgraphschedule.h" #include "widgets/cheat_widget.h" @@ -103,10 +102,7 @@ static int32 ClickChangeDateCheat(int32 p1, int32 p2) if (p1 == _cur_year) return _cur_year; Date new_date = ConvertYMDToDate(p1, ymd.month, ymd.day); - LinkGraph *lg; - FOR_ALL_LINK_GRAPHS(lg) lg->ShiftDates(new_date - _date); - LinkGraphJob *lgj; - FOR_ALL_LINK_GRAPH_JOBS(lgj) lgj->ShiftJoinDate(new_date - _date); + LinkGraphSchedule::Instance()->ShiftDates(new_date - _date); SetDate(new_date, _date_fract); EnginesMonthlyLoop(); SetWindowDirty(WC_STATUS_BAR, 0); diff --git a/src/linkgraph/linkgraphschedule.cpp b/src/linkgraph/linkgraphschedule.cpp index 7e2c66f8f..366a3c517 100644 --- a/src/linkgraph/linkgraphschedule.cpp +++ b/src/linkgraph/linkgraphschedule.cpp @@ -126,6 +126,19 @@ void LinkGraphSchedule::SpawnAll() } /** + * Shift all dates (join dates and edge annotations) of link graphs and link + * graph jobs by the number of days given. + * @param interval Number of days to be added or subtracted. + */ +void LinkGraphSchedule::ShiftDates(int interval) +{ + LinkGraph *lg; + FOR_ALL_LINK_GRAPHS(lg) lg->ShiftDates(interval); + LinkGraphJob *lgj; + FOR_ALL_LINK_GRAPH_JOBS(lgj) lgj->ShiftJoinDate(interval); +} + +/** * Create a link graph schedule and initialize its handlers. */ LinkGraphSchedule::LinkGraphSchedule() diff --git a/src/linkgraph/linkgraphschedule.h b/src/linkgraph/linkgraphschedule.h index 911fa389a..25c56904f 100644 --- a/src/linkgraph/linkgraphschedule.h +++ b/src/linkgraph/linkgraphschedule.h @@ -62,6 +62,7 @@ public: void SpawnNext(); void JoinNext(); void SpawnAll(); + void ShiftDates(int interval); /** * Queue a link graph for execution. diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index b5eb7efb9..767811c35 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -1111,6 +1111,19 @@ void ToggleDirtyBlocks() } /** + * Set the starting year for a scenario. + * @param year New starting year. + */ +void SetStartingYear(Year year) +{ + _settings_game.game_creation.starting_year = Clamp(year, MIN_YEAR, MAX_YEAR); + Date new_date = ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1); + /* If you open a savegame as scenario there may already be link graphs.*/ + LinkGraphSchedule::Instance()->ShiftDates(new_date - _date); + SetDate(new_date, 0); +} + +/** * Choose the proper callback function for the main toolbar's help menu. * @param index The menu index which was selected. * @return CBF_NONE @@ -1169,8 +1182,7 @@ static CallBackFunction ToolbarScenDateBackward(Window *w) w->HandleButtonClick(WID_TE_DATE_BACKWARD); w->SetDirty(); - _settings_game.game_creation.starting_year = Clamp(_settings_game.game_creation.starting_year - 1, MIN_YEAR, MAX_YEAR); - SetDate(ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1), 0); + SetStartingYear(_settings_game.game_creation.starting_year - 1); } _left_button_clicked = false; return CBF_NONE; @@ -1183,8 +1195,7 @@ static CallBackFunction ToolbarScenDateForward(Window *w) w->HandleButtonClick(WID_TE_DATE_FORWARD); w->SetDirty(); - _settings_game.game_creation.starting_year = Clamp(_settings_game.game_creation.starting_year + 1, MIN_YEAR, MAX_YEAR); - SetDate(ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1), 0); + SetStartingYear(_settings_game.game_creation.starting_year + 1); } _left_button_clicked = false; return CBF_NONE; @@ -2119,8 +2130,7 @@ struct ScenarioEditorToolbarWindow : Window { /* An empty string means revert to the default */ value = DEF_START_YEAR; } - _settings_game.game_creation.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR); - SetDate(ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1), 0); + SetStartingYear(value); this->SetDirty(); } |