From d40af370a83641edf51d6ea0a1763d2d044cb878 Mon Sep 17 00:00:00 2001 From: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com> Date: Fri, 17 Nov 2023 04:31:20 +0100 Subject: [PATCH] Upgrade brewing menu the usual : make variables dynamic, use call screen instead of show screen... --- game/scripts/interface/brewing.rpy | 78 ++++++++++++------------------ 1 file changed, 32 insertions(+), 46 deletions(-) diff --git a/game/scripts/interface/brewing.rpy b/game/scripts/interface/brewing.rpy index 39f568fe..169b2c51 100644 --- a/game/scripts/interface/brewing.rpy +++ b/game/scripts/interface/brewing.rpy @@ -13,55 +13,41 @@ init python: return item + def __actuate(): + global menu_items + global current_item + + menu_items = brewing_sortfilter(inventory.get_instances_of_type("potion"), current_sorting, current_filter) + + if current_item not in menu_items: + current_item = next(iter(menu_items), None) + label brewing: $ gui.in_context("brewing_menu") return +label .make(item): + if item.has_ingredients(): + play sound "sounds/bubble.ogg" + $ item.make() + else: + gen "It appears I'm missing some key ingredients..." ("base", xpos="far_left", ypos="head") + return + label brewing_menu(xx=150, yy=90): - python: - items_shown = 36 - current_filter = "Unlocked" - current_sorting = "A-z" + $ renpy.dynamic( + "menu_items", + items_shown = 36, + current_filter = "Unlocked", + current_sorting = "A-z", + current_item = None, + ) + $ __actuate() - menu_items = brewing_sortfilter(inventory.get_instances_of_type("potion"), current_sorting, current_filter) - current_item = next(iter(menu_items), None) + call screen brewing(xx, yy) - show screen brewing(xx, yy) - - label .after_init: - $ renpy.dynamic(__choice = ui.interact()) - - if __choice[0] == "select": - $ current_item = __choice[1] - elif __choice == "filter": - if current_filter == "Unlocked": - $ current_filter = None - elif current_filter is None: - $ current_filter = "Unlocked" - - $ menu_items = brewing_sortfilter(inventory.get_instances_of_type("potion"), current_sorting, current_filter) - $ current_item = next(iter(menu_items), None) - elif __choice == "sort": - if current_sorting == "A-z": - $ current_sorting = "z-A" - else: - $ current_sorting = "A-z" - - $ menu_items = brewing_sortfilter(inventory.get_instances_of_type("potion"), current_sorting, current_filter) - #$ current_item = next(iter(menu_items), None) - elif __choice[0] == "make": - if __choice[1].has_ingredients(): - play sound "sounds/bubble.ogg" - $ __choice[1].make() - else: - gen "It appears I'm missing some key ingredients..." ("base", xpos="far_left", ypos="head") - else: - $ enable_game_menu() - hide screen brewing - return - - jump .after_init + return screen brewing(xx, yy): tag brewing @@ -115,7 +101,7 @@ screen brewing_menu(): else: hover_background gui.format("interface/achievements/{}/highlight_left_b.webp") selected (current_item == i) - action Return(["select", i]) + action SetVariable("current_item", i) add gui.format("interface/achievements/{}/spacer_left.webp") @@ -135,10 +121,10 @@ screen brewing_menu(): pos (6, 384) if current_filter is None: - textbutton "Show: All" action Return("filter") + textbutton "Show: All" action [SetVariable("current_filter", "Unlocked"), Function(__actuate)] else: - textbutton "Show: [current_filter]" action Return("filter") - textbutton "Sort by: [current_sorting]" action Return("sort") + textbutton "Show: [current_filter]" action [SetVariable("current_filter", None), Function(__actuate)] + textbutton "Sort by: [current_sorting]" action [SetVariable("current_sorting", current_sorting[::-1]), Function(__actuate),] screen brewing_menuitem(): default turned_on = False @@ -235,7 +221,7 @@ screen brewing_menuitem(): focus_mask None pos (381, 311) anchor (0.5, 0.5) - action Return(["make", current_item]) + action Call("brewing.make", current_item, from_current=True) if current_item.has_ingredients(): hover image_hover("cauldron_on") hovered [Play("background", "sounds/brewing_idle.ogg"), SetLocalVariable("turned_on", True)]