Add controller support

This commit is contained in:
csd4ni3l
2025-06-25 11:00:35 +02:00
parent 227d5416e0
commit d294ef3ebd
7 changed files with 61 additions and 46 deletions

View File

@@ -1,13 +1,15 @@
import arcade, arcade.gui, asyncio, pypresence, time, copy, json
from utils.preload import button_texture, button_hovered_texture
from utils.constants import button_style, discord_presence_id
from utils.utils import FakePyPresence
from arcade.gui.experimental.focus import UIFocusGroup
class Main(arcade.gui.UIView):
def __init__(self, pypresence_client=None):
super().__init__()
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout())
self.anchor = self.add_widget(UIFocusGroup(size_hint=(1, 1)))
self.box = self.anchor.add(arcade.gui.UIBoxLayout(space_between=10), anchor_x='center', anchor_y='center')
self.pypresence_client = pypresence_client
@@ -57,6 +59,8 @@ class Main(arcade.gui.UIView):
self.settings_button = self.box.add(arcade.gui.UITextureButton(text="Settings", texture=button_texture, texture_hovered=button_hovered_texture, width=self.window.width / 2, height=150, style=button_style))
self.settings_button.on_click = lambda event: self.settings()
self.anchor.detect_focusable_widgets()
def play(self):
from game.play import Game
self.window.show_view(Game(self.pypresence_client))

View File

@@ -6,7 +6,6 @@ from utils.constants import button_style, dropdown_style, slider_style, settings
from utils.utils import FakePyPresence
from utils.preload import button_texture, button_hovered_texture, theme_sound
from arcade.gui import UIBoxLayout, UIAnchorLayout
from arcade.gui.experimental.focus import UIFocusGroup
class Settings(arcade.gui.UIView):
@@ -30,16 +29,16 @@ class Settings(arcade.gui.UIView):
self.modified_settings = {}
def create_layouts(self):
self.anchor = self.add_widget(UIAnchorLayout(size_hint=(1, 1)))
self.anchor = self.add_widget(UIFocusGroup(size_hint=(1, 1)))
self.box = UIBoxLayout(space_between=50, align="center", vertical=False)
self.box = arcade.gui.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)
self.top_box = UIBoxLayout(space_between=self.window.width / 160, vertical=False)
self.top_box = arcade.gui.UIBoxLayout(space_between=self.window.width / 160, vertical=False)
self.anchor.add(self.top_box, anchor_x="left", anchor_y="top", align_x=10, align_y=-10)
self.key_layout = self.box.add(UIBoxLayout(space_between=20, align='left'))
self.value_layout = self.box.add(UIBoxLayout(space_between=13, align='left'))
self.key_layout = self.box.add(arcade.gui.UIBoxLayout(space_between=20, align='left'))
self.value_layout = self.box.add(arcade.gui.UIBoxLayout(space_between=13, align='left'))
def on_show_view(self):
super().on_show_view()
@@ -67,6 +66,8 @@ class Settings(arcade.gui.UIView):
self.top_box.add(category_button)
self.anchor.detect_focusable_widgets()
def display_category(self, category):
if hasattr(self, 'apply_button'):
self.anchor.remove(self.apply_button)
@@ -135,6 +136,8 @@ class Settings(arcade.gui.UIView):
self.apply_button.on_click = lambda e: self.apply_settings()
self.anchor.add(self.apply_button, anchor_x="right", anchor_y="bottom", align_x=-10, align_y=10)
self.anchor.detect_focusable_widgets()
def apply_settings(self):
for config_key, value in self.modified_settings.items():
self.settings_dict[config_key] = value