I have been spending lots of time (*cough* days*cough* ) trying to figure out how to code an inventory with images instead of text and I came up with this:
(By the way, the text is long but the question is very simple)
Code: Select all
screen picture:
#the background with a pretty detailed frame
add "black_background.jpg"
add "frame.png"
#a sexy grid
grid 4 2:
spacing 28
xpos 330
ypos 113
#The items, those are images instead of text!!
imagebutton idle"001.png" hover "002.png" hovered Show("description") unhovered Hide("description") action Jump("itemmenu")
imagebutton idle"003.png" hover "003.png" hovered Show("description") unhovered Hide("description") action Jump("itemmenu")
imagebutton idle"007.png" hover "007.png" hovered Show("description") unhovered Hide("description") action Show("itemmenu")
imagebutton idle"008.png" hover "008.png" hovered Show("description") unhovered Hide("description") action Show("itemmenu")
imagebutton idle"009.png" hover "009.png" hovered Show("description") unhovered Hide("description") action Show("itemmenu")
imagebutton idle"001.png" hover "002.png" hovered Show("description") unhovered Hide("description") action Show("itemmenu")
imagebutton idle"012.png" hover "012.png" hovered Show("description") unhovered Hide("description") action Show("itemmenu")
imagebutton idle"011.png" hover "011.png" hovered Show("description") unhovered Hide("description") action Show("itemmenu")
>I want the inventory to have 8 items max
>When hover the imagebutton/item shows screen description
>When clicked they show a small screen menu with options like "Use", "Send them back to storage/Delete", "Return"(hide itemmenu).
Ok, so I have about 30 different obtainable items with different descriptions and uses...
I calculated two different solutions:
Use lots of IF statements:
Something like:
Code: Select all
if item 001:
imagebutton idle"001.png" hover "002.png" hovered Show("description") unhovered Hide("description") action Jump("start")
This might be the messiest and the longest path though...
Use lists
This is the best path I found and the one I'm working on.
However... Apparently I can't python at all. I need help...
Let's start,
I create a list:
Code: Select all
label start:
$ item= [] #The list is empty
Then before the label start I put this code I snatched from here:
Code: Select all
init python:
class Item:
def __init__(self, name, cost, description, displayable):
self.name = name
self.cost = cost
self.description = description
self.displayable = displayable #image.png goes there, I hope this is possible
class Inventory: #I guess this is the money...
def __init__(self, money=10):
self.money = money
self.items = []
def buy(self, item):
if self.money >= item.cost:
self.money -= item.cost
self.items.append(item)
return True
else:
return False
def earn(self, amount):
self.money += amount
def has_item(self, item):
if item in self.items:
return True
else:
return False
Code: Select all
label start:
$ item= []
python:
inventory = Inventory() #HUN? What does this mean?
spaghetti = Item("Spaghetti", 3, "Spaghetti: This pasta is good for cooking", "00a.png")
olives = Item("Olives", 4, "Olives: They taste good. ", "00b.png")
chocolate = Item("Chocolate", 11, "Chocolate: A sweet milk chocolate tablet", "00c.png")
cabbage = ("Cabbage", 27, "Cabbage: Cabbages are healthy!", "00d.png")
#those are examples
I have to use "for" but how ? I think the code I want is similar to the one used to display the save/load screens:
Code: Select all
# Display ten file slots, numbered 1 - 10.
for i in range(1, columns * rows + 1):
# Each file slot is a button.
button:
action FileAction(i)
xfill True
has hbox
# Add the screenshot.
add FileScreenshot(i)
# Format the description, and add it as text.
$ description = "% 2s. %s\n%s" % (
FileSlotName(i, columns * rows),
FileTime(i, empty=_("Empty Slot.")),
FileSaveName(i))
text description
key "save_delete" action FileDelete(i)
Thanks for reading. Any help appreciated !