From 430b918a99a1677530def95a5574fe727d34bc52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Fri, 28 Jun 2024 23:17:27 +0300 Subject: [PATCH] d --- v5/desktop.py | 2 ++ v5/desktop_Platform.py | 2 ++ v5/desktop_Window.py | 10 ++++++---- v5/desktop_aux.py | 12 ++++++++++++ v5/main-gui.py | 2 ++ 5 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 v5/desktop_aux.py diff --git a/v5/desktop.py b/v5/desktop.py index 394269a..efd21bb 100644 --- a/v5/desktop.py +++ b/v5/desktop.py @@ -48,3 +48,5 @@ def desktop_createSelectedTiles(p): tile.top = pos[1] # Invisible by default. tile.visible = False + #} +#} diff --git a/v5/desktop_Platform.py b/v5/desktop_Platform.py index 62b76e9..e4f6143 100644 --- a/v5/desktop_Platform.py +++ b/v5/desktop_Platform.py @@ -3,7 +3,9 @@ import arcade class desktop_Platform: def __init__(self): self.c = None + self.ctrl = None self.deselectedTiles = [] + self.mousePosition = [] self.selectedTiles = [] self.sprites = arcade.SpriteList() self.textures = [] diff --git a/v5/desktop_Window.py b/v5/desktop_Window.py index 4bf4c77..7ca0ebd 100644 --- a/v5/desktop_Window.py +++ b/v5/desktop_Window.py @@ -1,4 +1,5 @@ import arcade +from desktop_aux import * class desktop_Window(arcade.Window): def __init__(self, p): @@ -16,10 +17,11 @@ class desktop_Window(arcade.Window): self.p.sprites.draw() def on_mouse_press(self, x, y, button, key_modifiers): - print("click", x, y) - sprites = arcade.get_sprites_at_point([x, y], self.p.sprites) - id = sprites[0].guid - print("selected id: ", id) + id = desktop_aux_tileIdAt(self.p, x, y) + if ( + id != None + ): + self.p.ctrl.set("selectedId", id) def on_update(self, delta): self.p.sprites.update_animation() diff --git a/v5/desktop_aux.py b/v5/desktop_aux.py new file mode 100644 index 0000000..17bbe97 --- /dev/null +++ b/v5/desktop_aux.py @@ -0,0 +1,12 @@ +import arcade + +# Find tile id at the specified location +def desktop_aux_tileIdAt(p, x, y): + sprites = arcade.get_sprites_at_point([x, y], p.sprites) + if ( + len(sprites) != 0 + ): + return sprites[0].guid + #} + return None +#} diff --git a/v5/main-gui.py b/v5/main-gui.py index 5fcd3ba..310776a 100644 --- a/v5/main-gui.py +++ b/v5/main-gui.py @@ -81,6 +81,8 @@ ctrl.registerCallback(printOutput) ctrl.registerFieldCallback("exit", lambda c: sys.exit(0)) p = desktop_Platform() +# Keep copy of ctrl in platform, too. +p.ctrl = ctrl # Copy context to platform. def copyContext(c):