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

Generated on Sun Jan 23 01:49:03 2011 for OpenTTD by  doxygen 1.6.1