Merge branch upstream/master while introducing compile errors and reverting parts of Android changes, video BPP options are gone

This commit is contained in:
Sergii Pylypenko
2021-11-29 02:17:14 +02:00
667 changed files with 66564 additions and 29169 deletions

View File

@@ -80,7 +80,7 @@ static const StringID _font_zoom_dropdown[] = {
static Dimension _circle_size; ///< Dimension of the circle +/- icon. This is here as not all users are within the class of the settings window.
static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd);
static const void *ResolveObject(const GameSettings *settings_ptr, const IntSettingDesc *sd);
/**
* Get index of the current screen resolution.
@@ -131,7 +131,7 @@ struct BaseSetTextfileWindow : public TextfileWindow {
{
if (widget == WID_TF_CAPTION) {
SetDParam(0, content_type);
SetDParamStr(1, this->baseset->name.c_str());
SetDParamStr(1, this->baseset->name);
}
}
};
@@ -145,7 +145,7 @@ struct BaseSetTextfileWindow : public TextfileWindow {
template <class TBaseSet>
void ShowBaseSetTextfileWindow(TextfileType file_type, const TBaseSet* baseset, StringID content_type)
{
DeleteWindowById(WC_TEXTFILE, file_type);
CloseWindowById(WC_TEXTFILE, file_type);
new BaseSetTextfileWindow<TBaseSet>(file_type, baseset, content_type);
}
@@ -180,11 +180,12 @@ struct GameOptionsWindow : Window {
this->OnInvalidateData(0);
}
~GameOptionsWindow()
void Close() override
{
DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
DeleteWindowByClass(WC_TEXTFILE);
CloseWindowById(WC_CUSTOM_CURRENCY, 0);
CloseWindowByClass(WC_TEXTFILE);
if (this->reload) _switch_mode = SM_MENU;
this->Window::Close();
if (!_exit_game) SaveToConfig(); // Save all settings immediately on Android, because users tend to kill the app instead of pressing 'Quit' button
}
@@ -328,10 +329,10 @@ struct GameOptionsWindow : Window {
case WID_GO_TEXT_SIZE_DROPDOWN: SetDParam(0, _freetype.medium.size); break;
case WID_GO_GUI_ZOOM_DROPDOWN: SetDParam(0, _gui_zoom_dropdown[_gui_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _gui_zoom_cfg + 1 : 0]); break;
case WID_GO_FONT_ZOOM_DROPDOWN: SetDParam(0, _font_zoom_dropdown[_font_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _font_zoom_cfg + 1 : 0]); break;
case WID_GO_BASE_GRF_DROPDOWN: SetDParamStr(0, BaseGraphics::GetUsedSet()->name.c_str()); break;
case WID_GO_BASE_GRF_DROPDOWN: SetDParamStr(0, BaseGraphics::GetUsedSet()->name); break;
case WID_GO_BASE_GRF_STATUS: SetDParam(0, BaseGraphics::GetUsedSet()->GetNumInvalid()); break;
case WID_GO_BASE_SFX_DROPDOWN: SetDParamStr(0, BaseSounds::GetUsedSet()->name.c_str()); break;
case WID_GO_BASE_MUSIC_DROPDOWN: SetDParamStr(0, BaseMusic::GetUsedSet()->name.c_str()); break;
case WID_GO_BASE_SFX_DROPDOWN: SetDParamStr(0, BaseSounds::GetUsedSet()->name); break;
case WID_GO_BASE_MUSIC_DROPDOWN: SetDParamStr(0, BaseMusic::GetUsedSet()->name); break;
case WID_GO_BASE_MUSIC_STATUS: SetDParam(0, BaseMusic::GetUsedSet()->GetNumInvalid()); break;
case WID_GO_REFRESH_RATE_DROPDOWN: SetDParam(0, _settings_client.gui.refresh_rate); break;
case WID_GO_RESOLUTION_DROPDOWN: {
@@ -470,7 +471,7 @@ struct GameOptionsWindow : Window {
ShowErrorMessage(STR_ERROR_FULLSCREEN_FAILED, INVALID_STRING_ID, WL_ERROR);
}
this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON, _fullscreen);
this->SetDirty();
this->SetWidgetDirty(WID_GO_FULLSCREEN_BUTTON);
break;
case WID_GO_WINDOWS_TITLEBARS:
@@ -486,36 +487,6 @@ struct GameOptionsWindow : Window {
ReconstructUserInterface();
break;
case WID_GO_8BPP_BUTTON:
if (this->IsWidgetLowered(WID_GO_8BPP_BUTTON)) break;
_ini_blitter = "8bpp-optimized";
_exit_game = true;
_restart_game = true;
#ifdef __ANDROID__
SDL_ANDROID_SetConfigOption(SDL_ANDROID_CONFIG_VIDEO_DEPTH_BPP, 16);
#endif
break;
case WID_GO_16BPP_BUTTON:
if (this->IsWidgetLowered(WID_GO_16BPP_BUTTON)) break;
_ini_blitter = "16bpp-simple";
_exit_game = true;
_restart_game = true;
#ifdef __ANDROID__
SDL_ANDROID_SetConfigOption(SDL_ANDROID_CONFIG_VIDEO_DEPTH_BPP, 16);
#endif
break;
case WID_GO_32BPP_BUTTON:
if (this->IsWidgetLowered(WID_GO_32BPP_BUTTON)) break;
_ini_blitter = "32bpp-anim";
_exit_game = true;
_restart_game = true;
#ifdef __ANDROID__
SDL_ANDROID_SetConfigOption(SDL_ANDROID_CONFIG_VIDEO_DEPTH_BPP, 24);
#endif
break;
case WID_GO_MOUSE_CURSOR:
if (_settings_client.gui.draw_mouse_cursor) {
UndrawMouseCursor();
@@ -529,10 +500,11 @@ struct GameOptionsWindow : Window {
_video_hw_accel = !_video_hw_accel;
ShowErrorMessage(STR_GAME_OPTIONS_VIDEO_ACCELERATION_RESTART, INVALID_STRING_ID, WL_INFO);
this->SetWidgetLoweredState(WID_GO_VIDEO_ACCEL_BUTTON, _video_hw_accel);
this->SetWidgetDirty(WID_GO_VIDEO_ACCEL_BUTTON);
#ifndef __APPLE__
this->SetWidgetDisabledState(WID_GO_VIDEO_VSYNC_BUTTON, !_video_hw_accel);
this->SetWidgetDirty(WID_GO_VIDEO_VSYNC_BUTTON);
#endif
this->SetDirty();
break;
case WID_GO_VIDEO_VSYNC_BUTTON:
@@ -542,7 +514,7 @@ struct GameOptionsWindow : Window {
VideoDriver::GetInstance()->ToggleVsync(_video_vsync);
this->SetWidgetLoweredState(WID_GO_VIDEO_VSYNC_BUTTON, _video_vsync);
this->SetDirty();
this->SetWidgetDirty(WID_GO_VIDEO_VSYNC_BUTTON);
break;
case WID_GO_BASE_SFX_VOLUME:
@@ -550,7 +522,7 @@ struct GameOptionsWindow : Window {
byte &vol = (widget == WID_GO_BASE_MUSIC_VOLUME) ? _settings_client.music.music_vol : _settings_client.music.effect_vol;
if (ClickVolumeSliderWidget(this->GetWidget<NWidgetBase>(widget)->GetCurrentRect(), pt, vol)) {
if (widget == WID_GO_BASE_MUSIC_VOLUME) MusicDriver::GetInstance()->SetVolume(vol);
this->SetDirty();
this->SetWidgetDirty(widget);
SetWindowClassesDirty(WC_MUSIC_WINDOW);
}
@@ -606,7 +578,7 @@ struct GameOptionsWindow : Window {
case WID_GO_LANG_DROPDOWN: // Change interface language
ReadLanguagePack(&_languages[index]);
DeleteWindowByClass(WC_QUERY_STRING);
CloseWindowByClass(WC_QUERY_STRING);
CheckForMissingGlyphs();
ClearAllCachedNames();
UpdateAllVirtCoords();
@@ -698,9 +670,6 @@ struct GameOptionsWindow : Window {
#ifdef WIN32
this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON, _fullscreen);
#endif
this->SetWidgetLoweredState(WID_GO_8BPP_BUTTON, _ini_blitter == "8bpp-optimized");
this->SetWidgetLoweredState(WID_GO_16BPP_BUTTON, _ini_blitter == "16bpp-simple");
this->SetWidgetLoweredState(WID_GO_32BPP_BUTTON, _ini_blitter == "32bpp-anim" || _ini_blitter == "");
this->SetWidgetLoweredState(WID_GO_MOUSE_CURSOR, _settings_client.gui.draw_mouse_cursor);
#ifndef __APPLE__
@@ -750,9 +719,6 @@ static const NWidgetPart _nested_game_options_widgets[] = {
NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_FULLSCREEN, STR_NULL),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_FULLSCREEN_BUTTON), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_FULLSCREEN_TOOLTIP),
#endif
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_8BPP_BUTTON), SetMinimalSize(9, 9), SetDataTip(STR_CONFIG_SETTING_VIDEO_8BPP, STR_CONFIG_SETTING_VIDEO_8BPP_HELPTEXT),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_16BPP_BUTTON), SetMinimalSize(9, 9), SetDataTip(STR_CONFIG_SETTING_VIDEO_16BPP, STR_CONFIG_SETTING_VIDEO_16BPP_HELPTEXT),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_32BPP_BUTTON), SetMinimalSize(9, 9), SetDataTip(STR_CONFIG_SETTING_VIDEO_24BPP, STR_CONFIG_SETTING_VIDEO_24BPP_HELPTEXT),
EndContainer(),
EndContainer(),
NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_CONFIG_SETTING_MOUSE_CURSOR, STR_NULL),
@@ -834,7 +800,7 @@ static WindowDesc _game_options_desc(
/** Open the game options window. */
void ShowGameOptions()
{
DeleteWindowByClass(WC_GAME_OPTIONS);
CloseWindowByClass(WC_GAME_OPTIONS);
new GameOptionsWindow(&_game_options_desc);
}
@@ -915,9 +881,8 @@ protected:
/** Standard setting */
struct SettingEntry : BaseSettingEntry {
const char *name; ///< Name of the setting
const SettingDesc *setting; ///< Setting description of the setting
uint index; ///< Index of the setting in the settings table
const char *name; ///< Name of the setting
const IntSettingDesc *setting; ///< Setting description of the setting
SettingEntry(const char *name);
@@ -935,7 +900,7 @@ struct SettingEntry : BaseSettingEntry {
*/
inline StringID GetHelpText() const
{
return this->setting->desc.str_help;
return this->setting->str_help;
}
void SetValueDParams(uint first_param, int32 value) const;
@@ -1021,8 +986,7 @@ void BaseSettingEntry::Init(byte level)
bool BaseSettingEntry::IsVisible(const BaseSettingEntry *item) const
{
if (this->IsFiltered()) return false;
if (this == item) return true;
return false;
return this == item;
}
/**
@@ -1112,7 +1076,6 @@ SettingEntry::SettingEntry(const char *name)
{
this->name = name;
this->setting = nullptr;
this->index = 0;
}
/**
@@ -1122,15 +1085,13 @@ SettingEntry::SettingEntry(const char *name)
void SettingEntry::Init(byte level)
{
BaseSettingEntry::Init(level);
this->setting = GetSettingFromName(this->name, &this->index);
assert(this->setting != nullptr);
this->setting = GetSettingFromName(this->name)->AsIntSetting();
}
/* Sets the given setting entry to its default value */
void SettingEntry::ResetAll()
{
int32 default_value = ReadValue(&this->setting->desc.def, this->setting->save.conv);
SetSettingValue(this->index, default_value);
SetSettingValue(this->setting, this->setting->def);
}
/**
@@ -1170,34 +1131,31 @@ bool SettingEntry::IsVisibleByRestrictionMode(RestrictionMode mode) const
/* There shall not be any restriction, i.e. all settings shall be visible. */
if (mode == RM_ALL) return true;
GameSettings *settings_ptr = &GetGameSettings();
const SettingDesc *sd = this->setting;
const IntSettingDesc *sd = this->setting;
if (mode == RM_BASIC) return (this->setting->desc.cat & SC_BASIC_LIST) != 0;
if (mode == RM_ADVANCED) return (this->setting->desc.cat & SC_ADVANCED_LIST) != 0;
if (mode == RM_BASIC) return (this->setting->cat & SC_BASIC_LIST) != 0;
if (mode == RM_ADVANCED) return (this->setting->cat & SC_ADVANCED_LIST) != 0;
/* Read the current value. */
const void *var = ResolveVariableAddress(settings_ptr, sd);
int64 current_value = ReadValue(var, sd->save.conv);
const void *object = ResolveObject(&GetGameSettings(), sd);
int64 current_value = sd->Read(object);
int64 filter_value;
if (mode == RM_CHANGED_AGAINST_DEFAULT) {
/* This entry shall only be visible, if the value deviates from its default value. */
/* Read the default value. */
filter_value = ReadValue(&sd->desc.def, sd->save.conv);
filter_value = sd->def;
} else {
assert(mode == RM_CHANGED_AGAINST_NEW);
/* This entry shall only be visible, if the value deviates from
* its value is used when starting a new game. */
/* Make sure we're not comparing the new game settings against itself. */
assert(settings_ptr != &_settings_newgame);
assert(&GetGameSettings() != &_settings_newgame);
/* Read the new game's value. */
var = ResolveVariableAddress(&_settings_newgame, sd);
filter_value = ReadValue(var, sd->save.conv);
filter_value = sd->Read(ResolveObject(&_settings_newgame, sd));
}
return current_value != filter_value;
@@ -1215,15 +1173,13 @@ bool SettingEntry::UpdateFilterState(SettingFilter &filter, bool force_visible)
bool visible = true;
const SettingDesc *sd = this->setting;
const IntSettingDesc *sd = this->setting;
if (!force_visible && !filter.string.IsEmpty()) {
/* Process the search text filter for this item. */
filter.string.ResetState();
const SettingDescBase *sdb = &sd->desc;
SetDParam(0, STR_EMPTY);
filter.string.AddLine(sdb->str);
filter.string.AddLine(sd->str);
filter.string.AddLine(this->GetHelpText());
visible = filter.string.GetState();
@@ -1244,17 +1200,15 @@ bool SettingEntry::UpdateFilterState(SettingFilter &filter, bool force_visible)
return visible;
}
static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd)
static const void *ResolveObject(const GameSettings *settings_ptr, const IntSettingDesc *sd)
{
if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
if ((sd->flags & SF_PER_COMPANY) != 0) {
if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
return GetVariableAddress(&Company::Get(_local_company)->settings, &sd->save);
} else {
return GetVariableAddress(&_settings_client.company, &sd->save);
return &Company::Get(_local_company)->settings;
}
} else {
return GetVariableAddress(settings_ptr, &sd->save);
return &_settings_client.company;
}
return settings_ptr;
}
/**
@@ -1264,17 +1218,16 @@ static const void *ResolveVariableAddress(const GameSettings *settings_ptr, cons
*/
void SettingEntry::SetValueDParams(uint first_param, int32 value) const
{
const SettingDescBase *sdb = &this->setting->desc;
if (sdb->cmd == SDT_BOOLX) {
if (this->setting->IsBoolSetting()) {
SetDParam(first_param++, value != 0 ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
} else {
if ((sdb->flags & SGF_MULTISTRING) != 0) {
SetDParam(first_param++, sdb->str_val - sdb->min + value);
} else if ((sdb->flags & SGF_DISPLAY_ABS) != 0) {
SetDParam(first_param++, sdb->str_val + ((value >= 0) ? 1 : 0));
if ((this->setting->flags & SF_GUI_DROPDOWN) != 0) {
SetDParam(first_param++, this->setting->str_val - this->setting->min + value);
} else if ((this->setting->flags & SF_GUI_NEGATIVE_IS_SPECIAL) != 0) {
SetDParam(first_param++, this->setting->str_val + ((value >= 0) ? 1 : 0));
value = abs(value);
} else {
SetDParam(first_param++, sdb->str_val + ((value == 0 && (sdb->flags & SGF_0ISDISABLED) != 0) ? 1 : 0));
SetDParam(first_param++, this->setting->str_val + ((value == 0 && (this->setting->flags & SF_GUI_0_IS_SPECIAL) != 0) ? 1 : 0));
}
SetDParam(first_param++, value);
}
@@ -1290,9 +1243,7 @@ void SettingEntry::SetValueDParams(uint first_param, int32 value) const
*/
void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const
{
const SettingDesc *sd = this->setting;
const SettingDescBase *sdb = &sd->desc;
const void *var = ResolveVariableAddress(settings_ptr, sd);
const IntSettingDesc *sd = this->setting;
int state = this->flags & SEF_BUTTONS_MASK;
bool rtl = _current_text_dir == TD_RTL;
@@ -1305,20 +1256,20 @@ void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right,
bool editable = sd->IsEditable();
SetDParam(0, highlight ? STR_ORANGE_STRING1_WHITE : STR_ORANGE_STRING1_LTBLUE);
int32 value = (int32)ReadValue(var, sd->save.conv);
if (sdb->cmd == SDT_BOOLX) {
int32 value = sd->Read(ResolveObject(settings_ptr, sd));
if (sd->IsBoolSetting()) {
/* Draw checkbox for boolean-value either on/off */
DrawBoolButton(buttons_left, button_y, value != 0, editable);
} else if ((sdb->flags & SGF_MULTISTRING) != 0) {
} else if ((sd->flags & SF_GUI_DROPDOWN) != 0) {
/* Draw [v] button for settings of an enum-type */
DrawDropDownButton(buttons_left, button_y, COLOUR_YELLOW, state != 0, editable);
} else {
/* Draw [<][>] boxes for settings of an integer-type */
DrawArrowButtons(buttons_left, button_y, COLOUR_YELLOW, state,
editable && value != (sdb->flags & SGF_0ISDISABLED ? 0 : sdb->min), editable && (uint32)value != sdb->max);
editable && value != (sd->flags & SF_GUI_0_IS_SPECIAL ? 0 : sd->min), editable && (uint32)value != sd->max);
}
this->SetValueDParams(1, value);
DrawString(text_left, text_right, y + (SETTING_HEIGHT - FONT_HEIGHT_NORMAL) / 2, sdb->str, highlight ? TC_WHITE : TC_LIGHT_BLUE);
DrawString(text_left, text_right, y + (SETTING_HEIGHT - FONT_HEIGHT_NORMAL) / 2, sd->str, highlight ? TC_WHITE : TC_LIGHT_BLUE);
}
/* == SettingsContainer methods == */
@@ -1727,7 +1678,6 @@ static SettingsContainer &GetSettingsTree()
SettingsPage *construction = interface->Add(new SettingsPage(STR_CONFIG_SETTING_INTERFACE_CONSTRUCTION));
{
construction->Add(new SettingEntry("gui.link_terraform_toolbar"));
construction->Add(new SettingEntry("gui.enable_signal_gui"));
construction->Add(new SettingEntry("gui.persistent_buildingtools"));
construction->Add(new SettingEntry("gui.quick_goto"));
construction->Add(new SettingEntry("gui.default_rail_type"));
@@ -1777,8 +1727,8 @@ static SettingsContainer &GetSettingsTree()
SettingsPage *company = main->Add(new SettingsPage(STR_CONFIG_SETTING_COMPANY));
{
company->Add(new SettingEntry("gui.semaphore_build_before"));
company->Add(new SettingEntry("gui.default_signal_type"));
company->Add(new SettingEntry("gui.cycle_signal_types"));
company->Add(new SettingEntry("gui.signal_gui_mode"));
company->Add(new SettingEntry("gui.drag_signals_fixed_distance"));
company->Add(new SettingEntry("gui.auto_remove_signals"));
company->Add(new SettingEntry("gui.new_nonstop"));
@@ -1800,6 +1750,7 @@ static SettingsContainer &GetSettingsTree()
accounting->Add(new SettingEntry("difficulty.initial_interest"));
accounting->Add(new SettingEntry("difficulty.max_loan"));
accounting->Add(new SettingEntry("difficulty.subsidy_multiplier"));
accounting->Add(new SettingEntry("difficulty.subsidy_duration"));
accounting->Add(new SettingEntry("economy.feeder_payment_share"));
accounting->Add(new SettingEntry("economy.infrastructure_maintenance"));
accounting->Add(new SettingEntry("difficulty.vehicle_costs"));
@@ -1955,6 +1906,11 @@ static SettingsContainer &GetSettingsTree()
ai->Add(new SettingEntry("economy.min_years_for_shares"));
}
SettingsPage *network = main->Add(new SettingsPage(STR_CONFIG_SETTING_NETWORK));
{
network->Add(new SettingEntry("network.use_relay_service"));
}
main->Init();
}
return *main;
@@ -2182,7 +2138,7 @@ struct GameSettingsWindow : Window {
case WID_GS_HELP_TEXT:
if (this->last_clicked != nullptr) {
const SettingDesc *sd = this->last_clicked->setting;
const IntSettingDesc *sd = this->last_clicked->setting;
int y = r.top;
switch (sd->GetType()) {
@@ -2194,8 +2150,7 @@ struct GameSettingsWindow : Window {
DrawString(r.left, r.right, y, STR_CONFIG_SETTING_TYPE);
y += FONT_HEIGHT_NORMAL;
int32 default_value = ReadValue(&sd->desc.def, sd->save.conv);
this->last_clicked->SetValueDParams(0, default_value);
this->last_clicked->SetValueDParams(0, sd->def);
DrawString(r.left, r.right, y, STR_CONFIG_SETTING_DEFAULT_VALUE);
y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
@@ -2286,7 +2241,7 @@ struct GameSettingsWindow : Window {
SettingEntry *pe = dynamic_cast<SettingEntry*>(clicked_entry);
assert(pe != nullptr);
const SettingDesc *sd = pe->setting;
const IntSettingDesc *sd = pe->setting;
/* return if action is only active in network, or only settable by server */
if (!sd->IsEditable()) {
@@ -2294,12 +2249,10 @@ struct GameSettingsWindow : Window {
return;
}
const void *var = ResolveVariableAddress(settings_ptr, sd);
int32 value = (int32)ReadValue(var, sd->save.conv);
int32 value = sd->Read(ResolveObject(settings_ptr, sd));
/* clicked on the icon on the left side. Either scroller, bool on/off or dropdown */
if (x < SETTING_BUTTON_WIDTH && (sd->desc.flags & SGF_MULTISTRING)) {
const SettingDescBase *sdb = &sd->desc;
if (x < SETTING_BUTTON_WIDTH && (sd->flags & SF_GUI_DROPDOWN)) {
this->SetDisplayedHelpText(pe);
if (this->valuedropdown_entry == pe) {
@@ -2327,8 +2280,8 @@ struct GameSettingsWindow : Window {
this->valuedropdown_entry->SetButtons(SEF_LEFT_DEPRESSED);
DropDownList list;
for (int i = sdb->min; i <= (int)sdb->max; i++) {
list.emplace_back(new DropDownListStringItem(sdb->str_val + i - sdb->min, i, false));
for (int i = sd->min; i <= (int)sd->max; i++) {
list.emplace_back(new DropDownListStringItem(sd->str_val + i - sd->min, i, false));
}
ShowDropDownListAt(this, std::move(list), value, -1, wi_rect, COLOUR_ORANGE, true);
@@ -2337,71 +2290,61 @@ struct GameSettingsWindow : Window {
this->SetDirty();
} else if (x < SETTING_BUTTON_WIDTH) {
this->SetDisplayedHelpText(pe);
const SettingDescBase *sdb = &sd->desc;
int32 oldvalue = value;
switch (sdb->cmd) {
case SDT_BOOLX: value ^= 1; break;
case SDT_ONEOFMANY:
case SDT_NUMX: {
/* Add a dynamic step-size to the scroller. In a maximum of
* 50-steps you should be able to get from min to max,
* unless specified otherwise in the 'interval' variable
* of the current setting. */
uint32 step = (sdb->interval == 0) ? ((sdb->max - sdb->min) / 50) : sdb->interval;
if (step == 0) step = 1;
if (sd->IsBoolSetting()) {
value ^= 1;
} else {
/* Add a dynamic step-size to the scroller. In a maximum of
* 50-steps you should be able to get from min to max,
* unless specified otherwise in the 'interval' variable
* of the current setting. */
uint32 step = (sd->interval == 0) ? ((sd->max - sd->min) / 50) : sd->interval;
if (step == 0) step = 1;
/* don't allow too fast scrolling */
if ((this->flags & WF_TIMEOUT) && this->timeout_timer > 1) {
_left_button_clicked = false;
return;
}
/* Increase or decrease the value and clamp it to extremes */
if (x >= SETTING_BUTTON_WIDTH / 2) {
value += step;
if (sdb->min < 0) {
assert((int32)sdb->max >= 0);
if (value > (int32)sdb->max) value = (int32)sdb->max;
} else {
if ((uint32)value > sdb->max) value = (int32)sdb->max;
}
if (value < sdb->min) value = sdb->min; // skip between "disabled" and minimum
} else {
value -= step;
if (value < sdb->min) value = (sdb->flags & SGF_0ISDISABLED) ? 0 : sdb->min;
}
/* Set up scroller timeout for numeric values */
if (value != oldvalue) {
if (this->clicked_entry != nullptr) { // Release previous buttons if any
this->clicked_entry->SetButtons(0);
}
this->clicked_entry = pe;
this->clicked_entry->SetButtons((x >= SETTING_BUTTON_WIDTH / 2) != (_current_text_dir == TD_RTL) ? SEF_RIGHT_DEPRESSED : SEF_LEFT_DEPRESSED);
this->SetTimeout();
_left_button_clicked = false;
}
break;
/* don't allow too fast scrolling */
if ((this->flags & WF_TIMEOUT) && this->timeout_timer > 1) {
_left_button_clicked = false;
return;
}
default: NOT_REACHED();
/* Increase or decrease the value and clamp it to extremes */
if (x >= SETTING_BUTTON_WIDTH / 2) {
value += step;
if (sd->min < 0) {
assert((int32)sd->max >= 0);
if (value > (int32)sd->max) value = (int32)sd->max;
} else {
if ((uint32)value > sd->max) value = (int32)sd->max;
}
if (value < sd->min) value = sd->min; // skip between "disabled" and minimum
} else {
value -= step;
if (value < sd->min) value = (sd->flags & SF_GUI_0_IS_SPECIAL) ? 0 : sd->min;
}
/* Set up scroller timeout for numeric values */
if (value != oldvalue) {
if (this->clicked_entry != nullptr) { // Release previous buttons if any
this->clicked_entry->SetButtons(0);
}
this->clicked_entry = pe;
this->clicked_entry->SetButtons((x >= SETTING_BUTTON_WIDTH / 2) != (_current_text_dir == TD_RTL) ? SEF_RIGHT_DEPRESSED : SEF_LEFT_DEPRESSED);
this->SetTimeout();
_left_button_clicked = false;
}
}
if (value != oldvalue) {
if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
SetCompanySetting(pe->index, value);
} else {
SetSettingValue(pe->index, value);
}
SetSettingValue(sd, value);
this->SetDirty();
}
} else {
/* Only open editbox if clicked for the second time, and only for types where it is sensible for. */
if (this->last_clicked == pe && sd->desc.cmd != SDT_BOOLX && !(sd->desc.flags & SGF_MULTISTRING)) {
if (this->last_clicked == pe && !sd->IsBoolSetting() && !(sd->flags & SF_GUI_DROPDOWN)) {
int64 value64 = value;
/* Show the correct currency-translated value */
if (sd->desc.flags & SGF_CURRENCY) value64 *= _currency->rate;
if (sd->flags & SF_GUI_CURRENCY) value64 *= _currency->rate;
this->valuewindow_entry = pe;
SetDParam(0, value64);
@@ -2427,25 +2370,21 @@ struct GameSettingsWindow : Window {
if (str == nullptr) return;
assert(this->valuewindow_entry != nullptr);
const SettingDesc *sd = this->valuewindow_entry->setting;
const IntSettingDesc *sd = this->valuewindow_entry->setting;
int32 value;
if (!StrEmpty(str)) {
long long llvalue = atoll(str);
/* Save the correct currency-translated value */
if (sd->desc.flags & SGF_CURRENCY) llvalue /= _currency->rate;
if (sd->flags & SF_GUI_CURRENCY) llvalue /= _currency->rate;
value = (int32)ClampToI32(llvalue);
} else {
value = (int32)(size_t)sd->desc.def;
value = sd->def;
}
if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
SetCompanySetting(this->valuewindow_entry->index, value);
} else {
SetSettingValue(this->valuewindow_entry->index, value);
}
SetSettingValue(this->valuewindow_entry->setting, value);
this->SetDirty();
}
@@ -2478,15 +2417,10 @@ struct GameSettingsWindow : Window {
if (widget < 0) {
/* Deal with drop down boxes on the panel. */
assert(this->valuedropdown_entry != nullptr);
const SettingDesc *sd = this->valuedropdown_entry->setting;
assert(sd->desc.flags & SGF_MULTISTRING);
if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
SetCompanySetting(this->valuedropdown_entry->index, index);
} else {
SetSettingValue(this->valuedropdown_entry->index, index);
}
const IntSettingDesc *sd = this->valuedropdown_entry->setting;
assert(sd->flags & SF_GUI_DROPDOWN);
SetSettingValue(sd, index);
this->SetDirty();
}
break;
@@ -2615,7 +2549,7 @@ static WindowDesc _settings_selection_desc(
/** Open advanced settings window. */
void ShowGameSettings()
{
DeleteWindowByClass(WC_GAME_OPTIONS);
CloseWindowByClass(WC_GAME_OPTIONS);
new GameSettingsWindow(&_settings_selection_desc);
}
@@ -2769,7 +2703,7 @@ struct CustomCurrencyWindow : Window {
case WID_CC_SEPARATOR:
SetDParamStr(0, _custom_currency.separator);
str = STR_JUST_RAW_STRING;
len = sizeof(_custom_currency.separator) - 1; // Number of characters excluding '\0' termination
len = 7;
line = WID_CC_SEPARATOR;
break;
@@ -2777,7 +2711,7 @@ struct CustomCurrencyWindow : Window {
case WID_CC_PREFIX:
SetDParamStr(0, _custom_currency.prefix);
str = STR_JUST_RAW_STRING;
len = sizeof(_custom_currency.prefix) - 1; // Number of characters excluding '\0' termination
len = 15;
line = WID_CC_PREFIX;
break;
@@ -2785,7 +2719,7 @@ struct CustomCurrencyWindow : Window {
case WID_CC_SUFFIX:
SetDParamStr(0, _custom_currency.suffix);
str = STR_JUST_RAW_STRING;
len = sizeof(_custom_currency.suffix) - 1; // Number of characters excluding '\0' termination
len = 15;
line = WID_CC_SUFFIX;
break;
@@ -2829,15 +2763,15 @@ struct CustomCurrencyWindow : Window {
break;
case WID_CC_SEPARATOR: // Thousands separator
strecpy(_custom_currency.separator, str, lastof(_custom_currency.separator));
_custom_currency.separator = str;
break;
case WID_CC_PREFIX:
strecpy(_custom_currency.prefix, str, lastof(_custom_currency.prefix));
_custom_currency.prefix = str;
break;
case WID_CC_SUFFIX:
strecpy(_custom_currency.suffix, str, lastof(_custom_currency.suffix));
_custom_currency.suffix = str;
break;
case WID_CC_YEAR: { // Year to switch to euro
@@ -2907,7 +2841,7 @@ static WindowDesc _cust_currency_desc(
/** Open custom currency window. */
static void ShowCustCurrency()
{
DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
CloseWindowById(WC_CUSTOM_CURRENCY, 0);
new CustomCurrencyWindow(&_cust_currency_desc);
}