1
0
Fork 0

Codechange: make WindowNumber accept ConvertibleThroughBase types

pull/13450/head
Rubidium 2025-02-02 17:41:24 +01:00 committed by rubidium42
parent fb55ab0742
commit 9bfddcdbbe
4 changed files with 29 additions and 34 deletions

View File

@ -728,7 +728,7 @@ public:
void OnGameTick() override void OnGameTick() override
{ {
if (this->stations.NeedResort()) { 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<int>(this->window_number));
this->SetDirty(); this->SetDirty();
} }
} }

View File

@ -12,7 +12,6 @@
#include "window_type.h" #include "window_type.h"
#include "company_type.h" #include "company_type.h"
#include "core/convertible_through_base.hpp"
#include "core/geometry_type.hpp" #include "core/geometry_type.hpp"
Window *FindWindowById(WindowClass cls, WindowNumber number); Window *FindWindowById(WindowClass cls, WindowNumber number);
@ -20,11 +19,6 @@ Window *FindWindowByClass(WindowClass cls);
Window *GetMainWindow(); Window *GetMainWindow();
void ChangeWindowOwner(Owner old_owner, Owner new_owner); 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); void ResizeWindow(Window *w, int x, int y, bool clamp_to_screen = true, bool schedule_resize = true);
int PositionMainToolbar(Window *w); int PositionMainToolbar(Window *w);
int PositionStatusbar(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 InvalidateWindowData(WindowClass cls, WindowNumber number, int data = 0, bool gui_scope = false);
void InvalidateWindowClassesData(WindowClass cls, 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 CloseNonVitalWindows();
void CloseAllNonVitalWindows(); void CloseAllNonVitalWindows();
void DeleteAllMessages(); void DeleteAllMessages();
@ -65,19 +54,9 @@ void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, WidgetID widget_
void SetWindowDirty(WindowClass cls, WindowNumber number); void SetWindowDirty(WindowClass cls, WindowNumber number);
void SetWindowClassesDirty(WindowClass cls); 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 CloseWindowById(WindowClass cls, WindowNumber number, bool force = true, int data = 0);
void CloseWindowByClass(WindowClass cls, 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 EditBoxInGlobalFocus();
bool FocusedWindowIsConsole(); bool FocusedWindowIsConsole();
Point GetCaretPosition(); Point GetCaretPosition();

View File

@ -348,11 +348,6 @@ public:
void CreateNestedTree(); void CreateNestedTree();
void FinishInitNested(WindowNumber window_number = 0); 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. * Set the timeout flag of the window and initiate the timer.
*/ */
@ -995,11 +990,6 @@ public:
Window *BringWindowToFrontById(WindowClass cls, WindowNumber number); Window *BringWindowToFrontById(WindowClass cls, WindowNumber number);
Window *FindWindowFromPt(int x, int y); Window *FindWindowFromPt(int x, int y);
Window *BringWindowToFrontById(WindowClass cls, ConvertibleThroughBase auto number)
{
return BringWindowToFrontById(cls, number.base());
}
/** /**
* Open a new window. * Open a new window.
* @tparam Twindow %Window class to use if the window does not exist. * @tparam Twindow %Window class to use if the window does not exist.

View File

@ -10,6 +10,8 @@
#ifndef WINDOW_TYPE_H #ifndef WINDOW_TYPE_H
#define WINDOW_TYPE_H #define WINDOW_TYPE_H
#include "core/convertible_through_base.hpp"
/** /**
* Widget ID. * Widget ID.
* Even though the ID is signed, actual IDs must be non-negative. * Even though the ID is signed, actual IDs must be non-negative.
@ -736,8 +738,32 @@ enum GameOptionsInvalidationData : uint8_t {
struct Window; 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 <typename T> requires (std::is_enum_v<T> || std::is_class_v<T>)
operator T() const { return static_cast<T>(value); };
};
/** State of handling an event. */ /** State of handling an event. */
enum EventState : uint8_t { enum EventState : uint8_t {