@@ -48,3 +48,5 @@ def desktop_createSelectedTiles(p): | |||||
tile.top = pos[1] | tile.top = pos[1] | ||||
# Invisible by default. | # Invisible by default. | ||||
tile.visible = False | tile.visible = False | ||||
#} | |||||
#} |
@@ -3,7 +3,9 @@ import arcade | |||||
class desktop_Platform: | class desktop_Platform: | ||||
def __init__(self): | def __init__(self): | ||||
self.c = None | self.c = None | ||||
self.ctrl = None | |||||
self.deselectedTiles = [] | self.deselectedTiles = [] | ||||
self.mousePosition = [] | |||||
self.selectedTiles = [] | self.selectedTiles = [] | ||||
self.sprites = arcade.SpriteList() | self.sprites = arcade.SpriteList() | ||||
self.textures = [] | self.textures = [] |
@@ -1,4 +1,5 @@ | |||||
import arcade | import arcade | ||||
from desktop_aux import * | |||||
class desktop_Window(arcade.Window): | class desktop_Window(arcade.Window): | ||||
def __init__(self, p): | def __init__(self, p): | ||||
@@ -16,10 +17,11 @@ class desktop_Window(arcade.Window): | |||||
self.p.sprites.draw() | self.p.sprites.draw() | ||||
def on_mouse_press(self, x, y, button, key_modifiers): | 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): | def on_update(self, delta): | ||||
self.p.sprites.update_animation() | self.p.sprites.update_animation() |
@@ -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 | |||||
#} |
@@ -81,6 +81,8 @@ ctrl.registerCallback(printOutput) | |||||
ctrl.registerFieldCallback("exit", lambda c: sys.exit(0)) | ctrl.registerFieldCallback("exit", lambda c: sys.exit(0)) | ||||
p = desktop_Platform() | p = desktop_Platform() | ||||
# Keep copy of ctrl in platform, too. | |||||
p.ctrl = ctrl | |||||
# Copy context to platform. | # Copy context to platform. | ||||
def copyContext(c): | def copyContext(c): | ||||