Code: Select all
name cost action
item1 34 [use] [sell]
item2 34 [use] [sell]
item3 234 [sell] [drop]
Code: Select all
name cost action
item1 34 [use] [sell]
item2 34 [use] [sell]
item3 234 [sell] [drop]
You create a screen and assign a grid.newbiemate wrote: ↑Fri Feb 16, 2018 11:45 am How can I generate a table so that the player can see organized data? Something like this:
Where the action column has textbuttons, but the rest are just text. Does renpy have a displayable I can use to render this? If not, could someone give an example?Code: Select all
name cost action item1 34 [use] [sell] item2 34 [use] [sell] item3 234 [sell] [drop]
Code: Select all
init python:
class Item():
def __init__(self, name, price):
self.name = name
self.price = price
def use_item(i):
pass #for now, this is a function just for testing purposes
default item1 = Item("apple", 10)
default item2 = Item("orange", 5)
default item3 = Item("mango", 15)
default inv = [item1, item2, item3]
screen inventory_table():
vbox:
xalign .3
yalign .5
label "Name"
for i in inv:
text "{}".format(i.name)
vbox:
label "Price"
xalign .5
yalign .5
for i in inv:
text "{}".format(i.price)
vbox:
label "Action"
xalign .7
yalign .5
for i in inv:
textbutton "Use" action Function(use_item(i))
Code: Select all
screen my_scr():
$ bg_hover = Solid("#c0c0c0")
side "c r":
area (100, 100, 550, 200)
viewport id "vp":
draggable True
vbox:
hbox:
button:
background Solid("#FF9900cc")
xsize 250
text "Name"
action None
button:
background Solid("#FF9900cc")
xsize 150
text "Score"
action None
button:
background Solid("#FF9900cc")
xsize 150
text "Level"
action None
for i,l in enumerate(my_list):
if i%2 == 0:
$ bg = Solid("#FADFADcc")
else:
$ bg = Solid("#FFBF00cc")
if l["state"] == 0:
$ bg_button = bg
else:
$ bg_button = bg_hover
hbox:
button:
background bg_button
xsize 250
text str(l["name"])
hovered SetDict(l,"state", 1)
unhovered SetDict(l,"state", 0)
action [[]]
button:
background bg_button
xsize 150
text str(l["score"])
hovered SetDict(l,"state", 1)
unhovered SetDict(l,"state", 0)
action [[]]
button:
background bg_button
xsize 150
text str(l["level"])
hovered SetDict(l,"state", 1)
unhovered SetDict(l,"state", 0)
action [[]]
vbar value YScrollValue("vp")
# The game starts here.
label start:
$ my_list = [ {"name":"Name_1", "score": 10, "level": 5, "state":0},
{"name":"Name_2", "score": 100, "level": 15, "state":0},
{"name":"Name_3", "score": 10, "level": 5, "state":0},
{"name":"Name_4", "score": 100, "level": 15, "state":0},
]
"..."
show screen my_scr
"*"
$ my_list.append({"name":"Name_5", "score": 999, "level": 99, "state":0})
"?"
Users browsing this forum: Google [Bot], Majestic-12 [Bot]