# genworld_gui.cpp

Go to the documentation of this file.

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