main_gui.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 "currency.h"
00014 #include "spritecache.h"
00015 #include "window_gui.h"
00016 #include "window_func.h"
00017 #include "textbuf_gui.h"
00018 #include "viewport_func.h"
00019 #include "command_func.h"
00020 #include "console_gui.h"
00021 #include "genworld.h"
00022 #include "transparency_gui.h"
00023 #include "map_func.h"
00024 #include "sound_func.h"
00025 #include "transparency.h"
00026 #include "strings_func.h"
00027 #include "zoom_func.h"
00028 #include "company_base.h"
00029 #include "company_func.h"
00030 #include "toolbar_gui.h"
00031 #include "statusbar_gui.h"
00032 #include "tilehighlight_func.h"
00033 #include "hotkeys.h"
00034 
00035 #include "saveload/saveload.h"
00036 
00037 #include "network/network.h"
00038 #include "network/network_func.h"
00039 #include "network/network_gui.h"
00040 #include "network/network_base.h"
00041 
00042 #include "table/sprites.h"
00043 #include "table/strings.h"
00044 
00045 static int _rename_id = 1;
00046 static int _rename_what = -1;
00047 
00048 void CcGiveMoney(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
00049 {
00050 #ifdef ENABLE_NETWORK
00051   if (result.Failed() || !_settings_game.economy.give_money) return;
00052 
00053   /* Inform the company of the action of one of its clients (controllers). */
00054   char msg[64];
00055   SetDParam(0, p2);
00056   GetString(msg, STR_COMPANY_NAME, lastof(msg));
00057 
00058   if (!_network_server) {
00059     NetworkClientSendChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, p2, msg, p1);
00060   } else {
00061     NetworkServerSendChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, p2, msg, CLIENT_ID_SERVER, p1);
00062   }
00063 #endif /* ENABLE_NETWORK */
00064 }
00065 
00066 void HandleOnEditText(const char *str)
00067 {
00068   switch (_rename_what) {
00069 #ifdef ENABLE_NETWORK
00070   case 3: { // Give money, you can only give money in excess of loan
00071     const Company *c = Company::GetIfValid(_local_company);
00072     if (c == NULL) break;
00073     Money money = min(c->money - c->current_loan, (Money)(atoi(str) / _currency->rate));
00074 
00075     uint32 money_c = Clamp(ClampToI32(money), 0, 20000000); // Clamp between 20 million and 0
00076 
00077     /* Give 'id' the money, and substract it from ourself */
00078     DoCommandP(0, money_c, _rename_id, CMD_GIVE_MONEY | CMD_MSG(STR_ERROR_INSUFFICIENT_FUNDS), CcGiveMoney, str);
00079     break;
00080   }
00081 #endif /* ENABLE_NETWORK */
00082     default: NOT_REACHED();
00083   }
00084 
00085   _rename_id = _rename_what = -1;
00086 }
00087 
00098 bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyle mode)
00099 {
00100   if (w->IsWidgetDisabled(widget)) return false;
00101 
00102   SndPlayFx(SND_15_BEEP);
00103   w->SetDirty();
00104 
00105   if (w->IsWidgetLowered(widget)) {
00106     ResetObjectToPlace();
00107     return false;
00108   }
00109 
00110   SetObjectToPlace(cursor, PAL_NONE, mode, w->window_class, w->window_number);
00111   w->LowerWidget(widget);
00112   return true;
00113 }
00114 
00115 
00116 void CcPlaySound10(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
00117 {
00118   if (result.Succeeded()) SndPlayTileFx(SND_12_EXPLOSION, tile);
00119 }
00120 
00121 #ifdef ENABLE_NETWORK
00122 void ShowNetworkGiveMoneyWindow(CompanyID company)
00123 {
00124   _rename_id = company;
00125   _rename_what = 3;
00126   ShowQueryString(STR_EMPTY, STR_NETWORK_GIVE_MONEY_CAPTION, 30, NULL, CS_NUMERAL, QSF_NONE);
00127 }
00128 #endif /* ENABLE_NETWORK */
00129 
00130 
00138 bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
00139 {
00140   ViewPort *vp;
00141 
00142   assert(w != NULL);
00143   vp = w->viewport;
00144 
00145   switch (how) {
00146     case ZOOM_NONE:
00147       /* On initialisation of the viewport we don't do anything. */
00148       break;
00149 
00150     case ZOOM_IN:
00151       if (vp->zoom == ZOOM_LVL_MIN) return false;
00152       vp->zoom = (ZoomLevel)((int)vp->zoom - 1);
00153       vp->virtual_width >>= 1;
00154       vp->virtual_height >>= 1;
00155 
00156       w->viewport->scrollpos_x += vp->virtual_width >> 1;
00157       w->viewport->scrollpos_y += vp->virtual_height >> 1;
00158       w->viewport->dest_scrollpos_x = w->viewport->scrollpos_x;
00159       w->viewport->dest_scrollpos_y = w->viewport->scrollpos_y;
00160       w->viewport->follow_vehicle = INVALID_VEHICLE;
00161       break;
00162     case ZOOM_OUT:
00163       if (vp->zoom == ZOOM_LVL_MAX) return false;
00164       vp->zoom = (ZoomLevel)((int)vp->zoom + 1);
00165 
00166       w->viewport->scrollpos_x -= vp->virtual_width >> 1;
00167       w->viewport->scrollpos_y -= vp->virtual_height >> 1;
00168       w->viewport->dest_scrollpos_x = w->viewport->scrollpos_x;
00169       w->viewport->dest_scrollpos_y = w->viewport->scrollpos_y;
00170 
00171       vp->virtual_width <<= 1;
00172       vp->virtual_height <<= 1;
00173       w->viewport->follow_vehicle = INVALID_VEHICLE;
00174       break;
00175   }
00176   if (vp != NULL) { // the vp can be null when how == ZOOM_NONE
00177     vp->virtual_left = w->viewport->scrollpos_x;
00178     vp->virtual_top = w->viewport->scrollpos_y;
00179   }
00180   /* Update the windows that have zoom-buttons to perhaps disable their buttons */
00181   w->InvalidateData();
00182   return true;
00183 }
00184 
00185 void ZoomInOrOutToCursorWindow(bool in, Window *w)
00186 {
00187   assert(w != NULL);
00188 
00189   if (_game_mode != GM_MENU) {
00190     ViewPort *vp = w->viewport;
00191     if ((in && vp->zoom == ZOOM_LVL_MIN) || (!in && vp->zoom == ZOOM_LVL_MAX)) return;
00192 
00193     Point pt = GetTileZoomCenterWindow(in, w);
00194     if (pt.x != -1) {
00195       ScrollWindowTo(pt.x, pt.y, -1, w, true);
00196 
00197       DoZoomInOutWindow(in ? ZOOM_IN : ZOOM_OUT, w);
00198     }
00199   }
00200 }
00201 
00203 enum MainWindowWidgets {
00204   MW_VIEWPORT, 
00205 };
00206 
00207 static const struct NWidgetPart _nested_main_window_widgets[] = {
00208   NWidget(NWID_VIEWPORT, INVALID_COLOUR, MW_VIEWPORT), SetResize(1, 1),
00209 };
00210 
00211 static const WindowDesc _main_window_desc(
00212   WDP_MANUAL, 0, 0,
00213   WC_MAIN_WINDOW, WC_NONE,
00214   0,
00215   _nested_main_window_widgets, lengthof(_nested_main_window_widgets)
00216 );
00217 
00218 enum {
00219   GHK_QUIT,
00220   GHK_ABANDON,
00221   GHK_CONSOLE,
00222   GHK_BOUNDING_BOXES,
00223   GHK_CENTER,
00224   GHK_CENTER_ZOOM,
00225   GHK_RESET_OBJECT_TO_PLACE,
00226   GHK_DELETE_WINDOWS,
00227   GHK_DELETE_NONVITAL_WINDOWS,
00228   GHK_REFRESH_SCREEN,
00229   GHK_CRASH,
00230   GHK_MONEY,
00231   GHK_UPDATE_COORDS,
00232   GHK_TOGGLE_TRANSPARENCY,
00233   GHK_TOGGLE_INVISIBILITY = GHK_TOGGLE_TRANSPARENCY + 9,
00234   GHK_TRANSPARENCY_TOOLBAR = GHK_TOGGLE_INVISIBILITY + 8,
00235   GHK_TRANSPARANCY,
00236   GHK_CHAT,
00237   GHK_CHAT_ALL,
00238   GHK_CHAT_COMPANY,
00239   GHK_CHAT_SERVER,
00240 };
00241 
00242 struct MainWindow : Window
00243 {
00244   MainWindow() : Window()
00245   {
00246     this->InitNested(&_main_window_desc, 0);
00247     ResizeWindow(this, _screen.width, _screen.height);
00248 
00249     NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(MW_VIEWPORT);
00250     nvp->InitializeViewport(this, TileXY(32, 32), ZOOM_LVL_VIEWPORT);
00251   }
00252 
00253   virtual void OnPaint()
00254   {
00255     this->DrawWidgets();
00256     if (_game_mode == GM_MENU) {
00257       static const SpriteID title_sprites[] = {SPR_OTTD_O, SPR_OTTD_P, SPR_OTTD_E, SPR_OTTD_N, SPR_OTTD_T, SPR_OTTD_T, SPR_OTTD_D};
00258       static const uint LETTER_SPACING = 10;
00259       int name_width = (lengthof(title_sprites) - 1) * LETTER_SPACING;
00260 
00261       for (uint i = 0; i < lengthof(title_sprites); i++) {
00262         name_width += GetSpriteSize(title_sprites[i]).width;
00263       }
00264       int off_x = (this->width - name_width) / 2;
00265 
00266       for (uint i = 0; i < lengthof(title_sprites); i++) {
00267         DrawSprite(title_sprites[i], PAL_NONE, off_x, 50);
00268         off_x += GetSpriteSize(title_sprites[i]).width + LETTER_SPACING;
00269       }
00270     }
00271   }
00272 
00273   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
00274   {
00275     int num = CheckHotkeyMatch(global_hotkeys, keycode, this);
00276     if (num == GHK_QUIT) {
00277       HandleExitGameRequest();
00278       return ES_HANDLED;
00279     }
00280 
00281     /* Disable all key shortcuts, except quit shortcuts when
00282      * generating the world, otherwise they create threading
00283      * problem during the generating, resulting in random
00284      * assertions that are hard to trigger and debug */
00285     if (IsGeneratingWorld()) return ES_NOT_HANDLED;
00286 
00287     switch (num) {
00288       case GHK_ABANDON:
00289         /* No point returning from the main menu to itself */
00290         if (_game_mode == GM_MENU) return ES_HANDLED;
00291         if (_settings_client.gui.autosave_on_exit) {
00292           DoExitSave();
00293           _switch_mode = SM_MENU;
00294         } else {
00295           AskExitToGameMenu();
00296         }
00297         return ES_HANDLED;
00298 
00299       case GHK_CONSOLE:
00300         IConsoleSwitch();
00301         return ES_HANDLED;
00302 
00303       case GHK_BOUNDING_BOXES:
00304         extern bool _draw_bounding_boxes;
00305         _draw_bounding_boxes = !_draw_bounding_boxes;
00306         MarkWholeScreenDirty();
00307         return ES_HANDLED;
00308     }
00309 
00310     if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
00311 
00312     switch (num) {
00313       case GHK_CENTER:
00314       case GHK_CENTER_ZOOM: {
00315         Point pt = GetTileBelowCursor();
00316         if (pt.x != -1) {
00317           bool instant = (num == GHK_CENTER_ZOOM && this->viewport->zoom != ZOOM_LVL_MIN);
00318           if (num == GHK_CENTER_ZOOM) MaxZoomInOut(ZOOM_IN, this);
00319           ScrollMainWindowTo(pt.x, pt.y, -1, instant);
00320         }
00321         break;
00322       }
00323 
00324       case GHK_RESET_OBJECT_TO_PLACE: ResetObjectToPlace(); break;
00325       case GHK_DELETE_WINDOWS: DeleteNonVitalWindows(); break;
00326       case GHK_DELETE_NONVITAL_WINDOWS: DeleteAllNonVitalWindows(); break;
00327       case GHK_REFRESH_SCREEN: MarkWholeScreenDirty(); break;
00328 
00329       case GHK_CRASH: // Crash the game
00330         *(volatile byte *)0 = 0;
00331         break;
00332 
00333       case GHK_MONEY: // Gimme money
00334         /* You can only cheat for money in single player. */
00335         if (!_networking) DoCommandP(0, 10000000, 0, CMD_MONEY_CHEAT);
00336         break;
00337 
00338       case GHK_UPDATE_COORDS: // Update the coordinates of all station signs
00339         UpdateAllVirtCoords();
00340         break;
00341 
00342       case GHK_TOGGLE_TRANSPARENCY:
00343       case GHK_TOGGLE_TRANSPARENCY + 1:
00344       case GHK_TOGGLE_TRANSPARENCY + 2:
00345       case GHK_TOGGLE_TRANSPARENCY + 3:
00346       case GHK_TOGGLE_TRANSPARENCY + 4:
00347       case GHK_TOGGLE_TRANSPARENCY + 5:
00348       case GHK_TOGGLE_TRANSPARENCY + 6:
00349       case GHK_TOGGLE_TRANSPARENCY + 7:
00350       case GHK_TOGGLE_TRANSPARENCY + 8:
00351         /* Transparency toggle hot keys */
00352         ToggleTransparency((TransparencyOption)(num - GHK_TOGGLE_TRANSPARENCY));
00353         MarkWholeScreenDirty();
00354         break;
00355 
00356       case GHK_TOGGLE_INVISIBILITY:
00357       case GHK_TOGGLE_INVISIBILITY + 1:
00358       case GHK_TOGGLE_INVISIBILITY + 2:
00359       case GHK_TOGGLE_INVISIBILITY + 3:
00360       case GHK_TOGGLE_INVISIBILITY + 4:
00361       case GHK_TOGGLE_INVISIBILITY + 5:
00362       case GHK_TOGGLE_INVISIBILITY + 6:
00363       case GHK_TOGGLE_INVISIBILITY + 7:
00364         /* Invisibility toggle hot keys */
00365         ToggleInvisibilityWithTransparency((TransparencyOption)(num - GHK_TOGGLE_INVISIBILITY));
00366         MarkWholeScreenDirty();
00367         break;
00368 
00369       case GHK_TRANSPARENCY_TOOLBAR:
00370         ShowTransparencyToolbar();
00371         break;
00372 
00373       case GHK_TRANSPARANCY:
00374         ResetRestoreAllTransparency();
00375         break;
00376 
00377 #ifdef ENABLE_NETWORK
00378       case GHK_CHAT: // smart chat; send to team if any, otherwise to all
00379         if (_networking) {
00380           const NetworkClientInfo *cio = NetworkClientInfo::GetByClientID(_network_own_client_id);
00381           if (cio == NULL) break;
00382 
00383           ShowNetworkChatQueryWindow(NetworkClientPreferTeamChat(cio) ? DESTTYPE_TEAM : DESTTYPE_BROADCAST, cio->client_playas);
00384         }
00385         break;
00386 
00387       case GHK_CHAT_ALL: // send text message to all clients
00388         if (_networking) ShowNetworkChatQueryWindow(DESTTYPE_BROADCAST, 0);
00389         break;
00390 
00391       case GHK_CHAT_COMPANY: // send text to all team mates
00392         if (_networking) {
00393           const NetworkClientInfo *cio = NetworkClientInfo::GetByClientID(_network_own_client_id);
00394           if (cio == NULL) break;
00395 
00396           ShowNetworkChatQueryWindow(DESTTYPE_TEAM, cio->client_playas);
00397         }
00398         break;
00399 
00400       case GHK_CHAT_SERVER: // send text to the server
00401         if (_networking && !_network_server) {
00402           ShowNetworkChatQueryWindow(DESTTYPE_CLIENT, CLIENT_ID_SERVER);
00403         }
00404         break;
00405 #endif
00406 
00407       default: return ES_NOT_HANDLED;
00408     }
00409     return ES_HANDLED;
00410   }
00411 
00412   virtual void OnScroll(Point delta)
00413   {
00414     this->viewport->scrollpos_x += ScaleByZoom(delta.x, this->viewport->zoom);
00415     this->viewport->scrollpos_y += ScaleByZoom(delta.y, this->viewport->zoom);
00416     this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x;
00417     this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y;
00418   }
00419 
00420   virtual void OnMouseWheel(int wheel)
00421   {
00422     if (_settings_client.gui.scrollwheel_scrolling == 0) {
00423       ZoomInOrOutToCursorWindow(wheel < 0, this);
00424     }
00425   }
00426 
00427   virtual void OnResize()
00428   {
00429     if (this->viewport != NULL) {
00430       NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(MW_VIEWPORT);
00431       nvp->UpdateViewportCoordinates(this);
00432     }
00433   }
00434 
00440   virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
00441   {
00442     if (!gui_scope) return;
00443     /* Forward the message to the appropiate toolbar (ingame or scenario editor) */
00444     InvalidateWindowData(WC_MAIN_TOOLBAR, 0, data, true);
00445   }
00446 
00447   static Hotkey<MainWindow> global_hotkeys[];
00448 };
00449 
00450 const uint16 _ghk_quit_keys[] = {'Q' | WKC_CTRL, 'Q' | WKC_META, 0};
00451 const uint16 _ghk_abandon_keys[] = {'W' | WKC_CTRL, 'W' | WKC_META, 0};
00452 const uint16 _ghk_chat_keys[] = {WKC_RETURN, 'T', 0};
00453 const uint16 _ghk_chat_all_keys[] = {WKC_SHIFT | WKC_RETURN, WKC_SHIFT | 'T', 0};
00454 const uint16 _ghk_chat_company_keys[] = {WKC_CTRL | WKC_RETURN, WKC_CTRL | 'T', 0};
00455 const uint16 _ghk_chat_server_keys[] = {WKC_CTRL | WKC_SHIFT | WKC_RETURN, WKC_CTRL | WKC_SHIFT | 'T', 0};
00456 
00457 Hotkey<MainWindow> MainWindow::global_hotkeys[] = {
00458   Hotkey<MainWindow>(_ghk_quit_keys, "quit", GHK_QUIT),
00459   Hotkey<MainWindow>(_ghk_abandon_keys, "abandon", GHK_ABANDON),
00460   Hotkey<MainWindow>(WKC_BACKQUOTE, "console", GHK_CONSOLE),
00461   Hotkey<MainWindow>('B' | WKC_CTRL, "bounding_boxes", GHK_BOUNDING_BOXES),
00462   Hotkey<MainWindow>('C', "center", GHK_CENTER),
00463   Hotkey<MainWindow>('Z', "center_zoom", GHK_CENTER_ZOOM),
00464   Hotkey<MainWindow>(WKC_ESC, "reset_object_to_place", GHK_RESET_OBJECT_TO_PLACE),
00465   Hotkey<MainWindow>(WKC_DELETE, "delete_windows", GHK_DELETE_WINDOWS),
00466   Hotkey<MainWindow>(WKC_DELETE | WKC_SHIFT, "delete_all_windows", GHK_DELETE_NONVITAL_WINDOWS),
00467   Hotkey<MainWindow>('R' | WKC_CTRL, "refresh_screen", GHK_REFRESH_SCREEN),
00468 #if defined(_DEBUG)
00469   Hotkey<MainWindow>('0' | WKC_ALT, "crash_game", GHK_CRASH),
00470   Hotkey<MainWindow>('1' | WKC_ALT, "money", GHK_MONEY),
00471   Hotkey<MainWindow>('2' | WKC_ALT, "update_coordinates", GHK_UPDATE_COORDS),
00472 #endif
00473   Hotkey<MainWindow>('1' | WKC_CTRL, "transparency_signs", GHK_TOGGLE_TRANSPARENCY),
00474   Hotkey<MainWindow>('2' | WKC_CTRL, "transparency_trees", GHK_TOGGLE_TRANSPARENCY + 1),
00475   Hotkey<MainWindow>('3' | WKC_CTRL, "transparency_houses", GHK_TOGGLE_TRANSPARENCY + 2),
00476   Hotkey<MainWindow>('4' | WKC_CTRL, "transparency_industries", GHK_TOGGLE_TRANSPARENCY + 3),
00477   Hotkey<MainWindow>('5' | WKC_CTRL, "transparency_buildings", GHK_TOGGLE_TRANSPARENCY + 4),
00478   Hotkey<MainWindow>('6' | WKC_CTRL, "transparency_bridges", GHK_TOGGLE_TRANSPARENCY + 5),
00479   Hotkey<MainWindow>('7' | WKC_CTRL, "transparency_structures", GHK_TOGGLE_TRANSPARENCY + 6),
00480   Hotkey<MainWindow>('8' | WKC_CTRL, "transparency_catenary", GHK_TOGGLE_TRANSPARENCY + 7),
00481   Hotkey<MainWindow>('9' | WKC_CTRL, "transparency_loading", GHK_TOGGLE_TRANSPARENCY + 8),
00482   Hotkey<MainWindow>('1' | WKC_CTRL | WKC_SHIFT, "invisibility_signs", GHK_TOGGLE_INVISIBILITY),
00483   Hotkey<MainWindow>('2' | WKC_CTRL | WKC_SHIFT, "invisibility_trees", GHK_TOGGLE_INVISIBILITY + 1),
00484   Hotkey<MainWindow>('3' | WKC_CTRL | WKC_SHIFT, "invisibility_houses", GHK_TOGGLE_INVISIBILITY + 2),
00485   Hotkey<MainWindow>('4' | WKC_CTRL | WKC_SHIFT, "invisibility_industries", GHK_TOGGLE_INVISIBILITY + 3),
00486   Hotkey<MainWindow>('5' | WKC_CTRL | WKC_SHIFT, "invisibility_buildings", GHK_TOGGLE_INVISIBILITY + 4),
00487   Hotkey<MainWindow>('6' | WKC_CTRL | WKC_SHIFT, "invisibility_bridges", GHK_TOGGLE_INVISIBILITY + 5),
00488   Hotkey<MainWindow>('7' | WKC_CTRL | WKC_SHIFT, "invisibility_structures", GHK_TOGGLE_INVISIBILITY + 6),
00489   Hotkey<MainWindow>('8' | WKC_CTRL | WKC_SHIFT, "invisibility_catenary", GHK_TOGGLE_INVISIBILITY + 7),
00490   Hotkey<MainWindow>('X' | WKC_CTRL, "transparency_toolbar", GHK_TRANSPARENCY_TOOLBAR),
00491   Hotkey<MainWindow>('X', "toggle_transparency", GHK_TRANSPARANCY),
00492 #ifdef ENABLE_NETWORK
00493   Hotkey<MainWindow>(_ghk_chat_keys, "chat", GHK_CHAT),
00494   Hotkey<MainWindow>(_ghk_chat_all_keys, "chat_all", GHK_CHAT_ALL),
00495   Hotkey<MainWindow>(_ghk_chat_company_keys, "chat_company", GHK_CHAT_COMPANY),
00496   Hotkey<MainWindow>(_ghk_chat_server_keys, "chat_server", GHK_CHAT_SERVER),
00497 #endif
00498   HOTKEY_LIST_END(MainWindow)
00499 };
00500 Hotkey<MainWindow> *_global_hotkeys = MainWindow::global_hotkeys;
00501 
00507 bool IsQuitKey(uint16 keycode)
00508 {
00509   int num = CheckHotkeyMatch<MainWindow>(_global_hotkeys, keycode, NULL);
00510   return num == GHK_QUIT;
00511 }
00512 
00513 
00514 void ShowSelectGameWindow();
00515 
00519 void SetupColoursAndInitialWindow()
00520 {
00521   for (uint i = 0; i != 16; i++) {
00522     const byte *b = GetNonSprite(PALETTE_RECOLOUR_START + i, ST_RECOLOUR);
00523 
00524     assert(b);
00525     memcpy(_colour_gradient[i], b + 0xC6, sizeof(_colour_gradient[i]));
00526   }
00527 
00528   new MainWindow;
00529 
00530   /* XXX: these are not done */
00531   switch (_game_mode) {
00532     default: NOT_REACHED();
00533     case GM_MENU:
00534       ShowSelectGameWindow();
00535       break;
00536 
00537     case GM_NORMAL:
00538     case GM_EDITOR:
00539       ShowVitalWindows();
00540       break;
00541   }
00542 }
00543 
00547 void ShowVitalWindows()
00548 {
00549   AllocateToolbar();
00550 
00551   /* Status bad only for normal games */
00552   if (_game_mode == GM_EDITOR) return;
00553 
00554   ShowStatusBar();
00555 }
00556 
00561 void GameSizeChanged()
00562 {
00563   _cur_resolution.width  = _screen.width;
00564   _cur_resolution.height = _screen.height;
00565   ScreenSizeChanged();
00566   RelocateAllWindows(_screen.width, _screen.height);
00567   MarkWholeScreenDirty();
00568 }