mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 10:30:28 +00:00
(svn r25867) -Fix [FS#5764]: Shift dates on link graphs when using scenario editor date tool.
This commit is contained in:
parent
a6fe1f2f63
commit
5ab204c8a1
@ -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);
|
||||
|
@ -125,6 +125,19 @@ void LinkGraphSchedule::SpawnAll()
|
||||
inst->schedule.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
@ -62,6 +62,7 @@ public:
|
||||
void SpawnNext();
|
||||
void JoinNext();
|
||||
void SpawnAll();
|
||||
void ShiftDates(int interval);
|
||||
|
||||
/**
|
||||
* Queue a link graph for execution.
|
||||
|
@ -1110,6 +1110,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.
|
||||
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user