Re: Inventory Screen
Posted: Tue Mar 31, 2020 10:27 am
hi, how can i stop inventory screen to close itself up when you click on an item? I wanted to close it only with Close Inventory textbutton/
Thanks
Thanks
Supporting creators of visual novels and story-based games since 2003.
https://lemmasoft.renai.us/forums/
Thank you. Yeah it was textbutton and i switched it to imagebutton and it works nice right nowM-77 wrote: ↑Wed Apr 01, 2020 3:51 pm Hello Tesspolar, see my comments/code on page 5 (and 6). You will see that I add a "Imagebutton" for that function, and blocked the older code with # above my imagebutton code.
#Imagebutton for hide inventory:
imagebutton idle "HUDINV_idle001.png" hover "HUDINV_hover001.png" xpos 0.933 ypos 0.417 action [Hide("inventory_screen")]
And I also did some changes to made this inventory code fit to my basic requirements in my project.
Just read the last two pages and compare to your code. You need to put some short lines in the screen.rpy for the imagebutton. You need to do a png/jpg pic for the botton too. It is relative easy to do, as I am also beginner in Renpy. Just try around what happens. Made notes on paper. Do one change at a time to see what is doing what.
Code: Select all
$inventory.buy(gun)
"Me" "Nice"
$inventory.add(laser)
Just want to share how thankful I am for this Leon!leon wrote: ↑Tue Sep 03, 2013 6:17 pm While there are a couple of inventory examples in the cookbook already, they don't address using pictures for inventory items. So here's one that does that, completed with hover effects, tooltips and selectable items. The inventory system here is using classes, so you might want to check Money and Inventory Systems for more detailed explanation on how these work.
fancy_inventory_screen.png
The code is taken from Time Labyrinth and simplified for this example. Feel free to use the code however you like (same goes for Time Labyrinth code).
Code: Select all
screen inventory_screen:
add "gui/inventory.png" xalign .5 yalign .5
modal True
#use battle_frame(char=player, position=(.97,.20)) # we show characters stats (mp, hp) on the inv. screen
#use battle_frame(char=dog, position=(.97,.50))
hbox align (.95,.04) spacing 5:
textbutton "Close Inventory" action [ Hide("inventory_screen"), Return(None)]
$ x = 960 # coordinates of the top left item position
$ y = 200
$ i = 0
$ sorted_items = sorted(inventory.items, key=attrgetter('element'), reverse=True) # we sort the items, so non-consumable items that change elemental damage (guns) are listed first
$ next_inv_page = inv_page + 1
if next_inv_page > int(len(inventory.items)/9):
$ next_inv_page = 0
for item in sorted_items:
if i+1 <= (inv_page+1)*9 and i+1>inv_page*9:
$ x += 190
if i%3==0:
$ y += 170
$ x = 515
$ pic = item.image
$ my_tooltip = "tooltip_inventory_" + pic.replace("gui/inv_", "").replace(".png", "") # we use tooltips to describe what the item does.
imagebutton idle pic hover pic xpos x ypos y action [Hide("gui_tooltip"), SetVariable("item", item), Hide("inventory_screen"), item_use] hovered [ Play ("sound", "Types.ogg"), Show("gui_tooltip", my_picture=my_tooltip, my_tt_ypos=693) ] unhovered [Hide("gui_tooltip")] at inv_eff
if player.element and (player.element==item.element): #indicate the selected gun
add "gui/selected.png" xpos x ypos y anchor(.5,.5)
$ i += 1
if len(inventory.items)>9:
textbutton _("Next Page") action [SetVariable('inv_page', next_inv_page), Show("inventory_screen")] xpos .475 ypos .83
Can you please outline what you did? Because I looked in the thread too, and didn't find an exact, specific fix. Using M-77's code didn't work for me.ZeAwesomeHobo wrote: ↑Wed Aug 04, 2021 5:16 pm EDIT: I realized there were quite a few more comments in this thread, and after looking through them I figured out the issue. Both values needed to be changed.
However. There is a caveat to this during editing. And you're going to be hitting a wall for hours if it's not obvious.Code: Select all
[color=#BF4000]$ x = -960[/color] # coordinates of the top left item position (this is the first value you change) $ y = 200 $ i = 0 $ sorted_items = sorted(inventory.items, key=attrgetter('element'), reverse=True) # we sort the items, so non-consumable items that change elemental damage (guns) are listed first $ next_inv_page = inv_page + 1 if next_inv_page > int(len(inventory.items)/9): $ next_inv_page = 0 for item in sorted_items: if i+1 <= (inv_page+1)*9 and i+1>inv_page*9: $ x += 350 if i%3==0: $ y += 170 $[color=#BF4000] x = 960[/color] # this is the other value you change. Make sure they match!
Both numbers have to match exactly. If they're off in any way, it'll go to some "default" position, and not move regardless.
Hope that helps.
I'm having trouble moving the top left item x position. Y works just find, but regardless of what number I plug in for "x," the item grid's position remains the same.
Even with negative numbers, there's no change. I haven't had any other problems, I just want to move the grid to the center of my game's screen.Code: Select all
screen inventory_screen: add "gui/inventory.png" xalign .5 yalign .5 modal True #use battle_frame(char=player, position=(.97,.20)) # we show characters stats (mp, hp) on the inv. screen #use battle_frame(char=dog, position=(.97,.50)) hbox align (.95,.04) spacing 5: textbutton "Close Inventory" action [ Hide("inventory_screen"), Return(None)] $ x = 960 # coordinates of the top left item position $ y = 200 $ i = 0 $ sorted_items = sorted(inventory.items, key=attrgetter('element'), reverse=True) # we sort the items, so non-consumable items that change elemental damage (guns) are listed first $ next_inv_page = inv_page + 1 if next_inv_page > int(len(inventory.items)/9): $ next_inv_page = 0 for item in sorted_items: if i+1 <= (inv_page+1)*9 and i+1>inv_page*9: $ x += 190 if i%3==0: $ y += 170 $ x = 515 $ pic = item.image $ my_tooltip = "tooltip_inventory_" + pic.replace("gui/inv_", "").replace(".png", "") # we use tooltips to describe what the item does. imagebutton idle pic hover pic xpos x ypos y action [Hide("gui_tooltip"), SetVariable("item", item), Hide("inventory_screen"), item_use] hovered [ Play ("sound", "Types.ogg"), Show("gui_tooltip", my_picture=my_tooltip, my_tt_ypos=693) ] unhovered [Hide("gui_tooltip")] at inv_eff if player.element and (player.element==item.element): #indicate the selected gun add "gui/selected.png" xpos x ypos y anchor(.5,.5) $ i += 1 if len(inventory.items)>9: textbutton _("Next Page") action [SetVariable('inv_page', next_inv_page), Show("inventory_screen")] xpos .475 ypos .83