1
0
Fork 0

Compare commits

...

3 Commits

Author SHA1 Message Date
SamuXarick 4663765f93
Merge 3c56c0fe2e into 03672ed8eb 2025-07-18 11:04:57 +00:00
Jonathan G Rennison 03672ed8eb
Fix: EngineImageType mismatch between sizing and drawing in preview window (#14455) 2025-07-18 07:02:46 -04:00
SamuXarick 3c56c0fe2e Add: [Script] Default button in query string to reset an integer setting 2025-06-08 23:15:20 +01:00
5 changed files with 54 additions and 9 deletions

View File

@ -84,7 +84,7 @@ struct EnginePreviewWindow : Window {
/* Get size of engine sprite, on loan from depot_gui.cpp */
EngineID engine = static_cast<EngineID>(this->window_number);
EngineImageType image_type = EIT_PURCHASE;
EngineImageType image_type = EIT_PREVIEW;
uint x, y;
int x_offs, y_offs;

View File

@ -325,7 +325,7 @@ struct GSConfigWindow : public Window {
}
} else if (!bool_item && !config_item.complete_labels) {
/* Display a query box so users can enter a custom value. */
ShowQueryString(GetString(STR_JUST_INT, old_val), STR_CONFIG_SETTING_QUERY_CAPTION, INT32_DIGITS_WITH_SIGN_AND_TERMINATION, this, CS_NUMERAL_SIGNED, {});
ShowQueryString(GetString(STR_JUST_INT, old_val), STR_CONFIG_SETTING_QUERY_CAPTION, INT32_DIGITS_WITH_SIGN_AND_TERMINATION, this, CS_NUMERAL_SIGNED, QueryStringFlag::EnableDefault);
}
this->SetDirty();
break;
@ -347,10 +347,17 @@ struct GSConfigWindow : public Window {
void OnQueryTextFinished(std::optional<std::string> str) override
{
/* The user pressed cancel */
if (!str.has_value()) return;
auto value = ParseInteger<int32_t>(*str, 10, true);
if (!value.has_value()) return;
this->SetValue(*value);
if (!str->empty()) {
auto value = ParseInteger<int32_t>(*str, 10, true);
if (!value.has_value()) return;
this->SetValue(*value);
} else {
this->SetDefaultValue();
}
}
void OnDropdownSelect(WidgetID widget, int index, int) override
@ -419,6 +426,14 @@ private:
this->gs_config->SetSetting(config_item.name, value);
this->SetDirty();
}
void SetDefaultValue()
{
const ScriptConfigItem &config_item = *this->visible_settings[this->clicked_row];
if (_game_mode == GM_NORMAL && !config_item.flags.Test(ScriptConfigFlag::InGame)) return;
this->gs_config->ResetSetting(config_item.name);
this->SetDirty();
}
};
/** Open the GS config window. */

View File

@ -106,6 +106,16 @@ void ScriptConfig::ResetSettings()
this->settings.clear();
}
void ScriptConfig::ResetSetting(std::string_view name)
{
if (this->info == nullptr) return;
const ScriptConfigItem *config_item = this->info->GetConfigItem(name);
if (config_item == nullptr) return;
this->settings.erase(std::string{name});
}
void ScriptConfig::ResetEditableSettings(bool yet_to_start)
{
if (this->info == nullptr) return ResetSettings();

View File

@ -129,6 +129,11 @@ public:
*/
void ResetSettings();
/**
* Reset a setting to its default value.
*/
void ResetSetting(std::string_view name);
/**
* Reset only editable and visible settings to their default value.
*/

View File

@ -470,7 +470,7 @@ struct ScriptSettingsWindow : public Window {
}
} else if (!bool_item && !config_item.complete_labels) {
/* Display a query box so users can enter a custom value. */
ShowQueryString(GetString(STR_JUST_INT, old_val), STR_CONFIG_SETTING_QUERY_CAPTION, INT32_DIGITS_WITH_SIGN_AND_TERMINATION, this, CS_NUMERAL_SIGNED, {});
ShowQueryString(GetString(STR_JUST_INT, old_val), STR_CONFIG_SETTING_QUERY_CAPTION, INT32_DIGITS_WITH_SIGN_AND_TERMINATION, this, CS_NUMERAL_SIGNED, QueryStringFlag::EnableDefault);
}
this->SetDirty();
break;
@ -485,10 +485,17 @@ struct ScriptSettingsWindow : public Window {
void OnQueryTextFinished(std::optional<std::string> str) override
{
/* The user pressed cancel */
if (!str.has_value()) return;
auto value = ParseInteger<int32_t>(*str, 10, true);
if (!value.has_value()) return;
this->SetValue(*value);
if (!str->empty()) {
auto value = ParseInteger<int32_t>(*str, 10, true);
if (!value.has_value()) return;
this->SetValue(*value);
} else {
this->SetDefaultValue();
}
}
void OnDropdownSelect(WidgetID widget, int index, int) override
@ -552,6 +559,14 @@ private:
this->script_config->SetSetting(config_item.name, value);
this->SetDirty();
}
void SetDefaultValue()
{
const ScriptConfigItem &config_item = *this->visible_settings[this->clicked_row];
if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && !config_item.flags.Test(ScriptConfigFlag::InGame)) return;
this->script_config->ResetSetting(config_item.name);
this->SetDirty();
}
};
/** Widgets for the Script settings window. */