diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index d603f811b8..ab95847c16 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -2749,24 +2749,26 @@ static WindowDesc _build_vehicle_desc( ); static WindowDesc _build_template_vehicle_desc( - WDP_AUTO, "build_vehicle", 240, 268, + WDP_AUTO, nullptr, 240, 268, WC_BUILD_VIRTUAL_TRAIN, WC_CREATE_TEMPLATE, WDF_CONSTRUCTION, - _nested_build_vehicle_widgets, lengthof(_nested_build_vehicle_widgets) + _nested_build_vehicle_widgets, lengthof(_nested_build_vehicle_widgets), + nullptr, &_build_vehicle_desc ); static WindowDesc _build_vehicle_desc_train_advanced( - WDP_AUTO, "build_vehicle", 480, 268, + WDP_AUTO, "build_vehicle_dual", 480, 268, WC_BUILD_VEHICLE, WC_NONE, WDF_CONSTRUCTION, _nested_build_vehicle_widgets_train_advanced, lengthof(_nested_build_vehicle_widgets_train_advanced) ); static WindowDesc _build_template_vehicle_desc_advanced( - WDP_AUTO, "build_vehicle", 480, 268, + WDP_AUTO, nullptr, 480, 268, WC_BUILD_VIRTUAL_TRAIN, WC_CREATE_TEMPLATE, WDF_CONSTRUCTION, - _nested_build_vehicle_widgets_train_advanced, lengthof(_nested_build_vehicle_widgets_train_advanced) + _nested_build_vehicle_widgets_train_advanced, lengthof(_nested_build_vehicle_widgets_train_advanced), + nullptr, &_build_vehicle_desc_train_advanced ); diff --git a/src/settings.cpp b/src/settings.cpp index ff9a2e257d..960635053d 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -832,7 +832,7 @@ static void IniSaveSettingList(IniFile &ini, const char *grpname, StringList &li * Load a WindowDesc from config. * @param ini IniFile handle to the ini file with the source data * @param grpname character string identifying the section-header of the ini file that will be parsed - * @param desc Destination WindowDesc + * @param desc Destination WindowDescPreferences */ void IniLoadWindowSettings(IniFile &ini, const char *grpname, void *desc) { @@ -843,7 +843,7 @@ void IniLoadWindowSettings(IniFile &ini, const char *grpname, void *desc) * Save a WindowDesc to config. * @param ini IniFile handle to the ini file where the destination data is saved * @param grpname character string identifying the section-header of the ini file - * @param desc Source WindowDesc + * @param desc Source WindowDescPreferences */ void IniSaveWindowSettings(IniFile &ini, const char *grpname, void *desc) { diff --git a/src/table/settings/window_settings.ini b/src/table/settings/window_settings.ini index 2c11818347..67c3347836 100644 --- a/src/table/settings/window_settings.ini +++ b/src/table/settings/window_settings.ini @@ -13,11 +13,11 @@ static const SettingTable _window_settings{ [post-amble] }; [templates] -SDT_BOOL = SDT_BOOL(WindowDesc, $var, $flags, $def, $str, $strhelp, $strval, $pre_cb, $post_cb, $from, $to, $extver, $cat, $guiproc, $startup, nullptr), -SDT_VAR = SDT_VAR(WindowDesc, $var, $type, $flags, $def, $min, $max, $interval, $str, $strhelp, $strval, $pre_cb, $post_cb, $from, $to, $extver, $cat, $guiproc, $startup, nullptr), +SDT_BOOL = SDT_BOOL(WindowDescPreferences, $var, $flags, $def, $str, $strhelp, $strval, $pre_cb, $post_cb, $from, $to, $extver, $cat, $guiproc, $startup, nullptr), +SDT_VAR = SDT_VAR(WindowDescPreferences, $var, $type, $flags, $def, $min, $max, $interval, $str, $strhelp, $strval, $pre_cb, $post_cb, $from, $to, $extver, $cat, $guiproc, $startup, nullptr), [validation] -SDT_VAR = static_assert($max <= MAX_$type, "Maximum value for WindowDesc.$var exceeds storage size"); +SDT_VAR = static_assert($max <= MAX_$type, "Maximum value for WindowDescPreferences.$var exceeds storage size"); [defaults] flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC diff --git a/src/window.cpp b/src/window.cpp index 479dbd0123..dd1ba33ee0 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -96,7 +96,7 @@ std::string _windows_file; /** Window description constructor. */ WindowDesc::WindowDesc(WindowPosition def_pos, const char *ini_key, int16 def_width_trad, int16 def_height_trad, WindowClass window_class, WindowClass parent_class, uint32 flags, - const NWidgetPart *nwid_parts, int16 nwid_length, HotkeyList *hotkeys) : + const NWidgetPart *nwid_parts, int16 nwid_length, HotkeyList *hotkeys, WindowDesc *ini_parent) : default_pos(def_pos), cls(window_class), parent_cls(parent_class), @@ -105,9 +105,8 @@ WindowDesc::WindowDesc(WindowPosition def_pos, const char *ini_key, int16 def_wi nwid_parts(nwid_parts), nwid_length(nwid_length), hotkeys(hotkeys), - pref_sticky(false), - pref_width(0), - pref_height(0), + ini_parent(ini_parent), + prefs({ false, 0, 0 }), default_width_trad(def_width_trad), default_height_trad(def_height_trad) { @@ -120,6 +119,11 @@ WindowDesc::~WindowDesc() _window_descs->erase(std::find(_window_descs->begin(), _window_descs->end(), this)); } +const WindowDescPreferences &WindowDesc::GetPreferences() const +{ + return this->ini_parent != nullptr ? this->ini_parent->prefs : this->prefs; +} + /** * Determine default width of window. * This is either a stored user preferred size, or the built-in default. @@ -127,7 +131,8 @@ WindowDesc::~WindowDesc() */ int16 WindowDesc::GetDefaultWidth() const { - return this->pref_width != 0 ? this->pref_width : ScaleGUITrad(this->default_width_trad); + const WindowDescPreferences &prefs = this->GetPreferences(); + return prefs.pref_width != 0 ? prefs.pref_width : ScaleGUITrad(this->default_width_trad); } /** @@ -137,7 +142,8 @@ int16 WindowDesc::GetDefaultWidth() const */ int16 WindowDesc::GetDefaultHeight() const { - return this->pref_height != 0 ? this->pref_height : ScaleGUITrad(this->default_height_trad); + const WindowDescPreferences &prefs = this->GetPreferences(); + return prefs.pref_height != 0 ? prefs.pref_height : ScaleGUITrad(this->default_height_trad); } /** @@ -149,7 +155,7 @@ void WindowDesc::LoadFromConfig() ini.LoadFromDisk(_windows_file, NO_DIRECTORY); for (WindowDesc *wd : *_window_descs) { if (wd->ini_key == nullptr) continue; - IniLoadWindowSettings(ini, wd->ini_key, wd); + IniLoadWindowSettings(ini, wd->ini_key, &(wd->prefs)); } } @@ -174,7 +180,7 @@ void WindowDesc::SaveToConfig() ini.LoadFromDisk(_windows_file, NO_DIRECTORY); for (WindowDesc *wd : *_window_descs) { if (wd->ini_key == nullptr) continue; - IniSaveWindowSettings(ini, wd->ini_key, wd); + IniSaveWindowSettings(ini, wd->ini_key, &(wd->prefs)); } ini.SaveToDisk(_windows_file); } @@ -185,10 +191,10 @@ void WindowDesc::SaveToConfig() void Window::ApplyDefaults() { if (this->nested_root != nullptr && this->nested_root->GetWidgetOfType(WWT_STICKYBOX) != nullptr) { - if (this->window_desc->pref_sticky) this->flags |= WF_STICKY; + if (this->window_desc->GetPreferences().pref_sticky) this->flags |= WF_STICKY; } else { /* There is no stickybox; clear the preference in case someone tried to be funny */ - this->window_desc->pref_sticky = false; + this->window_desc->prefs.pref_sticky = false; } } @@ -741,8 +747,8 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count) case WWT_DEFSIZEBOX: { if (_ctrl_pressed) { - w->window_desc->pref_width = w->width; - w->window_desc->pref_height = w->height; + w->window_desc->GetPreferences().pref_width = w->width; + w->window_desc->GetPreferences().pref_height = w->height; } else { int16 def_width = std::max(std::min(w->window_desc->GetDefaultWidth(), _screen.width), w->nested_root->smallest_x); int16 def_height = std::max(std::min(w->window_desc->GetDefaultHeight(), _screen.height - 50), w->nested_root->smallest_y); @@ -774,7 +780,7 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count) case WWT_STICKYBOX: w->flags ^= WF_STICKY; nw->SetDirty(w); - if (_ctrl_pressed) w->window_desc->pref_sticky = (w->flags & WF_STICKY) != 0; + if (_ctrl_pressed) w->window_desc->GetPreferences().pref_sticky = (w->flags & WF_STICKY) != 0; return; default: diff --git a/src/window_gui.h b/src/window_gui.h index 990938d42f..f160db4c92 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -173,6 +173,12 @@ Point GetToolbarAlignedWindowPosition(int window_width); struct HotkeyList; +struct WindowDescPreferences { + bool pref_sticky; ///< Preferred stickyness. + int16 pref_width; ///< User-preferred width of the window. Zero if unset. + int16 pref_height; ///< User-preferred height of the window. Zero if unset. +}; + /** * High level window description */ @@ -180,7 +186,7 @@ struct WindowDesc { WindowDesc(WindowPosition default_pos, const char *ini_key, int16 def_width_trad, int16 def_height_trad, WindowClass window_class, WindowClass parent_class, uint32 flags, - const NWidgetPart *nwid_parts, int16 nwid_length, HotkeyList *hotkeys = nullptr); + const NWidgetPart *nwid_parts, int16 nwid_length, HotkeyList *hotkeys = nullptr, WindowDesc *ini_parent = nullptr); ~WindowDesc(); @@ -192,10 +198,12 @@ struct WindowDesc { const NWidgetPart *nwid_parts; ///< Nested widget parts describing the window. int16 nwid_length; ///< Length of the #nwid_parts array. HotkeyList *hotkeys; ///< Hotkeys for the window. + WindowDesc *ini_parent; ///< Other window desc to use for WindowDescPreferences. - bool pref_sticky; ///< Preferred stickyness. - int16 pref_width; ///< User-preferred width of the window. Zero if unset. - int16 pref_height; ///< User-preferred height of the window. Zero if unset. + WindowDescPreferences prefs; ///< Preferences for this window + + const WindowDescPreferences &GetPreferences() const; + WindowDescPreferences &GetPreferences() { return const_cast(const_cast(this)->GetPreferences()); } int16 GetDefaultWidth() const; int16 GetDefaultHeight() const;