From 1780ab7e8d510e55f81765471c81a1f3e0926f1a Mon Sep 17 00:00:00 2001 From: csd4ni3l Date: Wed, 25 Jun 2025 09:54:19 +0200 Subject: [PATCH] Remove unnecesseray double UIAnchorLayout with controller support and setting of controller events on window --- game/iter_fractal_viewer.py | 3 --- game/sierpinsky_carpet.py | 4 +--- menus/fractal_chooser.py | 5 ++--- menus/main.py | 5 ++--- menus/settings.py | 20 +++++++++----------- 5 files changed, 14 insertions(+), 23 deletions(-) diff --git a/game/iter_fractal_viewer.py b/game/iter_fractal_viewer.py index 474295a..e4b3de0 100644 --- a/game/iter_fractal_viewer.py +++ b/game/iter_fractal_viewer.py @@ -25,9 +25,6 @@ class IterFractalViewer(arcade.gui.UIView): def on_show_view(self): super().on_show_view() - self.window.on_stick_motion = self.on_stick_motion - self.window.on_button_press = self.on_button_press - self.window.on_button_release = self.on_button_release self.shader_program, self.fractal_image = create_iter_calc_shader( self.fractal_name, diff --git a/game/sierpinsky_carpet.py b/game/sierpinsky_carpet.py index 13377bf..608165e 100644 --- a/game/sierpinsky_carpet.py +++ b/game/sierpinsky_carpet.py @@ -17,9 +17,7 @@ class SierpinskyCarpetViewer(arcade.gui.UIView): self.zoom = 1.0 self.click_center = (self.width / 2, self.height / 2) self.has_controller = False - - self.window.on_stick_motion = self.on_stick_motion - + def on_show_view(self): super().on_show_view() diff --git a/menus/fractal_chooser.py b/menus/fractal_chooser.py index b56c519..81feabd 100644 --- a/menus/fractal_chooser.py +++ b/menus/fractal_chooser.py @@ -12,8 +12,7 @@ class FractalChooser(arcade.gui.UIView): self.pypresence_client = pypresence_client self.iter_fractal_buttons = [] - self.root = self.add_widget(UIFocusGroup()) - self.anchor = self.root.add(arcade.gui.UIAnchorLayout(size_hint=(1, 1))) + self.anchor = self.add_widget(UIFocusGroup(size_hint=(1, 1))) self.grid = self.add_widget(arcade.gui.UIGridLayout(row_count=4, column_count=3, horizontal_spacing=10, vertical_spacing=10)) self.anchor.add(self.grid, anchor_x="center", anchor_y="center") @@ -40,7 +39,7 @@ class FractalChooser(arcade.gui.UIView): self.sierpinsky_carpet_button = self.grid.add(arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='Sierpinsky Carpet', style=button_style, width=200, height=200), row=row, column=col) self.sierpinsky_carpet_button.on_click = lambda event: self.sierpinsky_carpet() - self.root.detect_focusable_widgets() + self.anchor.detect_focusable_widgets() def main_exit(self): from menus.main import Main diff --git a/menus/main.py b/menus/main.py index 9794949..fdd317e 100644 --- a/menus/main.py +++ b/menus/main.py @@ -7,8 +7,7 @@ class Main(arcade.gui.UIView): def __init__(self, pypresence_client=None): super().__init__() - self.root = self.add_widget(UIFocusGroup()) - self.anchor = self.root.add(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 @@ -59,7 +58,7 @@ 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=big_button_style)) self.settings_button.on_click = lambda event: self.settings() - self.root.detect_focusable_widgets() + self.anchor.detect_focusable_widgets() def play(self): from menus.fractal_chooser import FractalChooser diff --git a/menus/settings.py b/menus/settings.py index 105a110..eac80d4 100644 --- a/menus/settings.py +++ b/menus/settings.py @@ -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 -from arcade.gui import UIBoxLayout, UIAnchorLayout from arcade.gui.experimental.focus import UIFocusGroup class Settings(arcade.gui.UIView): @@ -30,17 +29,16 @@ class Settings(arcade.gui.UIView): self.modified_settings = {} def create_layouts(self): - self.root = self.add_widget(UIFocusGroup()) - self.anchor = self.root.add(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() @@ -68,7 +66,7 @@ class Settings(arcade.gui.UIView): self.top_box.add(category_button) - self.root.detect_focusable_widgets() + self.anchor.detect_focusable_widgets() def display_category(self, category): if hasattr(self, 'apply_button'): @@ -96,7 +94,7 @@ class Settings(arcade.gui.UIView): self.value_layout.add(dropdown) elif setting_dict['type'] == "bool": - button_layout = self.value_layout.add(arcade.gui.UIBoxLayout(space_between=50, vertical=False)) + button_layout = self.value_layout.add(arcade.gui.arcade.gui.UIBoxLayout(space_between=50, vertical=False)) on_radiobutton = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text="ON", style=button_style, width=150, height=50) self.on_radiobuttons[setting] = on_radiobutton @@ -139,7 +137,7 @@ 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() + self.anchor.detect_focusable_widgets() def apply_settings(self): for config_key, value in self.modified_settings.items(): @@ -272,7 +270,7 @@ class Settings(arcade.gui.UIView): self.key_layout.add(self.credits_label) - self.root.detect_focusable_widgets() + self.anchor.detect_focusable_widgets() def set_highlighted_style(self, element): element.texture = button_hovered_texture