# genworld_gui.cpp

Go to the documentation of this file.

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