mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-06-20 12:09:32 +01:00
Though where similar calls are checked for nullptr as in those instances of the use of that function it can actually return nullptr. In other words, write down the assumption that the function never returns nullptr in an assert.
61 lines
2.0 KiB
C++
61 lines
2.0 KiB
C++
/*
|
|
* This file is part of OpenTTD.
|
|
* 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.
|
|
* 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.
|
|
* 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/>.
|
|
*/
|
|
|
|
/** @file script_window.cpp Implementation of ScriptWindow. */
|
|
|
|
#include "../../stdafx.h"
|
|
#include "script_window.hpp"
|
|
#include "script_game.hpp"
|
|
#include "../../window_func.h"
|
|
#include "../../window_gui.h"
|
|
|
|
#include "../../safeguards.h"
|
|
|
|
/* static */ void ScriptWindow::Close(WindowClass window, uint32 number)
|
|
{
|
|
if (ScriptGame::IsMultiplayer()) return;
|
|
|
|
if (number == NUMBER_ALL) {
|
|
CloseWindowByClass((::WindowClass)window);
|
|
return;
|
|
}
|
|
|
|
CloseWindowById((::WindowClass)window, number);
|
|
}
|
|
|
|
/* static */ bool ScriptWindow::IsOpen(WindowClass window, uint32 number)
|
|
{
|
|
if (ScriptGame::IsMultiplayer()) return false;
|
|
|
|
if (number == NUMBER_ALL) {
|
|
return (FindWindowByClass((::WindowClass)window) != nullptr);
|
|
}
|
|
|
|
return FindWindowById((::WindowClass)window, number) != nullptr;
|
|
}
|
|
|
|
/* static */ void ScriptWindow::Highlight(WindowClass window, uint32 number, uint8 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;
|
|
|
|
Window *w = FindWindowById((::WindowClass)window, number);
|
|
assert(w != nullptr);
|
|
|
|
if (widget == WIDGET_ALL) {
|
|
if (colour != TC_INVALID) return;
|
|
w->DisableAllWidgetHighlight();
|
|
return;
|
|
}
|
|
|
|
const NWidgetBase *wid = w->GetWidget<NWidgetBase>(widget);
|
|
if (wid == nullptr) return;
|
|
w->SetWidgetHighlight(widget, (::TextColour)colour);
|
|
}
|