main_gui.cpp

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