def display_menu(items, window_style='menu_window', interact=True, with_none=None, **kwargs): """ Displays a menu containing the given items, returning the value of the item the user selects. @param items: A list of tuples that are the items to be added to this menu. The first element of a tuple is a string that is used for this menuitem. The second element is the value to be returned if this item is selected, or None if this item is a non-selectable caption. @param interact: If True, then an interaction occurs. If False, no suc interaction occurs, and the user should call ui.interact() manually. @param with_none: If True, performs a with None after the input. If None, takes the value from config.implicit_with_none. """ choice_for_skipping() # The possible choices in the menu. choices = [val for label, val in items] while None in choices: choices.remove(None) # Roll forward. roll_forward = renpy.exports.roll_forward_info() if roll_forward not in choices: roll_forward = None # Auto choosing. if renpy.config.auto_choice_delay: renpy.ui.pausebehavior(renpy.config.auto_choice_delay, random.choice(choices)) # Show the menu. renpy.ui.window(style=window_style) renpy.ui.menu(items, location=renpy.game.context().current, focus="choices", default=True, **kwargs) renpy.exports.shown_window() # Log the chosen choice. for label, val in items: if val: log("Choice: " + label) else: log(label) log("") if interact: rv = renpy.ui.interact(mouse='menu', type="menu", roll_forward=roll_forward) for label, val in items: if rv == val: log("User chose: " + label) break else: log("No choice chosen.") log("") checkpoint(rv) if with_none is None: with_none = renpy.config.implicit_with_none if with_none: renpy.game.interface.do_with(None, None) return rv return None
def display_menu(items, window_style="menu_window", interact=True, with_none=None, **kwargs): """ Displays a menu containing the given items, returning the value of the item the user selects. @param items: A list of tuples that are the items to be added to this menu. The first element of a tuple is a string that is used for this menuitem. The second element is the value to be returned if this item is selected, or None if this item is a non-selectable caption. @param interact: If True, then an interaction occurs. If False, no suc interaction occurs, and the user should call ui.interact() manually. @param with_none: If True, performs a with None after the input. If None, takes the value from config.implicit_with_none. """ choice_for_skipping() # The possible choices in the menu. choices = [val for label, val in items] while None in choices: choices.remove(None) # Roll forward. roll_forward = renpy.exports.roll_forward_info() if roll_forward not in choices: roll_forward = None # Auto choosing. if renpy.config.auto_choice_delay: renpy.ui.pausebehavior(renpy.config.auto_choice_delay, random.choice(choices)) # Show the menu. renpy.ui.window(style=window_style) renpy.ui.menu(items, location=renpy.game.context().current, focus="choices", default=True, **kwargs) renpy.exports.shown_window() # Log the chosen choice. for label, val in items: if val: log("Choice: " + label) else: log(label) log("") if interact: rv = renpy.ui.interact(mouse="menu", type="menu", roll_forward=roll_forward) for label, val in items: if rv == val: log("User chose: " + label) break else: log("No choice chosen.") log("") checkpoint(rv) if with_none is None: with_none = renpy.config.implicit_with_none if with_none: renpy.game.interface.do_with(None, None) return rv return None
def display_menu(items, window_style='menu_window', interact=True, with_none=None, caption_style='menu_caption', choice_style='menu_choice', choice_chosen_style='menu_choice_chosen', choice_button_style='menu_choice_button', choice_chosen_button_style='menu_choice_chosen_button', scope={ }, widget_properties=None, screen="choice", type="menu", #@ReservedAssignment predict_only=False, **kwargs): """ Displays a menu containing the given items, returning the value of the item the user selects. @param items: A list of tuples that are the items to be added to this menu. The first element of a tuple is a string that is used for this menuitem. The second element is the value to be returned if this item is selected, or None if this item is a non-selectable caption. @param interact: If True, then an interaction occurs. If False, no suc interaction occurs, and the user should call ui.interact() manually. @param with_none: If True, performs a with None after the input. If None, takes the value from config.implicit_with_none. """ if interact: renpy.exports.mode(type) choice_for_skipping() # The possible choices in the menu. choices = [ val for label, val in items ] while None in choices: choices.remove(None) # Roll forward. roll_forward = renpy.exports.roll_forward_info() if roll_forward not in choices: roll_forward = None # Auto choosing. if renpy.config.auto_choice_delay: renpy.ui.pausebehavior(renpy.config.auto_choice_delay, random.choice(choices)) # The chosen dictionary. chosen = renpy.game.persistent._chosen if chosen is None: chosen = renpy.game.persistent._chosen = { } # The location location=renpy.game.context().current # Show the menu. if has_screen(screen): item_actions = [ ] if widget_properties is None: props = { } else: props = widget_properties for (label, value) in items: if not label: value = None if value is not None: action = renpy.ui.returns(value) else: action = None label_chosen = ((location, label) in chosen) if renpy.config.choice_screen_chosen: item_actions.append((label, action, label_chosen)) else: item_actions.append((label, action)) show_screen(screen, items=item_actions, _widget_properties=props, _transient=True, **scope) else: renpy.ui.window(style=window_style, focus="menu") renpy.ui.menu(items, location=renpy.game.context().current, focus="choices", default=True, caption_style=caption_style, choice_style=choice_style, choice_chosen_style=choice_chosen_style, choice_button_style=choice_button_style, choice_chosen_button_style=choice_chosen_button_style, **kwargs) renpy.exports.shown_window() # Log the chosen choice. for label, val in items: if val is not None: log("Choice: " + label) else: log(label) log("") if interact: rv = renpy.ui.interact(mouse='menu', type=type, roll_forward=roll_forward) # Mark this as chosen. for label, val in items: if rv == val: chosen[(location, label)] = True for label, val in items: if rv == val: log("User chose: " + label) break else: log("No choice chosen.") log("") checkpoint(rv) if with_none is None: with_none = renpy.config.implicit_with_none if with_none: renpy.game.interface.do_with(None, None) return rv return None
def display_menu( items, window_style='menu_window', interact=True, with_none=None, caption_style='menu_caption', choice_style='menu_choice', choice_chosen_style='menu_choice_chosen', choice_button_style='menu_choice_button', choice_chosen_button_style='menu_choice_chosen_button', scope={}, widget_properties=None, screen="choice", type="menu", #@ReservedAssignment predict_only=False, **kwargs): """ Displays a menu containing the given items, returning the value of the item the user selects. @param items: A list of tuples that are the items to be added to this menu. The first element of a tuple is a string that is used for this menuitem. The second element is the value to be returned if this item is selected, or None if this item is a non-selectable caption. @param interact: If True, then an interaction occurs. If False, no suc interaction occurs, and the user should call ui.interact() manually. @param with_none: If True, performs a with None after the input. If None, takes the value from config.implicit_with_none. """ if interact: renpy.exports.mode(type) choice_for_skipping() # The possible choices in the menu. choices = [val for label, val in items] while None in choices: choices.remove(None) # Roll forward. roll_forward = renpy.exports.roll_forward_info() if roll_forward not in choices: roll_forward = None # Auto choosing. if renpy.config.auto_choice_delay: renpy.ui.pausebehavior(renpy.config.auto_choice_delay, random.choice(choices)) # The chosen dictionary. chosen = renpy.game.persistent._chosen if chosen is None: chosen = renpy.game.persistent._chosen = {} # The location location = renpy.game.context().current # Show the menu. if has_screen(screen): item_actions = [] if widget_properties is None: props = {} else: props = widget_properties for (label, value) in items: if not label: value = None if value is not None: action = renpy.ui.returns(value) else: action = None label_chosen = ((location, label) in chosen) if renpy.config.choice_screen_chosen: item_actions.append((label, action, label_chosen)) else: item_actions.append((label, action)) show_screen(screen, items=item_actions, _widget_properties=props, _transient=True, **scope) else: renpy.ui.window(style=window_style, focus="menu") renpy.ui.menu(items, location=renpy.game.context().current, focus="choices", default=True, caption_style=caption_style, choice_style=choice_style, choice_chosen_style=choice_chosen_style, choice_button_style=choice_button_style, choice_chosen_button_style=choice_chosen_button_style, **kwargs) renpy.exports.shown_window() # Log the chosen choice. for label, val in items: if val is not None: log("Choice: " + label) else: log(label) log("") if interact: rv = renpy.ui.interact(mouse='menu', type=type, roll_forward=roll_forward) # Mark this as chosen. for label, val in items: if rv == val: chosen[(location, label)] = True for label, val in items: if rv == val: log("User chose: " + label) break else: log("No choice chosen.") log("") checkpoint(rv) if with_none is None: with_none = renpy.config.implicit_with_none if with_none: renpy.game.interface.do_with(None, None) return rv return None