diff options
author | truebrain <truebrain@openttd.org> | 2011-12-19 21:05:14 +0000 |
---|---|---|
committer | truebrain <truebrain@openttd.org> | 2011-12-19 21:05:14 +0000 |
commit | 403cd3acdb7b7fedf2b5e823326611bb32113385 (patch) | |
tree | dff28e68ec5c8015279ea1120dc822f2896f9ace /src/script/api/script_window.cpp | |
parent | 3ada3b9cc5b63a593c2b2655aafedbcbdedcd041 (diff) | |
download | openttd-403cd3acdb7b7fedf2b5e823326611bb32113385.tar.xz |
(svn r23631) -Add: ScriptWindow, to manipulate windows on the client (GameScript only)
Diffstat (limited to 'src/script/api/script_window.cpp')
-rw-r--r-- | src/script/api/script_window.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/script/api/script_window.cpp b/src/script/api/script_window.cpp new file mode 100644 index 000000000..086e59f63 --- /dev/null +++ b/src/script/api/script_window.cpp @@ -0,0 +1,59 @@ +/* $Id$ */ + +/* + * 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" + +/* static */ void ScriptWindow::Close(WindowClass window, uint32 number) +{ + if (ScriptGame::IsMultiplayer()) return; + + if (number == NUMBER_ALL) { + DeleteWindowByClass((::WindowClass)window); + return; + } + + DeleteWindowById((::WindowClass)window, number); +} + +/* static */ bool ScriptWindow::IsOpen(WindowClass window, uint32 number) +{ + if (ScriptGame::IsMultiplayer()) return false; + + if (number == NUMBER_ALL) { + return (FindWindowByClass((::WindowClass)window) != NULL); + } + + return FindWindowById((::WindowClass)window, number) != NULL; +} + +/* 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); + + if (widget == WIDGET_ALL) { + if (colour != TC_INVALID) return; + w->DisableAllWidgetHighlight(); + return; + } + + const NWidgetBase *wid = w->GetWidget<NWidgetBase>(widget); + if (wid == NULL) return; + w->SetWidgetHighlight(widget, (::TextColour)colour); +} |