OptionCreator: pre-RC1 fixes (#5680)

* fix str default on text choice

* fix range with default random

* forgot module update

* handle namedrange default special

* handle option group of options we should not render

* Update OptionsCreator.py

* Update OptionsCreator.py

* grammar
This commit is contained in:
Silvris
2025-11-29 18:23:13 -06:00
committed by GitHub
parent 775065715d
commit 3fa2745c37
3 changed files with 22 additions and 8 deletions

View File

@@ -1545,6 +1545,7 @@ class PlandoItems(Option[typing.List[PlandoItem]]):
default = () default = ()
supports_weighting = False supports_weighting = False
display_name = "Plando Items" display_name = "Plando Items"
visibility = Visibility.template | Visibility.spoiler
def __init__(self, value: typing.Iterable[PlandoItem]) -> None: def __init__(self, value: typing.Iterable[PlandoItem]) -> None:
self.value = list(deepcopy(value)) self.value = list(deepcopy(value))

View File

@@ -1,3 +1,9 @@
if __name__ == "__main__":
import ModuleUpdate
ModuleUpdate.update()
from kvui import (ThemedApp, ScrollBox, MainLayout, ContainerLayout, dp, Widget, MDBoxLayout, TooltipLabel, MDLabel, from kvui import (ThemedApp, ScrollBox, MainLayout, ContainerLayout, dp, Widget, MDBoxLayout, TooltipLabel, MDLabel,
ToggleButton, MarkupDropdown, ResizableTextField) ToggleButton, MarkupDropdown, ResizableTextField)
from kivy.uix.behaviors.button import ButtonBehavior from kivy.uix.behaviors.button import ButtonBehavior
@@ -330,6 +336,11 @@ class OptionsCreator(ThemedApp):
box.range.slider.dropdown.open() box.range.slider.dropdown.open()
box = VisualNamedRange(option=option, name=name, range_widget=self.create_range(option, name)) box = VisualNamedRange(option=option, name=name, range_widget=self.create_range(option, name))
if option.default in option.special_range_names:
# value can get mismatched in this case
box.range.slider.value = min(max(option.special_range_names[option.default], option.range_start),
option.range_end)
box.range.tag.text = str(int(box.range.slider.value))
box.range.slider.bind(on_touch_move=lambda _, _2: set_to_custom(box)) box.range.slider.bind(on_touch_move=lambda _, _2: set_to_custom(box))
items = [ items = [
{ {
@@ -365,7 +376,7 @@ class OptionsCreator(ThemedApp):
# for some reason this fixes an issue causing some to not open # for some reason this fixes an issue causing some to not open
dropdown.open() dropdown.open()
default_random = option.default == "random" default_string = isinstance(option.default, str)
main_button = VisualChoice(option=option, name=name) main_button = VisualChoice(option=option, name=name)
main_button.bind(on_release=open_dropdown) main_button.bind(on_release=open_dropdown)
@@ -377,7 +388,7 @@ class OptionsCreator(ThemedApp):
for choice in option.name_lookup for choice in option.name_lookup
] ]
dropdown = MDDropdownMenu(caller=main_button, items=items) dropdown = MDDropdownMenu(caller=main_button, items=items)
self.options[name] = option.name_lookup[option.default] if not default_random else option.default self.options[name] = option.name_lookup[option.default] if not default_string else option.default
return main_button return main_button
def create_text_choice(self, option: typing.Type[TextChoice], name: str): def create_text_choice(self, option: typing.Type[TextChoice], name: str):
@@ -560,8 +571,11 @@ class OptionsCreator(ThemedApp):
groups[group].append((name, option)) groups[group].append((name, option))
for group, options in groups.items(): for group, options in groups.items():
options = [(name, option) for name, option in options
if name and option.visibility & Visibility.simple_ui]
if not options: if not options:
continue # Game Options can be empty if every other option is in another group continue # Game Options can be empty if every other option is in another group
# Can also have an option group of options that should not render on simple ui
group_item = MDExpansionPanel(size_hint_y=None) group_item = MDExpansionPanel(size_hint_y=None)
group_header = MDExpansionPanelHeader(MDListItem(MDListItemSupportingText(text=group), group_header = MDExpansionPanelHeader(MDListItem(MDListItemSupportingText(text=group),
TrailingPressedIconButton(icon="chevron-right", TrailingPressedIconButton(icon="chevron-right",
@@ -583,8 +597,7 @@ class OptionsCreator(ThemedApp):
group_box.layout.orientation = "vertical" group_box.layout.orientation = "vertical"
group_box.layout.spacing = dp(3) group_box.layout.spacing = dp(3)
for name, option in options: for name, option in options:
if name and option is not Removed and option.visibility & Visibility.simple_ui: group_content.add_widget(self.create_option(option, name, cls))
group_content.add_widget(self.create_option(option, name, cls))
expansion_box.layout.add_widget(group_item) expansion_box.layout.add_widget(group_item)
self.option_layout.add_widget(expansion_box) self.option_layout.add_widget(expansion_box)
self.game_label.text = f"Game: {self.current_game}" self.game_label.text = f"Game: {self.current_game}"

View File

@@ -6,12 +6,12 @@
tag: tag tag: tag
MDLabel: MDLabel:
id: tag id: tag
text: str(this.option.default) if this.option.default != "random" else this.option.range_start text: str(this.option.default) if not isinstance(this.option.default, str) else str(this.option.range_start)
MDSlider: MDSlider:
id: slider id: slider
min: this.option.range_start min: this.option.range_start
max: this.option.range_end max: this.option.range_end
value: min(max(this.option.default, this.option.range_start), this.option.range_end) if this.option.default != "random" else this.option.range_start value: min(max(this.option.default, this.option.range_start), this.option.range_end) if not isinstance(this.option.default, str) else this.option.range_start
step: 1 step: 1
step_point_size: 0 step_point_size: 0
MDSliderHandle: MDSliderHandle:
@@ -23,7 +23,7 @@
text: text text: text
MDButtonText: MDButtonText:
id: text id: text
text: this.option.get_option_name(this.option.default if this.option.default != "random" else list(this.option.options.values())[0]) text: this.option.get_option_name(this.option.default if not isinstance(this.option.default, str) else list(this.option.options.values())[0])
theme_text_color: "Primary" theme_text_color: "Primary"
<VisualNamedRange>: <VisualNamedRange>:
@@ -38,7 +38,7 @@
text: text text: text
MDButtonText: MDButtonText:
id: text id: text
text: this.option.special_range_names.get(list(this.option.special_range_names.values()).index(this.option.default)) if this.option.default in this.option.special_range_names else "Custom" text: this.option.default.title() if this.option.default in this.option.special_range_names else "Custom"
<VisualFreeText>: <VisualFreeText>:
multiline: False multiline: False