From 25f375c88b5ffa47de6061dff8659ea982203121 Mon Sep 17 00:00:00 2001 From: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com> Date: Thu, 16 Nov 2023 18:05:57 +0100 Subject: [PATCH] Better and faster iteration, using foreach --- game/scripts/interface/inventory.rpy | 59 +++++++++++++--------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/game/scripts/interface/inventory.rpy b/game/scripts/interface/inventory.rpy index ec9591d3..168d3a2a 100644 --- a/game/scripts/interface/inventory.rpy +++ b/game/scripts/interface/inventory.rpy @@ -330,42 +330,39 @@ screen inventory_menuitem(xx, yy): style "empty" pos (24, 113) - for i in range(current_page*items_shown, (current_page*items_shown)+items_shown): - if i < menu_items_length: - $ row = (i // 9) % 4 - $ col = i % 9 - frame: - style "empty" - xsize 48 - ysize 48 - add gui.format("interface/achievements/{}/iconbox.webp") + for it_item in menu_items[current_page*items_shown:(current_page+1)*items_shown]: + frame: + style "empty" + xsize 48 + ysize 48 + add gui.format("interface/achievements/{}/iconbox.webp") - if current_item is not None and current_item.id == menu_items[i].id: - add "interface/achievements/glow.webp" align (0.5, 0.5) zoom 0.105 alpha 0.7 at rotate_circular + if current_item is not None and current_item.id == it_item.id: + add "interface/achievements/glow.webp" align (0.5, 0.5) zoom 0.105 alpha 0.7 at rotate_circular - add crop_image_zoom(menu_items[i].get_image(), 42, 42, menu_items[i].owned <= 0) align (0.5, 0.5) + add crop_image_zoom(it_item.get_image(), 42, 42, it_item.owned <= 0) align (0.5, 0.5) - button: - style gui.theme("overlay_button") - background "interface/achievements/glass_iconbox.webp" - xsize 46 ysize 46 - action Return(["select", menu_items[i]]) - tooltip menu_items[i].name + button: + style gui.theme("overlay_button") + background "interface/achievements/glass_iconbox.webp" + xsize 46 ysize 46 + action Return(["select", it_item]) + tooltip it_item.name - if menu_items[i].limit > 1 and menu_items[i].owned > 0: - if menu_items[i].infinite: - text "{unicode}∞{/unicode}" size 20 align (0.1, 0.1) offset(-1, -9) color "#FFFFFF" outlines [ (1, "#000", 0, 0) ] - else: - text str(menu_items[i].owned) size 10 align (0.1, 0.1) color "#FFFFFF" outlines [ (1, "#000", 0, 0) ] - elif current_category == "Decorations": - if menu_items[i].in_use: - add "interface/topbar/icon_check.webp" anchor (1.0, 1.0) align (1.0, 1.0) offset (-3, -3) zoom 0.5 - elif current_category in ("Books", "Quest Items"): - if menu_items[i].used: - add "interface/topbar/icon_check.webp" anchor (1.0, 1.0) align (1.0, 1.0) offset (-3, -3) zoom 0.5 + 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) ] + 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 + elif current_category in ("Books", "Quest Items"): + if it_item.used: + add "interface/topbar/icon_check.webp" anchor (1.0, 1.0) align (1.0, 1.0) offset (-3, -3) zoom 0.5 - if inventory_mode == 1 and (not menu_items[i].givable or not states.active_girl in menu_items[i].usable_on): - add "#b2000040" + if inventory_mode == 1 and (not it_item.givable or not states.active_girl in it_item.usable_on): + add "#b2000040" if menu_items_length <= 0: text "Nothing here yet" align (0.5, 0.5) anchor (0.5, 0.5) size 24