Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions OptionsCreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,14 @@ def open_dropdown(button):
self.options[name] = default
return box

def create_free_text(self, option: typing.Type[FreeText] | typing.Type[TextChoice], name: str):
def create_free_text(self, option: typing.Type[FreeText] | typing.Type[TextChoice], name: str, bind=True):
text = VisualFreeText(option=option, name=name)

def set_value(instance, value):
self.options[name] = value

text.bind(text=set_value)
if bind:
text.bind(text=set_value)
self.options[name] = option.default
return text

Expand All @@ -401,6 +402,9 @@ def set_value(text, value):
dropdown.dismiss()

def open_dropdown(button):
# clicking the edge of a choice button apparently still runs this?
if button.disabled:
return
# for some reason this fixes an issue causing some to not open
dropdown.open()

Expand All @@ -426,13 +430,13 @@ def set_button_text(button: MDButton, text: str):
child.text = text

box = VisualTextChoice(option=option, name=name, choice=self.create_choice(option, name),
text=self.create_free_text(option, name))
text=self.create_free_text(option, name, bind=False))

def set_value(instance):
def set_value(instance, value):
set_button_text(box.choice, "Custom")
self.options[name] = instance.text
self.options[name] = value

box.text.bind(on_text_validate=set_value)
box.text.bind(text=set_value)
return box

def create_toggle(self, option: typing.Type[Toggle], name: str) -> Widget:
Expand Down Expand Up @@ -529,11 +533,12 @@ def create_option(self, option: typing.Type[Option], name: str, world: typing.Ty
option_base.add_widget(self.create_choice(option, name))
elif issubclass(option, FreeText):
option_base.add_widget(self.create_free_text(option, name))
elif any(issubclass(option, cls) for cls in (OptionSet, OptionList, OptionCounter)):
elif issubclass(option, (OptionSet, OptionList, OptionCounter)):
option_base.add_widget(self.create_option_set_list_counter(option, name, world))
else:
option_base.add_widget(MDLabel(text="This option isn't supported by the option creator.\n"
"Please edit your yaml manually to set this option."))
return option_base

if option_can_be_randomized(option):
def randomize_option(instance: Widget, value: str):
Expand All @@ -559,6 +564,12 @@ def randomize_option(instance: Widget, value: str):
random_toggle.bind(state=randomize_option)
label_box.add_widget(random_toggle)
if default_random:
# change stored value to match displayed one before randomizing it
if issubclass(option, Range):
self.options[name] = option.range_start
elif issubclass(option, Choice):
self.options[name] = list(option.options.values())[0]

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TextChoices here keep the random text in the textbox, which I guess is fine but doesn't seem super preferable. I tried to change this and also make it so picking an option from the dropdown clears the textbox, but this kind of brings madness since it doesn't seem like there's a way in kivy to distinguish the user changing the text compared to modifying .text manually in the program. Gotta love kivy.

This also does technically change how the exported options may look in the yaml compared to selecting them normally, but it should at least give a correct way of representing the value.


randomize_option(random_toggle, "down")

return option_base
Expand Down
Loading