コード例 #1
0
 def handle_context_action(self):
     context_menu_options = []
     player = self.parent
     state_stack = player.game_state.value.menu_prompt_stack
     stack_pop_function = menu.BackToGameFunction(state_stack)
     if player.pick_up_item_action.can_act(
             source_entity=self.parent,
             target_entity=self.parent,
             game_state=self.parent.game_state.value):
         pickup_option = player.pick_up_item_action.delayed_act(
             source_entity=player,
             target_entity=player,
             game_state=player.game_state.value)
         functions = [pickup_option, stack_pop_function]
         context_menu_options.append(
             menu.MenuOption(player.pick_up_item_action.name, functions))
     context_menu_options.extend(
         menufactory.get_dungeon_feature_menu_options(
             player, stack_pop_function))
     if len(context_menu_options
            ) == 1 and context_menu_options[0].can_activate:
         context_menu_options[0].activate()
     elif len(context_menu_options) > 1:
         tile_menu = menufactory.get_menu_with_options(
             context_menu_options, state_stack)
         self.parent.game_state.value.start_prompt(tile_menu)
コード例 #2
0
def context_menu(player, state_stack):
    current_dungeon_feature = (player.dungeon_level.value.get_tile(player.position.value).get_dungeon_feature())
    context_options = []
    stack_pop_function = menu.BackToGameFunction(state_stack)
    if not current_dungeon_feature is None:
        context_options.extend(get_dungeon_feature_menu_options(player, stack_pop_function))

    status_menu = player_status_menu(player)
    open_status_option = menu.MenuOption("Player Status", [lambda: state_stack.push(status_menu)])
    context_options.append(open_status_option)

    inventory_menu_opt = inventory_menu(player, state_stack)
    open_inventory_option = menu.MenuOption("Inventory", [lambda: state_stack.push(inventory_menu_opt)],
                                            (lambda: not player.inventory.is_empty()))
    context_options.append(open_inventory_option)

    equipment_menu_opt = equipment_menu(player, state_stack)
    open_equipment_option = menu.MenuOption("Equipment", [lambda: state_stack.push(equipment_menu_opt)])
    context_options.append(open_equipment_option)

    context_menu_rect = rectfactory.center_of_screen_rect(max(option.width for option in context_options) + 4,
                                                          len(context_options) * 2 + 3)
    resulting_menu = menu.StaticMenu(context_menu_rect.top_left, context_options, state_stack,
                                     margin=style.menu_theme.margin)
    background_rect = get_menu_background(context_menu_rect)

    ui_elements = [background_rect, resulting_menu]
    ui_state = state.UIState(gui.UIElementList(ui_elements))
    return ui_state
コード例 #3
0
def sacrifice_menu(player, powers, post_power_gain_function):
    game_state = player.game_state.value
    state_stack = game_state.menu_prompt_stack
    context_options = []
    stack_pop_function = menu.BackToGameFunction(state_stack)
    width = 24

    for power in powers:
        power_caption = power.description.name + str(power.buy_cost).rjust(width - len(power.description.name))
        power_option = menu.MenuOption(power_caption, [lambda p=power: player.set_child(p),
                                                       lambda p=power: p.on_power_gained(),
                                                       lambda p=power: sacrifice.sacrifice_health(player, p.buy_cost),
                                                       lambda: player.actor.add_energy_spent(gametime.single_turn),
                                                       post_power_gain_function,
                                                       stack_pop_function],
                                       (lambda: player.health.hp.value > power.buy_cost), payload=power)
        context_options.append(power_option)

    cancel_option = menu.MenuOption("Cancel", [stack_pop_function], (lambda: True))
    context_options.append(cancel_option)

    tmp = (0, 0)
    menu_stack_panel = gui.StackPanelVertical(tmp, style.menu_theme.margin, vertical_space=0,
                                              alignment=gui.StackPanelVertical.ALIGN_CENTER)

    heading_stack_panel = gui.StackPanelHorizontal((0, 0), (0, 0), horizontal_space=2)
    menu_stack_panel.append(heading_stack_panel)
    if any(powers):
        power_caption = "Power" + str("Cost").rjust(width - len("Cost   "))
        heading_stack_panel.append(gui.TextBox(power_caption, (1, 0), colors.GRAY))
        heading_stack_panel.append(gui.SymbolUIElement((0, 0), graphic.GraphicChar(colors.DARK_BLUE, colors.HP_BAR_FULL, icon.HEALTH_STAT)))
        menu_stack_panel.append(gui.VerticalSpace(2))
    else:
        power_caption = "There are no more powers."
        menu_stack_panel.append(gui.VerticalSpace(4))
        heading_stack_panel.append(gui.TextBox(power_caption, (1, 0), colors.GRAY))

    item_description_card = gui.new_item_description_card()
    resulting_menu = menu.StaticMenu((0, 0), context_options, state_stack, selected_payload_callback=(lambda item: item_description_card.set_item(item)))
    menu_stack_panel.append(resulting_menu)

    context_menu_rect = rectfactory.center_of_screen_rect(max(menu_stack_panel.total_width, 24),
                                                          max(menu_stack_panel.total_height, 6))
    menu_stack_panel.offset = context_menu_rect.top_left
    background_rect = get_menu_background(context_menu_rect, style.sacrifice_menu_theme.rect_style)

    dock = gui.UIDock(rectfactory.full_screen_rect())
    dock.bottom = item_description_card

    ui_elements = [background_rect, menu_stack_panel, dock]
    ui_state = state.UIState(gui.UIElementList(ui_elements))
    return ui_state
コード例 #4
0
def filtered_by_action_item_menu(player, state_stack, item_action_tag, heading_text):
    menu_stack_panel = get_item_menu_stack_panel_template(heading_text,
                                                          graphic.GraphicChar(None,
                                                                              colors.INVENTORY_HEADING,
                                                                              icon.INVENTORY_ICON))
    item_description_card = gui.new_item_description_card()
    stack_pop_function = menu.BackToGameFunction(state_stack)
    menu_items = []
    for item in player.inventory.get_items_sorted():
        if len(item.get_children_with_tag(item_action_tag)) > 0:
            item_action = item.get_children_with_tag(item_action_tag)[0]
            item_action_option = _get_item_action_option(item, item_action, player, stack_pop_function)
            menu_items.append(item_action_option)

    action_menu = menu.StaticMenu((0, 1), menu_items, state_stack,
                                  (0, 0), vertical_space=0, selected_payload_callback=(lambda item: item_description_card.set_item(item)))
    menu_stack_panel.append(action_menu)
    return _get_item_menu_composition(item_description_card, menu_stack_panel)
コード例 #5
0
def get_save_quit_menu(player, state_stack):
    options = []
    game_state = player.game_state.value
    exit_menu_function = menu.BackToGameFunction(state_stack)
    save_and_quit_graphic_active = graphic.GraphicChar(None, colors.WHITE, icon.GUNSLINGER_THIN)
    save_and_quit_graphic_inactive = graphic.GraphicChar(None, colors.GRAY, icon.GUNSLINGER_THIN)
    options.append(menu.MenuOptionWithSymbols("Save and Quit", save_and_quit_graphic_active,
                                              save_and_quit_graphic_inactive,
                                              [lambda: save.save(game_state), exit_menu_function,
                                               game_state.current_stack.pop,
                                               (lambda: player.actor.add_energy_spent(gametime.single_turn))]))

    give_up_graphic_active = graphic.GraphicChar(None, colors.WHITE, icon.SKULL)
    give_up_graphic_inactive = graphic.GraphicChar(None, colors.GRAY, icon.SKULL)
    options.append(menu.MenuOptionWithSymbols("Give Up", give_up_graphic_active, give_up_graphic_inactive,
                                              [player.health_modifier.kill, exit_menu_function,
                                               (lambda: player.actor.add_energy_spent(gametime.single_turn))]))

    return get_menu_with_options(options, state_stack, 6, 5)
コード例 #6
0
def item_type_menu_callback_menu(player, state_stack, item_type, heading_text, item_callback,
                                 can_callback_activate=(lambda: True)):
    menu_stack_panel = get_item_menu_stack_panel_template(heading_text,
                                                          graphic.GraphicChar(None,
                                                                              colors.INVENTORY_HEADING,
                                                                              icon.INVENTORY_ICON))
    item_description_card = gui.new_item_description_card()
    stack_pop_function = menu.BackToGameFunction(state_stack)
    menu_items = []
    for item in player.inventory.get_items_sorted():
        if item.item_type.value == item_type:
            item_action_option = _get_item_callback_option(item, item_callback, can_callback_activate,
                                                           player, stack_pop_function)
            menu_items.append(item_action_option)

    _equip_menu = menu.StaticMenu((0, 1), menu_items, state_stack, (0, 0), vertical_space=0,
                                  selected_payload_callback=(lambda item: item_description_card.set_item(item)))
    menu_stack_panel.append(_equip_menu)
    return _get_item_menu_composition(item_description_card, menu_stack_panel)