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