Update: Translations from eints
[openttd-github.git] / src / script / api / script_window.cpp
blob42b5614c038425470df1b962dcf7c489584e740c
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /** @file script_window.cpp Implementation of ScriptWindow. */
10 #include "../../stdafx.h"
11 #include "script_window.hpp"
12 #include "script_game.hpp"
13 #include "../../window_func.h"
14 #include "../../window_gui.h"
16 #include "../../safeguards.h"
18 /* static */ void ScriptWindow::Close(WindowClass window, SQInteger number)
20 if (ScriptGame::IsMultiplayer()) return;
22 if (number == NUMBER_ALL) {
23 CloseWindowByClass((::WindowClass)window);
24 return;
27 number = Clamp<SQInteger>(number, 0, INT32_MAX);
29 CloseWindowById((::WindowClass)window, number);
32 /* static */ bool ScriptWindow::IsOpen(WindowClass window, SQInteger number)
34 if (ScriptGame::IsMultiplayer()) return false;
36 if (number == NUMBER_ALL) {
37 return (FindWindowByClass((::WindowClass)window) != nullptr);
40 number = Clamp<SQInteger>(number, 0, INT32_MAX);
42 return FindWindowById((::WindowClass)window, number) != nullptr;
45 /* static */ void ScriptWindow::Highlight(WindowClass window, SQInteger number, SQInteger widget, TextColour colour)
47 if (ScriptGame::IsMultiplayer()) return;
48 if (number == NUMBER_ALL) return;
49 if (!IsOpen(window, number)) return;
50 if (colour != TC_INVALID && (::TextColour)colour >= ::TC_END) return;
52 number = Clamp<SQInteger>(number, 0, INT32_MAX);
54 Window *w = FindWindowById((::WindowClass)window, number);
55 assert(w != nullptr);
57 if (widget == WIDGET_ALL) {
58 if (colour != TC_INVALID) return;
59 w->DisableAllWidgetHighlight();
60 return;
63 widget = Clamp<SQInteger>(widget, 0, UINT8_MAX);
65 const NWidgetBase *wid = w->GetWidget<NWidgetBase>(widget);
66 if (wid == nullptr) return;
67 w->SetWidgetHighlight(widget, (::TextColour)colour);