From aa0791686e714bf78fc24f60dff9fd297a2b309e Mon Sep 17 00:00:00 2001 From: GenevensiS <66968533+G-e-n-e-v-e-n-s-i-S@users.noreply.github.com> Date: Sat, 13 Dec 2025 23:06:18 +0100 Subject: [PATCH] restrict slider ui to slider fields --- src/data/field/choice.hpp | 17 +++++++++-------- src/data/field/slider.cpp | 2 ++ src/gui/value/choice.cpp | 26 ++++++++++---------------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/data/field/choice.hpp b/src/data/field/choice.hpp index 5953792c..14f81d25 100644 --- a/src/data/field/choice.hpp +++ b/src/data/field/choice.hpp @@ -33,14 +33,15 @@ public: class Choice; typedef intrusive_ptr ChoiceP; - ChoiceP choices; ///< A choice group of possible choices - OptionalScript script; ///< Script to apply to all values - OptionalScript default_script; ///< Script that generates the default value - String initial; ///< Initial choice of a new value, or "" - String default_name; ///< Name of "default" value - map choice_colors; ///< Colors for the various choices (when color_cardlist) - map choice_colors_cardlist; ///< Colors for the various choices, for in the card list - + ChoiceP choices; ///< A choice group of possible choices + OptionalScript script; ///< Script to apply to all values + OptionalScript default_script; ///< Script that generates the default value + String initial; ///< Initial choice of a new value, or "" + String default_name; ///< Name of "default" value + map choice_colors; ///< Colors for the various choices (when color_cardlist) + map choice_colors_cardlist; ///< Colors for the various choices, for in the card list + bool is_slider = false; ///< Should the UI be displayed as a slider? + void initDependencies(Context&, const Dependency&) const override; void after_reading(Version ver) override; }; diff --git a/src/data/field/slider.cpp b/src/data/field/slider.cpp index 47b3001e..b1e6758c 100644 --- a/src/data/field/slider.cpp +++ b/src/data/field/slider.cpp @@ -35,6 +35,8 @@ IMPLEMENT_REFLECTION(SliderField) { void SliderField::after_reading(Version ver) { Field::after_reading(ver); + is_slider = true; + int choice_count = choices->choices.size(); if (maximum < minimum) swap(minimum, maximum); diff --git a/src/gui/value/choice.cpp b/src/gui/value/choice.cpp index 64172a81..ed971683 100644 --- a/src/gui/value/choice.cpp +++ b/src/gui/value/choice.cpp @@ -200,29 +200,23 @@ END_EVENT_TABLE() DropDownChoiceList::DropDownChoiceList(Window* parent, bool is_submenu, ValueViewer& cve, ChoiceField::ChoiceP group) : DropDownChoiceListBase(parent, is_submenu, cve, group) -{ +{ // determine if slider - size_t count = itemCount(); - if (count > 3) { - int value; - try { - String first_item = capitalize(itemText(0)); - if (first_item != _("Default")) value = std::stoi(first_item.ToStdString()); - value = std::stoi(itemText(1).ToStdString()); - value = std::stoi(itemText(count - 2).ToStdString()); - value = std::stoi(itemText(count - 1).ToStdString()); - // the choices are numbers, use a slider - is_slider = true; - // load slider images if needed - if (!slider_loaded) { - slider_loaded = true; + if (itemCount() > 1 && field().is_slider) { + is_slider = true; + // load slider images if needed + if (!slider_loaded) { + slider_loaded = true; + try { slider_left = load_resource_image(_("slider_left")); slider_right = load_resource_image(_("slider_right")); slider_center = load_resource_image(_("slider_center")); slider_tick = load_resource_image(_("slider_tick")); } + catch (...) { + throw InternalError(_("Can't load slider resources")); + } } - catch (...) {} } }