# intro_gui.cpp

Go to the documentation of this file.

    00001 /* $Id: intro_gui.cpp 11994 2008-01-27 17:32:12Z maedhros $ */
    00002
    00005 #include "stdafx.h"
    00006 #include "openttd.h"
    00007 #include "gui.h"
    00008 #include "window_gui.h"
    00009 #include "textbuf_gui.h"
    00010 #include "network/network.h"
    00011 #include "variables.h"
    00012 #include "heightmap.h"
    00013 #include "genworld.h"
    00014 #include "network/network_gui.h"
    00015 #include "newgrf.h"
    00016 #include "strings_func.h"
    00017 #include "window_func.h"
    00018 #include "fios.h"
    00019 #include "gfx_func.h"
    00020 #include "settings_type.h"
    00021
    00022 #include "table/strings.h"
    00023 #include "table/sprites.h"
    00024
    00025 static const Widget _select_game_widgets[] = {
    00026 {    WWT_CAPTION, RESIZE_NONE, 13,   0, 335,   0,  13, STR_0307_OPENTTD,         STR_NULL},
    00027 {      WWT_PANEL, RESIZE_NONE, 13,   0, 335,  14, 194, 0x0,                      STR_NULL},
    00028 { WWT_PUSHTXTBTN, RESIZE_NONE, 12,  10, 167,  22,  33, STR_0140_NEW_GAME,        STR_02FB_START_A_NEW_GAME},
    00029 { WWT_PUSHTXTBTN, RESIZE_NONE, 12, 168, 325,  22,  33, STR_0141_LOAD_GAME,       STR_02FC_LOAD_A_SAVED_GAME},
    00030 { WWT_PUSHTXTBTN, RESIZE_NONE, 12,  10, 167,  40,  51, STR_029A_PLAY_SCENARIO,   STR_0303_START_A_NEW_GAME_USING},
    00031 { WWT_PUSHTXTBTN, RESIZE_NONE, 12, 168, 325,  40,  51, STR_PLAY_HEIGHTMAP,       STR_PLAY_HEIGHTMAP_HINT},
    00032 { WWT_PUSHTXTBTN, RESIZE_NONE, 12,  10, 167,  58,  69, STR_SCENARIO_EDITOR,      STR_02FE_CREATE_A_CUSTOMIZED_GAME},
    00033 { WWT_PUSHTXTBTN, RESIZE_NONE, 12, 168, 325,  58,  69, STR_MULTIPLAYER,          STR_0300_SELECT_MULTIPLAYER_GAME},
    00034
    00035 {   WWT_IMGBTN_2, RESIZE_NONE, 12,  10,  86,  77, 131, SPR_SELECT_TEMPERATE,     STR_030E_SELECT_TEMPERATE_LANDSCAPE},
    00036 {   WWT_IMGBTN_2, RESIZE_NONE, 12,  90, 166,  77, 131, SPR_SELECT_SUB_ARCTIC,    STR_030F_SELECT_SUB_ARCTIC_LANDSCAPE},
    00037 {   WWT_IMGBTN_2, RESIZE_NONE, 12, 170, 246,  77, 131, SPR_SELECT_SUB_TROPICAL,  STR_0310_SELECT_SUB_TROPICAL_LANDSCAPE},
    00038 {   WWT_IMGBTN_2, RESIZE_NONE, 12, 250, 326,  77, 131, SPR_SELECT_TOYLAND,       STR_0311_SELECT_TOYLAND_LANDSCAPE},
    00039
    00040 { WWT_PUSHTXTBTN, RESIZE_NONE, 12,  10, 167, 139, 150, STR_0148_GAME_OPTIONS,    STR_0301_DISPLAY_GAME_OPTIONS},
    00041 { WWT_PUSHTXTBTN, RESIZE_NONE, 12, 168, 325, 139, 150, STR_01FE_DIFFICULTY,      STR_0302_DISPLAY_DIFFICULTY_OPTIONS},
    00042 { WWT_PUSHTXTBTN, RESIZE_NONE, 12,  10, 167, 157, 168, STR_CONFIG_PATCHES,       STR_CONFIG_PATCHES_TIP},
    00043 { WWT_PUSHTXTBTN, RESIZE_NONE, 12, 168, 325, 157, 168, STR_NEWGRF_SETTINGS_BUTTON, STR_NULL},
    00044
    00045 { WWT_PUSHTXTBTN, RESIZE_NONE, 12, 104, 231, 175, 186, STR_0304_QUIT,            STR_0305_QUIT_OPENTTD},
    00046 {   WIDGETS_END},
    00047 };
    00048
    00049 static inline void SetNewLandscapeType(byte landscape)
    00050 {
    00051   _opt_newgame.landscape = landscape;
    00052   InvalidateWindowClasses(WC_SELECT_GAME);
    00053 }
    00054
    00055 enum SelectGameIntroWidgets {
    00056   SGI_GENERATE_GAME = 2,
    00057   SGI_LOAD_GAME,
    00058   SGI_PLAY_SCENARIO,
    00059   SGI_PLAY_HEIGHTMAP,
    00060   SGI_EDIT_SCENARIO,
    00061   SGI_PLAY_NETWORK,
    00062   SGI_TEMPERATE_LANDSCAPE,
    00063   SGI_ARCTIC_LANDSCAPE,
    00064   SGI_TROPIC_LANDSCAPE,
    00065   SGI_TOYLAND_LANDSCAPE,
    00066   SGI_OPTIONS,
    00067   SGI_DIFFICULTIES,
    00068   SGI_PATCHES_OPTIONS,
    00069   SGI_GRF_SETTINGS,
    00070   SGI_EXIT,
    00071 };
    00072
    00073 static void SelectGameWndProc(Window *w, WindowEvent *e)
    00074 {
    00075   switch (e->event) {
    00076     case WE_CREATE: w->LowerWidget(_opt_newgame.landscape + 8); break;
    00077
    00078     case WE_PAINT:
    00079       w->SetWidgetLoweredState(SGI_TEMPERATE_LANDSCAPE, _opt_newgame.landscape == LT_TEMPERATE);
    00080       w->SetWidgetLoweredState(SGI_ARCTIC_LANDSCAPE, _opt_newgame.landscape == LT_ARCTIC);
    00081       w->SetWidgetLoweredState(SGI_TROPIC_LANDSCAPE, _opt_newgame.landscape == LT_TROPIC);
    00082       w->SetWidgetLoweredState(SGI_TOYLAND_LANDSCAPE, _opt_newgame.landscape == LT_TOYLAND);
    00083       SetDParam(0, STR_6801_EASY + _opt_newgame.diff_level);
    00084       DrawWindowWidgets(w);
    00085       break;
    00086
    00087     case WE_CLICK:
    00088 #ifdef ENABLE_NETWORK
    00089       /* Do not create a network server when you (just) have closed one of the game
    00090        * creation/load windows for the network server. */
    00091       if (SGI_GENERATE_GAME <= e->we.click.widget && e->we.click.widget <= SGI_EDIT_SCENARIO) _is_network_server = false;
    00092 #endif /* ENABLE_NETWORK */
    00093
    00094       switch (e->we.click.widget) {
    00095         case SGI_GENERATE_GAME:  ShowGenerateLandscape(); break;
    00096         case SGI_LOAD_GAME:      ShowSaveLoadDialog(SLD_LOAD_GAME); break;
    00097         case SGI_PLAY_SCENARIO:  ShowSaveLoadDialog(SLD_LOAD_SCENARIO); break;
    00098         case SGI_PLAY_HEIGHTMAP: ShowSaveLoadDialog(SLD_LOAD_HEIGHTMAP); break;
    00099         case SGI_EDIT_SCENARIO:  StartScenarioEditor(); break;
    00100
    00101         case SGI_PLAY_NETWORK:
    00102           if (!_network_available) {
    00103             ShowErrorMessage(INVALID_STRING_ID, STR_NETWORK_ERR_NOTAVAILABLE, 0, 0);
    00104           } else {
    00105             ShowNetworkGameWindow();
    00106           }
    00107           break;
    00108
    00109         case SGI_TEMPERATE_LANDSCAPE: case SGI_ARCTIC_LANDSCAPE:
    00110         case SGI_TROPIC_LANDSCAPE: case SGI_TOYLAND_LANDSCAPE:
    00111           w->RaiseWidget(_opt_newgame.landscape + SGI_TEMPERATE_LANDSCAPE);
    00112           SetNewLandscapeType(e->we.click.widget - SGI_TEMPERATE_LANDSCAPE);
    00113           break;
    00114
    00115         case SGI_OPTIONS:         ShowGameOptions(); break;
    00116         case SGI_DIFFICULTIES:    ShowGameDifficulty(); break;
    00117         case SGI_PATCHES_OPTIONS: ShowPatchesSelection(); break;
    00118         case SGI_GRF_SETTINGS:    ShowNewGRFSettings(true, true, false, &_grfconfig_newgame); break;
    00119         case SGI_EXIT:            HandleExitGameRequest(); break;
    00120       }
    00121       break;
    00122   }
    00123 }
    00124
    00125 static const WindowDesc _select_game_desc = {
    00126   WDP_CENTER, WDP_CENTER, 336, 195, 336, 195,
    00127   WC_SELECT_GAME, WC_NONE,
    00128   WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
    00129   _select_game_widgets,
    00130   SelectGameWndProc
    00131 };
    00132
    00133 void ShowSelectGameWindow()
    00134 {
    00135   AllocateWindowDesc(&_select_game_desc);
    00136 }
    00137
    00138 static void AskExitGameCallback(Window *w, bool confirmed)
    00139 {
    00140   if (confirmed) _exit_game = true;
    00141 }
    00142
    00143 void AskExitGame()
    00144 {
    00145 #if defined(_WIN32)
    00146     SetDParam(0, STR_OSNAME_WINDOWS);
    00147 #elif defined(__APPLE__)
    00148     SetDParam(0, STR_OSNAME_OSX);
    00149 #elif defined(__BEOS__)
    00150     SetDParam(0, STR_OSNAME_BEOS);
    00151 #elif defined(__MORPHOS__)
    00152     SetDParam(0, STR_OSNAME_MORPHOS);
    00153 #elif defined(__AMIGA__)
    00154     SetDParam(0, STR_OSNAME_AMIGAOS);
    00155 #elif defined(__OS2__)
    00156     SetDParam(0, STR_OSNAME_OS2);
    00157 #elif defined(SUNOS)
    00158     SetDParam(0, STR_OSNAME_SUNOS);
    00159 #else
    00160     SetDParam(0, STR_OSNAME_UNIX);
    00161 #endif
    00162   ShowQuery(
    00163     STR_00C7_QUIT,
    00164     STR_00CA_ARE_YOU_SURE_YOU_WANT_TO,
    00165     NULL,
    00166     AskExitGameCallback
    00167   );
    00168 }
    00169
    00170
    00171 static void AskExitToGameMenuCallback(Window *w, bool confirmed)
    00172 {
    00173   if (confirmed) _switch_mode = SM_MENU;
    00174 }
    00175
    00176 void AskExitToGameMenu()
    00177 {
    00178   ShowQuery(
    00179     STR_0161_QUIT_GAME,
    00180     (_game_mode != GM_EDITOR) ? STR_ABANDON_GAME_QUERY : STR_QUIT_SCENARIO_QUERY,
    00181     NULL,
    00182     AskExitToGameMenuCallback
    00183   );
    00184 }