# intro_gui.cpp

Go to the documentation of this file.

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