def event_targeting_acquire(self): # targeted tile is currently selected target_tile = self._renderSelectedTile # hack to avoid lingering selection tile self._renderSelectedTile = None # find target based on targetType if self._targetType == TARGET.TILE: my_target = target_tile elif self._targetType == TARGET.ACTOR: # Currently this finds all ACTORS, not limited to CHARACTERS # find target actor on tile if len(target_tile.actors) == 0: return if len(target_tile.actors) == 1: my_target = target_tile.actors[0] else: # show menu with options to target header = 'Select target (escape to cancel)' options = [] for a in target_tile.actors: options.append(a.name + ' (' + str(a.currentHitPoints) + '/' + str(a.maxHitPoints) + ')') selection = GuiUtilities.show_menu(self.surface_display, header, options) if selection is None: return else: my_target = target_tile.actors[selection] # use target item on target self.game.player.try_use_item(self._targetingItem, my_target) # Leave targeting mode self.event_targeting_stop()
def _update_screen(self): self.surface_display.blit(self.surface_version, self.version_position) self.selection = GuiUtilities.show_menu(self.surface_display, 'Main Menu', self.options, self.keys) if self.selection is None: return else: print('Main Menu: ' + self.options[self.selection]) self.handlers[self.selection]()
def drop_inventory(self): """ Present inventory to player with possibility to drop an item. """ if self.game is not None and self.game.player is not None: header = "Select item to drop, escape to cancel" options = [] items = self.game.player.inventory.items for item in items: options.append(item.name) selection = GuiUtilities.show_menu(self.surface_display, header, options) if selection is not None: self.game.player.tryDropItem(items[selection])
def show_game_menu(self): options = ['Controls', 'Quit Game'] keys = ['c', 'q'] selection = GuiUtilities.show_menu(self.surface_display, 'Game Menu', options, keys) if selection is None: return elif selection == 0: print('Game Menu: ' + options[0]) GuiUtilities.show_message_controls(self.surface_display) elif selection == 1: print('Game Menu: ' + options[1]) self.stop_game() else: print('Game Menu: unknown selection...?')
def use_inventory(self): """ Present inventory to player with possibility to use an item. """ if self.game is not None and self.game.player is not None: header = "Select item to use, escape to cancel" options = [] items = self.game.player.inventory.items for item in items: options.append(item.name) selection = GuiUtilities.show_menu(self.surface_display, header, options) if selection is not None: use_item = items[selection] if use_item.targeted: # ask player for target self.event_targeting_start(use_item) else: # try to use the item self.game.player.try_use_item(use_item)
def show_main_menu(self): options = ['New local game', 'Controls', 'Quit', 'Debug Maps', 'Connect to server'] keys = ['n', 'c', 'q', 'd', 's'] selection = GuiUtilities.show_menu(self.surface_display, 'Main Menu', options, keys) if selection is None: return elif selection == 0: print('Main Menu: ' + options[0]) self.new_game() elif selection == 1: print('Main Menu: ' + options[1]) GuiUtilities.show_message_controls(self.surface_display) elif selection == 2: print('Main Menu: ' + options[2]) sys.exit() elif selection == 3: print('Main Menu: ' + options[3]) self.debug_maps() elif selection == 4: print('Main Menu: ' + options[4]) self.connect_to_server() else: print('Main menu: unknown selection...?')