add controller support for ui

This commit is contained in:
csd4ni3l
2025-06-24 19:38:03 +02:00
parent dbdee7d054
commit 1672f35211
4 changed files with 26 additions and 11 deletions

View File

@@ -1,4 +1,4 @@
import copy, pypresence, json, os
import copy, pypresence, json
import arcade, arcade.gui
@@ -30,7 +30,8 @@ class Settings(arcade.gui.UIView):
self.modified_settings = {}
def create_layouts(self):
self.anchor = self.add_widget(UIAnchorLayout(size_hint=(1, 1)))
self.root = self.add_widget(UIFocusGroup())
self.anchor = self.root.add(UIAnchorLayout(size_hint=(1, 1)))
self.box = UIBoxLayout(space_between=50, align="center", vertical=False)
self.anchor.add(self.box, anchor_x="center", anchor_y="top", align_x=10, align_y=-75)
@@ -46,7 +47,7 @@ class Settings(arcade.gui.UIView):
self.create_layouts()
self.ui.push_handlers(self)
self.ui.push_handlers(self) # required for controller stuff
self.back_button = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='<--', style=button_style, width=100, height=50)
self.back_button.on_click = lambda e: self.main_exit()
@@ -67,6 +68,8 @@ class Settings(arcade.gui.UIView):
self.top_box.add(category_button)
self.root.detect_focusable_widgets()
def display_category(self, category):
if hasattr(self, 'apply_button'):
self.anchor.remove(self.apply_button)
@@ -136,6 +139,8 @@ class Settings(arcade.gui.UIView):
self.apply_button.on_click = lambda event: self.apply_settings()
self.anchor.add(self.apply_button, anchor_x="right", anchor_y="bottom", align_x=-10, align_y=10)
self.root.detect_focusable_widgets()
def apply_settings(self):
for config_key, value in self.modified_settings.items():
self.settings_dict[config_key] = value
@@ -208,7 +213,6 @@ class Settings(arcade.gui.UIView):
file.write(json.dumps(self.settings_dict, indent=4))
def update(self, setting=None, button_state=None, setting_type="bool"):
setting_dict = settings[self.current_category][setting]
config_key = settings[self.current_category][setting]["config_key"]
if setting_type == "option":
@@ -268,6 +272,8 @@ class Settings(arcade.gui.UIView):
self.key_layout.add(self.credits_label)
self.root.detect_focusable_widgets()
def set_highlighted_style(self, element):
element.texture = button_hovered_texture
element.texture_hovered = button_texture