00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "stdafx.h"
00013 #include "error.h"
00014 #include "gui.h"
00015 #include "window_gui.h"
00016 #include "textbuf_gui.h"
00017 #include "network/network.h"
00018 #include "genworld.h"
00019 #include "network/network_gui.h"
00020 #include "network/network_content.h"
00021 #include "landscape_type.h"
00022 #include "strings_func.h"
00023 #include "fios.h"
00024 #include "ai/ai_gui.hpp"
00025 #include "gfx_func.h"
00026 #include "core/geometry_func.hpp"
00027 #include "language.h"
00028 #include "rev.h"
00029 #include "highscore.h"
00030
00031 #include "widgets/intro_widget.h"
00032
00033 #include "table/strings.h"
00034 #include "table/sprites.h"
00035
00036 struct SelectGameWindow : public Window {
00037
00038 SelectGameWindow(WindowDesc *desc) : Window(desc)
00039 {
00040 this->CreateNestedTree();
00041 this->FinishInitNested(0);
00042 this->OnInvalidateData();
00043 }
00044
00050 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
00051 {
00052 if (!gui_scope) return;
00053 this->SetWidgetLoweredState(WID_SGI_TEMPERATE_LANDSCAPE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
00054 this->SetWidgetLoweredState(WID_SGI_ARCTIC_LANDSCAPE, _settings_newgame.game_creation.landscape == LT_ARCTIC);
00055 this->SetWidgetLoweredState(WID_SGI_TROPIC_LANDSCAPE, _settings_newgame.game_creation.landscape == LT_TROPIC);
00056 this->SetWidgetLoweredState(WID_SGI_TOYLAND_LANDSCAPE, _settings_newgame.game_creation.landscape == LT_TOYLAND);
00057 }
00058
00059 virtual void OnInit()
00060 {
00061 bool missing = _current_language->missing >= _settings_client.gui.missing_strings_threshold && !IsReleasedVersion();
00062 this->GetWidget<NWidgetStacked>(WID_SGI_TRANSLATION_SELECTION)->SetDisplayedPlane(missing ? 0 : SZSP_NONE);
00063 }
00064
00065 virtual void DrawWidget(const Rect &r, int widget) const
00066 {
00067 switch (widget) {
00068 case WID_SGI_TRANSLATION:
00069 SetDParam(0, _current_language->missing);
00070 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_INTRO_TRANSLATION, TC_FROMSTRING, SA_CENTER);
00071 break;
00072 }
00073 }
00074
00075 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
00076 {
00077 switch (widget) {
00078 case WID_SGI_TRANSLATION: {
00079 SetDParam(0, _current_language->missing);
00080 int height = GetStringHeight(STR_INTRO_TRANSLATION, size->width);
00081 if (height > 3 * FONT_HEIGHT_NORMAL) {
00082
00083 Dimension textdim = GetStringBoundingBox(STR_INTRO_TRANSLATION);
00084 textdim.height *= 3;
00085 textdim.width -= textdim.width / 2;
00086 *size = maxdim(*size, textdim);
00087 } else {
00088 size->height = height + padding.height;
00089 }
00090 break;
00091 }
00092 }
00093 }
00094
00095 virtual void OnClick(Point pt, int widget, int click_count)
00096 {
00097 #ifdef ENABLE_NETWORK
00098
00099
00100 if (IsInsideMM(widget, WID_SGI_GENERATE_GAME, WID_SGI_EDIT_SCENARIO + 1)) _is_network_server = false;
00101 #endif
00102
00103 switch (widget) {
00104 case WID_SGI_GENERATE_GAME:
00105 if (_ctrl_pressed) {
00106 StartNewGameWithoutGUI(GENERATE_NEW_SEED);
00107 } else {
00108 ShowGenerateLandscape();
00109 }
00110 break;
00111
00112 case WID_SGI_LOAD_GAME: ShowSaveLoadDialog(SLD_LOAD_GAME); break;
00113 case WID_SGI_PLAY_SCENARIO: ShowSaveLoadDialog(SLD_LOAD_SCENARIO); break;
00114 case WID_SGI_PLAY_HEIGHTMAP: ShowSaveLoadDialog(SLD_LOAD_HEIGHTMAP); break;
00115 case WID_SGI_EDIT_SCENARIO: StartScenarioEditor(); break;
00116
00117 case WID_SGI_PLAY_NETWORK:
00118 if (!_network_available) {
00119 ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
00120 } else {
00121 ShowNetworkGameWindow();
00122 }
00123 break;
00124
00125 case WID_SGI_TEMPERATE_LANDSCAPE: case WID_SGI_ARCTIC_LANDSCAPE:
00126 case WID_SGI_TROPIC_LANDSCAPE: case WID_SGI_TOYLAND_LANDSCAPE:
00127 SetNewLandscapeType(widget - WID_SGI_TEMPERATE_LANDSCAPE);
00128 break;
00129
00130 case WID_SGI_OPTIONS: ShowGameOptions(); break;
00131 case WID_SGI_HIGHSCORE: ShowHighscoreTable(); break;
00132 case WID_SGI_SETTINGS_OPTIONS:ShowGameSettings(); break;
00133 case WID_SGI_GRF_SETTINGS: ShowNewGRFSettings(true, true, false, &_grfconfig_newgame); break;
00134 case WID_SGI_CONTENT_DOWNLOAD:
00135 if (!_network_available) {
00136 ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
00137 } else {
00138 ShowNetworkContentListWindow();
00139 }
00140 break;
00141 case WID_SGI_AI_SETTINGS: ShowAIConfigWindow(); break;
00142 case WID_SGI_EXIT: HandleExitGameRequest(); break;
00143 }
00144 }
00145 };
00146
00147 static const NWidgetPart _nested_select_game_widgets[] = {
00148 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_INTRO_CAPTION, STR_NULL),
00149 NWidget(WWT_PANEL, COLOUR_BROWN),
00150 NWidget(NWID_SPACER), SetMinimalSize(0, 8),
00151
00152
00153 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
00154 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_GENERATE_GAME), SetMinimalSize(158, 12),
00155 SetDataTip(STR_INTRO_NEW_GAME, STR_INTRO_TOOLTIP_NEW_GAME), SetPadding(0, 0, 0, 10), SetFill(1, 0),
00156 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_LOAD_GAME), SetMinimalSize(158, 12),
00157 SetDataTip(STR_INTRO_LOAD_GAME, STR_INTRO_TOOLTIP_LOAD_GAME), SetPadding(0, 10, 0, 0), SetFill(1, 0),
00158 EndContainer(),
00159
00160 NWidget(NWID_SPACER), SetMinimalSize(0, 6),
00161
00162
00163 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
00164 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_PLAY_SCENARIO), SetMinimalSize(158, 12),
00165 SetDataTip(STR_INTRO_PLAY_SCENARIO, STR_INTRO_TOOLTIP_PLAY_SCENARIO), SetPadding(0, 0, 0, 10), SetFill(1, 0),
00166 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_PLAY_HEIGHTMAP), SetMinimalSize(158, 12),
00167 SetDataTip(STR_INTRO_PLAY_HEIGHTMAP, STR_INTRO_TOOLTIP_PLAY_HEIGHTMAP), SetPadding(0, 10, 0, 0), SetFill(1, 0),
00168 EndContainer(),
00169
00170 NWidget(NWID_SPACER), SetMinimalSize(0, 6),
00171
00172
00173 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
00174 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_EDIT_SCENARIO), SetMinimalSize(158, 12),
00175 SetDataTip(STR_INTRO_SCENARIO_EDITOR, STR_INTRO_TOOLTIP_SCENARIO_EDITOR), SetPadding(0, 0, 0, 10), SetFill(1, 0),
00176 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_PLAY_NETWORK), SetMinimalSize(158, 12),
00177 SetDataTip(STR_INTRO_MULTIPLAYER, STR_INTRO_TOOLTIP_MULTIPLAYER), SetPadding(0, 10, 0, 0), SetFill(1, 0),
00178 EndContainer(),
00179
00180 NWidget(NWID_SPACER), SetMinimalSize(0, 7),
00181
00182
00183 NWidget(NWID_HORIZONTAL),
00184 NWidget(NWID_SPACER), SetMinimalSize(10, 0), SetFill(1, 0),
00185 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_SGI_TEMPERATE_LANDSCAPE), SetMinimalSize(77, 55),
00186 SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
00187 NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
00188 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_SGI_ARCTIC_LANDSCAPE), SetMinimalSize(77, 55),
00189 SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
00190 NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
00191 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_SGI_TROPIC_LANDSCAPE), SetMinimalSize(77, 55),
00192 SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
00193 NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
00194 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_SGI_TOYLAND_LANDSCAPE), SetMinimalSize(77, 55),
00195 SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
00196 NWidget(NWID_SPACER), SetMinimalSize(10, 0), SetFill(1, 0),
00197 EndContainer(),
00198
00199 NWidget(NWID_SPACER), SetMinimalSize(0, 7),
00200 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SGI_TRANSLATION_SELECTION),
00201 NWidget(NWID_VERTICAL),
00202 NWidget(WWT_EMPTY, COLOUR_ORANGE, WID_SGI_TRANSLATION), SetMinimalSize(316, 12), SetFill(1, 0), SetPadding(0, 10, 7, 10),
00203 EndContainer(),
00204 EndContainer(),
00205
00206
00207 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
00208 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_OPTIONS), SetMinimalSize(158, 12),
00209 SetDataTip(STR_INTRO_GAME_OPTIONS, STR_INTRO_TOOLTIP_GAME_OPTIONS), SetPadding(0, 0, 0, 10), SetFill(1, 0),
00210 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_SETTINGS_OPTIONS), SetMinimalSize(158, 12),
00211 SetDataTip(STR_INTRO_ADVANCED_SETTINGS, STR_INTRO_TOOLTIP_ADVANCED_SETTINGS), SetPadding(0, 10, 0, 0), SetFill(1, 0),
00212 EndContainer(),
00213
00214 NWidget(NWID_SPACER), SetMinimalSize(0, 6),
00215
00216
00217 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
00218 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_AI_SETTINGS), SetMinimalSize(158, 12),
00219 SetDataTip(STR_INTRO_SCRIPT_SETTINGS, STR_INTRO_TOOLTIP_SCRIPT_SETTINGS), SetPadding(0, 0, 0, 10), SetFill(1, 0),
00220 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_GRF_SETTINGS), SetMinimalSize(158, 12),
00221 SetDataTip(STR_INTRO_NEWGRF_SETTINGS, STR_INTRO_TOOLTIP_NEWGRF_SETTINGS), SetPadding(0, 10, 0, 0), SetFill(1, 0),
00222 EndContainer(),
00223
00224 NWidget(NWID_SPACER), SetMinimalSize(0, 6),
00225
00226
00227 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
00228 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_CONTENT_DOWNLOAD), SetMinimalSize(158, 12),
00229 SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT), SetPadding(0, 0, 0, 10), SetFill(1, 0),
00230 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_HIGHSCORE), SetMinimalSize(158, 12),
00231 SetDataTip(STR_INTRO_HIGHSCORE, STR_INTRO_TOOLTIP_HIGHSCORE), SetPadding(0, 10, 0, 0), SetFill(1, 0),
00232 EndContainer(),
00233
00234 NWidget(NWID_SPACER), SetMinimalSize(0, 6),
00235
00236
00237 NWidget(NWID_HORIZONTAL),
00238 NWidget(NWID_SPACER), SetFill(1, 0),
00239 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_SGI_EXIT), SetMinimalSize(128, 12),
00240 SetDataTip(STR_INTRO_QUIT, STR_INTRO_TOOLTIP_QUIT),
00241 NWidget(NWID_SPACER), SetFill(1, 0),
00242 EndContainer(),
00243
00244 NWidget(NWID_SPACER), SetMinimalSize(0, 8),
00245
00246 EndContainer(),
00247 };
00248
00249 static WindowDesc _select_game_desc(
00250 WDP_CENTER, NULL, 0, 0,
00251 WC_SELECT_GAME, WC_NONE,
00252 0,
00253 _nested_select_game_widgets, lengthof(_nested_select_game_widgets)
00254 );
00255
00256 void ShowSelectGameWindow()
00257 {
00258 new SelectGameWindow(&_select_game_desc);
00259 }
00260
00261 static void AskExitGameCallback(Window *w, bool confirmed)
00262 {
00263 if (confirmed) _exit_game = true;
00264 }
00265
00266 void AskExitGame()
00267 {
00268 #if defined(_WIN32)
00269 SetDParam(0, STR_OSNAME_WINDOWS);
00270 #elif defined(__APPLE__)
00271 SetDParam(0, STR_OSNAME_OSX);
00272 #elif defined(__BEOS__)
00273 SetDParam(0, STR_OSNAME_BEOS);
00274 #elif defined(__HAIKU__)
00275 SetDParam(0, STR_OSNAME_HAIKU);
00276 #elif defined(__MORPHOS__)
00277 SetDParam(0, STR_OSNAME_MORPHOS);
00278 #elif defined(__AMIGA__)
00279 SetDParam(0, STR_OSNAME_AMIGAOS);
00280 #elif defined(__OS2__)
00281 SetDParam(0, STR_OSNAME_OS2);
00282 #elif defined(SUNOS)
00283 SetDParam(0, STR_OSNAME_SUNOS);
00284 #elif defined(DOS)
00285 SetDParam(0, STR_OSNAME_DOS);
00286 #else
00287 SetDParam(0, STR_OSNAME_UNIX);
00288 #endif
00289 ShowQuery(
00290 STR_QUIT_CAPTION,
00291 STR_QUIT_ARE_YOU_SURE_YOU_WANT_TO_EXIT_OPENTTD,
00292 NULL,
00293 AskExitGameCallback
00294 );
00295 }
00296
00297
00298 static void AskExitToGameMenuCallback(Window *w, bool confirmed)
00299 {
00300 if (confirmed) {
00301 _switch_mode = SM_MENU;
00302 ClearErrorMessages();
00303 }
00304 }
00305
00306 void AskExitToGameMenu()
00307 {
00308 ShowQuery(
00309 STR_ABANDON_GAME_CAPTION,
00310 (_game_mode != GM_EDITOR) ? STR_ABANDON_GAME_QUERY : STR_ABANDON_SCENARIO_QUERY,
00311 NULL,
00312 AskExitToGameMenuCallback
00313 );
00314 }