# genworld_gui.cpp

Go to the documentation of this file.

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