mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Use SQInteger for generic numbers in script_window
This commit is contained in:
parent
f752d96125
commit
ca149447d7
|
@ -15,7 +15,7 @@
|
|||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ void ScriptWindow::Close(WindowClass window, uint32 number)
|
||||
/* static */ void ScriptWindow::Close(WindowClass window, SQInteger number)
|
||||
{
|
||||
if (ScriptGame::IsMultiplayer()) return;
|
||||
|
||||
|
@ -24,10 +24,12 @@
|
|||
return;
|
||||
}
|
||||
|
||||
number = Clamp<SQInteger>(number, 0, INT32_MAX);
|
||||
|
||||
CloseWindowById((::WindowClass)window, number);
|
||||
}
|
||||
|
||||
/* static */ bool ScriptWindow::IsOpen(WindowClass window, uint32 number)
|
||||
/* static */ bool ScriptWindow::IsOpen(WindowClass window, SQInteger number)
|
||||
{
|
||||
if (ScriptGame::IsMultiplayer()) return false;
|
||||
|
||||
|
@ -35,16 +37,20 @@
|
|||
return (FindWindowByClass((::WindowClass)window) != nullptr);
|
||||
}
|
||||
|
||||
number = Clamp<SQInteger>(number, 0, INT32_MAX);
|
||||
|
||||
return FindWindowById((::WindowClass)window, number) != nullptr;
|
||||
}
|
||||
|
||||
/* static */ void ScriptWindow::Highlight(WindowClass window, uint32 number, uint8 widget, TextColour colour)
|
||||
/* static */ void ScriptWindow::Highlight(WindowClass window, SQInteger number, SQInteger widget, TextColour colour)
|
||||
{
|
||||
if (ScriptGame::IsMultiplayer()) return;
|
||||
if (number == NUMBER_ALL) return;
|
||||
if (!IsOpen(window, number)) return;
|
||||
if (colour != TC_INVALID && (::TextColour)colour >= ::TC_END) return;
|
||||
|
||||
number = Clamp<SQInteger>(number, 0, INT32_MAX);
|
||||
|
||||
Window *w = FindWindowById((::WindowClass)window, number);
|
||||
assert(w != nullptr);
|
||||
|
||||
|
@ -54,6 +60,8 @@
|
|||
return;
|
||||
}
|
||||
|
||||
widget = Clamp<SQInteger>(widget, 0, UINT8_MAX);
|
||||
|
||||
const NWidgetBase *wid = w->GetWidget<NWidgetBase>(widget);
|
||||
if (wid == nullptr) return;
|
||||
w->SetWidgetHighlight(widget, (::TextColour)colour);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
${INCLUDES}
|
||||
|
||||
/**
|
||||
* Class that handles window interaction. A Window in OpenTTD has two imporant
|
||||
* Class that handles window interaction. A Window in OpenTTD has two important
|
||||
* values. The WindowClass, and a Window number. The first indicates roughly
|
||||
* which window it is. WC_TOWN_VIEW for example, is the view of a town.
|
||||
* The Window number is a bit more complex, as it depends mostly on the
|
||||
|
@ -67,45 +67,49 @@ public:
|
|||
* Special number values.
|
||||
*/
|
||||
enum NumberType {
|
||||
NUMBER_ALL = 0xFFFFFFFF, ///< Value to select all windows of a class.
|
||||
NUMBER_ALL = -1, ///< Value to select all windows of a class.
|
||||
};
|
||||
|
||||
/**
|
||||
* Special widget values.
|
||||
*/
|
||||
enum WidgetType {
|
||||
WIDGET_ALL = 0xFF, ///< Value to select all widgets of a window.
|
||||
WIDGET_ALL = -1, ///< Value to select all widgets of a window.
|
||||
};
|
||||
|
||||
/**
|
||||
* Close a window.
|
||||
* @param window The class of the window to close.
|
||||
* @param number The number of the window to close, or NUMBER_ALL to close all of this class.
|
||||
* The value will be clamped to 0 .. MAX(int32) when value is not NUMBER_ALL.
|
||||
* @pre !ScriptGame::IsMultiplayer().
|
||||
*/
|
||||
static void Close(WindowClass window, uint32 number);
|
||||
static void Close(WindowClass window, SQInteger number);
|
||||
|
||||
/**
|
||||
* Check if a window is open.
|
||||
* @param window The class of the window to check for.
|
||||
* @param number The number of the window to check for, or NUMBER_ALL to check for any in the class.
|
||||
* The value will be clamped to 0 .. MAX(int32) when value is not NUMBER_ALL.
|
||||
* @pre !ScriptGame::IsMultiplayer().
|
||||
* @return True if the window is open.
|
||||
*/
|
||||
static bool IsOpen(WindowClass window, uint32 number);
|
||||
static bool IsOpen(WindowClass window, SQInteger number);
|
||||
|
||||
/**
|
||||
* Highlight a widget in a window.
|
||||
* @param window The class of the window to highlight a widget in.
|
||||
* @param number The number of the window to highlight a widget in.
|
||||
* The value will be clamped to 0 .. MAX(int32) when value is not NUMBER_ALL.
|
||||
* @param widget The widget in the window to highlight, or WIDGET_ALL (in combination with TC_INVALID) to disable all widget highlighting on this window.
|
||||
* The value will be clamped to 0 .. MAX(uint8) when value is not WIDGET_ALL.
|
||||
* @param colour The colour of the highlight, or TC_INVALID for disabling.
|
||||
* @pre !ScriptGame::IsMultiplayer().
|
||||
* @pre number != NUMBER_ALL.
|
||||
* @pre colour < TC_END || (widget == WIDGET_ALL && colour == TC_INVALID).
|
||||
* @pre IsOpen(window, number).
|
||||
*/
|
||||
static void Highlight(WindowClass window, uint32 number, uint8 widget, TextColour colour);
|
||||
static void Highlight(WindowClass window, SQInteger number, SQInteger widget, TextColour colour);
|
||||
|
||||
// @enum .*Widgets ../../widgets/*_widget.h@ENUM_WIDGETS@
|
||||
// @endenum
|
||||
|
|
Loading…
Reference in New Issue