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  */
7 
8 /** @file script_window.cpp Implementation of ScriptWindow. */
9 
10 #include "../../stdafx.h"
11 #include "script_window.hpp"
12 #include "script_game.hpp"
13 #include "../../window_func.h"
14 #include "../../window_gui.h"
15 
16 #include "../../safeguards.h"
17 
Close(WindowClass window,uint32 number)18 /* static */ void ScriptWindow::Close(WindowClass window, uint32 number)
19 {
20 	if (ScriptGame::IsMultiplayer()) return;
21 
22 	if (number == NUMBER_ALL) {
23 		CloseWindowByClass((::WindowClass)window);
24 		return;
25 	}
26 
27 	CloseWindowById((::WindowClass)window, number);
28 }
29 
IsOpen(WindowClass window,uint32 number)30 /* static */ bool ScriptWindow::IsOpen(WindowClass window, uint32 number)
31 {
32 	if (ScriptGame::IsMultiplayer()) return false;
33 
34 	if (number == NUMBER_ALL) {
35 		return (FindWindowByClass((::WindowClass)window) != nullptr);
36 	}
37 
38 	return FindWindowById((::WindowClass)window, number) != nullptr;
39 }
40 
Highlight(WindowClass window,uint32 number,uint8 widget,TextColour colour)41 /* static */ void ScriptWindow::Highlight(WindowClass window, uint32 number, uint8 widget, TextColour colour)
42 {
43 	if (ScriptGame::IsMultiplayer()) return;
44 	if (number == NUMBER_ALL) return;
45 	if (!IsOpen(window, number)) return;
46 	if (colour != TC_INVALID && (::TextColour)colour >= ::TC_END) return;
47 
48 	Window *w = FindWindowById((::WindowClass)window, number);
49 
50 	if (widget == WIDGET_ALL) {
51 		if (colour != TC_INVALID) return;
52 		w->DisableAllWidgetHighlight();
53 		return;
54 	}
55 
56 	const NWidgetBase *wid = w->GetWidget<NWidgetBase>(widget);
57 	if (wid == nullptr) return;
58 	w->SetWidgetHighlight(widget, (::TextColour)colour);
59 }
60