Return to repo list

heart-of-gold

Tactical RPG written in python, using pygame.
Return to HMagellan.com

commit 8f545f741f00caf7dafbb66c7d7af7a737bb1c7e
parent fa8c10d13a497b29af730fa1adbdbed5316f5aa5
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Mon,  5 Oct 2020 16:04:40 -0500

Menu should now load correctly, plus button obj added

Diffstat:
Msrc/menu.py | 24+++++++++++++++++++++++-
Msrc/vgo.py | 21+++++++++++++++++++++
2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/src/menu.py b/src/menu.py @@ -75,6 +75,9 @@ class Menu(object): self.entities_group = pygame.sprite.LayeredDirty() self.definition = json.load(open(os.path.join(MENU_JSON_PATH, menufile))) + # TODO: This will not be permenant + self.contained_entities = 0 + # Load/setup menu self.load_menu() @@ -85,4 +88,23 @@ class Menu(object): anywhere else. """ if self.definition != None: - self.background = vgo.Entity( + + # Load background, if any + # TODO: Background should probably be a VGO subclass of its own rather than + # a generic entity. It would be better since currently decisions such + # as e.g. being animated are hardcoded here. + self.background = vgo.Entity(self.definition["bg_sheet"] + " _ent", self.contained_entities, + self.manager.game.sheet_manager.loaded_sheets[self.definition["bg_sheet"]], + None, False, True, None) + self.background.set_sprite(tuple(self.definition["bg_sprite"])) + self.contained_entities += 1 + + # Load buttons, if any + for b in self.definition["buttons"]: + nmb = vgo.MenuButton(b, self.contained_entities, + self.definitions["buttons"][b]["sheet"], None, False, True, None, + self.definitions["buttons"][b]["effect"]) + nmb.set_sprite(tuple(self.definition["buttons"][b]["sprite"])) + self.button_group.add(nmb) + + # TODO: add generic ent loader and some way to enumerate sublayouts. diff --git a/src/vgo.py b/src/vgo.py @@ -197,6 +197,27 @@ class Entity(VisibleGameObject): # Section 3 - Various Entity subclasses # ######################################### +class MenuButton(Entity): + """ + Object that represents pushable menu buttons in menu mode. Created + and managed by Menu objects. + """ + # TODO: MenuButton should probably eventually be passed info on its draw layer. + + def __init__(self, name, ent_id, sheet, animation = None, animated = False, passable = True, unit = None, effects = []): + + # Parent initialization + super().__init__(name, ent_id, sheet, animation, animated, passable, unit) + + # Saved values + self.effects = effects # A list of effects. Each effect goes with a method in MenuManager, and each one is triggered on a press. + + # VGO settings + self.custom_flags = None + + # DirtySprite settings + self.layer = 1 + class TileCursor(Entity): """ Object that follows the cursor to indicate selected/highlighted