diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 2e336e86fa..32698ad3c9 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -730,7 +730,7 @@ public: void OnGameTick() override { if (this->stations.NeedResort()) { - Debug(misc, 3, "Periodic rebuild station list company {}", this->window_number); + Debug(misc, 3, "Periodic rebuild station list company {}", static_cast(this->window_number)); this->SetDirty(); } } diff --git a/src/window_func.h b/src/window_func.h index 2bd314db99..530bad4ca1 100644 --- a/src/window_func.h +++ b/src/window_func.h @@ -12,7 +12,6 @@ #include "window_type.h" #include "company_type.h" -#include "core/convertible_through_base.hpp" #include "core/geometry_type.hpp" Window *FindWindowById(WindowClass cls, WindowNumber number); @@ -20,11 +19,6 @@ Window *FindWindowByClass(WindowClass cls); Window *GetMainWindow(); void ChangeWindowOwner(Owner old_owner, Owner new_owner); -Window *FindWindowById(WindowClass cls, ConvertibleThroughBase auto number) -{ - return FindWindowById(cls, number.base()); -} - void ResizeWindow(Window *w, int x, int y, bool clamp_to_screen = true, bool schedule_resize = true); int PositionMainToolbar(Window *w); int PositionStatusbar(Window *w); @@ -43,11 +37,6 @@ void InputLoop(); void InvalidateWindowData(WindowClass cls, WindowNumber number, int data = 0, bool gui_scope = false); void InvalidateWindowClassesData(WindowClass cls, int data = 0, bool gui_scope = false); -void InvalidateWindowData(WindowClass cls, ConvertibleThroughBase auto number, int data = 0, bool gui_scope = false) -{ - InvalidateWindowData(cls, number.base(), data, gui_scope); -} - void CloseNonVitalWindows(); void CloseAllNonVitalWindows(); void DeleteAllMessages(); @@ -65,19 +54,9 @@ void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, WidgetID widget_ void SetWindowDirty(WindowClass cls, WindowNumber number); void SetWindowClassesDirty(WindowClass cls); -void SetWindowDirty(WindowClass cls, ConvertibleThroughBase auto number) -{ - SetWindowDirty(cls, number.base()); -} - void CloseWindowById(WindowClass cls, WindowNumber number, bool force = true, int data = 0); void CloseWindowByClass(WindowClass cls, int data = 0); -void CloseWindowById(WindowClass cls, ConvertibleThroughBase auto number, bool force = true, int data = 0) -{ - CloseWindowById(cls, number.base(), force, data); -} - bool EditBoxInGlobalFocus(); bool FocusedWindowIsConsole(); Point GetCaretPosition(); diff --git a/src/window_gui.h b/src/window_gui.h index f1c67bb7d3..a024a09029 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -348,11 +348,6 @@ public: void CreateNestedTree(); void FinishInitNested(WindowNumber window_number = 0); - void FinishInitNested(ConvertibleThroughBase auto number) - { - this->FinishInitNested(number.base()); - } - /** * Set the timeout flag of the window and initiate the timer. */ @@ -995,11 +990,6 @@ public: Window *BringWindowToFrontById(WindowClass cls, WindowNumber number); Window *FindWindowFromPt(int x, int y); -Window *BringWindowToFrontById(WindowClass cls, ConvertibleThroughBase auto number) -{ - return BringWindowToFrontById(cls, number.base()); -} - /** * Open a new window. * @tparam Twindow %Window class to use if the window does not exist. diff --git a/src/window_type.h b/src/window_type.h index a71602e2a1..0c441689e4 100644 --- a/src/window_type.h +++ b/src/window_type.h @@ -10,6 +10,8 @@ #ifndef WINDOW_TYPE_H #define WINDOW_TYPE_H +#include "core/convertible_through_base.hpp" + /** * Widget ID. * Even though the ID is signed, actual IDs must be non-negative. @@ -736,8 +738,32 @@ enum GameOptionsInvalidationData : uint8_t { struct Window; -/** Number to differentiate different windows of the same class */ -typedef int32_t WindowNumber; +/** + * Number to differentiate different windows of the same class. This number generally + * implicitly passes some information, e.g. the TileIndex or Company associated with + * the window. To ease this use, the window number is lenient with what it accepts and + * broad with what it returns. + * + * Anything that converts into a number and ConvertibleThroughBase types will be accepted. + * When it's being used it returns int32_t or any other type when that's specifically + * requested, e.g. `VehicleType type = window_number` or `GetEngineListHeight(window_number)` + * in which the returned value will be a `VehicleType`. + */ +struct WindowNumber { +private: + int32_t value = 0; +public: + WindowNumber() = default; + WindowNumber(int32_t value) : value(value) {} + WindowNumber(ConvertibleThroughBase auto value) : value(value.base()) {} + + /* Automatically convert to int32_t. */ + operator int32_t() const { return value; } + + /* Automatically convert to any other type that might be requested. */ + template requires (std::is_enum_v || std::is_class_v) + operator T() const { return static_cast(value); }; +}; /** State of handling an event. */ enum EventState : uint8_t {