mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-29 15:14:33 +01:00
Codechange: Change SetDateCallback into a std::function, so there is no need for void* user data.
This commit is contained in:
@@ -26,8 +26,7 @@
|
||||
|
||||
/** Window to select a date graphically by using dropdowns */
|
||||
struct SetDateWindow : Window {
|
||||
SetDateCallback *callback = nullptr; ///< Callback to call when a date has been selected
|
||||
void *callback_data = nullptr; ///< Callback data pointer.
|
||||
SetDateCallback callback; ///< Callback to call when a date has been selected
|
||||
TimerGameEconomy::YearMonthDay date{}; ///< The currently selected date
|
||||
TimerGameEconomy::Year min_year{}; ///< The minimum year in the year dropdown
|
||||
TimerGameEconomy::Year max_year{}; ///< The maximum year (inclusive) in the year dropdown
|
||||
@@ -42,10 +41,9 @@ struct SetDateWindow : Window {
|
||||
* @param max_year the maximum year (inclusive) to show in the year dropdown
|
||||
* @param callback the callback to call once a date has been selected
|
||||
*/
|
||||
SetDateWindow(WindowDesc &desc, WindowNumber window_number, Window *parent, TimerGameEconomy::Date initial_date, TimerGameEconomy::Year min_year, TimerGameEconomy::Year max_year, SetDateCallback *callback, void *callback_data) :
|
||||
SetDateWindow(WindowDesc &desc, WindowNumber window_number, Window *parent, TimerGameEconomy::Date initial_date, TimerGameEconomy::Year min_year, TimerGameEconomy::Year max_year, SetDateCallback &&callback) :
|
||||
Window(desc),
|
||||
callback(callback),
|
||||
callback_data(callback_data),
|
||||
callback(std::move(callback)),
|
||||
min_year(std::max(EconomyTime::MIN_YEAR, min_year)),
|
||||
max_year(std::min(EconomyTime::MAX_YEAR, max_year))
|
||||
{
|
||||
@@ -149,7 +147,7 @@ struct SetDateWindow : Window {
|
||||
break;
|
||||
|
||||
case WID_SD_SET_DATE:
|
||||
if (this->callback != nullptr) this->callback(this, TimerGameEconomy::ConvertYMDToDate(this->date.year, this->date.month, this->date.day), this->callback_data);
|
||||
this->callback(this, TimerGameEconomy::ConvertYMDToDate(this->date.year, this->date.month, this->date.day));
|
||||
this->Close();
|
||||
break;
|
||||
}
|
||||
@@ -212,10 +210,9 @@ static WindowDesc _set_date_desc(
|
||||
* @param min_year the minimum year to show in the year dropdown
|
||||
* @param max_year the maximum year (inclusive) to show in the year dropdown
|
||||
* @param callback the callback to call once a date has been selected
|
||||
* @param callback_data extra callback data
|
||||
*/
|
||||
void ShowSetDateWindow(Window *parent, int window_number, TimerGameEconomy::Date initial_date, TimerGameEconomy::Year min_year, TimerGameEconomy::Year max_year, SetDateCallback *callback, void *callback_data)
|
||||
void ShowSetDateWindow(Window *parent, int window_number, TimerGameEconomy::Date initial_date, TimerGameEconomy::Year min_year, TimerGameEconomy::Year max_year, SetDateCallback &&callback)
|
||||
{
|
||||
CloseWindowByClass(WC_SET_DATE);
|
||||
new SetDateWindow(_set_date_desc, window_number, parent, initial_date, min_year, max_year, callback, callback_data);
|
||||
new SetDateWindow(_set_date_desc, window_number, parent, initial_date, min_year, max_year, std::move(callback));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user