From 38a94e774ba02ee29aa28a277e01b8697f53ad63 Mon Sep 17 00:00:00 2001 From: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com> Date: Fri, 17 Nov 2023 01:44:02 +0100 Subject: [PATCH] Some big work on the inventory system turn the show into a call screen replace all return actions with specific local actions (WIP, more changes to come) make the global variables at least dynamic make the mode parameter a parameter of the label (so, a dynamic variable too, as a result) replace the bigger actions with local labels tweak text entries, comparisons, iterations... details --- game/scripts/interface/gifts.rpy | 4 +- game/scripts/interface/inventory.rpy | 405 +++++++++++++++------------ 2 files changed, 225 insertions(+), 184 deletions(-) diff --git a/game/scripts/interface/gifts.rpy b/game/scripts/interface/gifts.rpy index 99cd351d..c093b3bf 100644 --- a/game/scripts/interface/gifts.rpy +++ b/game/scripts/interface/gifts.rpy @@ -1,7 +1,5 @@ label gift_menu: - $ inventory_mode = 1 - $ gui.in_context("inventory_menu") - $ inventory_mode = 0 + $ gui.in_context("inventory_menu", inventory_mode=1) return label give_gift(text, gift): diff --git a/game/scripts/interface/inventory.rpy b/game/scripts/interface/inventory.rpy index 168d3a2a..c6d0db0a 100644 --- a/game/scripts/interface/inventory.rpy +++ b/game/scripts/interface/inventory.rpy @@ -15,21 +15,109 @@ init python: return item -default inventory_mode = 0 # 0 - Inventory, 1 - gifts + class __SelectItem(Action): + def __init__(self, item): + self.item = item -#################################### -############# Menu ################# -#################################### + def __call__(self): + global current_item + current_item = self.item + renpy.restart_interaction() -label inventory: - $ gui.in_context("inventory_menu") - jump main_room_menu + class __SetCategory(Action): + def __init__(self, category): + self.category = category -label inventory_menu(xx=150, yy=90): - # Inventory dictionary + def __call__(self): + global current_category + global menu_items + global menu_items_length + global current_page + global current_item - python: + current_category = self.category + menu_items = inventory_sortfilter(inventory_dict[current_category], current_sorting, current_filter) + menu_items_length = len(menu_items) + if current_category == "Decorations": + menu_items.sort(key=lambda x: x.placement.id) + + current_page = 0 + current_item = next(iter(menu_items), None) + + renpy.restart_interaction() + + class __PageInc(Action): + def __call__(self): + global current_page + current_page += 1 + renpy.restart_interaction() + + class __PageDec(Action): + def __call__(self): + global current_page + current_page -= 1 + renpy.restart_interaction() + + class __Sort(Action): + def __call__(self): + global current_sorting + global menu_items + global menu_items_length + global current_page + global current_item + + if current_sorting == "A-z": + current_sorting = "z-A" + elif current_sorting == "z-A": + current_sorting = "Available" + elif current_sorting == "Available": + current_sorting = "Unavailable" + else: + current_sorting = "A-z" + menu_items = inventory_sortfilter(inventory_dict[current_category], current_sorting, current_filter) + menu_items_length = len(menu_items) + + if current_category == "Decorations": + menu_items.sort(key=lambda x: x.placement.id) + + current_page = 0 + + if current_item not in menu_items: + current_item = next(iter(menu_items), None) + + renpy.restart_interaction() + + class __Filter(Action): + def __call__(self): + global current_filter + global menu_items + global menu_items_length + global current_page + global current_item + + if current_filter is None: + current_filter = "Owned" + else: + current_filter = None + menu_items = inventory_sortfilter(inventory_dict[current_category], current_sorting, current_filter) + menu_items_length = len(menu_items) + + if current_category == "Decorations": + menu_items.sort(key=lambda x: x.placement.id) + + current_page = 0 + + if current_item not in menu_items: + current_item = next(iter(menu_items), None) + + renpy.restart_interaction() + + __Use = renpy.partial(Call, "inventory.use_item", from_current=True) # takes current_item + + __Give = renpy.partial(Call, "inventory.give_item", from_current=True) # takes current_item + + def __init_scope(): if inventory_mode == 0: inventory_dict = { "Gifts": inventory.get_instances_of_type("gift"), @@ -47,181 +135,138 @@ label inventory_menu(xx=150, yy=90): "Quest Items": inventory.get_instances_of_type("quest"), } - items_shown = 36 - current_page = 0 - current_category = next(iter(inventory_dict.keys())) - current_filter = "Owned" - current_sorting = "Available" + renpy.dynamic( + inventory_dict=inventory_dict, + current_page=0, + current_category="Gifts", + current_filter="Owned", + current_sorting="Available", + ) - category_items = inventory_dict[current_category] - menu_items = inventory_sortfilter(category_items, current_sorting, current_filter) - menu_items_length = len(menu_items) - current_item = next(iter(menu_items), None) + menu_items = inventory_sortfilter(inventory_dict[current_category], current_sorting, current_filter) + renpy.dynamic( + menu_items=menu_items, + menu_items_length=len(menu_items), + current_item=next(iter(menu_items), None), + ) - show screen inventory(xx, yy) +define items_shown = 36 - label .after_init: +#################################### +############# Menu ################# +#################################### - $ renpy.dynamic(__choice = ui.interact()) +label inventory: + $ gui.in_context("inventory_menu") + jump main_room_menu - if __choice[0] == "select": - $ current_item = __choice[1] - elif __choice[0] == "category": - python: - current_category = __choice[1] - category_items = inventory_dict[current_category] - menu_items = inventory_sortfilter(category_items, current_sorting, current_filter) - menu_items_length = len(menu_items) +label .use_item(item): + python: + enable_game_menu() + item.use() + return - if current_category == "Decorations": - menu_items = sorted(menu_items, key=lambda x: x.placement.id) +label .give_item(item): + if item.type == "gift": + if get_character_gifted(states.active_girl): + show screen blktone + with d3 + gen "I already gave her a gift today. Don't want to spoil her too much..." ("base", xpos="far_left", ypos="head") + hide screen blktone + with d3 + else: + call expression get_character_gift_label(states.active_girl) pass (item) - current_page = 0 - current_item = next(iter(menu_items), None) + elif item.type == "potion": + if not states.active_girl in item.usable_on: + show screen blktone + with d3 + gen "(Something tells me this potion won't work on [states.active_girl].)" ("base", xpos="far_left", ypos="head") + nar "Perhaps in the future..." + hide screen blktone + with d3 + elif not game.daytime: + show screen blktone + with d3 + gen "(Some grander force tells me I should give it to her during daytime only.)" ("base", xpos="far_left", ypos="head") + hide screen blktone + with d3 + elif get_character_mood(states.active_girl) > 0: + show screen blktone + with d3 + gen "(I don't think it's a good idea to give it to her when she's still upset with me...)" ("base", xpos="far_left", ypos="head") + gen "(I should wait for her to calm down first.)" ("base", xpos="far_left", ypos="head") + hide screen blktone + with d3 + elif states.active_girl == "hermione" and not states.her.favors_convinced_stage == 2 and is_in_lead(gryffindor): + show screen blktone + with d3 - elif __choice == "inc": - $ current_page += 1 - elif __choice == "dec": - $ current_page += -1 - elif __choice == "sort": - python: - if current_sorting == "A-z": - current_sorting = "z-A" - elif current_sorting == "z-A": - current_sorting = "Available" - elif current_sorting == "Available": - current_sorting = "Unavailable" - else: - current_sorting = "A-z" - menu_items = inventory_sortfilter(category_items, current_sorting, current_filter) - menu_items_length = len(menu_items) + gen "[name_hermione_genie], what would you say--" ("base", xpos="far_left", ypos="head") + her "I'm sorry professor but I don't need your help at the moment." + her "My house is already in the lead points wise." + gen "Figures..." ("base", xpos="far_left", ypos="head") - if current_category == "Decorations": - menu_items = sorted(menu_items, key=lambda x: x.placement.id) + call tutorial("points") - current_page = 0 + hide screen blktone + with d3 + else: + python: + enable_game_menu() + inventory_mode = 0 + item.give(states.active_girl) - if not current_item or not menu_items_length: - current_item = next(iter(menu_items), None) + elif item.type == "quest": + if not states.active_girl in item.usable_on: + show screen blktone + with d3 + gen "(Something tells me I cannot give this item to [states.active_girl].)" ("base", xpos="far_left", ypos="head") + nar "Perhaps in the future..." + hide screen blktone + with d3 + #TODO Add daytime check for buttplug give item event + #show screen blktone + #with d3 + #gen "(Some grander force tells me I should give it to her during daytime only.)" ("base", xpos="far_left", ypos="head") + #hide screen blktone + #with d3 + elif get_character_mood(states.active_girl) > 0: + show screen blktone + with d3 + gen "(I don't think it's a good idea to give it to her when she's still upset with me...)" ("base", xpos="far_left", ypos="head") + gen "(I should wait for her to calm down first.)" ("base", xpos="far_left", ypos="head") + hide screen blktone + with d3 + elif states.active_girl == "hermione" and not states.her.favors_convinced_stage == 2 and is_in_lead(gryffindor): + show screen blktone + with d3 - elif __choice == "filter": - python: - if current_filter is None: - current_filter = "Owned" - else: - current_filter = None - menu_items = inventory_sortfilter(category_items, current_sorting, current_filter) - menu_items_length = len(menu_items) + gen "[name_hermione_genie], I have something for you--" ("base", xpos="far_left", ypos="head") + her "I'm sorry professor but I don't need your help at the moment." + her "My house is already in the lead points wise." + gen "Figures..." ("base", xpos="far_left", ypos="head") - if current_category == "Decorations": - menu_items = sorted(menu_items, key=lambda x: x.placement.id) + call tutorial("points") - current_page = 0 + hide screen blktone + with d3 + else: + python: + enable_game_menu() + inventory_mode = 0 + item.give(states.active_girl) - if not current_item or not menu_items_length: - current_item = next(iter(menu_items), None) + return - elif __choice == "use": - python: - enable_game_menu() - current_item.use() - elif __choice == "give": +label inventory_menu(xx=150, yy=90, inventory_mode=0): # 0 - Inventory, 1 - gifts + # Inventory dictionary - if current_item.type == "gift": - if get_character_gifted(states.active_girl): - show screen blktone - with d3 - gen "I already gave her a gift today. Don't want to spoil her too much..." ("base", xpos="far_left", ypos="head") - hide screen blktone - with d3 - else: - hide screen inventory - $ renpy.call(get_character_gift_label(states.active_girl), current_item) - show screen inventory(xx, yy) - elif current_item.type == "potion": - if not states.active_girl in current_item.usable_on: - show screen blktone - with d3 - gen "(Something tells me this potion won't work on [states.active_girl].)" ("base", xpos="far_left", ypos="head") - nar "Perhaps in the future..." - hide screen blktone - with d3 - elif not game.daytime: - show screen blktone - with d3 - gen "(Some grander force tells me I should give it to her during daytime only.)" ("base", xpos="far_left", ypos="head") - hide screen blktone - with d3 - elif get_character_mood(states.active_girl) > 0: - show screen blktone - with d3 - gen "(I don't think it's a good idea to give it to her when she's still upset with me...)" ("base", xpos="far_left", ypos="head") - gen "(I should wait for her to calm down first.)" ("base", xpos="far_left", ypos="head") - hide screen blktone - with d3 - elif states.active_girl == "hermione" and not states.her.favors_convinced_stage == 2 and is_in_lead(gryffindor): - show screen blktone - with d3 + $ __init_scope() - gen "[name_hermione_genie], what would you say--" ("base", xpos="far_left", ypos="head") - her "I'm sorry professor but I don't need your help at the moment." - her "My house is already in the lead points wise." - gen "Figures..." ("base", xpos="far_left", ypos="head") + call screen inventory(xx, yy) - call tutorial("points") - - hide screen blktone - with d3 - else: - python: - enable_game_menu() - inventory_mode = 0 - current_item.give(states.active_girl) - elif current_item.type == "quest": - if not states.active_girl in current_item.usable_on: - show screen blktone - with d3 - gen "(Something tells me I cannot give this item to [states.active_girl].)" ("base", xpos="far_left", ypos="head") - nar "Perhaps in the future..." - hide screen blktone - with d3 - #TODO Add daytime check for buttplug give item event - #show screen blktone - #with d3 - #gen "(Some grander force tells me I should give it to her during daytime only.)" ("base", xpos="far_left", ypos="head") - #hide screen blktone - #with d3 - elif get_character_mood(states.active_girl) > 0: - show screen blktone - with d3 - gen "(I don't think it's a good idea to give it to her when she's still upset with me...)" ("base", xpos="far_left", ypos="head") - gen "(I should wait for her to calm down first.)" ("base", xpos="far_left", ypos="head") - hide screen blktone - with d3 - elif states.active_girl == "hermione" and not states.her.favors_convinced_stage == 2 and is_in_lead(gryffindor): - show screen blktone - with d3 - - gen "[name_hermione_genie], I have something for you--" ("base", xpos="far_left", ypos="head") - her "I'm sorry professor but I don't need your help at the moment." - her "My house is already in the lead points wise." - gen "Figures..." ("base", xpos="far_left", ypos="head") - - call tutorial("points") - - hide screen blktone - with d3 - else: - python: - enable_game_menu() - inventory_mode = 0 - current_item.give(states.active_girl) - - else: - hide screen inventory - return - - jump .after_init + return screen inventory(xx, yy): tag inventory @@ -253,7 +298,7 @@ screen inventory_menu(xx, yy): vbox: pos (6, 41) - for category in iter(inventory_dict.keys()): + for category in inventory_dict: vbox: textbutton category: style "empty" @@ -263,7 +308,7 @@ screen inventory_menu(xx, yy): background gui.format("interface/achievements/{}/highlight_left.webp") else: hover_background gui.format("interface/achievements/{}/highlight_left.webp") - action Return(["category", category]) + action __SetCategory(category) add gui.format("interface/achievements/{}/spacer_left.webp") # Gold & Tokens @@ -277,10 +322,10 @@ screen inventory_menu(xx, yy): style_prefix gui.theme('achievements_filters') pos (6, 384) if current_filter is None: - textbutton "Show: All" action Return("filter") + textbutton "Show: All" action __Filter() else: - textbutton "Show: [current_filter]" action Return("filter") - textbutton "Sort by: [current_sorting]" action Return("sort") + textbutton "Show: [current_filter]" action __Filter() + textbutton "Sort by: [current_sorting]" action __Sort() screen inventory_menuitem(xx, yy): window: @@ -315,15 +360,15 @@ screen inventory_menuitem(xx, yy): imagebutton: idle gui.format("interface/frames/{}/arrow_up.webp") - if not current_page <= 0: + if current_page > 0: hover image_hover(gui.format("interface/frames/{}/arrow_up.webp")) - action Return("dec") + action __PageDec() imagebutton: idle Transform(gui.format("interface/frames/{}/arrow_up.webp"), yzoom=-1) if current_page < math.ceil((menu_items_length-1)/items_shown)-1: hover Transform(image_hover(gui.format("interface/frames/{}/arrow_up.webp")), yzoom=-1) - action Return("inc") + action __PageInc() # Add items grid 9 4: @@ -346,14 +391,14 @@ screen inventory_menuitem(xx, yy): style gui.theme("overlay_button") background "interface/achievements/glass_iconbox.webp" xsize 46 ysize 46 - action Return(["select", it_item]) + action __SelectItem(it_item) tooltip it_item.name if it_item.limit > 1 and it_item.owned > 0: if it_item.infinite: text "{unicode}∞{/unicode}" size 20 align (0.1, 0.1) offset(-1, -9) color "#FFFFFF" outlines [ (1, "#000", 0, 0) ] else: - text str(it_item.owned) size 10 align (0.1, 0.1) color "#FFFFFF" outlines [ (1, "#000", 0, 0) ] + text "[it_item.owned]" size 10 align (0.1, 0.1) color "#FFFFFF" outlines [ (1, "#000", 0, 0) ] elif current_category == "Decorations": if it_item.in_use: add "interface/topbar/icon_check.webp" anchor (1.0, 1.0) align (1.0, 1.0) offset (-3, -3) zoom 0.5 @@ -400,20 +445,18 @@ screen inventory_menuitem(xx, yy): xalign 0.5 text current_item.name ypos 380 size 16 xoffset 45 - $ frame = Frame(gui.format("interface/frames/{}/iconframe.webp"), 6, 6) - if (inventory_mode == 0 and current_item.usable) or (inventory_mode == 1 and current_item.givable): textbutton "[current_item.caption]": style "inventory_button" - background frame + background Frame(gui.format("interface/frames/{}/iconframe.webp"), 6, 6) xalign 0.89 xoffset 45 ypos 374 sensitive (current_item.owned > 0) if inventory_mode == 0: - action Return("use") + action __Use(current_item) elif inventory_mode == 1: - action Return("give") + action __Give(current_item) hbox: pos (132, 407)