diff --git a/game/scripts/interface/inventory.rpy b/game/scripts/interface/inventory.rpy index 559ca6f8..519ff875 100644 --- a/game/scripts/interface/inventory.rpy +++ b/game/scripts/interface/inventory.rpy @@ -15,57 +15,10 @@ init python: return item - class __SelectItem(Action): - def __init__(self, item): - self.item = item - - def __call__(self): - global current_item - current_item = self.item - renpy.restart_interaction() - - class __SetCategory(Action): - def __init__(self, category): - self.category = category - - def __call__(self): - global current_category - global menu_items - global menu_items_length - global current_page - global current_item - - 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): + # TODO: replace with CycleVariable("current_sorting", ("A-z", "z-A", "Available", "Unavailable")) 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" @@ -75,31 +28,25 @@ init python: 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): + # TODO: replace with CycleVariable("current_filter", ("Owned", None)) + # (ToggleVariable would cause selectedness problems) 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 + + class __Actuate(Action): + def __call__(self): + global menu_items + global menu_items_length + global current_page + global current_item + menu_items = inventory_sortfilter(inventory_dict[current_category], current_sorting, current_filter) menu_items_length = len(menu_items) @@ -113,10 +60,6 @@ init python: 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 = { @@ -308,7 +251,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 __SetCategory(category) + action [SetVariable("current_category", category), __Actuate()] add gui.format("interface/achievements/{}/spacer_left.webp") # Gold & Tokens @@ -322,10 +265,10 @@ screen inventory_menu(xx, yy): style_prefix gui.theme('achievements_filters') pos (6, 384) if current_filter is None: - textbutton "Show: All" action __Filter() + textbutton "Show: All" action [__Filter(), __Actuate()] else: - textbutton "Show: [current_filter]" action __Filter() - textbutton "Sort by: [current_sorting]" action __Sort() + textbutton "Show: [current_filter]" action [__Filter(), __Actuate()] + textbutton "Sort by: [current_sorting]" action [__Sort(), __Actuate()] screen inventory_menuitem(xx, yy): window: @@ -362,13 +305,13 @@ screen inventory_menuitem(xx, yy): idle gui.format("interface/frames/{}/arrow_up.webp") if current_page > 0: hover image_hover(gui.format("interface/frames/{}/arrow_up.webp")) - action __PageDec() + action SetVariable("current_page", current_page-1) # TODO: replace with IncrementVariable("current_page", -1) 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 __PageInc() + action SetVariable("current_page", current_page+1) # TODO: replace with IncrementVariable("current_page") # Add items grid 9 4: @@ -391,7 +334,7 @@ screen inventory_menuitem(xx, yy): style gui.theme("overlay_button") background "interface/achievements/glass_iconbox.webp" xsize 46 ysize 46 - action __SelectItem(it_item) + action SetVariable("current_item", it_item) tooltip it_item.name if it_item.limit > 1 and it_item.owned > 0: @@ -454,9 +397,9 @@ screen inventory_menuitem(xx, yy): ypos 374 sensitive (current_item.owned > 0) if inventory_mode == 0: - action __Use(current_item) + action Call("inventory.use_item", current_item, from_current=True) elif inventory_mode == 1: - action __Give(current_item) + action Call("inventory.use_item", current_item, from_current=True) hbox: pos (132, 407)