Return to repo list

heart-of-gold

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

commit bf87579fa0a2179c619a2a30d9854a07b57cf8a5
parent 5a67ed50cef31db37ec2446d0bd795fa4ba68063
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Wed, 14 Oct 2020 16:04:06 -0500

Menu button pressing functionality

Diffstat:
Mdata/json/menus/mainmenu.json | 2+-
Msrc/game.py | 25+++++++++++++------------
Msrc/menu.py | 20++++++++++++++++++++
3 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/data/json/menus/mainmenu.json b/data/json/menus/mainmenu.json @@ -8,7 +8,7 @@ "sprite" : [0, 0], "pos" : [100, 100], "intlayer" : 0, - "effect" : ["me_quit"] + "effect" : ["me_shift_battle_mode"] }, "LoadGame" : { "sheet" : "mainmenu_buttons_1", diff --git a/src/game.py b/src/game.py @@ -38,7 +38,7 @@ class Game(object): # Mode management values # TODO: enum self.state_mode = "Main_Menu_Mode" - self.control_mode = None + self.control_mode = "Main_Menu_Normal" # Subsystems self.interface = GameInterface(self) @@ -75,7 +75,6 @@ class Game(object): self.board_manager.load_board_from_file(new_mode_def[action]["name"] + ".tmx") self.board_manager.switch_to_board(new_mode_def[action]["name"] + ".tmx") self.entity_manager.load_entities_from_json(new_mode_def[action]["name"] + ".json") - # TODO: entity loading should be able to assign units. entity jsons should have units listed then def shift_frames(self): """ @@ -204,17 +203,19 @@ class GameInterface(GameSubsystem): """ React to a mousebutton being clicked. """ - # TODO: Decision order should go "mode" -> "button" rather than - # "button" -> "mode" as currently here. if event.button == 1: - if self.control_mode == "Turn_Normal": - if self.game.entity_manager.select_entities_with_tile_cursor(self.game.board_manager.get_tile_at_position(pygame.mouse.get_pos())): - self.control_mode = "Turn_Select_Move" - elif self.control_mode == "Turn_Select_Move": - if self.game.entity_manager.set_entity_move_to_tile_pos(self.game.entity_manager.selected_entity, self.game.board_manager.get_overlay_move_vgo_at_pos(pygame.mouse.get_pos())): - self.control_mode = "Turn_Normal" - # TODO: Should this really be done here??? - self.game.board_manager.load_overlay() + if self.game.state_mode == "Main_Menu_Mode": + if self.game.control_mode == "Main_Menu_Normal": + self.game.menu_manager.trigger_button_at_pos(pygame.mouse.get_pos()) + elif self.game.state_mode == "Battle_Mode": + if self.game.control_mode == "Turn_Normal": + if self.game.entity_manager.select_entities_with_tile_cursor(self.game.board_manager.get_tile_at_position(pygame.mouse.get_pos())): + self.game.control_mode = "Turn_Select_Move" + elif self.game.control_mode == "Turn_Select_Move": + if self.game.entity_manager.set_entity_move_to_tile_pos(self.game.entity_manager.selected_entity, self.game.board_manager.get_overlay_move_vgo_at_pos(pygame.mouse.get_pos())): + self.game.control_mode = "Turn_Normal" + # TODO: Should this really be done here??? + self.game.board_manager.load_overlay() def handle_mouse_release(self, event): """ diff --git a/src/menu.py b/src/menu.py @@ -46,6 +46,26 @@ class MenuManager(manager.Manager): if menuname in self.loaded_menus.keys(): self.current_menu = self.loaded_menus[menuname] + def activate_menu_events(self, events): + """ + Activate one or more events in Menu mode. This is + a BIG method that accounts for almost everything + you can do in menus. + """ + for e in events: + if e == "me_quit": # Quit the game + self.game.on = False + + def trigger_button_at_pos(self, pos): + """ + Trigger a button if pos is within that button's + rect. + """ + if self.current_menu != None: + for b in self.current_menu.button_group: + if b.rect.collidepoint(pos): + self.activate_menu_events(b.effects) + def update_current_menu(self, surface = None): """ Update the current Menu object and all of its