193 lines
6.5 KiB
Plaintext
193 lines
6.5 KiB
Plaintext
# Functions (Initialised after item_store)
|
|
init 5 python in item_store:
|
|
import functools
|
|
|
|
get_icon = renpy.store.wardrobe.get_icon # Simple Proxy since both interfaces share the same code
|
|
|
|
def buy():
|
|
scope = renpy.get_screen("item_store_interface").scope
|
|
selected_item = scope["selected_item"]
|
|
|
|
renpy.call_in_new_context("purchase_item", selected_item)
|
|
|
|
section = scope["selected_section"]
|
|
_items = items(section)
|
|
# Avoid switching selection when not necessary
|
|
if selected_item.owned >= selected_item.limit or selected_item not in _items:
|
|
scope["selected_item"] = next(_items, None)
|
|
renpy.restart_interaction()
|
|
|
|
def select_item(item):
|
|
scope = renpy.get_screen("item_store_interface").scope
|
|
scope["selected_item"] = item
|
|
|
|
renpy.restart_interaction()
|
|
|
|
def change_section(section):
|
|
scope = renpy.get_screen("item_store_interface").scope
|
|
scope["selected_section"] = section
|
|
scope["selected_item"] = next(items(section), None)
|
|
|
|
def exit():
|
|
scope = renpy.get_screen("item_store_interface").scope
|
|
|
|
renpy.play("sounds/curtain_close.ogg")
|
|
|
|
# Handle exit animation
|
|
scope["navigation_last_frame_atl"] = renpy.store.navigation_last_frame_hide
|
|
scope["navigation_atl"] = renpy.store.wardrobe_hide
|
|
scope["information_atl"] = renpy.store.wardrobe_fade_hide
|
|
scope["character_atl"] = renpy.store.wardrobe_character_hide
|
|
scope["navigation_exit"] = True
|
|
|
|
# Reset states
|
|
renpy.restart_interaction()
|
|
|
|
def items(section):
|
|
# Sort the items by price in ascending order, then alphabetically by name if prices are the same
|
|
sorted_items = sorted(
|
|
(x for x in reversed(renpy.store.inventory.get_instances_of_type(section))
|
|
if x.unlocked and x.price > 0 and x.owned < x.limit),
|
|
key=lambda item: (item.price, renpy.store.natsort_key(item.name))
|
|
)
|
|
return iter(sorted_items)
|
|
|
|
# Context
|
|
label item_store_interface(inter_pause=True):
|
|
$ disable_game_menu()
|
|
play sound "sounds/curtain_open.ogg"
|
|
if inter_pause:
|
|
# Ensures all irrelevant screens are hidden before capturing the surface tree
|
|
with Pause(0.2)
|
|
call screen item_store_interface
|
|
$ enable_game_menu()
|
|
|
|
jump item_store.exit
|
|
|
|
# Interface
|
|
screen item_store_interface():
|
|
layer "interface"
|
|
zorder 0
|
|
style_prefix "store"
|
|
|
|
default navigation_atl = wardrobe_show
|
|
default information_atl = wardrobe_fade_show
|
|
default last_frame = (screenshot.capture() or screenshot.image)
|
|
default navigation_last_frame_atl = navigation_last_frame_show
|
|
default navigation_exit = False
|
|
|
|
default selected_section = "gift"
|
|
default selected_item = next(item_store.items(selected_section), None)
|
|
default cart = set()
|
|
|
|
add last_frame at navigation_last_frame_atl
|
|
|
|
add "gui_fade_both" at gui_fade
|
|
|
|
if navigation_exit:
|
|
timer 0.4 action Return()
|
|
|
|
if selected_item:
|
|
$ total_price = selected_item.price if selected_item else 0
|
|
if selected_item.currency == "tokens":
|
|
$ currency_prefix = _("T")
|
|
$ currency = states.env.tokens
|
|
$ total_gold = states.env.tokens-total_price
|
|
$ can_afford = states.env.tokens >= total_price
|
|
else:
|
|
$ currency_prefix = _("G")
|
|
$ currency = states.env.gold
|
|
$ total_gold = states.env.gold-total_price
|
|
$ can_afford = states.env.gold >= total_price
|
|
|
|
add crop_image_zoom(selected_item.get_image(), 256, 256, False) align (0.5, 0.5) xoffset 270
|
|
|
|
frame:
|
|
style "empty"
|
|
at information_atl
|
|
|
|
add "gui_fade_bottom"
|
|
|
|
vbox:
|
|
xpos 550
|
|
yoffset -10
|
|
yalign 1.0
|
|
xsize 350
|
|
|
|
hbox:
|
|
align (0.0, 1.0)
|
|
label selected_item.name
|
|
if selected_item.owned > 0:
|
|
text "{size=-4}x{/size}[selected_item.owned]"
|
|
add "frame_spacer" xsize 350
|
|
text selected_item.desc align (0.0, 1.0)
|
|
|
|
vbox:
|
|
pos (972, 468)
|
|
vbox:
|
|
xoffset -36
|
|
text _("[currency][currency_prefix]") xalign 1.0
|
|
text _("-[total_price][currency_prefix]") xalign 1.0
|
|
add "frame_spacer" xsize 100
|
|
if total_gold >= 0:
|
|
text "[total_gold][currency_prefix]" color "#0ead00" xalign 1.0
|
|
else:
|
|
text "[total_gold][currency_prefix]" color "#ad0000" xalign 1.0
|
|
|
|
label "[currency_prefix]" + str(selected_item.price) xoffset -50 style "store_pricetag_label"
|
|
|
|
|
|
frame:
|
|
style "empty"
|
|
at navigation_atl
|
|
vbox:
|
|
style_prefix "navigation_tabs"
|
|
pos (540, 300)
|
|
|
|
at navigation_tabs_show
|
|
|
|
textbutton _("Buy") action item_store.buy sensitive (can_afford and (selected_item != None)) at navigation_tabs
|
|
null height 35
|
|
textbutton _("Exit") action item_store.exit keysym "K_ESCAPE" at navigation_tabs
|
|
|
|
frame:
|
|
at navigation_atl
|
|
|
|
vbox:
|
|
# Sections
|
|
hbox:
|
|
spacing 0
|
|
|
|
for i in inventory.get_types():
|
|
|
|
button:
|
|
xysize (64, 64)
|
|
add item_store.get_icon(i) xysize (64, 64)
|
|
tooltip i
|
|
action Function(item_store.change_section, i) selected (selected_section == i)
|
|
|
|
null height 3
|
|
add "frame_spacer" xsize 500 xalign 0.5
|
|
null height 3
|
|
|
|
if not selected_item:
|
|
text _("SOLD OUT!") size 96 at transform:
|
|
align (0.5, 0.5)
|
|
rotate -45
|
|
# Item List
|
|
vpgrid:
|
|
cols 5
|
|
spacing 4
|
|
mousewheel True
|
|
scrollbars "vertical"
|
|
|
|
for item in item_store.items(selected_section):
|
|
button:
|
|
xysize (96, 96)
|
|
style "inventory_item_big_button"
|
|
add crop_image_zoom(item.get_image(), 96, 96, False) align (0.5, 0.5)
|
|
label "[currency_prefix][item.price]" style "store_pricetag_label_small"
|
|
|
|
action Function(item_store.select_item, item)
|
|
selected (selected_item == item)
|