def on_menu_selection(self, menuitem): def use_item(menuitem): player = self.game.player1 monster = menuitem.game_object self.game.pop_state() # close the monster menu if state == "CombatState": self.game.get_state_name("CombatState").enqueue_action( player, item, player.monsters[0]) self.game.pop_state() # pop this menu else: item.use(player, monster) self._initialize_items( ) # re-init, in case one item is gone now def decide_to_use(menuitem): self.game.pop_state() # close the confirm dialog if menuitem.label == "USE": self.game.push_state("MonsterMenuState", on_menu_selection=use_item) item = menuitem.game_object state = self.determine_state_called_from() if state in item.usable_in: self.game.push_state("UseItemConfirmMenuState", on_menu_selection=decide_to_use) else: rect = self.game.screen.get_rect() center = rect.center rect.height /= 6 rect.width *= .8 rect.center = center tools.open_dialog(self.game, ["%s cannot be used here!" % item.name])
def host_game(self): # check if server is already hosting a game if self.game.server.listening: self.game.pop_state(self) open_dialog(self.game, [trans('multiplayer_already_hosting')]) # not hosting, so start the process elif not self.game.isclient: # Configure this game to host self.game.ishost = True self.game.server.server.listen() self.game.server.listening = True # Enable the client, so we can connect to self self.game.client.enable_join_multiplayer = True self.game.client.client.listen() self.game.client.listening = True # connect to self while not self.game.client.client.registered: self.game.client.client.autodiscover(autoregister=False) for game in self.game.client.client.discovered_servers: self.game.client.client.register(game) # close this menu self.game.pop_state(self) # inform player that hosting is ready open_dialog(self.game, [trans('multiplayer_hosting_ready')])
def add(menuitem): monster = menuitem.game_object if monster.current_hp == 0: tools.open_dialog(self.game, ["Cannot choose because is fainted"]) else: self.game.pop_state() self.add_monster_into_play(player, monster)
def on_menu_selection(self, menuitem): logger.info("Saving!") try: save.save(self.game.player1, self.capture_screenshot(), self.selected_index + 1, self.game) except Exception as e: logger.error("Unable to save game!!") logger.error(e) open_dialog(self.game, ["There was a problem saving!"]) self.game.pop_state(self) else: open_dialog(self.game, ["Saved!"]) self.game.pop_state(self)
def use_item(menu_item): player = self.game.player1 monster = menu_item.game_object # item must be used before state is popped. # don't try to combine with "if result..." condition below result = item.use(player, monster) self.game.pop_state() # pop the monster screen self.game.pop_state() # pop the item screen if result["success"]: tools.open_dialog(self.game, [trans('item_success')]) else: tools.open_dialog(self.game, [trans('item_failure')])
def use_item(menu_item): player = self.game.player1 monster = menu_item.game_object # item must be used before state is popped. # don't try to combine with "if result..." condition below result = item.use(player, monster) self.game.pop_state() # pop the monster screen self.game.pop_state() # pop the item screen msg_type = 'success_trans' if result['success'] else 'failure_trans' template = getattr(item, msg_type) if template: message = trans(template) tools.open_dialog(self.game, [message])
def on_menu_selection(self, menu_item): """ Called when player has selected something from the inventory Currently, opens a new menu depending on the state context :param menu_item: :return: """ item = menu_item.game_object state = self.determine_state_called_from() if state in item.usable_in: self.open_confirm_use_menu(item) else: msg = trans('item_cannot_use_here', {'name': item.name}) tools.open_dialog(self.game, [msg])
def on_menu_selection(self, menuitem): logger.info("Saving!") try: save.save(self.game.player1, self.capture_screenshot(), self.selected_index + 1, self.game) except Exception as e: logger.error("Unable to save game!!") logger.error(e) open_dialog(self.game, [trans('save_failure')]) self.game.pop_state(self) else: open_dialog(self.game, [trans('save_success')]) self.game.pop_state(self)
def swap_it(menuitem): monster = menuitem.game_object trans = translator.translate if monster in self.game.get_state_name('CombatState').active_monsters: tools.open_dialog(self.game, [trans('combat_isactive', {"name": monster.name})]) return elif monster.current_hp < 1: tools.open_dialog(self.game, [trans('combat_fainted', {"name": monster.name})]) combat_state = self.game.get_state_name("CombatState") swap = Technique("technique_swap") swap.combat_state = combat_state player = self.game.player1 target = monster combat_state.enqueue_action(player, swap, target) self.game.pop_state() # close technique menu self.game.pop_state() # close the monster action menu
def dialog_chain(self, game, action): """Opens a chain of dialogs in order. Dialog chain must be ended with the ${{end}} keyword. :param game: The main game object that contains all the game's variables. :param action: The action (tuple) retrieved from the database that contains the action's parameters :type game: core.control.Control :type action: Tuple :rtype: None :returns: None Valid Parameters: text_to_display You may also use special variables in dialog events. Here is a list of available variables: * ${{name}} - The current player's name. * ${{end}} - Ends the dialog chain. **Examples:** >>> action.__dict__ { "type": "dialog_chain", "parameters": [ "Red:\\n This is some dialog!" ] } """ text = str(action.parameters[0]) text = self._replace_text(game, text) logger.info("Opening chain dialog window") if text == "${{end}}": # Open a dialog window in the current scene. open_dialog(game, self._dialog_chain_queue) self._dialog_chain_queue = list() else: self._dialog_chain_queue.append(text)
def swap_it(menuitem): monster = menuitem.game_object trans = translator.translate if monster in self.game.get_state_name( 'CombatState').active_monsters: tools.open_dialog( self.game, [trans('combat_isactive', {"name": monster.name})]) return elif monster.current_hp < 1: tools.open_dialog( self.game, [trans('combat_fainted', {"name": monster.name})]) player = self.game.player1 target = player.monsters[0] swap = Technique("technique_swap") swap.other = monster combat_state = self.game.get_state_name("CombatState") combat_state.enqueue_action(player, swap, target) self.game.pop_state() # close technique menu self.game.pop_state() # close the monster action menu
def dialog(self, game, action): """Opens a dialog window with text :param game: The main game object that contains all the game's variables. :param action: The action (tuple) retrieved from the database that contains the action's parameters :type game: core.control.Control :type action: Tuple :rtype: None :returns: None Valid Parameters: text_to_display You may also use special variables in dialog events. Here is a list of available variables: * ${{name}} - The current player's name. **Examples:** >>> action.__dict__ { "type": "dialog", "parameters": [ "Red:\\n This is some dialog!" ] } """ text = str(action.parameters[0]) text = self._replace_text(game, text) logger.info("Opening dialog window") # Open a dialog window in the current scene. open_dialog(game, [text])
def add(menuitem): monster = menuitem.game_object if monster.current_hp == 0: tools.open_dialog(self.game, [trans("combat_fainted", parameters={"name": monster.name})]) elif monster in self.active_monsters: tools.open_dialog(self.game, [trans("combat_isactive", parameters={"name": monster.name})]) msg = trans("combat_replacement_is_fainted") tools.open_dialog(self.game, [msg]) else: self.add_monster_into_play(player, monster) self.game.pop_state()
def not_implemented_dialog(): open_dialog(self.game, ["This feature is not implemented."])
def open_dialog(self, initial_text): logger.info("Opening chain dialog window") open_dialog(self.game, [initial_text])
def open_dialog(self, initial_text): logger.info("Opening dialog window") open_dialog(self.game, [initial_text])
def multiplayer_menu(): # self.game.replace_state("MultiplayerMenu") open_dialog(self.game, ["Multiplayer not supported."])
def execute(self, game): # Open a dialog window in the current scene. open_dialog(game, self._dialog_chain_queue, self._menu) self._dialog_chain_queue = list() self._menu = None
def open_monster_stats(): open_dialog(self.game, [translator.translate('not_implemented')])
def not_implemented_dialog(): open_dialog(self.game, [translator.translate('not_implemented')])