Page 1 of 1

Collapsible lists for a RenPy screen? [SOLVED]

Posted: Sat Apr 20, 2024 1:57 am
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.

Re: Collapsible lists for a RenPy screen?

Posted: Sat Apr 20, 2024 2:24 am
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."

Re: Collapsible lists for a RenPy screen?

Posted: Sat Apr 20, 2024 3:17 am
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)?

Re: Collapsible lists for a RenPy screen?

Posted: Sat Apr 20, 2024 7:20 am
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)

Re: Collapsible lists for a RenPy screen?

Posted: Sat Apr 20, 2024 5:11 pm
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.

Re: Collapsible lists for a RenPy screen? [SOLVED]

Posted: Mon May 13, 2024 3:57 am
by KarenThomas
Thank you so much for the information. Now, it is my turn to help you back and I will help you by sharing the https://domypaper.com/ website link with you. I am a college student and whenever I need help regarding my college essay assignments, I always visit the given link to find the best essay writer. You can also visit over there if you want to hire a professional essay writer.

Re: Collapsible lists for a RenPy screen? [SOLVED]

Posted: Mon May 13, 2024 7:27 am
by Andredron

Re: Collapsible lists for a RenPy screen? [SOLVED]

Posted: Fri May 17, 2024 11:55 am
by giorgi1111
Im using list screen for menu s. Im getting x y position to show near place where mouse clicked.and for list using imagebuttons with text or textbuttons.