Change: move townname generator selection to mapgen GUI.

This commit is contained in:
frosch 2021-01-12 23:02:16 +01:00 committed by frosch
parent f513a807db
commit c71d0f5e7f
4 changed files with 55 additions and 49 deletions

View File

@ -27,6 +27,8 @@
#include "saveload/saveload.h"
#include "progress.h"
#include "error.h"
#include "newgrf_townname.h"
#include "townname_type.h"
#include "widgets/genworld_widget.h"
@ -112,6 +114,7 @@ static const NWidgetPart _nested_generate_landscape_widgets[] = {
NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetFill(1, 1),
NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SMOOTHNESS, STR_NULL), SetFill(1, 1),
NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_QUANTITY_OF_RIVERS, STR_NULL), SetFill(1, 1),
NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_GAME_OPTIONS_TOWN_NAMES_FRAME, STR_NULL), SetFill(1, 1),
EndContainer(),
NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
/* Max. heightlevel. */
@ -134,6 +137,7 @@ static const NWidgetPart _nested_generate_landscape_widgets[] = {
EndContainer(),
NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_SMOOTHNESS_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_RIVER_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TOWNNAME_DROPDOWN), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_TOWN_NAMES_DROPDOWN_TOOLTIP), SetFill(1, 0),
EndContainer(),
EndContainer(),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_GL_GENERATE_BUTTON), SetMinimalSize(84, 0), SetDataTip(STR_MAPGEN_GENERATE, STR_NULL), SetFill(1, 1),
@ -225,6 +229,7 @@ static const NWidgetPart _nested_heightmap_load_widgets[] = {
NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAX_HEIGHTLEVEL, STR_NULL), SetFill(1, 1),
NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SNOW_LINE_HEIGHT, STR_NULL), SetFill(1, 1),
NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetFill(1, 1),
NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_GAME_OPTIONS_TOWN_NAMES_FRAME, STR_NULL), SetFill(1, 1),
EndContainer(),
NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
NWidget(NWID_HORIZONTAL),
@ -242,6 +247,7 @@ static const NWidgetPart _nested_heightmap_load_widgets[] = {
NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL), SetFill(1, 0),
NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_START_DATE_UP), SetDataTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_FORWARD), SetFill(0, 1),
EndContainer(),
NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TOWNNAME_DROPDOWN), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_TOWN_NAMES_DROPDOWN_TOOLTIP), SetFill(1, 0),
EndContainer(),
EndContainer(),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_GL_GENERATE_BUTTON), SetMinimalSize(84, 0), SetDataTip(STR_MAPGEN_GENERATE, STR_NULL), SetFill(1, 1),
@ -289,6 +295,34 @@ static DropDownList BuildMapsizeDropDown()
return list;
}
static DropDownList BuildTownNameDropDown()
{
DropDownList list;
/* Add and sort newgrf townnames generators */
const auto &grf_names = GetGRFTownNameList();
for (uint i = 0; i < grf_names.size(); i++) {
list.emplace_back(new DropDownListStringItem(grf_names[i], BUILTIN_TOWNNAME_GENERATOR_COUNT + i, false));
}
std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc);
size_t newgrf_size = list.size();
/* Insert newgrf_names at the top of the list */
if (newgrf_size > 0) {
list.emplace_back(new DropDownListItem(-1, false)); // separator line
newgrf_size++;
}
/* Add and sort original townnames generators */
for (uint i = 0; i < BUILTIN_TOWNNAME_GENERATOR_COUNT; i++) {
list.emplace_back(new DropDownListStringItem(STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + i, i, false));
}
std::sort(list.begin() + newgrf_size, list.end(), DropDownListStringItem::NatSortFunc);
return list;
}
static const StringID _elevations[] = {STR_TERRAIN_TYPE_VERY_FLAT, STR_TERRAIN_TYPE_FLAT, STR_TERRAIN_TYPE_HILLY, STR_TERRAIN_TYPE_MOUNTAINOUS, STR_TERRAIN_TYPE_ALPINIST, INVALID_STRING_ID};
static const StringID _sea_lakes[] = {STR_SEA_LEVEL_VERY_LOW, STR_SEA_LEVEL_LOW, STR_SEA_LEVEL_MEDIUM, STR_SEA_LEVEL_HIGH, STR_SEA_LEVEL_CUSTOM, INVALID_STRING_ID};
static const StringID _rivers[] = {STR_RIVERS_NONE, STR_RIVERS_FEW, STR_RIVERS_MODERATE, STR_RIVERS_LOT, INVALID_STRING_ID};
@ -344,6 +378,15 @@ struct GenerateLandscapeWindow : public Window {
}
break;
case WID_GL_TOWNNAME_DROPDOWN: {
uint gen = _settings_newgame.game_creation.town_name;
StringID name = gen < BUILTIN_TOWNNAME_GENERATOR_COUNT ?
STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + gen :
GetGRFTownNameName(gen - BUILTIN_TOWNNAME_GENERATOR_COUNT);
SetDParam(0, name);
break;
}
case WID_GL_INDUSTRY_PULLDOWN: SetDParam(0, _game_mode == GM_EDITOR ? STR_CONFIG_SETTING_OFF : _num_inds[_settings_newgame.difficulty.industry_density]); break;
case WID_GL_LANDSCAPE_PULLDOWN: SetDParam(0, _landscape[_settings_newgame.game_creation.land_generator]); break;
case WID_GL_TERRAIN_PULLDOWN: SetDParam(0, _elevations[_settings_newgame.difficulty.terrain_type]); break;
@ -540,6 +583,10 @@ struct GenerateLandscapeWindow : public Window {
ShowDropDownMenu(this, _num_towns, _settings_newgame.difficulty.number_towns, WID_GL_TOWN_PULLDOWN, 0, 0);
break;
case WID_GL_TOWNNAME_DROPDOWN: // Townname generator
ShowDropDownList(this, BuildTownNameDropDown(), _settings_newgame.game_creation.town_name, WID_GL_TOWNNAME_DROPDOWN);
break;
case WID_GL_INDUSTRY_PULLDOWN: // Number of industries
ShowDropDownMenu(this, _num_inds, _settings_newgame.difficulty.industry_density, WID_GL_INDUSTRY_PULLDOWN, 0, 0);
break;
@ -727,6 +774,13 @@ struct GenerateLandscapeWindow : public Window {
_settings_newgame.difficulty.number_towns = index;
break;
case WID_GL_TOWNNAME_DROPDOWN: // Town names
if (_game_mode == GM_MENU || Town::GetNumItems() == 0) {
_settings_newgame.game_creation.town_name = index;
SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS);
}
break;
case WID_GL_INDUSTRY_PULLDOWN: _settings_newgame.difficulty.industry_density = index; break;
case WID_GL_TERRAIN_PULLDOWN: _settings_newgame.difficulty.terrain_type = index; break;

View File

@ -16,8 +16,6 @@
#include "network/network.h"
#include "town.h"
#include "settings_internal.h"
#include "newgrf_townname.h"
#include "townname_type.h"
#include "strings_func.h"
#include "window_func.h"
#include "string_func.h"
@ -213,34 +211,6 @@ struct GameOptionsWindow : Window {
break;
}
case WID_GO_TOWNNAME_DROPDOWN: { // Setup townname dropdown
*selected_index = this->opt->game_creation.town_name;
int enabled_item = (_game_mode == GM_MENU || Town::GetNumItems() == 0) ? -1 : *selected_index;
/* Add and sort newgrf townnames generators */
const auto &grf_names = GetGRFTownNameList();
for (uint i = 0; i < grf_names.size(); i++) {
int result = BUILTIN_TOWNNAME_GENERATOR_COUNT + i;
list.emplace_back(new DropDownListStringItem(grf_names[i], result, enabled_item != result && enabled_item >= 0));
}
std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc);
size_t newgrf_size = list.size();
/* Insert newgrf_names at the top of the list */
if (newgrf_size > 0) {
list.emplace_back(new DropDownListItem(-1, false)); // separator line
newgrf_size++;
}
/* Add and sort original townnames generators */
for (int i = 0; i < BUILTIN_TOWNNAME_GENERATOR_COUNT; i++) {
list.emplace_back(new DropDownListStringItem(STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + i, i, enabled_item != i && enabled_item >= 0));
}
std::sort(list.begin() + newgrf_size, list.end(), DropDownListStringItem::NatSortFunc);
break;
}
case WID_GO_AUTOSAVE_DROPDOWN: { // Setup autosave dropdown
*selected_index = _settings_client.gui.autosave;
const StringID *items = _autosave_dropdown;
@ -307,14 +277,6 @@ struct GameOptionsWindow : Window {
switch (widget) {
case WID_GO_CURRENCY_DROPDOWN: SetDParam(0, _currency_specs[this->opt->locale.currency].name); break;
case WID_GO_ROADSIDE_DROPDOWN: SetDParam(0, STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_LEFT + this->opt->vehicle.road_side); break;
case WID_GO_TOWNNAME_DROPDOWN: {
int gen = this->opt->game_creation.town_name;
StringID name = gen < BUILTIN_TOWNNAME_GENERATOR_COUNT ?
STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + gen :
GetGRFTownNameName(gen - BUILTIN_TOWNNAME_GENERATOR_COUNT);
SetDParam(0, name);
break;
}
case WID_GO_AUTOSAVE_DROPDOWN: SetDParam(0, _autosave_dropdown[_settings_client.gui.autosave]); break;
case WID_GO_LANG_DROPDOWN: SetDParamStr(0, _current_language->own_name); break;
case WID_GO_RESOLUTION_DROPDOWN: SetDParam(0, GetCurRes() == _resolutions.size() ? STR_GAME_OPTIONS_RESOLUTION_OTHER : SPECSTR_RESOLUTION_START + GetCurRes()); break;
@ -494,13 +456,6 @@ struct GameOptionsWindow : Window {
}
break;
case WID_GO_TOWNNAME_DROPDOWN: // Town names
if (_game_mode == GM_MENU || Town::GetNumItems() == 0) {
this->opt->game_creation.town_name = index;
SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS);
}
break;
case WID_GO_AUTOSAVE_DROPDOWN: // Autosave options
_settings_client.gui.autosave = index;
this->SetDirty();
@ -613,9 +568,6 @@ static const NWidgetPart _nested_game_options_widgets[] = {
EndContainer(),
NWidget(NWID_VERTICAL), SetPIP(0, 6, 0),
NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_TOWN_NAMES_FRAME, STR_NULL),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_TOWNNAME_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_TOWN_NAMES_DROPDOWN_TOOLTIP), SetFill(1, 0),
EndContainer(),
NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_LANGUAGE, STR_NULL),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_LANG_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_LANGUAGE_TOOLTIP), SetFill(1, 0),
EndContainer(),

View File

@ -21,6 +21,7 @@ enum GenerateLandscapeWidgets {
WID_GL_MAPSIZE_Y_PULLDOWN, ///< Dropdown 'map Y size'.
WID_GL_TOWN_PULLDOWN, ///< Dropdown 'No. of towns'.
WID_GL_TOWNNAME_DROPDOWN, ///< Dropdown 'Townnames'.
WID_GL_INDUSTRY_PULLDOWN, ///< Dropdown 'No. of industries'.
WID_GL_GENERATE_BUTTON, ///< 'Generate' button.

View File

@ -16,7 +16,6 @@ enum GameOptionsWidgets {
WID_GO_CURRENCY_DROPDOWN, ///< Currency dropdown.
WID_GO_DISTANCE_DROPDOWN, ///< Measuring unit dropdown.
WID_GO_ROADSIDE_DROPDOWN, ///< Dropdown to select the road side (to set the right side ;)).
WID_GO_TOWNNAME_DROPDOWN, ///< Town name dropdown.
WID_GO_AUTOSAVE_DROPDOWN, ///< Dropdown to say how often to autosave.
WID_GO_LANG_DROPDOWN, ///< Language dropdown.
WID_GO_RESOLUTION_DROPDOWN, ///< Dropdown for the resolution.