Add virtual cursor for controller support

This commit is contained in:
csd4ni3l
2025-06-24 21:41:21 +02:00
parent 1672f35211
commit ffcf12552a
5 changed files with 63 additions and 7 deletions

View File

@@ -2,7 +2,7 @@ import arcade, arcade.gui, pyglet, json
from game.shader import create_sierpinsky_carpet_shader
from utils.constants import button_style
from utils.preload import button_texture, button_hovered_texture
from utils.preload import button_texture, button_hovered_texture, cursor_texture
class SierpinskyCarpetViewer(arcade.gui.UIView):
def __init__(self, pypresence_client):
@@ -16,6 +16,9 @@ class SierpinskyCarpetViewer(arcade.gui.UIView):
self.depth = self.settings_dict.get("sierpinsky_depth", 10)
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()
@@ -30,6 +33,17 @@ class SierpinskyCarpetViewer(arcade.gui.UIView):
self.setup_ui()
if self.window.get_controllers():
self.sprite_list = arcade.SpriteList()
self.cursor_sprite = arcade.Sprite(cursor_texture)
self.sprite_list.append(self.cursor_sprite)
self.has_controller = True
def on_stick_motion(self, controller, name, vector):
if name == "leftstick":
self.cursor_sprite.center_x += vector.x * 5
self.cursor_sprite.center_y += vector.y * 5
def main_exit(self):
from menus.main import Main
self.window.show_view(Main(self.pypresence_client))
@@ -53,8 +67,6 @@ class SierpinskyCarpetViewer(arcade.gui.UIView):
self.shader_program.dispatch(self.sierpinsky_carpet_image.width, self.sierpinsky_carpet_image.height, 1, barrier=pyglet.gl.GL_ALL_BARRIER_BITS)
def on_mouse_press(self, x: int, y: int, button: int, modifiers: int) -> bool | None:
super().on_mouse_press(x, y, button, modifiers)
if button == arcade.MOUSE_BUTTON_LEFT:
zoom = self.settings_dict.get("sierpinsky_zoom_increase", 2)
elif button == arcade.MOUSE_BUTTON_RIGHT:
@@ -72,7 +84,13 @@ class SierpinskyCarpetViewer(arcade.gui.UIView):
self.pypresence_client.update(state='Viewing Sierpinsky Carpet', details=f'Zoom: {self.zoom}\nDepth: {self.depth}', start=self.pypresence_client.start_time)
def on_button_press(self, controller, name):
if name == "a":
self.on_mouse_press(self.cursor_sprite.left, self.cursor_sprite.bottom, arcade.MOUSE_BUTTON_LEFT, 0)
def on_draw(self):
self.window.clear()
self.sierpinsky_carpet_sprite.draw()
self.ui.draw()
if self.has_controller:
self.sprite_list.draw()