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