I'm really sorry about the confusion, my bad.
Code: Select all
init -1 python:
import renpy.store as store
import renpy.exports as renpy # we need this so Ren'Py properly handles rollback with classes
from operator import attrgetter # we need this for sorting items
inv_page = 0 # initial page of the inventory screen
item = None
class Item(store.object):
def __init__(self, name, usable, used, image=""):
self.name = name
self.image=image # image file to use for this item
self.usable=usable
self.used=used
def use(self): #here we define what should happen when we use the item
if self.usable == True:
self.used = True
inventory.drop(self)
renpy.jump(self.name)
class Inventory(store.object):
def __init__(self, money=10):
self.money = money
self.items = []
def add(self, item): # a simple method that adds an item; we could also add conditions here (like check if there is space in the inventory)
self.items.append(item)
def drop(self, item):
self.items.remove(item)
def buy(self, item):
if self.money >= item.cost:
self.items.append(item)
self.money -= item.cost
def item_use():
item.use()
#Tooltips:
style.tips_top = Style(style.default)
style.tips_top.size=36
style.tips_top.color="302725"
style.tips_bottom = Style(style.tips_top)
style.tips_top.size=36
showitems = True #turn True to debug the inventory
screen inventory_button:
imagebutton idle "backpack.png" hover "backpack.png" action [ Show("inventory_screen"), Hide("inventory_button")] align (.95,.04)
screen inventory_screen:
zorder 3
imagemap:
ground "inventory_screen_idle.jpg"
idle "inventory_screen_idle.jpg"
hover "inventory_screen_hover.jpg"
hotspot (239,578,132,62) action ShowMenu("save") activate_sound "click.mp3" hover_sound "click.mp3"
hotspot (206,652,164,54) action ShowMenu("load") activate_sound "click.mp3" hover_sound "click.mp3"
hotspot (219,722,152,55) action MainMenu() activate_sound "click.mp3" hover_sound "click.mp3"
hotspot (944,255,162,145) action NullAction() hover_sound "click.mp3"
hotspot (1117,255,162,145) action NullAction() hover_sound "click.mp3"
hotspot (1290,255,162,145) action NullAction() hover_sound "click.mp3"
hotspot (944,412,162,145) action NullAction() hover_sound "click.mp3"
hotspot (1117,412,162,145) action NullAction() hover_sound "click.mp3"
hotspot (1290,412,162,145) action NullAction() hover_sound "click.mp3"
hotspot (944,569,162,145) action NullAction() hover_sound "click.mp3"
hotspot (1117,569,162,145) action NullAction() hover_sound "click.mp3"
hotspot (1290,569,162,145) action NullAction() hover_sound "click.mp3"
modal True #prevent clicking on other stuff when inventory is shown
hbox align (.95,.04) spacing 20:
imagebutton idle "backpack.png" hover "backpack.png" action [ Hide("inventory_screen"), Show("inventory_button")]
$ x = 1020 # coordinates of the top left item position
$ y = 165
$ i = 0
$ sorted_items = sorted(inventory.items, key=attrgetter('name'), reverse=True) # we sort the items, so non-consumable items that change elemental damage (guns) are listed first
$ next_inv_page = inv_page + 1
$ previous_inv_page = inv_page - 1
if next_inv_page > int(len(inventory.items)/9):
$ next_inv_page = 0
if previous_inv_page > int(len(inventory.items)/9):
$ previous_inv_page = 0
for item in sorted_items:
if i+1 <= (inv_page+1)*9 and i+1>inv_page*9:
$ x += 170
if i%3==0:
$ y += 160
$ x = 1020
$ pic = item.image
$ my_tooltip = "tooltip_inventory_" + pic.replace("Icon.png", "") # we use tooltips to describe what the item does.
imagebutton idle pic hover pic xpos x ypos y action [Hide("gui_tooltip"), Show("inventory_button"), SetVariable("item", item), Hide("inventory_screen"), item_use] hovered [ Play ("sound", "click.mp3"), Show("gui_tooltip", my_picture=my_tooltip, my_tt_ypos=250)] unhovered [Hide("gui_tooltip")] at inv_eff
# if player.element and (player.element==item.element): #indicate the selected gun
# add "selected.png" xpos x ypos y anchor(.5,.5)
$ i += 1
if len(inventory.items)>9:
imagebutton idle "next_arrow.png" hover "next_arrow.png" xpos 1412 ypos 735 action [SetVariable('inv_page', next_inv_page), Show("inventory_screen")]
imagebutton idle "previous_arrow.png" hover "previous_arrow.png" xpos 965 ypos 735 action [SetVariable('inv_page', next_inv_page), Show("inventory_screen")]
screen gui_tooltip (my_picture="", my_tt_xpos=530, my_tt_ypos=250):
add my_picture xpos my_tt_xpos ypos my_tt_ypos
init -1:
transform inv_eff: # too lazy to make another version of each item, we just use ATL to make hovered items super bright
zoom 0.5 xanchor 0.5 yanchor 0.5
on idle:
linear 0.2 alpha 1.0
on hover:
linear 0.2 alpha 2.5
#Tooltips-inventory:
image tooltip_inventory_Silverweed=LiveComposite((300, 300), (0,0), ImageReference("silverweedView"),(5,300), Text("عشبة ذات زهرة صفراء جميلة.", style="tips_bottom"))
image tooltip_inventory_Tetterwort=LiveComposite((300, 300), (0,0), ImageReference("tetterwortView"),(5,300), Text("رائحة هذه العشبة تشبه رائحة السمك.", style="tips_bottom"))
image tooltip_inventory_Chasteberry=LiveComposite((300, 300), (0,0), ImageReference("chasteberryView"),(5,300), Text("عشبة يابسة ذات شكل غريب.", style="tips_bottom"))
image tooltip_inventory_Jequirity=LiveComposite((300, 300), (0,0), ImageReference("jequirityView"), (50,300), Text("بذرةٌ حمراء اللون.", style="tips_bottom"))
image tooltip_inventory_LadysMantles=LiveComposite((300, 300), (0,0), ImageReference("ladysmantlesView"), (5,300), Text("عشبةٌ بأوراقٍ مسننة و أزهارٍ صغيرة.", style="tips_bottom"))
image tooltip_inventory_RedRobin=LiveComposite((300, 300), (0,0), ImageReference("redrobinView"), (5,300), Text("عشبةٌ بساقٍ حمراء و أوراقٍ مثلثة و زهرةٍ بنفسجية.", style="tips_bottom"))
image tooltip_inventory_Medicine=LiveComposite((300, 300), (0,0), ImageReference("medicineView"), (50,300), Text("الدواء الذي أعطتني إياه الساحرة.رائحته كريهة و لونه لا يشجع على شربه.", style="tips_bottom"))
This is my whole inventory code. It is placed before the start label.
I have another script file for the second chapter and I want to define new items.
However, the tool tips are not working & I have no idea why.
All of the items shown in the above code are defined in the first chapter and the code works fine with them.
Hopefully things are clearer now.
Thank you for all your help.