How to have an Imagebutton in Viewport? [Solved]

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
AJFLink
Newbie
Posts: 16
Joined: Mon Nov 05, 2018 2:04 am
Contact:

How to have an Imagebutton in Viewport? [Solved]

#1 Post by AJFLink » Wed May 20, 2020 11:57 am

I'm trying to have inventory system that can be viewed any time in the story to view obtained items and objects.

This is what it is right now with static images:

Code: Select all

screen inventory():

	tag menu
	
	use game_menu(_("Inventory"),scroll="viewport"):
	
		style_prefix "about"
		
		vbox:
			text "Some descriptive text here for item 1."
			image "inv_item_1.png"
			
			text "Some descriptive text here for item 2."
			image "inv_item_2.png"
			
			text "Some descriptive text here for item 3."
			image "inv_item_3.png"
			
			text "Some descriptive text here for item 4."
			image "inv_item_4.png"
How do I convert this so that instead of a viewable and scrollable list of text and static images it is a viewable and scrollable list of text and selectable images?

The main purpose behind this is so that when the image is selected/clicked it merely displays an enlarged version of selected image.
Last edited by AJFLink on Thu May 21, 2020 10:18 am, edited 1 time in total.

User avatar
Alex
Lemma-Class Veteran
Posts: 2500
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: How to have an Imagebutton in Viewport?

#2 Post by Alex » Wed May 20, 2020 2:24 pm

AJFLink wrote:
Wed May 20, 2020 11:57 am
...How do I convert this so that instead of a viewable and scrollable list of text and static images it is a viewable and scrollable list of text and selectable images? ...
Just replace text and image with the imagebutton.
Since you making an inventory, I suppose you have a list of items, so you could iterate through it to create buttons.
So, it might looks like

Code: Select all

default my_inventory = [
    {"name":"apple", "img":"apple.pg", "description":"An apple"},
    {"name":"lemon", "img":"lemon.pg", "description":"A lemon"},
    {"name":"plum", "img":"plum.pg", "description":"A plum"},
]

screen description_scr(txt):
    text txt align(0.5, 0.5)

screen inventory():

    tag menu
	
    use game_menu(_("Inventory"),scroll="viewport"):
	
        style_prefix "about"
		
        vbox:
            for item in my_inventory:
                imagebutton:
                    idle item["img"]
                    hover item["img"]
                    action NullAction() # change it to desirable action
                    hovered Show("description_scr", txt=item["description"])
                    unhovered Hide("description_scr")
https://www.renpy.org/doc/html/screen_actions.html#Show
https://www.renpy.org/doc/html/screen_actions.html#Hide
https://docs.python.org/release/2.6/tut ... ctionaries

AJFLink
Newbie
Posts: 16
Joined: Mon Nov 05, 2018 2:04 am
Contact:

Re: How to have an Imagebutton in Viewport?

#3 Post by AJFLink » Thu May 21, 2020 10:18 am

Alex wrote:
Wed May 20, 2020 2:24 pm
AJFLink wrote:
Wed May 20, 2020 11:57 am
...How do I convert this so that instead of a viewable and scrollable list of text and static images it is a viewable and scrollable list of text and selectable images? ...
Just replace text and image with the imagebutton.
Since you making an inventory, I suppose you have a list of items, so you could iterate through it to create buttons.
So, it might looks like

Code: Select all

default my_inventory = [
    {"name":"apple", "img":"apple.pg", "description":"An apple"},
    {"name":"lemon", "img":"lemon.pg", "description":"A lemon"},
    {"name":"plum", "img":"plum.pg", "description":"A plum"},
]

screen description_scr(txt):
    text txt align(0.5, 0.5)

screen inventory():

    tag menu
	
    use game_menu(_("Inventory"),scroll="viewport"):
	
        style_prefix "about"
		
        vbox:
            for item in my_inventory:
                imagebutton:
                    idle item["img"]
                    hover item["img"]
                    action NullAction() # change it to desirable action
                    hovered Show("description_scr", txt=item["description"])
                    unhovered Hide("description_scr")
https://www.renpy.org/doc/html/screen_actions.html#Show
https://www.renpy.org/doc/html/screen_actions.html#Hide
https://docs.python.org/release/2.6/tut ... ctionaries
Thanks! That helps out a lot!

Post Reply

Who is online

Users browsing this forum: SavedByZero