@@ -1,11 +1,12 @@ | |||
import arcade | |||
from gui_aux import * | |||
from desktop_Platform import * | |||
def desktop_createDeselectedTiles(p): | |||
for (id, pos) in enumerate(p.c.tilePositions): | |||
tile = arcade.AnimatedTimeBasedSprite() | |||
p.deselectedTiles.append(tile) | |||
p.sprites.append(tile) | |||
p.deselectedSprites.append(tile) | |||
tile.guid = id | |||
tile.texture = p.textures[0] | |||
@@ -24,7 +25,7 @@ def desktop_createSelectedTiles(p): | |||
for (id, pos) in enumerate(p.c.tilePositions): | |||
tile = arcade.Sprite() | |||
p.selectedTiles.append(tile) | |||
p.sprites.append(tile) | |||
p.selectedSprites.append(tile) | |||
tile.guid = id | |||
tile.texture = p.textures[2 + p.c.playfieldItems[id]] | |||
@@ -36,6 +37,18 @@ def desktop_createSelectedTiles(p): | |||
#} | |||
#} | |||
def desktop_createTitle(p): | |||
p.title = arcade.Sprite() | |||
p.titleSprites.append(p.title) | |||
p.title.texture = p.titleTextures[0] | |||
# Position. | |||
pos = gui_aux_cellScreenPosition(p.c, p.c.titlePosition) | |||
p.title.left = pos[0] | |||
p.title.top = pos[1] | |||
# Invisible by default. | |||
p.title.visible = False | |||
#} | |||
# Deselect mismatched tiles | |||
# | |||
# Conditions: | |||
@@ -80,6 +93,7 @@ def desktop_hideMatchingTiles(p): | |||
#} | |||
#} | |||
# Load tile textures | |||
def desktop_loadTextures(p): | |||
texs = [] | |||
for (id, td) in enumerate(p.c.textureDescriptions): | |||
@@ -95,6 +109,22 @@ def desktop_loadTextures(p): | |||
p.textures = texs | |||
#} | |||
# Load tiTLe textures | |||
def desktop_loadTitleTextures(p): | |||
texs = [] | |||
for (id, td) in enumerate(p.c.titleTextureDescriptions): | |||
tex = arcade.load_texture( | |||
td.fileName, | |||
x = td.x, | |||
y = td.y, | |||
width = td.width, | |||
height = td.height | |||
) | |||
texs.append(tex) | |||
#} | |||
p.titleTextures = texs | |||
#} | |||
# Postpone deselection of mismatched tiles for better UX | |||
# | |||
# Conditions: | |||
@@ -4,9 +4,13 @@ class desktop_Platform: | |||
def __init__(self): | |||
self.c = None | |||
self.ctrl = None | |||
self.deselectedSprites = arcade.SpriteList() | |||
self.deselectedTiles = [] | |||
self.mousePosition = [] | |||
self.selectedTiles = [] | |||
self.sequentialTimer = None | |||
self.sprites = arcade.SpriteList() | |||
self.selectedSprites = arcade.SpriteList() | |||
self.textures = [] | |||
self.title = None | |||
self.titleSprites = arcade.SpriteList() | |||
self.titleTextures = [] |
@@ -14,7 +14,9 @@ class desktop_Window(arcade.Window): | |||
def on_draw(self): | |||
arcade.start_render() | |||
self.p.sprites.draw() | |||
self.p.deselectedSprites.draw() | |||
self.p.selectedSprites.draw() | |||
self.p.titleSprites.draw() | |||
def on_mouse_press(self, x, y, button, key_modifiers): | |||
id = desktop_aux_tileIdAt(self.p, x, y) | |||
@@ -24,5 +26,5 @@ class desktop_Window(arcade.Window): | |||
self.p.ctrl.set("selectedId", id) | |||
def on_update(self, delta): | |||
self.p.sprites.update_animation() | |||
self.p.deselectedSprites.update_animation() | |||
self.p.sequentialTimer.update() |
@@ -2,7 +2,7 @@ import arcade | |||
# Find a visible tile id at the specified location | |||
def desktop_aux_tileIdAt(p, x, y): | |||
sprites = arcade.get_sprites_at_point([x, y], p.sprites) | |||
sprites = arcade.get_sprites_at_point([x, y], p.deselectedSprites) | |||
if ( | |||
len(sprites) != 0 and | |||
sprites[0].visible | |||
@@ -3,11 +3,10 @@ from gui_TextureDescription import * | |||
from llm import * | |||
from memory_Context import * | |||
# Generate textures descriptions | |||
# Generate texture descriptions for tiles | |||
# | |||
# Conditions: | |||
# 1. tileImage or tileImageCount or tileImageHeight or tileImageWidth has just changed | |||
# 2. tileImage, tileImageCount, tileImageHeight, tileImageWidth are not empty | |||
@llm_by_value | |||
def gui_generateTextureDescriptions( | |||
c: memory_Context | |||
@@ -76,3 +75,35 @@ def gui_generateTilePositions( | |||
return c | |||
#} | |||
# Generate texture descriptions for tiTLes | |||
# | |||
# Conditions: | |||
# 1. titleImage, titleImageCount, titleImageHeight, or titleImageWidth has just changed | |||
@llm_by_value | |||
def gui_generateTitleTextureDescriptions( | |||
c: memory_Context | |||
) -> memory_Context: | |||
if ( | |||
c.recentField == "titleImage" or | |||
c.recentField == "titleImageCount" or | |||
c.recentField == "titleImageHeight" or | |||
c.recentField == "titleImageWidth" | |||
): | |||
tds: list[gui_TextureDescription] = [] | |||
for id in range(0, c.titleImageCount): | |||
td = gui_createTextureDescription() | |||
td.fileName = c.titleImage | |||
td.height = c.titleImageHeight | |||
td.width = c.titleImageWidth | |||
td.x = id * c.titleImageWidth | |||
td.y = 0 | |||
tds.append(td) | |||
#} | |||
c.titleTextureDescriptions = tds | |||
c.recentField = "titleTextureDescriptions" | |||
return c | |||
#} | |||
c.recentField = "none" | |||
return c | |||
#} |
@@ -69,6 +69,7 @@ ctrl.registerFunctions([ | |||
# cli_showHelp, | |||
gui_generateTextureDescriptions, | |||
gui_generateTilePositions, | |||
gui_generateTitleTextureDescriptions, | |||
memory_detectMismatchedItems, | |||
memory_detectVictory, | |||
memory_generateConstPlayfield, | |||
@@ -125,5 +126,8 @@ desktop_loadTextures(p) | |||
desktop_createDeselectedTiles(p) | |||
desktop_createSelectedTiles(p) | |||
desktop_loadTitleTextures(p) | |||
desktop_createTitle(p) | |||
wnd = desktop_Window(p) | |||
arcade.run() |
@@ -34,6 +34,7 @@ class memory_Context: | |||
self.titleImageHeight = 0 | |||
self.titleImageWidth = 0 | |||
self.titlePosition = [] | |||
self.titleTextureDescriptions = [] | |||
self.windowBackgroundColor = "#000000" | |||
self.windowHeight = 0 | |||
self.windowTitle = "" | |||