Collapsible lists for a RenPy screen? [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
User avatar
Yone28
Newbie
Posts: 12
Joined: Sat Feb 25, 2023 4:11 pm
Contact:

Collapsible lists for a RenPy screen? [SOLVED]

#1 Post by Yone28 »

Hey all!

I am currently coding a journal for my game. The purpouse of this journal is to show the in-game quests to the player. These quests are sorted in two main categories; Incomplete and Completed. Completed quests are further divided in three categories; Relationship, Optional, and Personal.

My idea was to make 4 different collapsible lists of textbuttons for each category (Incomplete, Completed, Relationship, Optional, Personal), so that the player can hide the categories that don't interest them and focus on the relevant ones. Quests are defined in a Python class.

The problem is that I have no idea on how to make a collapsible list and google has yielded no results so far. I'll attach a picture of what I mean by "collapsible" list, but basically, it's a type of list that you can click to hide or show, common in a lot of websites and almost always used in quest journals for videogames.
dfasdf.png
(182.05 KiB) Not downloaded yet
Any type of help is appreciated.
Last edited by Yone28 on Sat Apr 20, 2024 5:11 pm, edited 2 times in total.
I am losing it

User avatar
m_from_space
Miko-Class Veteran
Posts: 985
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Collapsible lists for a RenPy screen?

#2 Post by m_from_space »

Yone28 wrote: Sat Apr 20, 2024 1:57 am The problem is that I have no idea on how to make a collapsible list and google has yielded no results so far.
I suggest you create a sub-screen that acts as any collapsable list and then use it in another screen whenever you want to display it.

Code: Select all

default quests_incomplete = ["Quest 2", "Quest 3"]
default quests_complete = ["Quest 1"]

screen collapsable_list(title, items):
    default show_list = True
    vbox:
        textbutton "> [title]" action ToggleLocalVariable("show_list")
        if show_list:
            for item in items:
                text "- [item]"

screen journal():
    vbox:
        if quests_incomplete:
            use collapsable_list("Incomplete Quests", quests_incomplete)
        else:
            text "There are no incomplete quests."
        if quests_complete:
            use collapsable_list("Complete Quests", quests_complete)
        else:
            text "There are no completed quests."

User avatar
Yone28
Newbie
Posts: 12
Joined: Sat Feb 25, 2023 4:11 pm
Contact:

Re: Collapsible lists for a RenPy screen?

#3 Post by Yone28 »

m_from_space wrote: Sat Apr 20, 2024 2:24 am
Yone28 wrote: Sat Apr 20, 2024 1:57 am The problem is that I have no idea on how to make a collapsible list and google has yielded no results so far.
I suggest you create a sub-screen that acts as any collapsable list and then use it in another screen whenever you want to display it.

Code: Select all

default quests_incomplete = ["Quest 2", "Quest 3"]
default quests_complete = ["Quest 1"]

screen collapsable_list(title, items):
    default show_list = True
    vbox:
        textbutton "> [title]" action ToggleLocalVariable("show_list")
        if show_list:
            for item in items:
                text "- [item]"

screen journal():
    vbox:
        if quests_incomplete:
            use collapsable_list("Incomplete Quests", quests_incomplete)
        else:
            text "There are no incomplete quests."
        if quests_complete:
            use collapsable_list("Complete Quests", quests_complete)
        else:
            text "There are no completed quests."
Hm I see. Thanks for the response, chief. I do have a question, tho;
screen collapsable_list(title, items):
When I define screens, I have never used that parenthesis, and I can't figure what it is supposed to be doing here. If it's not too much trouble, could you give me a bit of an explanation/some resource to read up on that?

That aside- I assume your idea can customized so I can use my Python class, yes?

The way the class is structured is:

Code: Select all

class Quest:
        def __init__(self, name, description, type, available = False, started = False, completed = False):
            self.name = name
            self.description = description
            self.type = type
            self.available = available
            self.started = started
            self.completed = completed
An example quest:

Code: Select all

x_quest = Quest("MyQuest", "MyQuestDescription", "Personal", True, True, False
This quest would be, then, in the "incomplete" category and the "personal" category.

How can I make it so that it gets displayed alongside the rest of the incomplete and personal quests (and then moves to another list once it becomes completed)?
I am losing it

User avatar
m_from_space
Miko-Class Veteran
Posts: 985
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Collapsible lists for a RenPy screen?

#4 Post by m_from_space »

Yone28 wrote: Sat Apr 20, 2024 3:17 am Hm I see. Thanks for the response, chief. I do have a question, tho;
screen collapsable_list(title, items):
When I define screens, I have never used that parenthesis, and I can't figure what it is supposed to be doing here. If it's not too much trouble, could you give me a bit of an explanation/some resource to read up on that?
Screens are like functions, they can accept arguments. So when showing or calling a screen, you can send arguments to the screen.

So a screen without arguments normally looks like this, even though you can strip the parentheses. But it's the same for classes...

Code: Select all

screen myscreen():
# or
screen myscreen:
    
init python:
    class MyClass():
    # or
    class MyClass:
So since screens can be included inside other screen using the "use" keyword, you can send different arguments to each of the screen. Like I'm doing in that example, look inside the "journal" screen!
That aside- I assume your idea can customized so I can use my Python class, yes?
Sure I just gave you a simple example. Using data from class objects inside screens is as easy as anywhere else.
An example quest:

Code: Select all

x_quest = Quest("MyQuest", "MyQuestDescription", "Personal", True, True, False
This quest would be, then, in the "incomplete" category and the "personal" category.

How can I make it so that it gets displayed alongside the rest of the incomplete and personal quests (and then moves to another list once it becomes completed)?
So I assume you have a list of all the quests, completed or not and you spoke of 5 categories that should be collapsable:

Code: Select all

default all_quests = [x_quest, ...]

screen collapsable_list(title, questlist):
    default show_list = True
    vbox:
        textbutton "> [title]" action ToggleLocalVariable("show_list")
        if show_list:
            if questlist:
                for quest in questlist:
                    text "- [quest.name]"
                    text "([quest.description])"
            else:
                text "This list is empty."

screen journal():
    # these variables will update whenever you re-show the screen
    default quests_incomplete = [quest for quest in all_quests if not quest.completed]
    default quests_completed = [quest for quest in all_quests if quest.completed]
    default quests_relationship = [quest for quest in all_quests if quest.type == "Relationship"]
    default quests_optional = [quest for quest in all_quests if quest.type == "Optional"]
    default quests_personal = [quest for quest in all_quests if quest.type == "Personal"]
    vbox:
        use collapsable_list("Incomplete Quests", quests_incomplete)
        use collapsable_list("Completed Quests", quests_complete)
        use collapsable_list("Relationship Quests", quests_relationship)
        use collapsable_list("Optional Quests", quests_optional)
        use collapsable_list("Personal Quests", quests_personal)

User avatar
Yone28
Newbie
Posts: 12
Joined: Sat Feb 25, 2023 4:11 pm
Contact:

Re: Collapsible lists for a RenPy screen?

#5 Post by Yone28 »

So I assume you have a list of all the quests, completed or not and you spoke of 5 categories that should be collapsable:
EXACTLY what I needed. Cheers! I'll mark this as solved.
I am losing it

Post Reply

Who is online

Users browsing this forum: No registered users