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

@@ -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(),