Merge branch upstream/master
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "string_func.h"
|
||||
#include "widgets/dropdown_type.h"
|
||||
#include "widgets/dropdown_func.h"
|
||||
#include "widgets/slider_func.h"
|
||||
#include "highscore.h"
|
||||
#include "base_media_base.h"
|
||||
#include "company_base.h"
|
||||
@@ -36,7 +37,9 @@
|
||||
#include "fontcache.h"
|
||||
#include "settings_func.h"
|
||||
#include "zoom_func.h"
|
||||
#include "rev.h"
|
||||
#include "video/video_driver.hpp"
|
||||
#include "music/music_driver.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <iterator>
|
||||
@@ -224,7 +227,10 @@ struct GameOptionsWindow : Window {
|
||||
|
||||
case WID_GO_LANG_DROPDOWN: { // Setup interface language dropdown
|
||||
for (uint i = 0; i < _languages.size(); i++) {
|
||||
auto item = new DropDownListParamStringItem(STR_JUST_RAW_STRING, i, false);
|
||||
bool hide_language = IsReleasedVersion() && !_languages[i].IsReasonablyFinished();
|
||||
if (hide_language) continue;
|
||||
bool hide_percentage = IsReleasedVersion() || _languages[i].missing < _settings_client.gui.missing_strings_threshold;
|
||||
auto item = new DropDownListParamStringItem(hide_percentage ? STR_JUST_RAW_STRING : STR_GAME_OPTIONS_LANGUAGE_PERCENTAGE, i, false);
|
||||
if (&_languages[i] == _current_language) {
|
||||
*selected_index = i;
|
||||
item->SetParamStr(0, _languages[i].own_name);
|
||||
@@ -236,6 +242,7 @@ struct GameOptionsWindow : Window {
|
||||
* entries in the dropdown list. */
|
||||
item->SetParamStr(0, _languages[i].name);
|
||||
}
|
||||
item->SetParam(1, (LANGUAGE_TOTAL_STRINGS - _languages[i].missing) * 100 / LANGUAGE_TOTAL_STRINGS);
|
||||
list.emplace_back(item);
|
||||
}
|
||||
std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc);
|
||||
@@ -359,6 +366,14 @@ struct GameOptionsWindow : Window {
|
||||
SetDParamStr(0, BaseMusic::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
|
||||
DrawString(r.left, r.right, r.top, STR_BLACK_RAW_STRING);
|
||||
break;
|
||||
|
||||
case WID_GO_BASE_SFX_VOLUME:
|
||||
DrawVolumeSliderWidget(r, _settings_client.music.effect_vol);
|
||||
break;
|
||||
|
||||
case WID_GO_BASE_MUSIC_VOLUME:
|
||||
DrawVolumeSliderWidget(r, _settings_client.music.music_vol);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,9 +522,35 @@ 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);
|
||||
#ifndef __APPLE__
|
||||
this->SetWidgetDisabledState(WID_GO_VIDEO_VSYNC_BUTTON, !_video_hw_accel);
|
||||
#endif
|
||||
this->SetDirty();
|
||||
break;
|
||||
|
||||
case WID_GO_VIDEO_VSYNC_BUTTON:
|
||||
if (!_video_hw_accel) break;
|
||||
|
||||
_video_vsync = !_video_vsync;
|
||||
VideoDriver::GetInstance()->ToggleVsync(_video_vsync);
|
||||
|
||||
this->SetWidgetLoweredState(WID_GO_VIDEO_VSYNC_BUTTON, _video_vsync);
|
||||
this->SetDirty();
|
||||
break;
|
||||
|
||||
case WID_GO_BASE_SFX_VOLUME:
|
||||
case WID_GO_BASE_MUSIC_VOLUME: {
|
||||
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();
|
||||
SetWindowClassesDirty(WC_MUSIC_WINDOW);
|
||||
}
|
||||
|
||||
if (click_count > 0) this->mouse_capture_widget = widget;
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
int selected;
|
||||
DropDownList list = this->BuildDropDownList(widget, &selected);
|
||||
@@ -548,7 +589,7 @@ struct GameOptionsWindow : Window {
|
||||
case WID_GO_CURRENCY_DROPDOWN: // Currency
|
||||
if (index == CURRENCY_CUSTOM) ShowCustCurrency();
|
||||
this->opt->locale.currency = index;
|
||||
ReInitAllWindows();
|
||||
ReInitAllWindows(false);
|
||||
break;
|
||||
|
||||
case WID_GO_AUTOSAVE_DROPDOWN: // Autosave options
|
||||
@@ -563,7 +604,7 @@ struct GameOptionsWindow : Window {
|
||||
ClearAllCachedNames();
|
||||
UpdateAllVirtCoords();
|
||||
CheckBlitter();
|
||||
ReInitAllWindows();
|
||||
ReInitAllWindows(false);
|
||||
break;
|
||||
|
||||
case WID_GO_RESOLUTION_DROPDOWN: // Change resolution
|
||||
@@ -606,7 +647,7 @@ struct GameOptionsWindow : Window {
|
||||
UpdateCursorSize();
|
||||
UpdateAllVirtCoords();
|
||||
FixTitleGameZoom();
|
||||
ReInitAllWindows();
|
||||
ReInitAllWindows(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -620,6 +661,7 @@ struct GameOptionsWindow : Window {
|
||||
ClearFontCache();
|
||||
LoadStringWidthTable();
|
||||
UpdateAllVirtCoords();
|
||||
ReInitAllWindows(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -654,6 +696,11 @@ struct GameOptionsWindow : Window {
|
||||
this->SetWidgetLoweredState(WID_GO_16BPP_BUTTON, _ini_blitter == "16bpp-simple");
|
||||
this->SetWidgetLoweredState(WID_GO_32BPP_BUTTON, _ini_blitter == "32bpp-anim" || _ini_blitter == "");
|
||||
|
||||
#ifndef __APPLE__
|
||||
this->SetWidgetLoweredState(WID_GO_VIDEO_VSYNC_BUTTON, _video_vsync);
|
||||
this->SetWidgetDisabledState(WID_GO_VIDEO_VSYNC_BUTTON, !_video_hw_accel);
|
||||
#endif
|
||||
|
||||
bool missing_files = BaseGraphics::GetUsedSet()->GetNumMissing() == 0;
|
||||
this->GetWidget<NWidgetCore>(WID_GO_BASE_GRF_STATUS)->SetDataTip(missing_files ? STR_EMPTY : STR_GAME_OPTIONS_BASE_GRF_STATUS, STR_NULL);
|
||||
|
||||
@@ -822,6 +869,7 @@ struct BaseSettingEntry {
|
||||
virtual void Init(byte level = 0);
|
||||
virtual void FoldAll() {}
|
||||
virtual void UnFoldAll() {}
|
||||
virtual void ResetAll() = 0;
|
||||
|
||||
/**
|
||||
* Set whether this is the last visible entry of the parent node.
|
||||
@@ -858,6 +906,7 @@ struct SettingEntry : BaseSettingEntry {
|
||||
SettingEntry(const char *name);
|
||||
|
||||
virtual void Init(byte level = 0);
|
||||
virtual void ResetAll();
|
||||
virtual uint Length() const;
|
||||
virtual uint GetMaxHelpHeight(int maxw);
|
||||
virtual bool UpdateFilterState(SettingFilter &filter, bool force_visible);
|
||||
@@ -895,6 +944,7 @@ struct SettingsContainer {
|
||||
}
|
||||
|
||||
void Init(byte level = 0);
|
||||
void ResetAll();
|
||||
void FoldAll();
|
||||
void UnFoldAll();
|
||||
|
||||
@@ -917,6 +967,7 @@ struct SettingsPage : BaseSettingEntry, SettingsContainer {
|
||||
SettingsPage(StringID title);
|
||||
|
||||
virtual void Init(byte level = 0);
|
||||
virtual void ResetAll();
|
||||
virtual void FoldAll();
|
||||
virtual void UnFoldAll();
|
||||
|
||||
@@ -1059,6 +1110,13 @@ void SettingEntry::Init(byte level)
|
||||
assert(this->setting != nullptr);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the button-depressed flags (#SEF_LEFT_DEPRESSED and #SEF_RIGHT_DEPRESSED) to a specified value
|
||||
* @param new_val New value for the button flags
|
||||
@@ -1260,6 +1318,14 @@ void SettingsContainer::Init(byte level)
|
||||
}
|
||||
}
|
||||
|
||||
/** Resets all settings to their default values */
|
||||
void SettingsContainer::ResetAll()
|
||||
{
|
||||
for (auto settings_entry : this->entries) {
|
||||
settings_entry->ResetAll();
|
||||
}
|
||||
}
|
||||
|
||||
/** Recursively close all folds of sub-pages */
|
||||
void SettingsContainer::FoldAll()
|
||||
{
|
||||
@@ -1411,6 +1477,14 @@ void SettingsPage::Init(byte level)
|
||||
SettingsContainer::Init(level + 1);
|
||||
}
|
||||
|
||||
/** Resets all settings to their default values */
|
||||
void SettingsPage::ResetAll()
|
||||
{
|
||||
for (auto settings_entry : this->entries) {
|
||||
settings_entry->ResetAll();
|
||||
}
|
||||
}
|
||||
|
||||
/** Recursively close all (filtered) folds of sub-pages */
|
||||
void SettingsPage::FoldAll()
|
||||
{
|
||||
@@ -1887,6 +1961,20 @@ enum WarnHiddenResult {
|
||||
WHR_CATEGORY_TYPE, ///< Both category and type settings filtered matches away.
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback function for the reset all settings button
|
||||
* @param w Window which is calling this callback
|
||||
* @param confirmed boolean value, true when yes was clicked, false otherwise
|
||||
*/
|
||||
static void ResetAllSettingsConfirmationCallback(Window *w, bool confirmed)
|
||||
{
|
||||
if (confirmed) {
|
||||
GetSettingsTree().ResetAll();
|
||||
GetSettingsTree().FoldAll();
|
||||
w->InvalidateData();
|
||||
}
|
||||
}
|
||||
|
||||
/** Window to edit settings of the game. */
|
||||
struct GameSettingsWindow : Window {
|
||||
static const int SETTINGTREE_LEFT_OFFSET = 5; ///< Position of left edge of setting values
|
||||
@@ -2129,6 +2217,15 @@ struct GameSettingsWindow : Window {
|
||||
this->InvalidateData();
|
||||
break;
|
||||
|
||||
case WID_GS_RESET_ALL:
|
||||
ShowQuery(
|
||||
STR_CONFIG_SETTING_RESET_ALL_CONFIRMATION_DIALOG_CAPTION,
|
||||
STR_CONFIG_SETTING_RESET_ALL_CONFIRMATION_DIALOG_TEXT,
|
||||
this,
|
||||
ResetAllSettingsConfirmationCallback
|
||||
);
|
||||
break;
|
||||
|
||||
case WID_GS_RESTRICT_DROPDOWN: {
|
||||
DropDownList list = this->BuildDropDownList(widget);
|
||||
if (!list.empty()) {
|
||||
@@ -2485,6 +2582,7 @@ static const NWidgetPart _nested_settings_selection_widgets[] = {
|
||||
NWidget(NWID_HORIZONTAL),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_GS_EXPAND_ALL), SetDataTip(STR_CONFIG_SETTING_EXPAND_ALL, STR_NULL),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_GS_COLLAPSE_ALL), SetDataTip(STR_CONFIG_SETTING_COLLAPSE_ALL, STR_NULL),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_GS_RESET_ALL), SetDataTip(STR_CONFIG_SETTING_RESET_ALL, STR_NULL),
|
||||
NWidget(WWT_PANEL, COLOUR_MAUVE), SetFill(1, 0), SetResize(1, 0),
|
||||
EndContainer(),
|
||||
NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
|
||||
@@ -2655,7 +2753,7 @@ struct CustomCurrencyWindow : Window {
|
||||
case WID_CC_SEPARATOR:
|
||||
SetDParamStr(0, _custom_currency.separator);
|
||||
str = STR_JUST_RAW_STRING;
|
||||
len = 1;
|
||||
len = sizeof(_custom_currency.separator) - 1; // Number of characters excluding '\0' termination
|
||||
line = WID_CC_SEPARATOR;
|
||||
break;
|
||||
|
||||
@@ -2663,7 +2761,7 @@ struct CustomCurrencyWindow : Window {
|
||||
case WID_CC_PREFIX:
|
||||
SetDParamStr(0, _custom_currency.prefix);
|
||||
str = STR_JUST_RAW_STRING;
|
||||
len = 12;
|
||||
len = sizeof(_custom_currency.prefix) - 1; // Number of characters excluding '\0' termination
|
||||
line = WID_CC_PREFIX;
|
||||
break;
|
||||
|
||||
@@ -2671,7 +2769,7 @@ struct CustomCurrencyWindow : Window {
|
||||
case WID_CC_SUFFIX:
|
||||
SetDParamStr(0, _custom_currency.suffix);
|
||||
str = STR_JUST_RAW_STRING;
|
||||
len = 12;
|
||||
len = sizeof(_custom_currency.suffix) - 1; // Number of characters excluding '\0' termination
|
||||
line = WID_CC_SUFFIX;
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user