From 03578f5b6d89c3403b7796391cb5cf7e205fe286 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: Mon, 1 Jul 2024 00:05:29 +0300 Subject: [PATCH] d --- v5/desktop.py | 28 ++++++++++++++++++++++++++++ v5/desktop_Platform.py | 3 +++ v5/desktop_Window.py | 1 + v5/gui.py | 33 +++++++++++++++++++++++++++++++++ v5/main-gui.py | 11 ++++++++++- v5/memory_Context.py | 6 ++++++ 6 files changed, 81 insertions(+), 1 deletion(-) diff --git a/v5/desktop.py b/v5/desktop.py index 8380b13..0d39262 100644 --- a/v5/desktop.py +++ b/v5/desktop.py @@ -2,6 +2,18 @@ import arcade from gui_aux import * from desktop_Platform import * +def desktop_createDesc(p): + p.desc = arcade.Sprite() + p.descSprites.append(p.desc) + p.desc.texture = p.descTextures[0] + # Position. + pos = gui_aux_cellScreenPosition(p.c, p.c.descPosition) + p.desc.left = pos[0] + p.desc.top = pos[1] + # Invisible by default. + p.desc.visible = False +#} + def desktop_createDeselectedTiles(p): for (id, pos) in enumerate(p.c.tilePositions): tile = arcade.AnimatedTimeBasedSprite() @@ -124,6 +136,22 @@ def desktop_hideTitle(p): #} #} +# Load description textures +def desktop_loadDescTextures(p): + texs = [] + for (id, td) in enumerate(p.c.descTextureDescriptions): + tex = arcade.load_texture( + td.fileName, + x = td.x, + y = td.y, + width = td.width, + height = td.height + ) + texs.append(tex) + #} + p.descTextures = texs +#} + # Load tile textures def desktop_loadTextures(p): texs = [] diff --git a/v5/desktop_Platform.py b/v5/desktop_Platform.py index 9b31f48..383d53a 100644 --- a/v5/desktop_Platform.py +++ b/v5/desktop_Platform.py @@ -4,6 +4,9 @@ class desktop_Platform: def __init__(self): self.c = None self.ctrl = None + self.desc = None + self.descSprites = arcade.SpriteList() + self.descTextures = [] self.deselectedSprites = arcade.SpriteList() self.deselectedTiles = [] self.mousePosition = [] diff --git a/v5/desktop_Window.py b/v5/desktop_Window.py index b98a0dd..a150bc2 100644 --- a/v5/desktop_Window.py +++ b/v5/desktop_Window.py @@ -14,6 +14,7 @@ class desktop_Window(arcade.Window): def on_draw(self): arcade.start_render() + self.p.descSprites.draw() self.p.deselectedSprites.draw() self.p.selectedSprites.draw() self.p.titleSprites.draw() diff --git a/v5/gui.py b/v5/gui.py index 6d4aa0a..b24661a 100644 --- a/v5/gui.py +++ b/v5/gui.py @@ -3,6 +3,39 @@ from gui_TextureDescription import * from llm import * from memory_Context import * +# Generate texture descriptions for harm description +# +# Conditions: +# 1.descImage, descImageCount, descImageHeight, or descImageWidth has just changed +@llm_by_value +def gui_generateDescTextureDescriptions( + c: memory_Context +) -> memory_Context: + if ( + c.recentField == "descImage" or + c.recentField == "descImageCount" or + c.recentField == "descImageHeight" or + c.recentField == "descImageWidth" + ): + tds: list[gui_TextureDescription] = [] + for id in range(0, c.descImageCount): + td = gui_createTextureDescription() + td.fileName = c.descImage + td.height = c.descImageHeight + td.width = c.descImageWidth + td.x = id * c.descImageWidth + td.y = 0 + tds.append(td) + #} + c.descTextureDescriptions = tds + c.recentField = "descTextureDescriptions" + return c + #} + + c.recentField = "none" + return c +#} + # Generate texture descriptions for tiles # # Conditions: diff --git a/v5/main-gui.py b/v5/main-gui.py index 9934de5..b1562d9 100644 --- a/v5/main-gui.py +++ b/v5/main-gui.py @@ -67,6 +67,7 @@ ctrl.registerFunctions([ # cli_reportVictory, # cli_selectItem, # cli_showHelp, + gui_generateDescTextureDescriptions, gui_generateTextureDescriptions, gui_generateTilePositions, gui_generateTitleTextureDescriptions, @@ -79,7 +80,7 @@ ctrl.registerFunctions([ def printDbg(c): print(f"Dbg key/value: '{c.recentField}'/'{c.field(c.recentField)}'") -ctrl.registerCallback(printDbg) +#ctrl.registerCallback(printDbg) ctrl.registerFieldCallback("exit", lambda c: sys.exit(0)) p = desktop_Platform() @@ -108,6 +109,11 @@ ctrl.set("playfieldSize", 6) ctrl.set("cellPositions", gui_aux_cellHarmPositions()) ctrl.set("cellSize", 25) ctrl.set("deselectMismatchedTilesDelay", 500) +ctrl.set("descImage", "res/harm.png") +ctrl.set("descImageCount", 6) +ctrl.set("descImageHeight", 250) +ctrl.set("descImageWidth", 375) +ctrl.set("descPosition", [19, 12]) ctrl.set("hideMatchingTilesDelay", 500) ctrl.set("tileImage", "res/harmful-tiles.png") ctrl.set("tileImageCount", 8) @@ -131,5 +137,8 @@ desktop_createSelectedTiles(p) desktop_loadTitleTextures(p) desktop_createTitle(p) +desktop_loadDescTextures(p) +desktop_createDesc(p) + wnd = desktop_Window(p) arcade.run() diff --git a/v5/memory_Context.py b/v5/memory_Context.py index 0581e8c..39d9978 100644 --- a/v5/memory_Context.py +++ b/v5/memory_Context.py @@ -2,6 +2,12 @@ class memory_Context: def __init__(self): self.cellPositions = [] self.cellSize = 0 + self.descImage = "" + self.descImageCount = 0 + self.descImageHeight = 0 + self.descImageWidth = 0 + self.descPosition = [] + self.descTextureDescriptions = [] self.deselectMismatchedTiles = False self.deselectMismatchedTilesDelay = 0 self.didLaunch = False