Here's an example of how I define a food Item:
Code: Select all
define teacup = Item(name="Tea", desc="A steaming cup of tea.", category="Food", icon="images/items/Tea.png", act=Show("edible_popup", food="tea", message="A steaming cup of tea."))
Code: Select all
screen food_view(inventory, second_inventory=False, trade_mode=False, single_inventory=True):
side "c r":
style_group "invstyle"
area (0, 0, 1400, 700)
vpgrid id ("vp"+inventory.name):
draggable True
mousewheel True
allow_underfull True
xsize 1400 ysize 700
# if inventory.grid_view:
# cols 3 spacing 50
cols 3 spacing 50
$ food_items = [item for item in inventory.inv if item[0].category == "Food"]
if not food_items:
add Null(height=100,width=100)
else:
for item in food_items:
$ name = item[0].name
$ desc = item[0].desc
$ value = item[0].value
$ category = item[0].category
$ qty = str(item[1])
if item[0].category == "Food":
vbox:
if item[0].icon:
$ icon = item[0].icon
$ hover_icon = im.Sepia(icon)
imagebutton:
idle LiveComposite((370,320), (0,0), icon, (0,0), Text(qty))
hover LiveComposite((370,320), (0,0), hover_icon, (0,0), Text(qty))
action (If(not second_inventory, item[0].act, (If(trade_mode, Function(trade,inventory, second_inventory, item), Function(transaction,inventory, second_inventory, item)))))
hbox:
xalign 0.5
text name size 25
if not inventory.grid_view:
vbox:
text name
if not trade_mode:
text "List Value: [value]"
if second_inventory:
text ("Sell Value: " + str(calculate_price(item, second_inventory)) + ")")
else:
textbutton "[name] ([qty])" action (If(not second_inventory, item[0].act,(If(trade_mode, Function(trade,inventory, second_inventory, item), Function(transaction,inventory, second_inventory, item))))) hovered Show("tooltip",item=item,seller=second_inventory) unhovered Hide("tooltip")
if not inventory.grid_view:
vbox:
text "List Value: [value]"
if not trade_mode and second_inventory:
text "Sell Value: " + str(calculate_price(item, second_inventory)) + ")"
## maintains spacing in empty inventories.
if len(inventory.inv) == 0:
add Null(height=100,width=100)
vbar value YScrollValue("vp"+inventory.name)
I'm hoping that the player can buy the Fro Yo, then choose whether they want toppings... but that means that for each Fro Yo item, the icon would need to be its own composite determined by what the player chooses topping-wise.
The problem is, the icon is determined in the wider Item definition, so I'm not quite sure how to square that with my need for a for loop to determine it on an instance level.
If anybody has any thoughts for how I could get such a thing working, it would be greatly appreciated!