# genworld_gui.cpp

Go to the documentation of this file.

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