# intro_gui.cpp

Go to the documentation of this file.

    00001 /* $Id: intro_gui.cpp 15473 2009-02-13 21:24:21Z rubidium $ */
    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 "genworld.h"
    00013 #include "network/network_gui.h"
    00014 #include "network/network_content.h"
    00015 #include "landscape_type.h"
    00016 #include "strings_func.h"
    00017 #include "window_func.h"
    00018 #include "fios.h"
    00019 #include "settings_type.h"
    00020 #include "functions.h"
    00021 #include "newgrf_config.h"
    00022 #include "ai/ai_gui.hpp"
    00023
    00024 #include "table/strings.h"
    00025 #include "table/sprites.h"
    00026
    00027 static const Widget _select_game_widgets[] = {
    00028 {     WWT_CAPTION,  RESIZE_NONE,  COLOUR_BROWN,     0,  335,    0,   13,  STR_0307_OPENTTD,           STR_NULL},
    00029 {       WWT_PANEL,  RESIZE_NONE,  COLOUR_BROWN,     0,  335,   14,  212,  0x0,                        STR_NULL},
    00030 {  WWT_PUSHTXTBTN,  RESIZE_NONE,  COLOUR_ORANGE,   10,  167,   22,   33,  STR_0140_NEW_GAME,          STR_02FB_START_A_NEW_GAME},
    00031 {  WWT_PUSHTXTBTN,  RESIZE_NONE,  COLOUR_ORANGE,  168,  325,   22,   33,  STR_0141_LOAD_GAME,         STR_02FC_LOAD_A_SAVED_GAME},
    00032 {  WWT_PUSHTXTBTN,  RESIZE_NONE,  COLOUR_ORANGE,   10,  167,   40,   51,  STR_029A_PLAY_SCENARIO,     STR_0303_START_A_NEW_GAME_USING},
    00033 {  WWT_PUSHTXTBTN,  RESIZE_NONE,  COLOUR_ORANGE,  168,  325,   40,   51,  STR_PLAY_HEIGHTMAP,         STR_PLAY_HEIGHTMAP_HINT},
    00034 {  WWT_PUSHTXTBTN,  RESIZE_NONE,  COLOUR_ORANGE,   10,  167,   58,   69,  STR_SCENARIO_EDITOR,        STR_02FE_CREATE_A_CUSTOMIZED_GAME},
    00035 {  WWT_PUSHTXTBTN,  RESIZE_NONE,  COLOUR_ORANGE,  168,  325,   58,   69,  STR_MULTIPLAYER,            STR_0300_SELECT_MULTIPLAYER_GAME},
    00036
    00037 {    WWT_IMGBTN_2,  RESIZE_NONE,  COLOUR_ORANGE,   10,   86,   77,  131,  SPR_SELECT_TEMPERATE,       STR_030E_SELECT_TEMPERATE_LANDSCAPE},
    00038 {    WWT_IMGBTN_2,  RESIZE_NONE,  COLOUR_ORANGE,   90,  166,   77,  131,  SPR_SELECT_SUB_ARCTIC,      STR_030F_SELECT_SUB_ARCTIC_LANDSCAPE},
    00039 {    WWT_IMGBTN_2,  RESIZE_NONE,  COLOUR_ORANGE,  170,  246,   77,  131,  SPR_SELECT_SUB_TROPICAL,    STR_0310_SELECT_SUB_TROPICAL_LANDSCAPE},
    00040 {    WWT_IMGBTN_2,  RESIZE_NONE,  COLOUR_ORANGE,  250,  326,   77,  131,  SPR_SELECT_TOYLAND,         STR_0311_SELECT_TOYLAND_LANDSCAPE},
    00041
    00042 {  WWT_PUSHTXTBTN,  RESIZE_NONE,  COLOUR_ORANGE,   10,  167,  139,  150,  STR_0148_GAME_OPTIONS,      STR_0301_DISPLAY_GAME_OPTIONS},
    00043 {  WWT_PUSHTXTBTN,  RESIZE_NONE,  COLOUR_ORANGE,  168,  325,  139,  150,  STR_01FE_DIFFICULTY,        STR_0302_DISPLAY_DIFFICULTY_OPTIONS},
    00044 {  WWT_PUSHTXTBTN,  RESIZE_NONE,  COLOUR_ORANGE,   10,  167,  157,  168,  STR_CONFIG_SETTING,         STR_CONFIG_SETTING_TIP},
    00045 {  WWT_PUSHTXTBTN,  RESIZE_NONE,  COLOUR_ORANGE,  168,  325,  157,  168,  STR_NEWGRF_SETTINGS_BUTTON, STR_NEWGRF_SETTINGS_BUTTON_TIP},
    00046
    00047 {  WWT_PUSHTXTBTN,  RESIZE_NONE,  COLOUR_ORANGE,   10,  167,  175,  186,  STR_CONTENT_INTRO_BUTTON,   STR_CONTENT_INTRO_BUTTON_TIP},
    00048 {  WWT_PUSHTXTBTN,  RESIZE_NONE,  COLOUR_ORANGE,  168,  325,  175,  186,  STR_AI_SETTINGS_BUTTON,     STR_AI_SETTINGS_BUTTON_TIP},
    00049
    00050 {  WWT_PUSHTXTBTN,  RESIZE_NONE,  COLOUR_ORANGE,  104,  231,  193,  204,  STR_0304_QUIT,              STR_0305_QUIT_OPENTTD},
    00051
    00052 {     WIDGETS_END},
    00053 };
    00054
    00055 static inline void SetNewLandscapeType(byte landscape)
    00056 {
    00057   _settings_newgame.game_creation.landscape = landscape;
    00058   InvalidateWindowClasses(WC_SELECT_GAME);
    00059 }
    00060
    00061 struct SelectGameWindow : public Window {
    00062 private:
    00063   enum SelectGameIntroWidgets {
    00064     SGI_GENERATE_GAME = 2,
    00065     SGI_LOAD_GAME,
    00066     SGI_PLAY_SCENARIO,
    00067     SGI_PLAY_HEIGHTMAP,
    00068     SGI_EDIT_SCENARIO,
    00069     SGI_PLAY_NETWORK,
    00070     SGI_TEMPERATE_LANDSCAPE,
    00071     SGI_ARCTIC_LANDSCAPE,
    00072     SGI_TROPIC_LANDSCAPE,
    00073     SGI_TOYLAND_LANDSCAPE,
    00074     SGI_OPTIONS,
    00075     SGI_DIFFICULTIES,
    00076     SGI_SETTINGS_OPTIONS,
    00077     SGI_GRF_SETTINGS,
    00078     SGI_CONTENT_DOWNLOAD,
    00079     SGI_AI_SETTINGS,
    00080     SGI_EXIT,
    00081   };
    00082
    00083 public:
    00084   SelectGameWindow(const WindowDesc *desc) : Window(desc)
    00085   {
    00086     this->LowerWidget(_settings_newgame.game_creation.landscape + SGI_TEMPERATE_LANDSCAPE);
    00087     this->FindWindowPlacementAndResize(desc);
    00088   }
    00089
    00090   virtual void OnPaint()
    00091   {
    00092     this->SetWidgetLoweredState(SGI_TEMPERATE_LANDSCAPE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
    00093     this->SetWidgetLoweredState(SGI_ARCTIC_LANDSCAPE,    _settings_newgame.game_creation.landscape == LT_ARCTIC);
    00094     this->SetWidgetLoweredState(SGI_TROPIC_LANDSCAPE,    _settings_newgame.game_creation.landscape == LT_TROPIC);
    00095     this->SetWidgetLoweredState(SGI_TOYLAND_LANDSCAPE,   _settings_newgame.game_creation.landscape == LT_TOYLAND);
    00096     SetDParam(0, STR_6801_EASY + _settings_newgame.difficulty.diff_level);
    00097     this->DrawWidgets();
    00098   }
    00099
    00100   virtual void OnClick(Point pt, int widget)
    00101   {
    00102 #ifdef ENABLE_NETWORK
    00103     /* Do not create a network server when you (just) have closed one of the game
    00104      * creation/load windows for the network server. */
    00105     if (IsInsideMM(widget, SGI_GENERATE_GAME, SGI_EDIT_SCENARIO + 1)) _is_network_server = false;
    00106 #endif /* ENABLE_NETWORK */
    00107
    00108     switch (widget) {
    00109       case SGI_GENERATE_GAME:  ShowGenerateLandscape(); break;
    00110       case SGI_LOAD_GAME:      ShowSaveLoadDialog(SLD_LOAD_GAME); break;
    00111       case SGI_PLAY_SCENARIO:  ShowSaveLoadDialog(SLD_LOAD_SCENARIO); break;
    00112       case SGI_PLAY_HEIGHTMAP: ShowSaveLoadDialog(SLD_LOAD_HEIGHTMAP); break;
    00113       case SGI_EDIT_SCENARIO:  StartScenarioEditor(); break;
    00114
    00115       case SGI_PLAY_NETWORK:
    00116         if (!_network_available) {
    00117           ShowErrorMessage(INVALID_STRING_ID, STR_NETWORK_ERR_NOTAVAILABLE, 0, 0);
    00118         } else {
    00119           ShowNetworkGameWindow();
    00120         }
    00121         break;
    00122
    00123       case SGI_TEMPERATE_LANDSCAPE: case SGI_ARCTIC_LANDSCAPE:
    00124       case SGI_TROPIC_LANDSCAPE: case SGI_TOYLAND_LANDSCAPE:
    00125         this->RaiseWidget(_settings_newgame.game_creation.landscape + SGI_TEMPERATE_LANDSCAPE);
    00126         SetNewLandscapeType(widget - SGI_TEMPERATE_LANDSCAPE);
    00127         break;
    00128
    00129       case SGI_OPTIONS:         ShowGameOptions(); break;
    00130       case SGI_DIFFICULTIES:    ShowGameDifficulty(); break;
    00131       case SGI_SETTINGS_OPTIONS:ShowGameSettings(); break;
    00132       case SGI_GRF_SETTINGS:    ShowNewGRFSettings(true, true, false, &_grfconfig_newgame); break;
    00133       case SGI_CONTENT_DOWNLOAD:
    00134         if (!_network_available) {
    00135           ShowErrorMessage(INVALID_STRING_ID, STR_NETWORK_ERR_NOTAVAILABLE, 0, 0);
    00136         } else {
    00137           ShowNetworkContentListWindow();
    00138         }
    00139         break;
    00140       case SGI_AI_SETTINGS:     ShowAIConfigWindow(); break;
    00141       case SGI_EXIT:            HandleExitGameRequest(); break;
    00142     }
    00143   }
    00144 };
    00145
    00146 static const WindowDesc _select_game_desc = {
    00147   WDP_CENTER, WDP_CENTER, 336, 213, 336, 213,
    00148   WC_SELECT_GAME, WC_NONE,
    00149   WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
    00150   _select_game_widgets,
    00151 };
    00152
    00153 void ShowSelectGameWindow()
    00154 {
    00155   new SelectGameWindow(&_select_game_desc);
    00156 }
    00157
    00158 static void AskExitGameCallback(Window *w, bool confirmed)
    00159 {
    00160   if (confirmed) _exit_game = true;
    00161 }
    00162
    00163 void AskExitGame()
    00164 {
    00165 #if defined(_WIN32)
    00166     SetDParam(0, STR_OSNAME_WINDOWS);
    00167 #elif defined(__APPLE__)
    00168     SetDParam(0, STR_OSNAME_OSX);
    00169 #elif defined(__BEOS__)
    00170     SetDParam(0, STR_OSNAME_BEOS);
    00171 #elif defined(__MORPHOS__)
    00172     SetDParam(0, STR_OSNAME_MORPHOS);
    00173 #elif defined(__AMIGA__)
    00174     SetDParam(0, STR_OSNAME_AMIGAOS);
    00175 #elif defined(__OS2__)
    00176     SetDParam(0, STR_OSNAME_OS2);
    00177 #elif defined(SUNOS)
    00178     SetDParam(0, STR_OSNAME_SUNOS);
    00179 #elif defined(DOS)
    00180     SetDParam(0, STR_OSNAME_DOS);
    00181 #else
    00182     SetDParam(0, STR_OSNAME_UNIX);
    00183 #endif
    00184   ShowQuery(
    00185     STR_00C7_QUIT,
    00186     STR_00CA_ARE_YOU_SURE_YOU_WANT_TO,
    00187     NULL,
    00188     AskExitGameCallback
    00189   );
    00190 }
    00191
    00192
    00193 static void AskExitToGameMenuCallback(Window *w, bool confirmed)
    00194 {
    00195   if (confirmed) _switch_mode = SM_MENU;
    00196 }
    00197
    00198 void AskExitToGameMenu()
    00199 {
    00200   ShowQuery(
    00201     STR_0161_QUIT_GAME,
    00202     (_game_mode != GM_EDITOR) ? STR_ABANDON_GAME_QUERY : STR_QUIT_SCENARIO_QUERY,
    00203     NULL,
    00204     AskExitToGameMenuCallback
    00205   );
    00206 }