# genworld_gui.cpp

Go to the documentation of this file.

    00001 /* $Id: genworld_gui.cpp 18586 2009-12-21 16:16:37Z rubidium $ */
    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 "openttd.h"
    00014 #include "heightmap.h"
    00015 #include "variables.h"
    00016 #include "debug.h"
    00017 #include "genworld.h"
    00018 #include "network/network.h"
    00019 #include "newgrf_config.h"
    00020 #include "strings_func.h"
    00021 #include "window_func.h"
    00022 #include "date_func.h"
    00023 #include "sound_func.h"
    00024 #include "fios.h"
    00025 #include "string_func.h"
    00026 #include "gfx_func.h"
    00027 #include "widgets/dropdown_type.h"
    00028 #include "widgets/dropdown_func.h"
    00029 #include "landscape_type.h"
    00030 #include "querystring_gui.h"
    00031 #include "town.h"
    00032 #include "thread/thread.h"
    00033 #include "settings_func.h"
    00034
    00035 #include "table/strings.h"
    00036 #include "table/sprites.h"
    00037
    00041 enum glwp_modes {
    00042   GLWP_GENERATE,
    00043   GLWP_HEIGHTMAP,
    00044   GLWP_SCENARIO,
    00045   GLWP_END
    00046 };
    00047
    00048 extern void SwitchToMode(SwitchMode new_mode);
    00049 extern void MakeNewgameSettingsLive();
    00050
    00051 static inline void SetNewLandscapeType(byte landscape)
    00052 {
    00053   _settings_newgame.game_creation.landscape = landscape;
    00054   SetWindowClassesDirty(WC_SELECT_GAME);
    00055   SetWindowClassesDirty(WC_GENERATE_LANDSCAPE);
    00056 }
    00057
    00058 enum GenerateLandscapeWindowWidgets {
    00059   GLAND_TEMPERATE,
    00060   GLAND_ARCTIC,
    00061   GLAND_TROPICAL,
    00062   GLAND_TOYLAND,
    00063
    00064   GLAND_MAPSIZE_X_PULLDOWN,
    00065   GLAND_MAPSIZE_Y_PULLDOWN,
    00066
    00067   GLAND_TOWN_PULLDOWN,
    00068   GLAND_INDUSTRY_PULLDOWN,
    00069
    00070   GLAND_RANDOM_EDITBOX,
    00071   GLAND_RANDOM_BUTTON,
    00072
    00073   GLAND_GENERATE_BUTTON,
    00074
    00075   GLAND_START_DATE_DOWN,
    00076   GLAND_START_DATE_TEXT,
    00077   GLAND_START_DATE_UP,
    00078
    00079   GLAND_SNOW_LEVEL_DOWN,
    00080   GLAND_SNOW_LEVEL_TEXT,
    00081   GLAND_SNOW_LEVEL_UP,
    00082
    00083   GLAND_TREE_PULLDOWN,
    00084   GLAND_LANDSCAPE_PULLDOWN,
    00085   GLAND_HEIGHTMAP_NAME_TEXT,
    00086   GLAND_HEIGHTMAP_NAME_SPACER,
    00087   GLAND_HEIGHTMAP_SIZE_TEXT,
    00088   GLAND_HEIGHTMAP_ROTATION_PULLDOWN,
    00089
    00090   GLAND_TERRAIN_PULLDOWN,
    00091   GLAND_WATER_PULLDOWN,
    00092   GLAND_SMOOTHNESS_PULLDOWN,
    00093   GLAND_VARIETY_PULLDOWN,
    00094
    00095   GLAND_BORDER_TYPES,
    00096   GLAND_BORDERS_RANDOM,
    00097   GLAND_WATER_NW,
    00098   GLAND_WATER_NE,
    00099   GLAND_WATER_SE,
    00100   GLAND_WATER_SW,
    00101 };
    00102
    00103 static const NWidgetPart _nested_generate_landscape_widgets[] = {
    00104   NWidget(NWID_HORIZONTAL),
    00105     NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
    00106     NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MAPGEN_WORLD_GENERATION_CAPTION, STR_NULL),
    00107   EndContainer(),
    00108   NWidget(WWT_PANEL, COLOUR_BROWN),
    00109     NWidget(NWID_SPACER), SetMinimalSize(0, 10),
    00110     /* Landscape selection. */
    00111     NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 10),
    00112       NWidget(NWID_SPACER), SetFill(1, 0),
    00113       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, GLAND_TEMPERATE), SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
    00114       NWidget(NWID_SPACER), SetFill(1, 0),
    00115       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, GLAND_ARCTIC), SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
    00116       NWidget(NWID_SPACER), SetFill(1, 0),
    00117       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, GLAND_TROPICAL), SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
    00118       NWidget(NWID_SPACER), SetFill(1, 0),
    00119       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, GLAND_TOYLAND), SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
    00120       NWidget(NWID_SPACER), SetFill(1, 0),
    00121     EndContainer(),
    00122     NWidget(NWID_SPACER), SetMinimalSize(0, 11),
    00123     NWidget(NWID_HORIZONTAL), SetPIP(10, 5, 10),
    00124       NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
    00125         /* Left column with labels. */
    00126         NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
    00127           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAPSIZE, STR_NULL), SetFill(1, 1),
    00128           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_LAND_GENERATOR, STR_NULL), SetFill(1, 1),
    00129           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_TOWNS, STR_NULL), SetFill(1, 1),
    00130           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TERRAIN_TYPE, STR_NULL), SetFill(1, 1),
    00131           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_RANDOM_SEED, STR_NULL), SetFill(1, 1),
    00132           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_QUANTITY_OF_SEA_LAKES, STR_NULL), SetFill(1, 1),
    00133           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TREE_PLACER, STR_NULL), SetFill(1, 1),
    00134           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_VARIETY, STR_NULL), SetFill(1, 1),
    00135           NWidget(WWT_TEXT, COLOUR_ORANGE, GLAND_BORDER_TYPES), SetDataTip(STR_MAPGEN_BORDER_TYPE, STR_NULL), SetFill(1, 1),
    00136         EndContainer(),
    00137         /* Widgets at the right of the labels. */
    00138         NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
    00139           /* Mapsize X * Y. */
    00140           NWidget(NWID_HORIZONTAL), SetPIP(0, 4, 0),
    00141             NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_MAPSIZE_X_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetFill(1, 0),
    00142             NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BY, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(1, 1),
    00143             NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_MAPSIZE_Y_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetFill(1, 0),
    00144           EndContainer(),
    00145           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_LANDSCAPE_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00146           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_TOWN_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00147           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_TERRAIN_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00148           NWidget(WWT_EDITBOX, COLOUR_WHITE, GLAND_RANDOM_EDITBOX), SetDataTip(STR_MAPGEN_RANDOM_SEED_OSKTITLE, STR_MAPGEN_RANDOM_SEED_HELP), SetFill(1, 1),
    00149           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_WATER_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00150           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_TREE_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00151           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_VARIETY_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00152           NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, GLAND_BORDERS_RANDOM), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00153         EndContainer(),
    00154       EndContainer(),
    00155       NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
    00156         NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
    00157           NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
    00158             NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetFill(1, 1),
    00159             NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SNOW_LINE_HEIGHT, STR_NULL), SetFill(1, 1),
    00160             NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_INDUSTRIES, STR_NULL), SetFill(1, 1),
    00161             NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SMOOTHNESS, STR_NULL), SetFill(1, 1),
    00162           EndContainer(),
    00163           NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
    00164             /* Starting date. */
    00165             NWidget(NWID_HORIZONTAL),
    00166               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_START_DATE_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_BACKWARD), SetFill(0, 1),
    00167               NWidget(WWT_TEXTBTN, COLOUR_ORANGE, GLAND_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL), SetFill(1, 0),
    00168               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_START_DATE_UP), SetDataTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_FORWARD), SetFill(0, 1),
    00169             EndContainer(),
    00170             /* Snow line. */
    00171             NWidget(NWID_HORIZONTAL),
    00172               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_SNOW_LEVEL_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_SNOW_LINE_DOWN), SetFill(0, 1),
    00173               NWidget(WWT_TEXTBTN, COLOUR_ORANGE, GLAND_SNOW_LEVEL_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL), SetFill(1, 0),
    00174               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_SNOW_LEVEL_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_SNOW_LINE_UP), SetFill(0, 1),
    00175             EndContainer(),
    00176             NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_INDUSTRY_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_JUST_STRING), SetFill(1, 0),
    00177             NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_SMOOTHNESS_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00178           EndContainer(),
    00179         EndContainer(),
    00180         NWidget(WWT_TEXTBTN, COLOUR_ORANGE, GLAND_RANDOM_BUTTON), SetDataTip(STR_MAPGEN_RANDOM, STR_MAPGEN_RANDOM_HELP), SetFill(1, 0),
    00181         NWidget(NWID_SPACER), SetFill(1, 1),
    00182         NWidget(WWT_TEXTBTN, COLOUR_GREEN, GLAND_GENERATE_BUTTON), SetMinimalSize(84, 30), SetDataTip(STR_MAPGEN_GENERATE, STR_NULL), SetFill(1, 0),
    00183       EndContainer(),
    00184     EndContainer(),
    00185     NWidget(NWID_SPACER), SetMinimalSize(0, 4),
    00186     /* Map borders buttons for each edge. */
    00187     NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 0, 10),
    00188       NWidget(NWID_HORIZONTAL), SetPIP(0, 0, 3),
    00189         NWidget(NWID_SPACER), SetFill(1, 1),
    00190         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NORTHWEST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
    00191       EndContainer(),
    00192       NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, GLAND_WATER_NW), SetDataTip(STR_JUST_STRING, STR_MAPGEN_NORTHWEST), SetFill(1, 1),
    00193       NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, GLAND_WATER_NE), SetDataTip(STR_JUST_STRING, STR_MAPGEN_NORTHEAST), SetFill(1, 1),
    00194       NWidget(NWID_HORIZONTAL), SetPIP(3, 0, 0),
    00195         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NORTHEAST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
    00196         NWidget(NWID_SPACER), SetFill(1, 1),
    00197       EndContainer(),
    00198     EndContainer(),
    00199     NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 0, 10),
    00200       NWidget(NWID_HORIZONTAL), SetPIP(0, 0, 3),
    00201         NWidget(NWID_SPACER), SetFill(1, 1),
    00202         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SOUTHWEST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
    00203       EndContainer(),
    00204       NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, GLAND_WATER_SW), SetDataTip(STR_JUST_STRING, STR_MAPGEN_SOUTHWEST), SetFill(1, 1),
    00205       NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, GLAND_WATER_SE), SetDataTip(STR_JUST_STRING, STR_MAPGEN_SOUTHEAST), SetFill(1, 1),
    00206       NWidget(NWID_HORIZONTAL), SetPIP(3, 0, 0),
    00207         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SOUTHEAST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
    00208         NWidget(NWID_SPACER), SetFill(1, 1),
    00209       EndContainer(),
    00210     EndContainer(),
    00211     NWidget(NWID_SPACER), SetMinimalSize(0, 9), SetFill(1, 1),
    00212   EndContainer(),
    00213 };
    00214
    00215 static const NWidgetPart _nested_heightmap_load_widgets[] = {
    00216   /* Window header. */
    00217   NWidget(NWID_HORIZONTAL),
    00218     NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
    00219     NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MAPGEN_WORLD_GENERATION_CAPTION, STR_NULL),
    00220   EndContainer(),
    00221   NWidget(WWT_PANEL, COLOUR_BROWN),
    00222     NWidget(NWID_SPACER), SetMinimalSize(0, 10),
    00223     /* Landscape selection. */
    00224     NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 10),
    00225       NWidget(NWID_SPACER), SetFill(1, 0),
    00226       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, GLAND_TEMPERATE), SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
    00227       NWidget(NWID_SPACER), SetFill(1, 0),
    00228       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, GLAND_ARCTIC), SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
    00229       NWidget(NWID_SPACER), SetFill(1, 0),
    00230       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, GLAND_TROPICAL), SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
    00231       NWidget(NWID_SPACER), SetFill(1, 0),
    00232       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, GLAND_TOYLAND), SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
    00233       NWidget(NWID_SPACER), SetFill(1, 0),
    00234     EndContainer(),
    00235     NWidget(NWID_SPACER), SetMinimalSize(0, 11), SetFill(0, 1),
    00236     NWidget(NWID_HORIZONTAL), SetPIP(10, 3, 10),
    00237       /* Labels at the left side. */
    00238       NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
    00239         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_HEIGHTMAP_NAME, STR_NULL), SetFill(1, 1),
    00240         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAPSIZE, STR_NULL), SetFill(1, 1),
    00241         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_TOWNS, STR_NULL), SetFill(1, 1),
    00242         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_INDUSTRIES, STR_NULL), SetFill(1, 1),
    00243         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_RANDOM_SEED, STR_NULL), SetFill(1, 1),
    00244         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TREE_PLACER, STR_NULL), SetFill(1, 1),
    00245         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_HEIGHTMAP_ROTATION, STR_NULL), SetFill(1, 1),
    00246       EndContainer(),
    00247       /* Widgets at the right of the labels. */
    00248       NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
    00249         NWidget(WWT_EMPTY, COLOUR_ORANGE, GLAND_HEIGHTMAP_NAME_TEXT), SetFill(1, 0),
    00250         /* Mapsize X * Y. */
    00251         NWidget(NWID_HORIZONTAL), SetPIP(0, 4, 0),
    00252           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_MAPSIZE_X_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetFill(1, 0),
    00253           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BY, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(1, 1),
    00254           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_MAPSIZE_Y_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetFill(1, 0),
    00255         EndContainer(),
    00256         NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_TOWN_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00257         NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_INDUSTRY_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00258         NWidget(WWT_EDITBOX, COLOUR_WHITE, GLAND_RANDOM_EDITBOX), SetDataTip(STR_MAPGEN_RANDOM_SEED_OSKTITLE, STR_MAPGEN_RANDOM_SEED_HELP), SetFill(1, 1),
    00259         NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_TREE_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00260         NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_HEIGHTMAP_ROTATION_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00261       EndContainer(),
    00262       NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
    00263         NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
    00264           NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
    00265             NWidget(WWT_EMPTY, INVALID_COLOUR, GLAND_HEIGHTMAP_NAME_SPACER), SetFill(1, 0),
    00266             NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_HEIGHTMAP_SIZE_LABEL, STR_NULL), SetFill(1, 1),
    00267             NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetFill(1, 1),
    00268             NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SNOW_LINE_HEIGHT, STR_NULL), SetFill(1, 1),
    00269           EndContainer(),
    00270           NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
    00271             NWidget(WWT_EMPTY, INVALID_COLOUR, GLAND_HEIGHTMAP_NAME_SPACER), SetFill(1, 0),
    00272             NWidget(WWT_TEXT, COLOUR_ORANGE, GLAND_HEIGHTMAP_SIZE_TEXT), SetDataTip(STR_MAPGEN_HEIGHTMAP_SIZE, STR_NULL), SetFill(1, 0),
    00273             NWidget(NWID_HORIZONTAL),
    00274               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_START_DATE_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_BACKWARD), SetFill(0, 1),
    00275               NWidget(WWT_TEXTBTN, COLOUR_ORANGE, GLAND_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL), SetFill(1, 0),
    00276               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_START_DATE_UP), SetDataTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_FORWARD), SetFill(0, 1),
    00277             EndContainer(),
    00278             NWidget(NWID_HORIZONTAL),
    00279               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_SNOW_LEVEL_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_SNOW_LINE_DOWN), SetFill(0, 1),
    00280               NWidget(WWT_TEXTBTN, COLOUR_ORANGE, GLAND_SNOW_LEVEL_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL), SetFill(1, 0),
    00281               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_SNOW_LEVEL_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_SNOW_LINE_UP), SetFill(0, 1),
    00282             EndContainer(),
    00283           EndContainer(),
    00284         EndContainer(),
    00285         NWidget(WWT_TEXTBTN, COLOUR_ORANGE, GLAND_RANDOM_BUTTON), SetDataTip(STR_MAPGEN_RANDOM, STR_MAPGEN_RANDOM_HELP), SetFill(1, 0),
    00286         NWidget(WWT_TEXTBTN, COLOUR_GREEN, GLAND_GENERATE_BUTTON), SetDataTip(STR_MAPGEN_GENERATE, STR_NULL), SetFill(1, 1),
    00287       EndContainer(),
    00288     EndContainer(),
    00289     NWidget(NWID_SPACER), SetMinimalSize(0, 9), SetFill(1, 1),
    00290   EndContainer(),
    00291 };
    00292
    00293 static void StartGeneratingLandscape(glwp_modes mode)
    00294 {
    00295   DeleteAllNonVitalWindows();
    00296
    00297   /* Copy all XXX_newgame to XXX when coming from outside the editor */
    00298   MakeNewgameSettingsLive();
    00299   ResetGRFConfig(true);
    00300
    00301   SndPlayFx(SND_15_BEEP);
    00302   switch (mode) {
    00303     case GLWP_GENERATE:  _switch_mode = (_game_mode == GM_EDITOR) ? SM_GENRANDLAND    : SM_NEWGAME;         break;
    00304     case GLWP_HEIGHTMAP: _switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_HEIGHTMAP : SM_START_HEIGHTMAP; break;
    00305     case GLWP_SCENARIO:  _switch_mode = SM_EDITOR; break;
    00306     default: NOT_REACHED();
    00307   }
    00308 }
    00309
    00310 static void LandscapeGenerationCallback(Window *w, bool confirmed)
    00311 {
    00312   if (confirmed) StartGeneratingLandscape((glwp_modes)w->window_number);
    00313 }
    00314
    00315 static DropDownList *BuildMapsizeDropDown()
    00316 {
    00317   DropDownList *list = new DropDownList();
    00318
    00319   for (uint i = MIN_MAP_SIZE_BITS; i <= MAX_MAP_SIZE_BITS; i++) {
    00320     DropDownListParamStringItem *item = new DropDownListParamStringItem(STR_JUST_INT, i, false);
    00321     item->SetParam(0, 1 << i);
    00322     list->push_back(item);
    00323   }
    00324
    00325   return list;
    00326 }
    00327
    00328 static const StringID _elevations[]  = {STR_TERRAIN_TYPE_VERY_FLAT, STR_TERRAIN_TYPE_FLAT, STR_TERRAIN_TYPE_HILLY, STR_TERRAIN_TYPE_MOUNTAINOUS, INVALID_STRING_ID};
    00329 static const StringID _sea_lakes[]   = {STR_SEA_LEVEL_VERY_LOW, STR_SEA_LEVEL_LOW, STR_SEA_LEVEL_MEDIUM, STR_SEA_LEVEL_HIGH, INVALID_STRING_ID};
    00330 static const StringID _smoothness[]  = {STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_VERY_SMOOTH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_SMOOTH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_ROUGH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_VERY_ROUGH, INVALID_STRING_ID};
    00331 static const StringID _tree_placer[] = {STR_CONFIG_SETTING_TREE_PLACER_NONE, STR_CONFIG_SETTING_TREE_PLACER_ORIGINAL, STR_CONFIG_SETTING_TREE_PLACER_IMPROVED, INVALID_STRING_ID};
    00332 static const StringID _rotation[]    = {STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE, STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_CLOCKWISE, INVALID_STRING_ID};
    00333 static const StringID _landscape[]   = {STR_CONFIG_SETTING_LAND_GENERATOR_ORIGINAL, STR_CONFIG_SETTING_LAND_GENERATOR_TERRA_GENESIS, INVALID_STRING_ID};
    00334 static const StringID _num_towns[]   = {STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM, INVALID_STRING_ID};
    00335 static const StringID _num_inds[]    = {STR_NONE, STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, INVALID_STRING_ID};
    00336 static const StringID _variety[]     = {STR_VARIETY_NONE, STR_VARIETY_VERY_LOW, STR_VARIETY_LOW, STR_VARIETY_MEDIUM, STR_VARIETY_HIGH, STR_VARIETY_VERY_HIGH, INVALID_STRING_ID};
    00337
    00338 struct GenerateLandscapeWindow : public QueryStringBaseWindow {
    00339   uint widget_id;
    00340   uint x;
    00341   uint y;
    00342   char name[64];
    00343   glwp_modes mode;
    00344
    00345   GenerateLandscapeWindow(const WindowDesc *desc, WindowNumber number = 0) : QueryStringBaseWindow(11)
    00346   {
    00347     this->InitNested(desc, number);
    00348
    00349     this->LowerWidget(_settings_newgame.game_creation.landscape + GLAND_TEMPERATE);
    00350
    00351     /* snprintf() always outputs trailing '\0', so whole buffer can be used */
    00352     snprintf(this->edit_str_buf, this->edit_str_size, "%u", _settings_newgame.game_creation.generation_seed);
    00353     InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 120);
    00354     this->SetFocusedWidget(GLAND_RANDOM_EDITBOX);
    00355     this->caption = STR_NULL;
    00356     this->afilter = CS_NUMERAL;
    00357
    00358     this->mode = (glwp_modes)this->window_number;
    00359   }
    00360
    00361
    00362   virtual void SetStringParameters(int widget) const
    00363   {
    00364     switch (widget) {
    00365       case GLAND_START_DATE_TEXT:     SetDParam(0, ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1)); break;
    00366       case GLAND_MAPSIZE_X_PULLDOWN:  SetDParam(0, 1 << _settings_newgame.game_creation.map_x); break;
    00367       case GLAND_MAPSIZE_Y_PULLDOWN:  SetDParam(0, 1 << _settings_newgame.game_creation.map_y); break;
    00368       case GLAND_SNOW_LEVEL_TEXT:     SetDParam(0, _settings_newgame.game_creation.snow_line_height); break;
    00369       case GLAND_TOWN_PULLDOWN:       SetDParam(0, _game_mode == GM_EDITOR ? STR_DISASTERS_OFF : _num_towns[_settings_newgame.difficulty.number_towns]); break;
    00370       case GLAND_INDUSTRY_PULLDOWN:   SetDParam(0, _game_mode == GM_EDITOR ? STR_DISASTERS_OFF : _num_inds[_settings_newgame.difficulty.number_industries]); break;
    00371       case GLAND_LANDSCAPE_PULLDOWN:  SetDParam(0, _landscape[_settings_newgame.game_creation.land_generator]); break;
    00372       case GLAND_TREE_PULLDOWN:       SetDParam(0, _tree_placer[_settings_newgame.game_creation.tree_placer]); break;
    00373       case GLAND_TERRAIN_PULLDOWN:    SetDParam(0, _elevations[_settings_newgame.difficulty.terrain_type]); break;
    00374       case GLAND_WATER_PULLDOWN:      SetDParam(0, _sea_lakes[_settings_newgame.difficulty.quantity_sea_lakes]); break;
    00375       case GLAND_SMOOTHNESS_PULLDOWN: SetDParam(0, _smoothness[_settings_newgame.game_creation.tgen_smoothness]); break;
    00376       case GLAND_VARIETY_PULLDOWN:    SetDParam(0, _variety[_settings_newgame.game_creation.variety]); break;
    00377       case GLAND_BORDERS_RANDOM:      SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOMIZE : STR_MAPGEN_BORDER_MANUAL); break;
    00378       case GLAND_WATER_NE: SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOM : HasBit(_settings_newgame.game_creation.water_borders, BORDER_NE) ? STR_MAPGEN_BORDER_WATER : STR_MAPGEN_BORDER_FREEFORM); break;
    00379       case GLAND_WATER_NW: SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOM : HasBit(_settings_newgame.game_creation.water_borders, BORDER_NW) ? STR_MAPGEN_BORDER_WATER : STR_MAPGEN_BORDER_FREEFORM); break;
    00380       case GLAND_WATER_SE: SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOM : HasBit(_settings_newgame.game_creation.water_borders, BORDER_SE) ? STR_MAPGEN_BORDER_WATER : STR_MAPGEN_BORDER_FREEFORM); break;
    00381       case GLAND_WATER_SW: SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOM : HasBit(_settings_newgame.game_creation.water_borders, BORDER_SW) ? STR_MAPGEN_BORDER_WATER : STR_MAPGEN_BORDER_FREEFORM); break;
    00382       case GLAND_HEIGHTMAP_ROTATION_PULLDOWN: SetDParam(0, _rotation[_settings_newgame.game_creation.heightmap_rotation]); break;
    00383
    00384       case GLAND_HEIGHTMAP_SIZE_TEXT:
    00385         if (_settings_newgame.game_creation.heightmap_rotation == HM_CLOCKWISE) {
    00386           SetDParam(0, this->y);
    00387           SetDParam(1, this->x);
    00388         } else {
    00389           SetDParam(0, this->x);
    00390           SetDParam(1, this->y);
    00391         }
    00392         break;
    00393     }
    00394   }
    00395
    00396   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
    00397   {
    00398     const StringID *strs = NULL;
    00399     switch (widget) {
    00400       case GLAND_START_DATE_TEXT:
    00401         SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
    00402         *size = GetStringBoundingBox(STR_BLACK_DATE_LONG);
    00403         break;
    00404
    00405       case GLAND_MAPSIZE_X_PULLDOWN:
    00406       case GLAND_MAPSIZE_Y_PULLDOWN:
    00407         SetDParam(0, MAX_MAP_SIZE);
    00408         *size = GetStringBoundingBox(STR_JUST_INT);
    00409         break;
    00410
    00411       case GLAND_SNOW_LEVEL_TEXT:
    00412         SetDParam(0, MAX_TILE_HEIGHT);
    00413         *size = GetStringBoundingBox(STR_JUST_INT);
    00414         break;
    00415
    00416       case GLAND_HEIGHTMAP_SIZE_TEXT:
    00417         SetDParam(0, this->x);
    00418         SetDParam(1, this->y);
    00419         *size = GetStringBoundingBox(STR_MAPGEN_HEIGHTMAP_SIZE);
    00420         break;
    00421
    00422       case GLAND_TOWN_PULLDOWN:       strs = _num_towns; break;
    00423       case GLAND_INDUSTRY_PULLDOWN:   strs = _num_inds; break;
    00424       case GLAND_LANDSCAPE_PULLDOWN:  strs = _landscape; break;
    00425       case GLAND_TREE_PULLDOWN:       strs = _tree_placer; break;
    00426       case GLAND_TERRAIN_PULLDOWN:    strs = _elevations; break;
    00427       case GLAND_WATER_PULLDOWN:      strs = _sea_lakes; break;
    00428       case GLAND_SMOOTHNESS_PULLDOWN: strs = _smoothness; break;
    00429       case GLAND_VARIETY_PULLDOWN:    strs = _variety; break;
    00430       case GLAND_HEIGHTMAP_ROTATION_PULLDOWN: strs = _rotation; break;
    00431       case GLAND_BORDERS_RANDOM:
    00432         *size = maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_RANDOMIZE), GetStringBoundingBox(STR_MAPGEN_BORDER_MANUAL));
    00433         break;
    00434
    00435       case GLAND_WATER_NE:
    00436       case GLAND_WATER_NW:
    00437       case GLAND_WATER_SE:
    00438       case GLAND_WATER_SW:
    00439         *size = maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_RANDOM), maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_WATER), GetStringBoundingBox(STR_MAPGEN_BORDER_FREEFORM)));
    00440         break;
    00441
    00442       case GLAND_HEIGHTMAP_NAME_SPACER:
    00443       case GLAND_HEIGHTMAP_NAME_TEXT:
    00444         size->width = 0;
    00445         break;
    00446
    00447       default:
    00448         return;
    00449     }
    00450     if (strs != NULL) {
    00451       while (*strs != INVALID_STRING_ID) {
    00452         *size = maxdim(*size, GetStringBoundingBox(*strs++));
    00453       }
    00454     }
    00455     size->width += padding.width;
    00456     size->height = FONT_HEIGHT_NORMAL + WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM;
    00457   }
    00458
    00459   virtual void DrawWidget(const Rect &r, int widget) const
    00460   {
    00461     switch (widget) {
    00462       case GLAND_HEIGHTMAP_NAME_TEXT: {
    00463         /* Little bit of a hack going on here; just to get the widgets
    00464          * spaced without doing much magic. The space we can draw on is
    00465          * covered by both the spacer and text widgets, so take their
    00466          * outer most boundaries (left and right) as draw locations. */
    00467         const NWidgetBase *nwi_spacer = this->GetWidget<NWidgetBase>(GLAND_HEIGHTMAP_NAME_SPACER);
    00468         DrawString(min(r.left, nwi_spacer->pos_x), max<int>(r.right, nwi_spacer->pos_x + nwi_spacer->current_x), r.top, this->name, TC_ORANGE);
    00469       } break;
    00470     }
    00471   }
    00472
    00473   virtual void OnPaint()
    00474   {
    00475     /* You can't select smoothness / non-water borders if not terragenesis */
    00476     if (mode == GLWP_GENERATE) {
    00477       this->SetWidgetDisabledState(GLAND_SMOOTHNESS_PULLDOWN, _settings_newgame.game_creation.land_generator == 0);
    00478       this->SetWidgetDisabledState(GLAND_VARIETY_PULLDOWN, _settings_newgame.game_creation.land_generator == 0);
    00479       this->SetWidgetDisabledState(GLAND_BORDERS_RANDOM, _settings_newgame.game_creation.land_generator == 0 || !_settings_newgame.construction.freeform_edges);
    00480       this->SetWidgetsDisabledState(_settings_newgame.game_creation.land_generator == 0 || !_settings_newgame.construction.freeform_edges || _settings_newgame.game_creation.water_borders == BORDERS_RANDOM,
    00481           GLAND_WATER_NW, GLAND_WATER_NE, GLAND_WATER_SE, GLAND_WATER_SW, WIDGET_LIST_END);
    00482
    00483       this->SetWidgetLoweredState(GLAND_BORDERS_RANDOM, _settings_newgame.game_creation.water_borders == BORDERS_RANDOM);
    00484
    00485       this->SetWidgetLoweredState(GLAND_WATER_NW, HasBit(_settings_newgame.game_creation.water_borders, BORDER_NW));
    00486       this->SetWidgetLoweredState(GLAND_WATER_NE, HasBit(_settings_newgame.game_creation.water_borders, BORDER_NE));
    00487       this->SetWidgetLoweredState(GLAND_WATER_SE, HasBit(_settings_newgame.game_creation.water_borders, BORDER_SE));
    00488       this->SetWidgetLoweredState(GLAND_WATER_SW, HasBit(_settings_newgame.game_creation.water_borders, BORDER_SW));
    00489
    00490       this->SetWidgetsDisabledState(_settings_newgame.game_creation.land_generator == 0 && (_settings_newgame.game_creation.landscape == LT_ARCTIC || _settings_newgame.game_creation.landscape == LT_TROPIC),
    00491           GLAND_TERRAIN_PULLDOWN, GLAND_WATER_PULLDOWN, WIDGET_LIST_END);
    00492     }
    00493     /* Disable snowline if not hilly */
    00494     this->SetWidgetDisabledState(GLAND_SNOW_LEVEL_TEXT, _settings_newgame.game_creation.landscape != LT_ARCTIC);
    00495     /* Disable town, industry and trees in SE */
    00496     this->SetWidgetDisabledState(GLAND_TOWN_PULLDOWN,     _game_mode == GM_EDITOR);
    00497     this->SetWidgetDisabledState(GLAND_INDUSTRY_PULLDOWN, _game_mode == GM_EDITOR);
    00498     this->SetWidgetDisabledState(GLAND_TREE_PULLDOWN,     _game_mode == GM_EDITOR);
    00499
    00500     this->SetWidgetDisabledState(GLAND_START_DATE_DOWN, _settings_newgame.game_creation.starting_year <= MIN_YEAR);
    00501     this->SetWidgetDisabledState(GLAND_START_DATE_UP,   _settings_newgame.game_creation.starting_year >= MAX_YEAR);
    00502     this->SetWidgetDisabledState(GLAND_SNOW_LEVEL_DOWN, _settings_newgame.game_creation.snow_line_height <= MIN_SNOWLINE_HEIGHT || _settings_newgame.game_creation.landscape != LT_ARCTIC);
    00503     this->SetWidgetDisabledState(GLAND_SNOW_LEVEL_UP,   _settings_newgame.game_creation.snow_line_height >= MAX_SNOWLINE_HEIGHT || _settings_newgame.game_creation.landscape != LT_ARCTIC);
    00504
    00505     this->SetWidgetLoweredState(GLAND_TEMPERATE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
    00506     this->SetWidgetLoweredState(GLAND_ARCTIC,    _settings_newgame.game_creation.landscape == LT_ARCTIC);
    00507     this->SetWidgetLoweredState(GLAND_TROPICAL,  _settings_newgame.game_creation.landscape == LT_TROPIC);
    00508     this->SetWidgetLoweredState(GLAND_TOYLAND,   _settings_newgame.game_creation.landscape == LT_TOYLAND);
    00509
    00510     this->DrawWidgets();
    00511
    00512     this->DrawEditBox(GLAND_RANDOM_EDITBOX);
    00513   }
    00514
    00515   virtual void OnClick(Point pt, int widget)
    00516   {
    00517     switch (widget) {
    00518       case GLAND_TEMPERATE:
    00519       case GLAND_ARCTIC:
    00520       case GLAND_TROPICAL:
    00521       case GLAND_TOYLAND:
    00522         this->RaiseWidget(_settings_newgame.game_creation.landscape + GLAND_TEMPERATE);
    00523         SetNewLandscapeType(widget - GLAND_TEMPERATE);
    00524         break;
    00525
    00526       case GLAND_MAPSIZE_X_PULLDOWN: // Mapsize X
    00527         ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_x, GLAND_MAPSIZE_X_PULLDOWN);
    00528         break;
    00529
    00530       case GLAND_MAPSIZE_Y_PULLDOWN: // Mapsize Y
    00531         ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_y, GLAND_MAPSIZE_Y_PULLDOWN);
    00532         break;
    00533
    00534       case GLAND_TOWN_PULLDOWN: // Number of towns
    00535         ShowDropDownMenu(this, _num_towns, _settings_newgame.difficulty.number_towns, GLAND_TOWN_PULLDOWN, 0, 0);
    00536         break;
    00537
    00538       case GLAND_INDUSTRY_PULLDOWN: // Number of industries
    00539         ShowDropDownMenu(this, _num_inds, _settings_newgame.difficulty.number_industries, GLAND_INDUSTRY_PULLDOWN, 0, 0);
    00540         break;
    00541
    00542       case GLAND_RANDOM_BUTTON: // Random seed
    00543         _settings_newgame.game_creation.generation_seed = InteractiveRandom();
    00544         snprintf(this->edit_str_buf, this->edit_str_size, "%u", _settings_newgame.game_creation.generation_seed);
    00545         UpdateTextBufferSize(&this->text);
    00546         this->SetDirty();
    00547         break;
    00548
    00549       case GLAND_GENERATE_BUTTON: // Generate
    00550         MakeNewgameSettingsLive();
    00551
    00552         if (mode == GLWP_HEIGHTMAP &&
    00553             (this->x * 2 < (1U << _settings_newgame.game_creation.map_x) ||
    00554             this->x / 2 > (1U << _settings_newgame.game_creation.map_x) ||
    00555             this->y * 2 < (1U << _settings_newgame.game_creation.map_y) ||
    00556             this->y / 2 > (1U << _settings_newgame.game_creation.map_y))) {
    00557           ShowQuery(
    00558             STR_WARNING_HEIGHTMAP_SCALE_CAPTION,
    00559             STR_WARNING_HEIGHTMAP_SCALE_MESSAGE,
    00560             this,
    00561             LandscapeGenerationCallback);
    00562         } else {
    00563           StartGeneratingLandscape(mode);
    00564         }
    00565         break;
    00566
    00567       case GLAND_START_DATE_DOWN:
    00568       case GLAND_START_DATE_UP: // Year buttons
    00569         /* Don't allow too fast scrolling */
    00570         if ((this->flags4 & WF_TIMEOUT_MASK) <= WF_TIMEOUT_TRIGGER) {
    00571           this->HandleButtonClick(widget);
    00572           this->SetDirty();
    00573
    00574           _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - GLAND_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
    00575         }
    00576         _left_button_clicked = false;
    00577         break;
    00578
    00579       case GLAND_START_DATE_TEXT: // Year text
    00580         this->widget_id = GLAND_START_DATE_TEXT;
    00581         SetDParam(0, _settings_newgame.game_creation.starting_year);
    00582         ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, 100, this, CS_NUMERAL, QSF_NONE);
    00583         break;
    00584
    00585       case GLAND_SNOW_LEVEL_DOWN:
    00586       case GLAND_SNOW_LEVEL_UP: // Snow line buttons
    00587         /* Don't allow too fast scrolling */
    00588         if ((this->flags4 & WF_TIMEOUT_MASK) <= WF_TIMEOUT_TRIGGER) {
    00589           this->HandleButtonClick(widget);
    00590           this->SetDirty();
    00591
    00592           _settings_newgame.game_creation.snow_line_height = Clamp(_settings_newgame.game_creation.snow_line_height + widget - GLAND_SNOW_LEVEL_TEXT, MIN_SNOWLINE_HEIGHT, MAX_SNOWLINE_HEIGHT);
    00593         }
    00594         _left_button_clicked = false;
    00595         break;
    00596
    00597       case GLAND_SNOW_LEVEL_TEXT: // Snow line text
    00598         this->widget_id = GLAND_SNOW_LEVEL_TEXT;
    00599         SetDParam(0, _settings_newgame.game_creation.snow_line_height);
    00600         ShowQueryString(STR_JUST_INT, STR_MAPGEN_SNOW_LINE_QUERY_CAPT, 3, 100, this, CS_NUMERAL, QSF_NONE);
    00601         break;
    00602
    00603       case GLAND_TREE_PULLDOWN: // Tree placer
    00604         ShowDropDownMenu(this, _tree_placer, _settings_newgame.game_creation.tree_placer, GLAND_TREE_PULLDOWN, 0, 0);
    00605         break;
    00606
    00607       case GLAND_LANDSCAPE_PULLDOWN: // Landscape generator
    00608         ShowDropDownMenu(this, _landscape, _settings_newgame.game_creation.land_generator, GLAND_LANDSCAPE_PULLDOWN, 0, 0);
    00609         break;
    00610
    00611       case GLAND_HEIGHTMAP_ROTATION_PULLDOWN: // Heightmap rotation
    00612         ShowDropDownMenu(this, _rotation, _settings_newgame.game_creation.heightmap_rotation, GLAND_HEIGHTMAP_ROTATION_PULLDOWN, 0, 0);
    00613         break;
    00614
    00615       case GLAND_TERRAIN_PULLDOWN: // Terrain type
    00616         ShowDropDownMenu(this, _elevations, _settings_newgame.difficulty.terrain_type, GLAND_TERRAIN_PULLDOWN, 0, 0);
    00617         break;
    00618
    00619       case GLAND_WATER_PULLDOWN: // Water quantity
    00620         ShowDropDownMenu(this, _sea_lakes, _settings_newgame.difficulty.quantity_sea_lakes, GLAND_WATER_PULLDOWN, 0, 0);
    00621         break;
    00622
    00623       case GLAND_SMOOTHNESS_PULLDOWN: // Map smoothness
    00624         ShowDropDownMenu(this, _smoothness, _settings_newgame.game_creation.tgen_smoothness, GLAND_SMOOTHNESS_PULLDOWN, 0, 0);
    00625         break;
    00626
    00627       case GLAND_VARIETY_PULLDOWN: // Map variety
    00628         ShowDropDownMenu(this, _variety, _settings_newgame.game_creation.variety, GLAND_VARIETY_PULLDOWN, 0, 0);
    00629         break;
    00630
    00631       /* Freetype map borders */
    00632       case GLAND_WATER_NW:
    00633         _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_NW);
    00634         break;
    00635
    00636       case GLAND_WATER_NE:
    00637         _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_NE);
    00638         break;
    00639
    00640       case GLAND_WATER_SE:
    00641         _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_SE);
    00642         break;
    00643
    00644       case GLAND_WATER_SW:
    00645         _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_SW);
    00646         break;
    00647
    00648       case GLAND_BORDERS_RANDOM:
    00649         _settings_newgame.game_creation.water_borders = (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? 0 : BORDERS_RANDOM;
    00650         this->SetDirty();
    00651         break;
    00652     }
    00653   }
    00654
    00655   virtual void OnTimeout()
    00656   {
    00657     static const int raise_widgets[] = {GLAND_START_DATE_DOWN, GLAND_START_DATE_UP, GLAND_SNOW_LEVEL_UP, GLAND_SNOW_LEVEL_DOWN, WIDGET_LIST_END};
    00658     for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
    00659       if (this->IsWidgetLowered(*widget)) {
    00660         this->RaiseWidget(*widget);
    00661         this->SetWidgetDirty(*widget);
    00662       }
    00663     }
    00664   }
    00665
    00666   virtual void OnMouseLoop()
    00667   {
    00668     this->HandleEditBox(GLAND_RANDOM_EDITBOX);
    00669   }
    00670
    00671   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
    00672   {
    00673     EventState state;
    00674     this->HandleEditBoxKey(GLAND_RANDOM_EDITBOX, key, keycode, state);
    00675     /* the seed is unsigned, therefore atoi cannot be used.
    00676      * As UINT32_MAX is a 'magic' value (use random seed) it
    00677      * should not be possible to be entered into the input
    00678      * field; the generate seed button can be used instead. */
    00679     _settings_newgame.game_creation.generation_seed = minu(strtoul(this->edit_str_buf, NULL, 10), UINT32_MAX - 1);
    00680     return state;
    00681   }
    00682
    00683   virtual void OnDropdownSelect(int widget, int index)
    00684   {
    00685     switch (widget) {
    00686       case GLAND_MAPSIZE_X_PULLDOWN:     _settings_newgame.game_creation.map_x = index; break;
    00687       case GLAND_MAPSIZE_Y_PULLDOWN:     _settings_newgame.game_creation.map_y = index; break;
    00688       case GLAND_TREE_PULLDOWN:          _settings_newgame.game_creation.tree_placer = index; break;
    00689       case GLAND_SMOOTHNESS_PULLDOWN:    _settings_newgame.game_creation.tgen_smoothness = index;  break;
    00690       case GLAND_VARIETY_PULLDOWN:       _settings_newgame.game_creation.variety = index; break;
    00691
    00692       case GLAND_TOWN_PULLDOWN:
    00693         if ((uint)index == CUSTOM_TOWN_NUMBER_DIFFICULTY) {
    00694           this->widget_id = widget;
    00695           SetDParam(0, _settings_newgame.game_creation.custom_town_number);
    00696           ShowQueryString(STR_JUST_INT, STR_MAPGEN_NUMBER_OF_TOWNS, 5, 50, this, CS_NUMERAL, QSF_NONE);
    00697         };
    00698         IConsoleSetSetting("difficulty.number_towns", index);
    00699         break;
    00700
    00701       case GLAND_INDUSTRY_PULLDOWN:
    00702         IConsoleSetSetting("difficulty.number_industries", index);
    00703         break;
    00704
    00705       case GLAND_LANDSCAPE_PULLDOWN:
    00706       /* case GLAND_HEIGHTMAP_PULLDOWN: */
    00707         if (mode == GLWP_HEIGHTMAP) {
    00708           _settings_newgame.game_creation.heightmap_rotation = index;
    00709         } else {
    00710           _settings_newgame.game_creation.land_generator = index;
    00711         }
    00712         break;
    00713
    00714       case GLAND_TERRAIN_PULLDOWN: {
    00715         GameMode old_gm = _game_mode;
    00716         _game_mode = GM_MENU;
    00717         IConsoleSetSetting("difficulty.terrain_type", index);
    00718         _game_mode = old_gm;
    00719         break;
    00720       }
    00721
    00722       case GLAND_WATER_PULLDOWN: {
    00723         GameMode old_gm = _game_mode;
    00724         _game_mode = GM_MENU;
    00725         IConsoleSetSetting("difficulty.quantity_sea_lakes", index);
    00726         _game_mode = old_gm;
    00727         break;
    00728       }
    00729     }
    00730     this->SetDirty();
    00731   }
    00732
    00733   virtual void OnQueryTextFinished(char *str)
    00734   {
    00735     int32 value;
    00736     if (!StrEmpty(str)) {
    00737       value = atoi(str);
    00738     } else {
    00739       /* An empty string means revert to the default */
    00740       switch (this->widget_id) {
    00741         case GLAND_START_DATE_TEXT: value = DEF_START_YEAR; break;
    00742         case GLAND_SNOW_LEVEL_TEXT: value = DEF_SNOWLINE_HEIGHT; break;
    00743         case GLAND_TOWN_PULLDOWN:   value = 1; break; // There's not really a default
    00744         default: NOT_REACHED();
    00745       }
    00746     }
    00747
    00748     switch (this->widget_id) {
    00749       case GLAND_START_DATE_TEXT:
    00750         this->SetWidgetDirty(GLAND_START_DATE_TEXT);
    00751         _settings_newgame.game_creation.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
    00752         break;
    00753
    00754       case GLAND_SNOW_LEVEL_TEXT:
    00755         this->SetWidgetDirty(GLAND_SNOW_LEVEL_TEXT);
    00756         _settings_newgame.game_creation.snow_line_height = Clamp(value, MIN_SNOWLINE_HEIGHT, MAX_SNOWLINE_HEIGHT);
    00757         break;
    00758
    00759       case GLAND_TOWN_PULLDOWN:
    00760         _settings_newgame.game_creation.custom_town_number = Clamp(value, 1, CUSTOM_TOWN_MAX_NUMBER);
    00761         break;
    00762     }
    00763
    00764     this->SetDirty();
    00765   }
    00766 };
    00767
    00768 static const WindowDesc _generate_landscape_desc(
    00769   WDP_CENTER, 0, 0,
    00770   WC_GENERATE_LANDSCAPE, WC_NONE,
    00771   WDF_UNCLICK_BUTTONS,
    00772   _nested_generate_landscape_widgets, lengthof(_nested_generate_landscape_widgets)
    00773 );
    00774
    00775 static const WindowDesc _heightmap_load_desc(
    00776   WDP_CENTER, 0, 0,
    00777   WC_GENERATE_LANDSCAPE, WC_NONE,
    00778   WDF_UNCLICK_BUTTONS,
    00779   _nested_heightmap_load_widgets, lengthof(_nested_heightmap_load_widgets)
    00780 );
    00781
    00782 static void _ShowGenerateLandscape(glwp_modes mode)
    00783 {
    00784   uint x = 0;
    00785   uint y = 0;
    00786
    00787   DeleteWindowByClass(WC_GENERATE_LANDSCAPE);
    00788
    00789   /* Always give a new seed if not editor */
    00790   if (_game_mode != GM_EDITOR) _settings_newgame.game_creation.generation_seed = InteractiveRandom();
    00791
    00792   if (mode == GLWP_HEIGHTMAP) {
    00793     /* If the function returns negative, it means there was a problem loading the heightmap */
    00794     if (!GetHeightmapDimensions(_file_to_saveload.name, &x, &y)) return;
    00795   }
    00796
    00797   GenerateLandscapeWindow *w = AllocateWindowDescFront<GenerateLandscapeWindow>((mode == GLWP_HEIGHTMAP) ? &_heightmap_load_desc : &_generate_landscape_desc, mode);
    00798
    00799   if (mode == GLWP_HEIGHTMAP) {
    00800     w->x = x;
    00801     w->y = y;
    00802     strecpy(w->name, _file_to_saveload.title, lastof(w->name));
    00803   }
    00804
    00805   SetWindowDirty(WC_GENERATE_LANDSCAPE, mode);
    00806 }
    00807
    00808 void ShowGenerateLandscape()
    00809 {
    00810   _ShowGenerateLandscape(GLWP_GENERATE);
    00811 }
    00812
    00813 void ShowHeightmapLoad()
    00814 {
    00815   _ShowGenerateLandscape(GLWP_HEIGHTMAP);
    00816 }
    00817
    00818 void StartScenarioEditor()
    00819 {
    00820   StartGeneratingLandscape(GLWP_SCENARIO);
    00821 }
    00822
    00823 void StartNewGameWithoutGUI(uint seed)
    00824 {
    00825   /* GenerateWorld takes care of the possible GENERATE_NEW_SEED value in 'seed' */
    00826   _settings_newgame.game_creation.generation_seed = seed;
    00827
    00828   StartGeneratingLandscape(GLWP_GENERATE);
    00829 }
    00830
    00832 enum CreateScenarioWindowWidgets {
    00833   CSCEN_TEMPERATE,
    00834   CSCEN_ARCTIC,
    00835   CSCEN_TROPICAL,
    00836   CSCEN_TOYLAND,
    00837   CSCEN_EMPTY_WORLD,
    00838   CSCEN_RANDOM_WORLD,
    00839   CSCEN_MAPSIZE_X_PULLDOWN,
    00840   CSCEN_MAPSIZE_Y_PULLDOWN,
    00841   CSCEN_START_DATE_DOWN,
    00842   CSCEN_START_DATE_TEXT,
    00843   CSCEN_START_DATE_UP,
    00844   CSCEN_FLAT_LAND_HEIGHT_DOWN,
    00845   CSCEN_FLAT_LAND_HEIGHT_TEXT,
    00846   CSCEN_FLAT_LAND_HEIGHT_UP
    00847 };
    00848
    00849
    00850 struct CreateScenarioWindow : public Window
    00851 {
    00852   uint widget_id;
    00853
    00854   CreateScenarioWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
    00855   {
    00856     this->InitNested(desc, window_number);
    00857     this->LowerWidget(_settings_newgame.game_creation.landscape + CSCEN_TEMPERATE);
    00858   }
    00859
    00860   virtual void SetStringParameters(int widget) const
    00861   {
    00862     switch (widget) {
    00863       case CSCEN_START_DATE_TEXT:
    00864         SetDParam(0, ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1));
    00865         break;
    00866
    00867       case CSCEN_MAPSIZE_X_PULLDOWN:
    00868         SetDParam(0, 1 << _settings_newgame.game_creation.map_x);
    00869         break;
    00870
    00871       case CSCEN_MAPSIZE_Y_PULLDOWN:
    00872         SetDParam(0, 1 << _settings_newgame.game_creation.map_y);
    00873         break;
    00874
    00875       case CSCEN_FLAT_LAND_HEIGHT_TEXT:
    00876         SetDParam(0, _settings_newgame.game_creation.se_flat_world_height);
    00877         break;
    00878     }
    00879   }
    00880
    00881   virtual void OnPaint()
    00882   {
    00883     this->SetWidgetDisabledState(CSCEN_START_DATE_DOWN,       _settings_newgame.game_creation.starting_year <= MIN_YEAR);
    00884     this->SetWidgetDisabledState(CSCEN_START_DATE_UP,         _settings_newgame.game_creation.starting_year >= MAX_YEAR);
    00885     this->SetWidgetDisabledState(CSCEN_FLAT_LAND_HEIGHT_DOWN, _settings_newgame.game_creation.se_flat_world_height <= 0);
    00886     this->SetWidgetDisabledState(CSCEN_FLAT_LAND_HEIGHT_UP,   _settings_newgame.game_creation.se_flat_world_height >= MAX_TILE_HEIGHT);
    00887
    00888     this->SetWidgetLoweredState(CSCEN_TEMPERATE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
    00889     this->SetWidgetLoweredState(CSCEN_ARCTIC,    _settings_newgame.game_creation.landscape == LT_ARCTIC);
    00890     this->SetWidgetLoweredState(CSCEN_TROPICAL,  _settings_newgame.game_creation.landscape == LT_TROPIC);
    00891     this->SetWidgetLoweredState(CSCEN_TOYLAND,   _settings_newgame.game_creation.landscape == LT_TOYLAND);
    00892
    00893     this->DrawWidgets();
    00894   }
    00895
    00896   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
    00897   {
    00898     StringID str = STR_JUST_INT;
    00899     switch (widget) {
    00900       case CSCEN_START_DATE_TEXT:
    00901         SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
    00902         str = STR_BLACK_DATE_LONG;
    00903         break;
    00904
    00905       case CSCEN_MAPSIZE_X_PULLDOWN:
    00906       case CSCEN_MAPSIZE_Y_PULLDOWN:
    00907         SetDParam(0, MAX_MAP_SIZE);
    00908         break;
    00909
    00910       case CSCEN_FLAT_LAND_HEIGHT_TEXT:
    00911         SetDParam(0, MAX_TILE_HEIGHT);
    00912         break;
    00913
    00914       default:
    00915         return;
    00916     }
    00917     *size = GetStringBoundingBox(str);
    00918     size->width += padding.width;
    00919     size->height += padding.height;
    00920   }
    00921
    00922   virtual void OnClick(Point pt, int widget)
    00923   {
    00924     switch (widget) {
    00925       case CSCEN_TEMPERATE:
    00926       case CSCEN_ARCTIC:
    00927       case CSCEN_TROPICAL:
    00928       case CSCEN_TOYLAND:
    00929         this->RaiseWidget(_settings_newgame.game_creation.landscape + CSCEN_TEMPERATE);
    00930         SetNewLandscapeType(widget - CSCEN_TEMPERATE);
    00931         break;
    00932
    00933       case CSCEN_MAPSIZE_X_PULLDOWN: // Mapsize X
    00934         ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_x, CSCEN_MAPSIZE_X_PULLDOWN);
    00935         break;
    00936
    00937       case CSCEN_MAPSIZE_Y_PULLDOWN: // Mapsize Y
    00938         ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_y, CSCEN_MAPSIZE_Y_PULLDOWN);
    00939         break;
    00940
    00941       case CSCEN_EMPTY_WORLD: // Empty world / flat world
    00942         StartGeneratingLandscape(GLWP_SCENARIO);
    00943         break;
    00944
    00945       case CSCEN_RANDOM_WORLD: // Generate
    00946         ShowGenerateLandscape();
    00947         break;
    00948
    00949       case CSCEN_START_DATE_DOWN:
    00950       case CSCEN_START_DATE_UP: // Year buttons
    00951         /* Don't allow too fast scrolling */
    00952         if ((this->flags4 & WF_TIMEOUT_MASK) <= WF_TIMEOUT_TRIGGER) {
    00953           this->HandleButtonClick(widget);
    00954           this->SetDirty();
    00955
    00956           _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - CSCEN_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
    00957         }
    00958         _left_button_clicked = false;
    00959         break;
    00960
    00961       case CSCEN_START_DATE_TEXT: // Year text
    00962         this->widget_id = CSCEN_START_DATE_TEXT;
    00963         SetDParam(0, _settings_newgame.game_creation.starting_year);
    00964         ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, 100, this, CS_NUMERAL, QSF_NONE);
    00965         break;
    00966
    00967       case CSCEN_FLAT_LAND_HEIGHT_DOWN:
    00968       case CSCEN_FLAT_LAND_HEIGHT_UP: // Height level buttons
    00969         /* Don't allow too fast scrolling */
    00970         if ((this->flags4 & WF_TIMEOUT_MASK) <= WF_TIMEOUT_TRIGGER) {
    00971           this->HandleButtonClick(widget);
    00972           this->SetDirty();
    00973
    00974           _settings_newgame.game_creation.se_flat_world_height = Clamp(_settings_newgame.game_creation.se_flat_world_height + widget - CSCEN_FLAT_LAND_HEIGHT_TEXT, 0, MAX_TILE_HEIGHT);
    00975         }
    00976         _left_button_clicked = false;
    00977         break;
    00978
    00979       case CSCEN_FLAT_LAND_HEIGHT_TEXT: // Height level text
    00980         this->widget_id = CSCEN_FLAT_LAND_HEIGHT_TEXT;
    00981         SetDParam(0, _settings_newgame.game_creation.se_flat_world_height);
    00982         ShowQueryString(STR_JUST_INT, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_QUERY_CAPT, 3, 100, this, CS_NUMERAL, QSF_NONE);
    00983         break;
    00984     }
    00985   }
    00986
    00987   virtual void OnTimeout()
    00988   {
    00989     static const int raise_widgets[] = {CSCEN_START_DATE_DOWN, CSCEN_START_DATE_UP, CSCEN_FLAT_LAND_HEIGHT_DOWN, CSCEN_FLAT_LAND_HEIGHT_UP, WIDGET_LIST_END};
    00990     for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
    00991       if (this->IsWidgetLowered(*widget)) {
    00992         this->RaiseWidget(*widget);
    00993         this->SetWidgetDirty(*widget);
    00994       }
    00995     }
    00996   }
    00997
    00998   virtual void OnDropdownSelect(int widget, int index)
    00999   {
    01000     switch (widget) {
    01001       case CSCEN_MAPSIZE_X_PULLDOWN: _settings_newgame.game_creation.map_x = index; break;
    01002       case CSCEN_MAPSIZE_Y_PULLDOWN: _settings_newgame.game_creation.map_y = index; break;
    01003     }
    01004     this->SetDirty();
    01005   }
    01006
    01007   virtual void OnQueryTextFinished(char *str)
    01008   {
    01009     if (!StrEmpty(str)) {
    01010       int32 value = atoi(str);
    01011
    01012       switch (this->widget_id) {
    01013         case CSCEN_START_DATE_TEXT:
    01014           this->SetWidgetDirty(CSCEN_START_DATE_TEXT);
    01015           _settings_newgame.game_creation.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
    01016           break;
    01017
    01018         case CSCEN_FLAT_LAND_HEIGHT_TEXT:
    01019           this->SetWidgetDirty(CSCEN_FLAT_LAND_HEIGHT_TEXT);
    01020           _settings_newgame.game_creation.se_flat_world_height = Clamp(value, 0, MAX_TILE_HEIGHT);
    01021           break;
    01022       }
    01023
    01024       this->SetDirty();
    01025     }
    01026   }
    01027 };
    01028
    01029 static const NWidgetPart _nested_create_scenario_widgets[] = {
    01030   NWidget(NWID_HORIZONTAL),
    01031     NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
    01032     NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_SE_MAPGEN_CAPTION, STR_NULL),
    01033   EndContainer(),
    01034   NWidget(WWT_PANEL, COLOUR_BROWN),
    01035     NWidget(NWID_SPACER), SetMinimalSize(0, 10),
    01036     /* Landscape style selection. */
    01037     NWidget(NWID_HORIZONTAL), SetPIP(10, 3, 10),
    01038       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, CSCEN_TEMPERATE), SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
    01039       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, CSCEN_ARCTIC), SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
    01040       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, CSCEN_TROPICAL), SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
    01041       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, CSCEN_TOYLAND), SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
    01042     EndContainer(),
    01043     NWidget(NWID_HORIZONTAL), SetPIP(10, 8, 10),
    01044       /* Green generation type buttons: 'Flat land' and 'Random land'. */
    01045       NWidget(NWID_VERTICAL), SetPIP(10, 6, 10),
    01046         NWidget(WWT_TEXTBTN, COLOUR_GREEN, CSCEN_EMPTY_WORLD), SetDataTip(STR_SE_MAPGEN_FLAT_WORLD, STR_SE_MAPGEN_FLAT_WORLD_TOOLTIP), SetFill(1, 1),
    01047         NWidget(WWT_TEXTBTN, COLOUR_GREEN, CSCEN_RANDOM_WORLD), SetDataTip(STR_SE_MAPGEN_RANDOM_LAND, STR_TERRAFORM_TOOLTIP_GENERATE_RANDOM_LAND), SetFill(1, 1),
    01048       EndContainer(),
    01049       /* Labels + setting drop-downs */
    01050       NWidget(NWID_VERTICAL), SetPIP(10, 6, 10),
    01051         /* Map size. */
    01052         NWidget(NWID_HORIZONTAL),
    01053           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAPSIZE, STR_NULL), SetPadding(1, 0, 0, 0),
    01054           NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
    01055           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, CSCEN_MAPSIZE_X_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetPadding(0, 4, 0, 0),
    01056           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BY, STR_NULL), SetPadding(1, 2, 0, 0),
    01057           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, CSCEN_MAPSIZE_Y_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL),
    01058         EndContainer(),
    01059         /* Date. */
    01060         NWidget(NWID_HORIZONTAL),
    01061           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetPadding(1, 0, 0, 0),
    01062           NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
    01063           NWidget(WWT_IMGBTN, COLOUR_ORANGE, CSCEN_START_DATE_DOWN), SetFill(0, 1), SetDataTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_BACKWARD),
    01064           NWidget(WWT_TEXTBTN, COLOUR_ORANGE, CSCEN_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL),
    01065           NWidget(WWT_IMGBTN, COLOUR_ORANGE, CSCEN_START_DATE_UP), SetFill(0, 1), SetDataTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_FORWARD),
    01066         EndContainer(),
    01067         /* Flat map height. */
    01068         NWidget(NWID_HORIZONTAL),
    01069           NWidget(WWT_TEXT, COLOUR_ORANGE),
    01070                         SetDataTip(STR_SE_MAPGEN_FLAT_WORLD_HEIGHT, STR_NULL), SetPadding(1, 0, 0, 0),
    01071           NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
    01072           NWidget(WWT_IMGBTN, COLOUR_ORANGE, CSCEN_FLAT_LAND_HEIGHT_DOWN), SetFill(0, 1), SetDataTip(SPR_ARROW_DOWN, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_DOWN),
    01073           NWidget(WWT_TEXTBTN, COLOUR_ORANGE, CSCEN_FLAT_LAND_HEIGHT_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL),
    01074           NWidget(WWT_IMGBTN, COLOUR_ORANGE, CSCEN_FLAT_LAND_HEIGHT_UP), SetFill(0, 1), SetDataTip(SPR_ARROW_UP, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_UP),
    01075         EndContainer(),
    01076       EndContainer(),
    01077     EndContainer(),
    01078   EndContainer(),
    01079 };
    01080
    01081 static const WindowDesc _create_scenario_desc(
    01082   WDP_CENTER, 0, 0,
    01083   WC_GENERATE_LANDSCAPE, WC_NONE,
    01084   WDF_UNCLICK_BUTTONS,
    01085   _nested_create_scenario_widgets, lengthof(_nested_create_scenario_widgets)
    01086 );
    01087
    01088 void ShowCreateScenario()
    01089 {
    01090   DeleteWindowByClass(WC_GENERATE_LANDSCAPE);
    01091   new CreateScenarioWindow(&_create_scenario_desc, GLWP_SCENARIO);
    01092 }
    01093
    01094 enum GenerationProgressWindowWidgets {
    01095   GPWW_PROGRESS_BAR,
    01096   GPWW_PROGRESS_TEXT,
    01097   GPWW_ABORT,
    01098 };
    01099
    01100 static const NWidgetPart _nested_generate_progress_widgets[] = {
    01101   NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GENERATION_WORLD, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    01102   NWidget(WWT_PANEL, COLOUR_GREY),
    01103     NWidget(NWID_HORIZONTAL), SetPIP(20, 0, 20),
    01104       NWidget(NWID_VERTICAL), SetPIP(11, 8, 11),
    01105         NWidget(WWT_EMPTY, INVALID_COLOUR, GPWW_PROGRESS_BAR), SetFill(1, 0),
    01106         NWidget(WWT_EMPTY, INVALID_COLOUR, GPWW_PROGRESS_TEXT), SetFill(1, 0),
    01107         NWidget(WWT_TEXTBTN, COLOUR_WHITE, GPWW_ABORT), SetDataTip(STR_GENERATION_ABORT, STR_NULL), SetFill(1, 0),
    01108       EndContainer(),
    01109     EndContainer(),
    01110   EndContainer(),
    01111 };
    01112
    01113
    01114 static const WindowDesc _generate_progress_desc(
    01115   WDP_CENTER, 0, 0,
    01116   WC_GENERATE_PROGRESS_WINDOW, WC_NONE,
    01117   WDF_UNCLICK_BUTTONS,
    01118   _nested_generate_progress_widgets, lengthof(_nested_generate_progress_widgets)
    01119 );
    01120
    01121 struct tp_info {
    01122   uint percent;
    01123   StringID cls;
    01124   uint current;
    01125   uint total;
    01126   int timer;
    01127 };
    01128
    01129 static tp_info _tp;
    01130
    01131 static const StringID _generation_class_table[GWP_CLASS_COUNT]  = {
    01132   STR_GENERATION_WORLD_GENERATION,
    01133   STR_SCENEDIT_TOOLBAR_LANDSCAPE_GENERATION,
    01134   STR_GENERATION_CLEARING_TILES,
    01135   STR_SCENEDIT_TOOLBAR_TOWN_GENERATION,
    01136   STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION,
    01137   STR_GENERATION_UNMOVABLE_GENERATION,
    01138   STR_GENERATION_TREE_GENERATION,
    01139   STR_GENERATION_SETTINGUP_GAME,
    01140   STR_GENERATION_PREPARING_TILELOOP,
    01141   STR_GENERATION_PREPARING_GAME
    01142 };
    01143
    01144
    01145 static void AbortGeneratingWorldCallback(Window *w, bool confirmed)
    01146 {
    01147   if (confirmed) {
    01148     AbortGeneratingWorld();
    01149   } else if (IsGeneratingWorld() && !IsGeneratingWorldAborted()) {
    01150     SetMouseCursor(SPR_CURSOR_ZZZ, PAL_NONE);
    01151   }
    01152 }
    01153
    01154 struct GenerateProgressWindow : public Window {
    01155
    01156   GenerateProgressWindow() : Window()
    01157   {
    01158     this->InitNested(&_generate_progress_desc);
    01159   }
    01160
    01161   virtual void OnClick(Point pt, int widget)
    01162   {
    01163     switch (widget) {
    01164       case GPWW_ABORT:
    01165         if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE);
    01166         ShowQuery(
    01167           STR_GENERATION_ABORT_CAPTION,
    01168           STR_GENERATION_ABORT_MESSAGE,
    01169           this,
    01170           AbortGeneratingWorldCallback
    01171         );
    01172         break;
    01173     }
    01174   }
    01175
    01176   virtual void OnPaint()
    01177   {
    01178     this->DrawWidgets();
    01179   }
    01180
    01181   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
    01182   {
    01183     switch (widget) {
    01184       case GPWW_PROGRESS_BAR: {
    01185         SetDParam(0, 100);
    01186         *size = GetStringBoundingBox(STR_GENERATION_PROGRESS);
    01187         /* We need some spacing for the 'border' */
    01188         size->height += 8;
    01189         size->width += 8;
    01190       } break;
    01191
    01192       case GPWW_PROGRESS_TEXT:
    01193         for (uint i = 0; i < GWP_CLASS_COUNT; i++) {
    01194           size->width = max(size->width, GetStringBoundingBox(_generation_class_table[i]).width);
    01195         }
    01196         size->height = FONT_HEIGHT_NORMAL * 2 + WD_PAR_VSEP_NORMAL;
    01197         break;
    01198     }
    01199   }
    01200
    01201   virtual void DrawWidget(const Rect &r, int widget) const
    01202   {
    01203     switch (widget) {
    01204       case GPWW_PROGRESS_BAR:
    01205         /* Draw the % complete with a bar and a text */
    01206         DrawFrameRect(r.left, r.top, r.right, r.bottom, COLOUR_GREY, FR_BORDERONLY);
    01207         DrawFrameRect(r.left + 1, r.top + 1, (int)((r.right - r.left - 2) * _tp.percent / 100) + r.left + 1, r.bottom - 1, COLOUR_MAUVE, FR_NONE);
    01208         SetDParam(0, _tp.percent);
    01209         DrawString(r.left, r.right, r.top + 5, STR_GENERATION_PROGRESS, TC_FROMSTRING, SA_CENTER);
    01210         break;
    01211
    01212       case GPWW_PROGRESS_TEXT:
    01213         /* Tell which class we are generating */
    01214         DrawString(r.left, r.right, r.top, _tp.cls, TC_FROMSTRING, SA_CENTER);
    01215
    01216         /* And say where we are in that class */
    01217         SetDParam(0, _tp.current);
    01218         SetDParam(1, _tp.total);
    01219         DrawString(r.left, r.right, r.top + FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL, STR_GENERATION_PROGRESS_NUM, TC_FROMSTRING, SA_CENTER);
    01220     }
    01221   }
    01222 };
    01223
    01227 void PrepareGenerateWorldProgress()
    01228 {
    01229   _tp.cls   = STR_GENERATION_WORLD_GENERATION;
    01230   _tp.current = 0;
    01231   _tp.total   = 0;
    01232   _tp.percent = 0;
    01233   _tp.timer   = 0; // Forces to paint the progress window immediatelly
    01234 }
    01235
    01239 void ShowGenerateWorldProgress()
    01240 {
    01241   if (BringWindowToFrontById(WC_GENERATE_PROGRESS_WINDOW, 0)) return;
    01242   new GenerateProgressWindow();
    01243 }
    01244
    01245 static void _SetGeneratingWorldProgress(gwp_class cls, uint progress, uint total)
    01246 {
    01247   static const int percent_table[GWP_CLASS_COUNT + 1] = {0, 5, 15, 20, 40, 60, 65, 80, 85, 99, 100 };
    01248
    01249   assert(cls < GWP_CLASS_COUNT);
    01250
    01251   /* Do not run this function if we aren't in a thread */
    01252   if (!IsGenerateWorldThreaded() && !_network_dedicated) return;
    01253
    01254   if (IsGeneratingWorldAborted()) HandleGeneratingWorldAbortion();
    01255
    01256   if (total == 0) {
    01257     assert(_tp.cls == _generation_class_table[cls]);
    01258     _tp.current += progress;
    01259   } else {
    01260     _tp.cls   = _generation_class_table[cls];
    01261     _tp.current = progress;
    01262     _tp.total   = total;
    01263     _tp.percent = percent_table[cls];
    01264   }
    01265
    01266   /* Don't update the screen too often. So update it once in every once in a while... */
    01267   if (!_network_dedicated && _tp.timer != 0 && _realtime_tick - _tp.timer < GENWORLD_REDRAW_TIMEOUT) return;
    01268
    01269   /* Percentage is about the number of completed tasks, so 'current - 1' */
    01270   _tp.percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (_tp.current == 0 ? 0 : _tp.current - 1) / _tp.total;
    01271
    01272   if (_network_dedicated) {
    01273     static uint last_percent = 0;
    01274
    01275     /* Never display 0% */
    01276     if (_tp.percent == 0) return;
    01277     /* Reset if percent is lower than the last recorded */
    01278     if (_tp.percent < last_percent) last_percent = 0;
    01279     /* Display every 5%, but 6% is also very valid.. just not smaller steps than 5% */
    01280     if (_tp.percent % 5 != 0 && _tp.percent <= last_percent + 5) return;
    01281     /* Never show steps smaller than 2%, even if it is a mod 5% */
    01282     if (_tp.percent <= last_percent + 2) return;
    01283
    01284     DEBUG(net, 1, "Map generation percentage complete: %d", _tp.percent);
    01285     last_percent = _tp.percent;
    01286
    01287     /* Don't continue as dedicated never has a thread running */
    01288     return;
    01289   }
    01290
    01291   SetWindowDirty(WC_GENERATE_PROGRESS_WINDOW, 0);
    01292   MarkWholeScreenDirty();
    01293
    01294   /* Release the rights to the map generator, and acquire the rights to the
    01295    * paint thread. The 'other' thread already has the paint thread rights so
    01296    * this ensures us that we are waiting until the paint thread is done
    01297    * before we reacquire the mapgen rights */
    01298   _genworld_mapgen_mutex->EndCritical();
    01299   _genworld_paint_mutex->BeginCritical();
    01300   _genworld_mapgen_mutex->BeginCritical();
    01301   _genworld_paint_mutex->EndCritical();
    01302
    01303   _tp.timer = _realtime_tick;
    01304 }
    01305
    01314 void SetGeneratingWorldProgress(gwp_class cls, uint total)
    01315 {
    01316   if (total == 0) return;
    01317
    01318   _SetGeneratingWorldProgress(cls, 0, total);
    01319 }
    01320
    01328 void IncreaseGeneratingWorldProgress(gwp_class cls)
    01329 {
    01330   /* In fact the param 'class' isn't needed.. but for some security reasons, we want it around */
    01331   _SetGeneratingWorldProgress(cls, 1, 0);
    01332 }