--- /dev/null
+{
+ "widgets": [
+ {
+ "type" : "ImageWidget",
+ "props" : {
+ "source" : "smile.png",
+ "x" : 100,
+ "y" : 100,
+ "w" : 400,
+ "h" : 500,
+ "fit" : true
+ }
+ },
+ {
+ "type": "ImageWidget",
+ "props" : {
+ "w" : 250,
+ "h" : 250,
+ "x" : 1200,
+ "y" : 600,
+ "source" : "test.png",
+ "fit" : true
+ }
+ }
+ ]
+}
\ No newline at end of file
--- /dev/null
+import json
+from dataclasses import dataclass
+import GUI.ImageWidget as ImageWidget
+
+@dataclass
+class Event:
+ event : str
+
+class GuiManager:
+ def __init__(self) -> None:
+ self.widgetList = []
+ self.eventList = []
+
+ def loadWidget(self, jsonStr):
+ j = json.loads(jsonStr)
+ print(j)
+
+ def loadScene(self, path):
+ with open(path, "r") as file:
+ data = json.loads(file.read())
+ for widget in data["widgets"]:
+ if widget["type"] == "ImageWidget" :
+ props = widget["props"]
+ self.createImageWidget(
+ props["x"],
+ props["y"],
+ props["w"],
+ props["h"],
+ props["source"],
+ props["fit"]
+ )
+
+ def createImageWidget(self, x, y, w, h, path, fit) -> None:
+ self.widgetList.append(ImageWidget.ImageWidget(self, x, y, w, h, path, fit))
+
+ def mouseClicked(self, mouseX, mouseY) -> None:
+ # look through all widgets and see if the mouse hit it, if so call it's
+ # onClicked function
+ pass
+
+ def registerEvent(self, event) -> None:
+ self.eventList.append(event)
\ No newline at end of file
--- /dev/null
+import GUI.Widget as Widget
+import pygame
+import os
+
+class ImageWidget(Widget.Widget):
+ def __init__(self, gui, x, y, w, h, imagePath, fit) -> None:
+ super().__init__(gui)
+ self.screenX = x
+ self.screenY = y
+ self.screenW = w
+ self.screenH = h
+
+ image = pygame.image.load(os.path.join('Assets', imagePath))
+ if fit:
+ self.surface = pygame.transform.scale(image, (self.screenW, self.screenH))
+ else :
+ self.surface = image
+
--- /dev/null
+# This class needs a constructor, a list of pygame surfaces to be drawn, an emit function
+# A widget also needs a screenSpace XY coord
+# onClicked function
+
+import GUI.GuiManager as GuiManager
+
+class Widget:
+ def __init__(self, gui) -> None:
+ self.guiManager = gui
+ self.surface = None
+ self.screenX = 0
+ self.screenY = 0
+ self.width = 0
+ self.height = 0
+
+ def onClicked(self) -> None:
+ pass
+
+ def emit(self, emitString) -> None:
+ self.guiManager.registerEvent(GuiManager.Event(emitString))
\ No newline at end of file
+import os
import pygame
import pygame.font
import Player
import Algorithm
import Debug
import random
-
+import GUI.GuiManager as GM
def main():
random.seed(None)
renderer = Renderer.Renderer(1920, 1080)
+ guiManager = GM.GuiManager()
+
+ guiManager.loadScene(os.path.join('Assets', 'GUIScenes', 'TestScene.json'))
+
World.world = WorldGen.generateWorldGrowingRectangles((40, 60), 40)
player = Player.Player(World.worldWidth / 2, World.worldHeight / 2)
cam = (player.worldX, player.worldY)
renderer.renderWorld(cam, InputHandler.globalInputState.zoomLevel, player)
+
+ renderer.renderGuiObjects(guiManager.widgetList)
+
if InputHandler.globalInputState.debugLevel > 0:
renderer.renderDebugUI(player, deltaTime)
if InputHandler.globalInputState.debugLevel > 1:
import Texture
import World
import Debug
+#import GUI.Widget as Widget
class Renderer:
def __init__(self, screenWidth, screenHeight):
pygame.display.set_caption("pyRogue")
self.screen = pygame.display.set_mode([self.screenWidth, self.screenHeight])
+ def renderGuiObjects(self, widgetList):
+ for widget in widgetList:
+ self.screen.blit(widget.surface, (widget.screenX, widget.screenY))
+ pass
+
def renderWorld(self, cam, zoomLevel, player):
actualWidth = int(Texture.spriteSize * zoomLevel)
actualHeight = int(Texture.spriteSize * zoomLevel)