# genworld_gui.cpp

Go to the documentation of this file.

    00001 /* $Id: genworld_gui.cpp 22001 2011-02-06 18:26:50Z alberth $ */
    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
    00428   virtual void OnInvalidateData(int data = 0)
    00429   {
    00430     /* Update the climate buttons */
    00431     this->SetWidgetLoweredState(GLAND_TEMPERATE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
    00432     this->SetWidgetLoweredState(GLAND_ARCTIC,    _settings_newgame.game_creation.landscape == LT_ARCTIC);
    00433     this->SetWidgetLoweredState(GLAND_TROPICAL,  _settings_newgame.game_creation.landscape == LT_TROPIC);
    00434     this->SetWidgetLoweredState(GLAND_TOYLAND,   _settings_newgame.game_creation.landscape == LT_TOYLAND);
    00435
    00436     /* You can't select smoothness / non-water borders if not terragenesis */
    00437     if (mode == GLWM_GENERATE) {
    00438       this->SetWidgetDisabledState(GLAND_SMOOTHNESS_PULLDOWN, _settings_newgame.game_creation.land_generator == 0);
    00439       this->SetWidgetDisabledState(GLAND_VARIETY_PULLDOWN, _settings_newgame.game_creation.land_generator == 0);
    00440       this->SetWidgetDisabledState(GLAND_BORDERS_RANDOM, _settings_newgame.game_creation.land_generator == 0 || !_settings_newgame.construction.freeform_edges);
    00441       this->SetWidgetsDisabledState(_settings_newgame.game_creation.land_generator == 0 || !_settings_newgame.construction.freeform_edges || _settings_newgame.game_creation.water_borders == BORDERS_RANDOM,
    00442           GLAND_WATER_NW, GLAND_WATER_NE, GLAND_WATER_SE, GLAND_WATER_SW, WIDGET_LIST_END);
    00443
    00444       this->SetWidgetLoweredState(GLAND_BORDERS_RANDOM, _settings_newgame.game_creation.water_borders == BORDERS_RANDOM);
    00445
    00446       this->SetWidgetLoweredState(GLAND_WATER_NW, HasBit(_settings_newgame.game_creation.water_borders, BORDER_NW));
    00447       this->SetWidgetLoweredState(GLAND_WATER_NE, HasBit(_settings_newgame.game_creation.water_borders, BORDER_NE));
    00448       this->SetWidgetLoweredState(GLAND_WATER_SE, HasBit(_settings_newgame.game_creation.water_borders, BORDER_SE));
    00449       this->SetWidgetLoweredState(GLAND_WATER_SW, HasBit(_settings_newgame.game_creation.water_borders, BORDER_SW));
    00450
    00451       this->SetWidgetsDisabledState(_settings_newgame.game_creation.land_generator == 0 && (_settings_newgame.game_creation.landscape == LT_ARCTIC || _settings_newgame.game_creation.landscape == LT_TROPIC),
    00452           GLAND_TERRAIN_PULLDOWN, GLAND_WATER_PULLDOWN, WIDGET_LIST_END);
    00453     }
    00454
    00455     /* Disable snowline if not arctic */
    00456     this->SetWidgetDisabledState(GLAND_SNOW_LEVEL_TEXT, _settings_newgame.game_creation.landscape != LT_ARCTIC);
    00457
    00458     /* Update availability of decreasing / increasing start date and snow level */
    00459     this->SetWidgetDisabledState(GLAND_START_DATE_DOWN, _settings_newgame.game_creation.starting_year <= MIN_YEAR);
    00460     this->SetWidgetDisabledState(GLAND_START_DATE_UP,   _settings_newgame.game_creation.starting_year >= MAX_YEAR);
    00461     this->SetWidgetDisabledState(GLAND_SNOW_LEVEL_DOWN, _settings_newgame.game_creation.snow_line_height <= MIN_SNOWLINE_HEIGHT || _settings_newgame.game_creation.landscape != LT_ARCTIC);
    00462     this->SetWidgetDisabledState(GLAND_SNOW_LEVEL_UP,   _settings_newgame.game_creation.snow_line_height >= MAX_SNOWLINE_HEIGHT || _settings_newgame.game_creation.landscape != LT_ARCTIC);
    00463
    00464     /* Do not allow a custom sea level with the original land generator. */
    00465     if (_settings_newgame.game_creation.land_generator == 0 &&
    00466         _settings_newgame.difficulty.quantity_sea_lakes == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
    00467       _settings_newgame.difficulty.quantity_sea_lakes = CUSTOM_SEA_LEVEL_MIN_PERCENTAGE;
    00468     }
    00469
    00470   }
    00471
    00472   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
    00473   {
    00474     const StringID *strs = NULL;
    00475     switch (widget) {
    00476       case GLAND_START_DATE_TEXT:
    00477         SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
    00478         *size = GetStringBoundingBox(STR_BLACK_DATE_LONG);
    00479         break;
    00480
    00481       case GLAND_MAPSIZE_X_PULLDOWN:
    00482       case GLAND_MAPSIZE_Y_PULLDOWN:
    00483         SetDParam(0, MAX_MAP_SIZE);
    00484         *size = GetStringBoundingBox(STR_JUST_INT);
    00485         break;
    00486
    00487       case GLAND_SNOW_LEVEL_TEXT:
    00488         SetDParam(0, MAX_TILE_HEIGHT);
    00489         *size = GetStringBoundingBox(STR_JUST_INT);
    00490         break;
    00491
    00492       case GLAND_HEIGHTMAP_SIZE_TEXT:
    00493         SetDParam(0, this->x);
    00494         SetDParam(1, this->y);
    00495         *size = GetStringBoundingBox(STR_MAPGEN_HEIGHTMAP_SIZE);
    00496         break;
    00497
    00498       case GLAND_TOWN_PULLDOWN:
    00499         strs = _num_towns;
    00500         SetDParam(0, CUSTOM_TOWN_MAX_NUMBER);
    00501         *size = GetStringBoundingBox(STR_NUM_CUSTOM_NUMBER);
    00502         break;
    00503
    00504       case GLAND_INDUSTRY_PULLDOWN:   strs = _num_inds; break;
    00505       case GLAND_LANDSCAPE_PULLDOWN:  strs = _landscape; break;
    00506       case GLAND_TREE_PULLDOWN:       strs = _tree_placer; break;
    00507       case GLAND_TERRAIN_PULLDOWN:    strs = _elevations; break;
    00508       case GLAND_WATER_PULLDOWN:
    00509         strs = _sea_lakes;
    00510         SetDParam(0, CUSTOM_SEA_LEVEL_MAX_PERCENTAGE);
    00511         *size = GetStringBoundingBox(STR_SEA_LEVEL_CUSTOM_PERCENTAGE);
    00512         break;
    00513
    00514       case GLAND_SMOOTHNESS_PULLDOWN: strs = _smoothness; break;
    00515       case GLAND_VARIETY_PULLDOWN:    strs = _variety; break;
    00516       case GLAND_HEIGHTMAP_ROTATION_PULLDOWN: strs = _rotation; break;
    00517       case GLAND_BORDERS_RANDOM:
    00518         *size = maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_RANDOMIZE), GetStringBoundingBox(STR_MAPGEN_BORDER_MANUAL));
    00519         break;
    00520
    00521       case GLAND_WATER_NE:
    00522       case GLAND_WATER_NW:
    00523       case GLAND_WATER_SE:
    00524       case GLAND_WATER_SW:
    00525         *size = maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_RANDOM), maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_WATER), GetStringBoundingBox(STR_MAPGEN_BORDER_FREEFORM)));
    00526         break;
    00527
    00528       case GLAND_HEIGHTMAP_NAME_SPACER:
    00529       case GLAND_HEIGHTMAP_NAME_TEXT:
    00530         size->width = 0;
    00531         break;
    00532
    00533       default:
    00534         return;
    00535     }
    00536     if (strs != NULL) {
    00537       while (*strs != INVALID_STRING_ID) {
    00538         *size = maxdim(*size, GetStringBoundingBox(*strs++));
    00539       }
    00540     }
    00541     size->width += padding.width;
    00542     size->height = FONT_HEIGHT_NORMAL + WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM;
    00543   }
    00544
    00545   virtual void DrawWidget(const Rect &r, int widget) const
    00546   {
    00547     switch (widget) {
    00548       case GLAND_HEIGHTMAP_NAME_TEXT: {
    00549         /* Little bit of a hack going on here; just to get the widgets
    00550          * spaced without doing much magic. The space we can draw on is
    00551          * covered by both the spacer and text widgets, so take their
    00552          * outer most boundaries (left and right) as draw locations. */
    00553         const NWidgetBase *nwi_spacer = this->GetWidget<NWidgetBase>(GLAND_HEIGHTMAP_NAME_SPACER);
    00554         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);
    00555         break;
    00556       }
    00557     }
    00558   }
    00559
    00560   virtual void OnPaint()
    00561   {
    00562     this->DrawWidgets();
    00563     this->DrawEditBox(GLAND_RANDOM_EDITBOX);
    00564   }
    00565
    00566   virtual void OnClick(Point pt, int widget, int click_count)
    00567   {
    00568     switch (widget) {
    00569       case GLAND_TEMPERATE:
    00570       case GLAND_ARCTIC:
    00571       case GLAND_TROPICAL:
    00572       case GLAND_TOYLAND:
    00573         SetNewLandscapeType(widget - GLAND_TEMPERATE);
    00574         break;
    00575
    00576       case GLAND_MAPSIZE_X_PULLDOWN: // Mapsize X
    00577         ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_x, GLAND_MAPSIZE_X_PULLDOWN);
    00578         break;
    00579
    00580       case GLAND_MAPSIZE_Y_PULLDOWN: // Mapsize Y
    00581         ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_y, GLAND_MAPSIZE_Y_PULLDOWN);
    00582         break;
    00583
    00584       case GLAND_TOWN_PULLDOWN: // Number of towns
    00585         ShowDropDownMenu(this, _num_towns, _settings_newgame.difficulty.number_towns, GLAND_TOWN_PULLDOWN, 0, 0);
    00586         break;
    00587
    00588       case GLAND_INDUSTRY_PULLDOWN: // Number of industries
    00589         ShowDropDownMenu(this, _num_inds, _settings_newgame.difficulty.industry_density, GLAND_INDUSTRY_PULLDOWN, 0, 0);
    00590         break;
    00591
    00592       case GLAND_RANDOM_BUTTON: // Random seed
    00593         _settings_newgame.game_creation.generation_seed = InteractiveRandom();
    00594         snprintf(this->edit_str_buf, this->edit_str_size, "%u", _settings_newgame.game_creation.generation_seed);
    00595         UpdateTextBufferSize(&this->text);
    00596         this->SetDirty();
    00597         break;
    00598
    00599       case GLAND_GENERATE_BUTTON: // Generate
    00600         MakeNewgameSettingsLive();
    00601
    00602         if (mode == GLWM_HEIGHTMAP &&
    00603             (this->x * 2 < (1U << _settings_newgame.game_creation.map_x) ||
    00604             this->x / 2 > (1U << _settings_newgame.game_creation.map_x) ||
    00605             this->y * 2 < (1U << _settings_newgame.game_creation.map_y) ||
    00606             this->y / 2 > (1U << _settings_newgame.game_creation.map_y))) {
    00607           ShowQuery(
    00608             STR_WARNING_HEIGHTMAP_SCALE_CAPTION,
    00609             STR_WARNING_HEIGHTMAP_SCALE_MESSAGE,
    00610             this,
    00611             LandscapeGenerationCallback);
    00612         } else {
    00613           StartGeneratingLandscape(mode);
    00614         }
    00615         break;
    00616
    00617       case GLAND_START_DATE_DOWN:
    00618       case GLAND_START_DATE_UP: // Year buttons
    00619         /* Don't allow too fast scrolling */
    00620         if ((this->flags4 & WF_TIMEOUT_MASK) <= WF_TIMEOUT_TRIGGER) {
    00621           this->HandleButtonClick(widget);
    00622
    00623           _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - GLAND_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
    00624           this->InvalidateData();
    00625         }
    00626         _left_button_clicked = false;
    00627         break;
    00628
    00629       case GLAND_START_DATE_TEXT: // Year text
    00630         this->widget_id = GLAND_START_DATE_TEXT;
    00631         SetDParam(0, _settings_newgame.game_creation.starting_year);
    00632         ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, 100, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
    00633         break;
    00634
    00635       case GLAND_SNOW_LEVEL_DOWN:
    00636       case GLAND_SNOW_LEVEL_UP: // Snow line buttons
    00637         /* Don't allow too fast scrolling */
    00638         if ((this->flags4 & WF_TIMEOUT_MASK) <= WF_TIMEOUT_TRIGGER) {
    00639           this->HandleButtonClick(widget);
    00640
    00641           _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);
    00642           this->InvalidateData();
    00643         }
    00644         _left_button_clicked = false;
    00645         break;
    00646
    00647       case GLAND_SNOW_LEVEL_TEXT: // Snow line text
    00648         this->widget_id = GLAND_SNOW_LEVEL_TEXT;
    00649         SetDParam(0, _settings_newgame.game_creation.snow_line_height);
    00650         ShowQueryString(STR_JUST_INT, STR_MAPGEN_SNOW_LINE_QUERY_CAPT, 3, 100, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
    00651         break;
    00652
    00653       case GLAND_TREE_PULLDOWN: // Tree placer
    00654         ShowDropDownMenu(this, _tree_placer, _settings_newgame.game_creation.tree_placer, GLAND_TREE_PULLDOWN, 0, 0);
    00655         break;
    00656
    00657       case GLAND_LANDSCAPE_PULLDOWN: // Landscape generator
    00658         ShowDropDownMenu(this, _landscape, _settings_newgame.game_creation.land_generator, GLAND_LANDSCAPE_PULLDOWN, 0, 0);
    00659         break;
    00660
    00661       case GLAND_HEIGHTMAP_ROTATION_PULLDOWN: // Heightmap rotation
    00662         ShowDropDownMenu(this, _rotation, _settings_newgame.game_creation.heightmap_rotation, GLAND_HEIGHTMAP_ROTATION_PULLDOWN, 0, 0);
    00663         break;
    00664
    00665       case GLAND_TERRAIN_PULLDOWN: // Terrain type
    00666         ShowDropDownMenu(this, _elevations, _settings_newgame.difficulty.terrain_type, GLAND_TERRAIN_PULLDOWN, 0, 0);
    00667         break;
    00668
    00669       case GLAND_WATER_PULLDOWN: { // Water quantity
    00670         uint32 hidden_mask = 0;
    00671         /* Disable custom water level when the original map generator is active. */
    00672         if (_settings_newgame.game_creation.land_generator == 0) {
    00673           SetBit(hidden_mask, CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY);
    00674         }
    00675         ShowDropDownMenu(this, _sea_lakes, _settings_newgame.difficulty.quantity_sea_lakes, GLAND_WATER_PULLDOWN, 0, hidden_mask);
    00676         break;
    00677       }
    00678
    00679       case GLAND_SMOOTHNESS_PULLDOWN: // Map smoothness
    00680         ShowDropDownMenu(this, _smoothness, _settings_newgame.game_creation.tgen_smoothness, GLAND_SMOOTHNESS_PULLDOWN, 0, 0);
    00681         break;
    00682
    00683       case GLAND_VARIETY_PULLDOWN: // Map variety
    00684         ShowDropDownMenu(this, _variety, _settings_newgame.game_creation.variety, GLAND_VARIETY_PULLDOWN, 0, 0);
    00685         break;
    00686
    00687       /* Freetype map borders */
    00688       case GLAND_WATER_NW:
    00689         _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_NW);
    00690         this->InvalidateData();
    00691         break;
    00692
    00693       case GLAND_WATER_NE:
    00694         _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_NE);
    00695         this->InvalidateData();
    00696         break;
    00697
    00698       case GLAND_WATER_SE:
    00699         _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_SE);
    00700         this->InvalidateData();
    00701         break;
    00702
    00703       case GLAND_WATER_SW:
    00704         _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_SW);
    00705         this->InvalidateData();
    00706         break;
    00707
    00708       case GLAND_BORDERS_RANDOM:
    00709         _settings_newgame.game_creation.water_borders = (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? 0 : BORDERS_RANDOM;
    00710         this->InvalidateData();
    00711         break;
    00712     }
    00713   }
    00714
    00715   virtual void OnTimeout()
    00716   {
    00717     static const int raise_widgets[] = {GLAND_START_DATE_DOWN, GLAND_START_DATE_UP, GLAND_SNOW_LEVEL_UP, GLAND_SNOW_LEVEL_DOWN, WIDGET_LIST_END};
    00718     for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
    00719       if (this->IsWidgetLowered(*widget)) {
    00720         this->RaiseWidget(*widget);
    00721         this->SetWidgetDirty(*widget);
    00722       }
    00723     }
    00724   }
    00725
    00726   virtual void OnMouseLoop()
    00727   {
    00728     this->HandleEditBox(GLAND_RANDOM_EDITBOX);
    00729   }
    00730
    00731   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
    00732   {
    00733     EventState state = ES_NOT_HANDLED;
    00734     this->HandleEditBoxKey(GLAND_RANDOM_EDITBOX, key, keycode, state);
    00735     /* the seed is unsigned, therefore atoi cannot be used.
    00736      * As UINT32_MAX is a 'magic' value (use random seed) it
    00737      * should not be possible to be entered into the input
    00738      * field; the generate seed button can be used instead. */
    00739     _settings_newgame.game_creation.generation_seed = minu(strtoul(this->edit_str_buf, NULL, 10), UINT32_MAX - 1);
    00740     return state;
    00741   }
    00742
    00743   virtual void OnDropdownSelect(int widget, int index)
    00744   {
    00745     switch (widget) {
    00746       case GLAND_MAPSIZE_X_PULLDOWN:     _settings_newgame.game_creation.map_x = index; break;
    00747       case GLAND_MAPSIZE_Y_PULLDOWN:     _settings_newgame.game_creation.map_y = index; break;
    00748       case GLAND_TREE_PULLDOWN:          _settings_newgame.game_creation.tree_placer = index; break;
    00749       case GLAND_SMOOTHNESS_PULLDOWN:    _settings_newgame.game_creation.tgen_smoothness = index;  break;
    00750       case GLAND_VARIETY_PULLDOWN:       _settings_newgame.game_creation.variety = index; break;
    00751       case GLAND_LANDSCAPE_PULLDOWN:     _settings_newgame.game_creation.land_generator = index; break;
    00752       case GLAND_HEIGHTMAP_ROTATION_PULLDOWN: _settings_newgame.game_creation.heightmap_rotation = index; break;
    00753
    00754       case GLAND_TOWN_PULLDOWN:
    00755         if ((uint)index == CUSTOM_TOWN_NUMBER_DIFFICULTY) {
    00756           this->widget_id = widget;
    00757           SetDParam(0, _settings_newgame.game_creation.custom_town_number);
    00758           ShowQueryString(STR_JUST_INT, STR_MAPGEN_NUMBER_OF_TOWNS, 5, 50, this, CS_NUMERAL, QSF_NONE);
    00759         }
    00760         IConsoleSetSetting("difficulty.number_towns", index);
    00761         break;
    00762
    00763       case GLAND_INDUSTRY_PULLDOWN:
    00764         IConsoleSetSetting("difficulty.industry_density", index);
    00765         break;
    00766
    00767       case GLAND_TERRAIN_PULLDOWN: {
    00768         GameMode old_gm = _game_mode;
    00769         _game_mode = GM_MENU;
    00770         IConsoleSetSetting("difficulty.terrain_type", index);
    00771         _game_mode = old_gm;
    00772         break;
    00773       }
    00774
    00775       case GLAND_WATER_PULLDOWN: {
    00776         if ((uint)index == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
    00777           this->widget_id = widget;
    00778           SetDParam(0, _settings_newgame.game_creation.custom_sea_level);
    00779           ShowQueryString(STR_JUST_INT, STR_MAPGEN_QUANTITY_OF_SEA_LAKES, 3, 50, this, CS_NUMERAL, QSF_NONE);
    00780         }
    00781         GameMode old_gm = _game_mode;
    00782         _game_mode = GM_MENU;
    00783         IConsoleSetSetting("difficulty.quantity_sea_lakes", index);
    00784         _game_mode = old_gm;
    00785         break;
    00786       }
    00787     }
    00788     this->InvalidateData();
    00789   }
    00790
    00791   virtual void OnQueryTextFinished(char *str)
    00792   {
    00793     /* Was 'cancel' pressed? */
    00794     if (str == NULL) return;
    00795
    00796     int32 value;
    00797     if (!StrEmpty(str)) {
    00798       value = atoi(str);
    00799     } else {
    00800       /* An empty string means revert to the default */
    00801       switch (this->widget_id) {
    00802         case GLAND_START_DATE_TEXT: value = DEF_START_YEAR; break;
    00803         case GLAND_SNOW_LEVEL_TEXT: value = DEF_SNOWLINE_HEIGHT; break;
    00804         case GLAND_TOWN_PULLDOWN:   value = 1; break;
    00805         case GLAND_WATER_PULLDOWN:  value = CUSTOM_SEA_LEVEL_MIN_PERCENTAGE; break;
    00806         default: NOT_REACHED();
    00807       }
    00808     }
    00809
    00810     switch (this->widget_id) {
    00811       case GLAND_START_DATE_TEXT:
    00812         this->SetWidgetDirty(GLAND_START_DATE_TEXT);
    00813         _settings_newgame.game_creation.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
    00814         break;
    00815
    00816       case GLAND_SNOW_LEVEL_TEXT:
    00817         this->SetWidgetDirty(GLAND_SNOW_LEVEL_TEXT);
    00818         _settings_newgame.game_creation.snow_line_height = Clamp(value, MIN_SNOWLINE_HEIGHT, MAX_SNOWLINE_HEIGHT);
    00819         break;
    00820
    00821       case GLAND_TOWN_PULLDOWN:
    00822         _settings_newgame.game_creation.custom_town_number = Clamp(value, 1, CUSTOM_TOWN_MAX_NUMBER);
    00823         break;
    00824
    00825       case GLAND_WATER_PULLDOWN:
    00826         _settings_newgame.game_creation.custom_sea_level = Clamp(value, CUSTOM_SEA_LEVEL_MIN_PERCENTAGE, CUSTOM_SEA_LEVEL_MAX_PERCENTAGE);
    00827         break;
    00828     }
    00829
    00830     this->InvalidateData();
    00831   }
    00832 };
    00833
    00834 static const WindowDesc _generate_landscape_desc(
    00835   WDP_CENTER, 0, 0,
    00836   WC_GENERATE_LANDSCAPE, WC_NONE,
    00837   0,
    00838   _nested_generate_landscape_widgets, lengthof(_nested_generate_landscape_widgets)
    00839 );
    00840
    00841 static const WindowDesc _heightmap_load_desc(
    00842   WDP_CENTER, 0, 0,
    00843   WC_GENERATE_LANDSCAPE, WC_NONE,
    00844   0,
    00845   _nested_heightmap_load_widgets, lengthof(_nested_heightmap_load_widgets)
    00846 );
    00847
    00848 static void _ShowGenerateLandscape(GenenerateLandscapeWindowMode mode)
    00849 {
    00850   uint x = 0;
    00851   uint y = 0;
    00852
    00853   DeleteWindowByClass(WC_GENERATE_LANDSCAPE);
    00854
    00855   /* Always give a new seed if not editor */
    00856   if (_game_mode != GM_EDITOR) _settings_newgame.game_creation.generation_seed = InteractiveRandom();
    00857
    00858   if (mode == GLWM_HEIGHTMAP) {
    00859     /* If the function returns negative, it means there was a problem loading the heightmap */
    00860     if (!GetHeightmapDimensions(_file_to_saveload.name, &x, &y)) return;
    00861   }
    00862
    00863   GenerateLandscapeWindow *w = AllocateWindowDescFront<GenerateLandscapeWindow>((mode == GLWM_HEIGHTMAP) ? &_heightmap_load_desc : &_generate_landscape_desc, mode);
    00864
    00865   if (mode == GLWM_HEIGHTMAP) {
    00866     w->x = x;
    00867     w->y = y;
    00868     strecpy(w->name, _file_to_saveload.title, lastof(w->name));
    00869   }
    00870
    00871   SetWindowDirty(WC_GENERATE_LANDSCAPE, mode);
    00872 }
    00873
    00874 void ShowGenerateLandscape()
    00875 {
    00876   _ShowGenerateLandscape(GLWM_GENERATE);
    00877 }
    00878
    00879 void ShowHeightmapLoad()
    00880 {
    00881   _ShowGenerateLandscape(GLWM_HEIGHTMAP);
    00882 }
    00883
    00884 void StartScenarioEditor()
    00885 {
    00886   StartGeneratingLandscape(GLWM_SCENARIO);
    00887 }
    00888
    00889 void StartNewGameWithoutGUI(uint seed)
    00890 {
    00891   /* GenerateWorld takes care of the possible GENERATE_NEW_SEED value in 'seed' */
    00892   _settings_newgame.game_creation.generation_seed = seed;
    00893
    00894   StartGeneratingLandscape(GLWM_GENERATE);
    00895 }
    00896
    00898 enum CreateScenarioWindowWidgets {
    00899   CSCEN_TEMPERATE,
    00900   CSCEN_ARCTIC,
    00901   CSCEN_TROPICAL,
    00902   CSCEN_TOYLAND,
    00903   CSCEN_EMPTY_WORLD,
    00904   CSCEN_RANDOM_WORLD,
    00905   CSCEN_MAPSIZE_X_PULLDOWN,
    00906   CSCEN_MAPSIZE_Y_PULLDOWN,
    00907   CSCEN_START_DATE_DOWN,
    00908   CSCEN_START_DATE_TEXT,
    00909   CSCEN_START_DATE_UP,
    00910   CSCEN_FLAT_LAND_HEIGHT_DOWN,
    00911   CSCEN_FLAT_LAND_HEIGHT_TEXT,
    00912   CSCEN_FLAT_LAND_HEIGHT_UP
    00913 };
    00914
    00915
    00916 struct CreateScenarioWindow : public Window
    00917 {
    00918   uint widget_id;
    00919
    00920   CreateScenarioWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
    00921   {
    00922     this->InitNested(desc, window_number);
    00923     this->LowerWidget(_settings_newgame.game_creation.landscape + CSCEN_TEMPERATE);
    00924   }
    00925
    00926   virtual void SetStringParameters(int widget) const
    00927   {
    00928     switch (widget) {
    00929       case CSCEN_START_DATE_TEXT:
    00930         SetDParam(0, ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1));
    00931         break;
    00932
    00933       case CSCEN_MAPSIZE_X_PULLDOWN:
    00934         SetDParam(0, 1 << _settings_newgame.game_creation.map_x);
    00935         break;
    00936
    00937       case CSCEN_MAPSIZE_Y_PULLDOWN:
    00938         SetDParam(0, 1 << _settings_newgame.game_creation.map_y);
    00939         break;
    00940
    00941       case CSCEN_FLAT_LAND_HEIGHT_TEXT:
    00942         SetDParam(0, _settings_newgame.game_creation.se_flat_world_height);
    00943         break;
    00944     }
    00945   }
    00946
    00947   virtual void OnPaint()
    00948   {
    00949     this->SetWidgetDisabledState(CSCEN_START_DATE_DOWN,       _settings_newgame.game_creation.starting_year <= MIN_YEAR);
    00950     this->SetWidgetDisabledState(CSCEN_START_DATE_UP,         _settings_newgame.game_creation.starting_year >= MAX_YEAR);
    00951     this->SetWidgetDisabledState(CSCEN_FLAT_LAND_HEIGHT_DOWN, _settings_newgame.game_creation.se_flat_world_height <= 0);
    00952     this->SetWidgetDisabledState(CSCEN_FLAT_LAND_HEIGHT_UP,   _settings_newgame.game_creation.se_flat_world_height >= MAX_TILE_HEIGHT);
    00953
    00954     this->SetWidgetLoweredState(CSCEN_TEMPERATE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
    00955     this->SetWidgetLoweredState(CSCEN_ARCTIC,    _settings_newgame.game_creation.landscape == LT_ARCTIC);
    00956     this->SetWidgetLoweredState(CSCEN_TROPICAL,  _settings_newgame.game_creation.landscape == LT_TROPIC);
    00957     this->SetWidgetLoweredState(CSCEN_TOYLAND,   _settings_newgame.game_creation.landscape == LT_TOYLAND);
    00958
    00959     this->DrawWidgets();
    00960   }
    00961
    00962   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
    00963   {
    00964     StringID str = STR_JUST_INT;
    00965     switch (widget) {
    00966       case CSCEN_START_DATE_TEXT:
    00967         SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
    00968         str = STR_BLACK_DATE_LONG;
    00969         break;
    00970
    00971       case CSCEN_MAPSIZE_X_PULLDOWN:
    00972       case CSCEN_MAPSIZE_Y_PULLDOWN:
    00973         SetDParam(0, MAX_MAP_SIZE);
    00974         break;
    00975
    00976       case CSCEN_FLAT_LAND_HEIGHT_TEXT:
    00977         SetDParam(0, MAX_TILE_HEIGHT);
    00978         break;
    00979
    00980       default:
    00981         return;
    00982     }
    00983     *size = GetStringBoundingBox(str);
    00984     size->width += padding.width;
    00985     size->height += padding.height;
    00986   }
    00987
    00988   virtual void OnClick(Point pt, int widget, int click_count)
    00989   {
    00990     switch (widget) {
    00991       case CSCEN_TEMPERATE:
    00992       case CSCEN_ARCTIC:
    00993       case CSCEN_TROPICAL:
    00994       case CSCEN_TOYLAND:
    00995         this->RaiseWidget(_settings_newgame.game_creation.landscape + CSCEN_TEMPERATE);
    00996         SetNewLandscapeType(widget - CSCEN_TEMPERATE);
    00997         break;
    00998
    00999       case CSCEN_MAPSIZE_X_PULLDOWN: // Mapsize X
    01000         ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_x, CSCEN_MAPSIZE_X_PULLDOWN);
    01001         break;
    01002
    01003       case CSCEN_MAPSIZE_Y_PULLDOWN: // Mapsize Y
    01004         ShowDropDownList(this, BuildMapsizeDropDown(), _settings_newgame.game_creation.map_y, CSCEN_MAPSIZE_Y_PULLDOWN);
    01005         break;
    01006
    01007       case CSCEN_EMPTY_WORLD: // Empty world / flat world
    01008         StartGeneratingLandscape(GLWM_SCENARIO);
    01009         break;
    01010
    01011       case CSCEN_RANDOM_WORLD: // Generate
    01012         ShowGenerateLandscape();
    01013         break;
    01014
    01015       case CSCEN_START_DATE_DOWN:
    01016       case CSCEN_START_DATE_UP: // Year buttons
    01017         /* Don't allow too fast scrolling */
    01018         if ((this->flags4 & WF_TIMEOUT_MASK) <= WF_TIMEOUT_TRIGGER) {
    01019           this->HandleButtonClick(widget);
    01020           this->SetDirty();
    01021
    01022           _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - CSCEN_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
    01023         }
    01024         _left_button_clicked = false;
    01025         break;
    01026
    01027       case CSCEN_START_DATE_TEXT: // Year text
    01028         this->widget_id = CSCEN_START_DATE_TEXT;
    01029         SetDParam(0, _settings_newgame.game_creation.starting_year);
    01030         ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, 100, this, CS_NUMERAL, QSF_NONE);
    01031         break;
    01032
    01033       case CSCEN_FLAT_LAND_HEIGHT_DOWN:
    01034       case CSCEN_FLAT_LAND_HEIGHT_UP: // Height level buttons
    01035         /* Don't allow too fast scrolling */
    01036         if ((this->flags4 & WF_TIMEOUT_MASK) <= WF_TIMEOUT_TRIGGER) {
    01037           this->HandleButtonClick(widget);
    01038           this->SetDirty();
    01039
    01040           _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);
    01041         }
    01042         _left_button_clicked = false;
    01043         break;
    01044
    01045       case CSCEN_FLAT_LAND_HEIGHT_TEXT: // Height level text
    01046         this->widget_id = CSCEN_FLAT_LAND_HEIGHT_TEXT;
    01047         SetDParam(0, _settings_newgame.game_creation.se_flat_world_height);
    01048         ShowQueryString(STR_JUST_INT, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_QUERY_CAPT, 3, 100, this, CS_NUMERAL, QSF_NONE);
    01049         break;
    01050     }
    01051   }
    01052
    01053   virtual void OnTimeout()
    01054   {
    01055     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};
    01056     for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
    01057       if (this->IsWidgetLowered(*widget)) {
    01058         this->RaiseWidget(*widget);
    01059         this->SetWidgetDirty(*widget);
    01060       }
    01061     }
    01062   }
    01063
    01064   virtual void OnDropdownSelect(int widget, int index)
    01065   {
    01066     switch (widget) {
    01067       case CSCEN_MAPSIZE_X_PULLDOWN: _settings_newgame.game_creation.map_x = index; break;
    01068       case CSCEN_MAPSIZE_Y_PULLDOWN: _settings_newgame.game_creation.map_y = index; break;
    01069     }
    01070     this->SetDirty();
    01071   }
    01072
    01073   virtual void OnQueryTextFinished(char *str)
    01074   {
    01075     if (!StrEmpty(str)) {
    01076       int32 value = atoi(str);
    01077
    01078       switch (this->widget_id) {
    01079         case CSCEN_START_DATE_TEXT:
    01080           this->SetWidgetDirty(CSCEN_START_DATE_TEXT);
    01081           _settings_newgame.game_creation.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
    01082           break;
    01083
    01084         case CSCEN_FLAT_LAND_HEIGHT_TEXT:
    01085           this->SetWidgetDirty(CSCEN_FLAT_LAND_HEIGHT_TEXT);
    01086           _settings_newgame.game_creation.se_flat_world_height = Clamp(value, 0, MAX_TILE_HEIGHT);
    01087           break;
    01088       }
    01089
    01090       this->SetDirty();
    01091     }
    01092   }
    01093 };
    01094
    01095 static const NWidgetPart _nested_create_scenario_widgets[] = {
    01096   NWidget(NWID_HORIZONTAL),
    01097     NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
    01098     NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_SE_MAPGEN_CAPTION, STR_NULL),
    01099   EndContainer(),
    01100   NWidget(WWT_PANEL, COLOUR_BROWN),
    01101     NWidget(NWID_SPACER), SetMinimalSize(0, 10),
    01102     /* Landscape style selection. */
    01103     NWidget(NWID_HORIZONTAL), SetPIP(10, 3, 10),
    01104       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, CSCEN_TEMPERATE), SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
    01105       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, CSCEN_ARCTIC), SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
    01106       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, CSCEN_TROPICAL), SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
    01107       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, CSCEN_TOYLAND), SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
    01108     EndContainer(),
    01109     NWidget(NWID_HORIZONTAL), SetPIP(10, 8, 10),
    01110       /* Green generation type buttons: 'Flat land' and 'Random land'. */
    01111       NWidget(NWID_VERTICAL), SetPIP(10, 6, 10),
    01112         NWidget(WWT_TEXTBTN, COLOUR_GREEN, CSCEN_EMPTY_WORLD), SetDataTip(STR_SE_MAPGEN_FLAT_WORLD, STR_SE_MAPGEN_FLAT_WORLD_TOOLTIP), SetFill(1, 1),
    01113         NWidget(WWT_TEXTBTN, COLOUR_GREEN, CSCEN_RANDOM_WORLD), SetDataTip(STR_SE_MAPGEN_RANDOM_LAND, STR_TERRAFORM_TOOLTIP_GENERATE_RANDOM_LAND), SetFill(1, 1),
    01114       EndContainer(),
    01115       /* Labels + setting drop-downs */
    01116       NWidget(NWID_VERTICAL), SetPIP(10, 6, 10),
    01117         /* Map size. */
    01118         NWidget(NWID_HORIZONTAL),
    01119           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAPSIZE, STR_NULL), SetPadding(1, 0, 0, 0),
    01120           NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
    01121           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, CSCEN_MAPSIZE_X_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetPadding(0, 4, 0, 0),
    01122           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BY, STR_NULL), SetPadding(1, 2, 0, 0),
    01123           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, CSCEN_MAPSIZE_Y_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL),
    01124         EndContainer(),
    01125         /* Date. */
    01126         NWidget(NWID_HORIZONTAL),
    01127           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetPadding(1, 0, 0, 0),
    01128           NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
    01129           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),
    01130           NWidget(WWT_TEXTBTN, COLOUR_ORANGE, CSCEN_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL),
    01131           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),
    01132         EndContainer(),
    01133         /* Flat map height. */
    01134         NWidget(NWID_HORIZONTAL),
    01135           NWidget(WWT_TEXT, COLOUR_ORANGE),
    01136                         SetDataTip(STR_SE_MAPGEN_FLAT_WORLD_HEIGHT, STR_NULL), SetPadding(1, 0, 0, 0),
    01137           NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
    01138           NWidget(WWT_IMGBTN, COLOUR_ORANGE, CSCEN_FLAT_LAND_HEIGHT_DOWN), SetFill(0, 1), SetDataTip(SPR_ARROW_DOWN, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_DOWN),
    01139           NWidget(WWT_TEXTBTN, COLOUR_ORANGE, CSCEN_FLAT_LAND_HEIGHT_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL),
    01140           NWidget(WWT_IMGBTN, COLOUR_ORANGE, CSCEN_FLAT_LAND_HEIGHT_UP), SetFill(0, 1), SetDataTip(SPR_ARROW_UP, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_UP),
    01141         EndContainer(),
    01142       EndContainer(),
    01143     EndContainer(),
    01144   EndContainer(),
    01145 };
    01146
    01147 static const WindowDesc _create_scenario_desc(
    01148   WDP_CENTER, 0, 0,
    01149   WC_GENERATE_LANDSCAPE, WC_NONE,
    01150   WDF_UNCLICK_BUTTONS,
    01151   _nested_create_scenario_widgets, lengthof(_nested_create_scenario_widgets)
    01152 );
    01153
    01154 void ShowCreateScenario()
    01155 {
    01156   DeleteWindowByClass(WC_GENERATE_LANDSCAPE);
    01157   new CreateScenarioWindow(&_create_scenario_desc, GLWM_SCENARIO);
    01158 }
    01159
    01160 enum GenerationProgressWindowWidgets {
    01161   GPWW_PROGRESS_BAR,
    01162   GPWW_PROGRESS_TEXT,
    01163   GPWW_ABORT,
    01164 };
    01165
    01166 static const NWidgetPart _nested_generate_progress_widgets[] = {
    01167   NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GENERATION_WORLD, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    01168   NWidget(WWT_PANEL, COLOUR_GREY),
    01169     NWidget(NWID_HORIZONTAL), SetPIP(20, 0, 20),
    01170       NWidget(NWID_VERTICAL), SetPIP(11, 8, 11),
    01171         NWidget(WWT_EMPTY, INVALID_COLOUR, GPWW_PROGRESS_BAR), SetFill(1, 0),
    01172         NWidget(WWT_EMPTY, INVALID_COLOUR, GPWW_PROGRESS_TEXT), SetFill(1, 0),
    01173         NWidget(WWT_TEXTBTN, COLOUR_WHITE, GPWW_ABORT), SetDataTip(STR_GENERATION_ABORT, STR_NULL), SetFill(1, 0),
    01174       EndContainer(),
    01175     EndContainer(),
    01176   EndContainer(),
    01177 };
    01178
    01179
    01180 static const WindowDesc _generate_progress_desc(
    01181   WDP_CENTER, 0, 0,
    01182   WC_GENERATE_PROGRESS_WINDOW, WC_NONE,
    01183   WDF_UNCLICK_BUTTONS,
    01184   _nested_generate_progress_widgets, lengthof(_nested_generate_progress_widgets)
    01185 );
    01186
    01187 struct GenWorldStatus {
    01188   uint percent;
    01189   StringID cls;
    01190   uint current;
    01191   uint total;
    01192   int timer;
    01193 };
    01194
    01195 static GenWorldStatus _gws;
    01196
    01197 static const StringID _generation_class_table[]  = {
    01198   STR_GENERATION_WORLD_GENERATION,
    01199   STR_SCENEDIT_TOOLBAR_LANDSCAPE_GENERATION,
    01200   STR_GENERATION_CLEARING_TILES,
    01201   STR_SCENEDIT_TOOLBAR_TOWN_GENERATION,
    01202   STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION,
    01203   STR_GENERATION_OBJECT_GENERATION,
    01204   STR_GENERATION_TREE_GENERATION,
    01205   STR_GENERATION_SETTINGUP_GAME,
    01206   STR_GENERATION_PREPARING_TILELOOP,
    01207   STR_GENERATION_PREPARING_GAME
    01208 };
    01209 assert_compile(lengthof(_generation_class_table) == GWP_CLASS_COUNT);
    01210
    01211
    01212 static void AbortGeneratingWorldCallback(Window *w, bool confirmed)
    01213 {
    01214   if (confirmed) {
    01215     AbortGeneratingWorld();
    01216   } else if (IsGeneratingWorld() && !IsGeneratingWorldAborted()) {
    01217     SetMouseCursor(SPR_CURSOR_ZZZ, PAL_NONE);
    01218   }
    01219 }
    01220
    01221 struct GenerateProgressWindow : public Window {
    01222
    01223   GenerateProgressWindow() : Window()
    01224   {
    01225     this->InitNested(&_generate_progress_desc);
    01226   }
    01227
    01228   virtual void OnClick(Point pt, int widget, int click_count)
    01229   {
    01230     switch (widget) {
    01231       case GPWW_ABORT:
    01232         if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE);
    01233         ShowQuery(
    01234           STR_GENERATION_ABORT_CAPTION,
    01235           STR_GENERATION_ABORT_MESSAGE,
    01236           this,
    01237           AbortGeneratingWorldCallback
    01238         );
    01239         break;
    01240     }
    01241   }
    01242
    01243   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
    01244   {
    01245     switch (widget) {
    01246       case GPWW_PROGRESS_BAR: {
    01247         SetDParam(0, 100);
    01248         *size = GetStringBoundingBox(STR_GENERATION_PROGRESS);
    01249         /* We need some spacing for the 'border' */
    01250         size->height += 8;
    01251         size->width += 8;
    01252         break;
    01253       }
    01254
    01255       case GPWW_PROGRESS_TEXT:
    01256         for (uint i = 0; i < GWP_CLASS_COUNT; i++) {
    01257           size->width = max(size->width, GetStringBoundingBox(_generation_class_table[i]).width);
    01258         }
    01259         size->height = FONT_HEIGHT_NORMAL * 2 + WD_PAR_VSEP_NORMAL;
    01260         break;
    01261     }
    01262   }
    01263
    01264   virtual void DrawWidget(const Rect &r, int widget) const
    01265   {
    01266     switch (widget) {
    01267       case GPWW_PROGRESS_BAR:
    01268         /* Draw the % complete with a bar and a text */
    01269         DrawFrameRect(r.left, r.top, r.right, r.bottom, COLOUR_GREY, FR_BORDERONLY);
    01270         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);
    01271         SetDParam(0, _gws.percent);
    01272         DrawString(r.left, r.right, r.top + 5, STR_GENERATION_PROGRESS, TC_FROMSTRING, SA_HOR_CENTER);
    01273         break;
    01274
    01275       case GPWW_PROGRESS_TEXT:
    01276         /* Tell which class we are generating */
    01277         DrawString(r.left, r.right, r.top, _gws.cls, TC_FROMSTRING, SA_HOR_CENTER);
    01278
    01279         /* And say where we are in that class */
    01280         SetDParam(0, _gws.current);
    01281         SetDParam(1, _gws.total);
    01282         DrawString(r.left, r.right, r.top + FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL, STR_GENERATION_PROGRESS_NUM, TC_FROMSTRING, SA_HOR_CENTER);
    01283     }
    01284   }
    01285 };
    01286
    01290 void PrepareGenerateWorldProgress()
    01291 {
    01292   _gws.cls     = STR_GENERATION_WORLD_GENERATION;
    01293   _gws.current = 0;
    01294   _gws.total   = 0;
    01295   _gws.percent = 0;
    01296   _gws.timer   = 0; // Forces to paint the progress window immediately
    01297 }
    01298
    01302 void ShowGenerateWorldProgress()
    01303 {
    01304   if (BringWindowToFrontById(WC_GENERATE_PROGRESS_WINDOW, 0)) return;
    01305   new GenerateProgressWindow();
    01306 }
    01307
    01308 static void _SetGeneratingWorldProgress(GenWorldProgress cls, uint progress, uint total)
    01309 {
    01310   static const int percent_table[GWP_CLASS_COUNT + 1] = {0, 5, 15, 20, 40, 60, 65, 80, 85, 99, 100 };
    01311
    01312   assert(cls < GWP_CLASS_COUNT);
    01313
    01314   /* Do not run this function if we aren't in a thread */
    01315   if (!IsGenerateWorldThreaded() && !_network_dedicated) return;
    01316
    01317   if (IsGeneratingWorldAborted()) HandleGeneratingWorldAbortion();
    01318
    01319   if (total == 0) {
    01320     assert(_gws.cls == _generation_class_table[cls]);
    01321     _gws.current += progress;
    01322     assert(_gws.current <= _gws.total);
    01323   } else {
    01324     _gws.cls     = _generation_class_table[cls];
    01325     _gws.current = progress;
    01326     _gws.total   = total;
    01327     _gws.percent = percent_table[cls];
    01328   }
    01329
    01330   /* Don't update the screen too often. So update it once in every once in a while... */
    01331   if (!_network_dedicated && _gws.timer != 0 && _realtime_tick - _gws.timer < GENWORLD_REDRAW_TIMEOUT) return;
    01332
    01333   /* Percentage is about the number of completed tasks, so 'current - 1' */
    01334   _gws.percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (_gws.current == 0 ? 0 : _gws.current - 1) / _gws.total;
    01335
    01336   if (_network_dedicated) {
    01337     static uint last_percent = 0;
    01338
    01339     /* Never display 0% */
    01340     if (_gws.percent == 0) return;
    01341     /* Reset if percent is lower than the last recorded */
    01342     if (_gws.percent < last_percent) last_percent = 0;
    01343     /* Display every 5%, but 6% is also very valid.. just not smaller steps than 5% */
    01344     if (_gws.percent % 5 != 0 && _gws.percent <= last_percent + 5) return;
    01345     /* Never show steps smaller than 2%, even if it is a mod 5% */
    01346     if (_gws.percent <= last_percent + 2) return;
    01347
    01348     DEBUG(net, 1, "Map generation percentage complete: %d", _gws.percent);
    01349     last_percent = _gws.percent;
    01350
    01351     /* Don't continue as dedicated never has a thread running */
    01352     return;
    01353   }
    01354
    01355   SetWindowDirty(WC_GENERATE_PROGRESS_WINDOW, 0);
    01356   MarkWholeScreenDirty();
    01357
    01358   /* Release the rights to the map generator, and acquire the rights to the
    01359    * paint thread. The 'other' thread already has the paint thread rights so
    01360    * this ensures us that we are waiting until the paint thread is done
    01361    * before we reacquire the mapgen rights */
    01362   _genworld_mapgen_mutex->EndCritical();
    01363   _genworld_paint_mutex->BeginCritical();
    01364   _genworld_mapgen_mutex->BeginCritical();
    01365   _genworld_paint_mutex->EndCritical();
    01366
    01367   _gws.timer = _realtime_tick;
    01368 }
    01369
    01378 void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
    01379 {
    01380   if (total == 0) return;
    01381
    01382   _SetGeneratingWorldProgress(cls, 0, total);
    01383 }
    01384
    01392 void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
    01393 {
    01394   /* In fact the param 'class' isn't needed.. but for some security reasons, we want it around */
    01395   _SetGeneratingWorldProgress(cls, 1, 0);
    01396 }