script_window.cpp

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * 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.
00006  * 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.
00007  * 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/>.
00008  */
00009 
00012 #include "../../stdafx.h"
00013 #include "script_window.hpp"
00014 #include "script_game.hpp"
00015 #include "../../window_func.h"
00016 #include "../../window_gui.h"
00017 
00018 /* static */ void ScriptWindow::Close(WindowClass window, uint32 number)
00019 {
00020   if (ScriptGame::IsMultiplayer()) return;
00021 
00022   if (number == NUMBER_ALL) {
00023     DeleteWindowByClass((::WindowClass)window);
00024     return;
00025   }
00026 
00027   DeleteWindowById((::WindowClass)window, number);
00028 }
00029 
00030 /* static */ bool ScriptWindow::IsOpen(WindowClass window, uint32 number)
00031 {
00032   if (ScriptGame::IsMultiplayer()) return false;
00033 
00034   if (number == NUMBER_ALL) {
00035     return (FindWindowByClass((::WindowClass)window) != NULL);
00036   }
00037 
00038   return FindWindowById((::WindowClass)window, number) != NULL;
00039 }
00040 
00041 /* static */ void ScriptWindow::Highlight(WindowClass window, uint32 number, uint8 widget, TextColour colour)
00042 {
00043   if (ScriptGame::IsMultiplayer()) return;
00044   if (number == NUMBER_ALL) return;
00045   if (!IsOpen(window, number)) return;
00046   if (colour != TC_INVALID && (::TextColour)colour >= ::TC_END) return;
00047 
00048   Window *w = FindWindowById((::WindowClass)window, number);
00049 
00050   if (widget == WIDGET_ALL) {
00051     if (colour != TC_INVALID) return;
00052     w->DisableAllWidgetHighlight();
00053     return;
00054   }
00055 
00056   const NWidgetBase *wid = w->GetWidget<NWidgetBase>(widget);
00057   if (wid == NULL) return;
00058   w->SetWidgetHighlight(widget, (::TextColour)colour);
00059 }