Add a vertical bar when there are too many choices?

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
tcassat
Newbie
Posts: 24
Joined: Tue Oct 03, 2017 7:32 pm
Contact:

Add a vertical bar when there are too many choices?

#1 Post by tcassat » Wed Nov 08, 2017 5:55 pm

Hi.

In the current settings of my game, up to 9 choices fit on the screen. In a single situation, however, I need to extend this list. Is it possible to put a vertical bar so the player can scroll and see all the possible options?

Or would it be better to make a specific screen just for this part? If this is the best option, could someone explain how to make a screen with the various options and a vertical scrollbar? I tried to make one but the end result was poor (I like to keep the same formatting as the default choice screen, but with a vertical bar).

User avatar
Divona
Miko-Class Veteran
Posts: 678
Joined: Sun Jun 05, 2016 8:29 pm
Completed: The Falconers: Moonlight
Organization: Bionic Penguin
itch: bionicpenguin
Contact:

Re: Add a vertical bar when there are too many choices?

#2 Post by Divona » Wed Nov 08, 2017 11:34 pm

You have to make an edit to current "screen choice" in "screens.rpy" by add Viewport in:

Code: Select all

screen choice(items):
    style_prefix "choice"

    if len(items) >= 10:
        viewport:
            draggable True
            mousewheel True
            scrollbars "vertical"

            xsize gui.choice_button_width
            ysize config.screen_height - 180

            xalign 0.5
            yalign 0.5

            vbox:
                for i in items:
                    textbutton i.caption action i.action
    else:
        vbox:
            for i in items:
                textbutton i.caption action i.action
Completed:
Image

tcassat
Newbie
Posts: 24
Joined: Tue Oct 03, 2017 7:32 pm
Contact:

Re: Add a vertical bar when there are too many choices?

#3 Post by tcassat » Thu Nov 09, 2017 9:26 am

Thanks!! It worked "almost" perfectly. For some reason, the xalign and yalign are not having any effect (the viewport always starts at pixels 0x0), but I believe it is easy to solve this. I'll read the documentation to try to understand the problem. Bye!



EDIT: I believe I have to adjust the position of the viewport using these commands, but when I enter them in the code, Renpy accuses an error> the object is not adjustable.

xadjustment
The ui.adjustment() used for the x-axis of the viewport. When omitted, a new adjustment is created.
yadjustment
The ui.adjustment() used for the y-axis of the viewport. When omitted, a new adjustment is created.

User avatar
Divona
Miko-Class Veteran
Posts: 678
Joined: Sun Jun 05, 2016 8:29 pm
Completed: The Falconers: Moonlight
Organization: Bionic Penguin
itch: bionicpenguin
Contact:

Re: Add a vertical bar when there are too many choices?

#4 Post by Divona » Thu Nov 09, 2017 11:41 am

"xalign" and "yalign" both set to 0.5 so viewport should appear in the middle of the screen. Does that not the case?

"xadjustment" and "yadjustment" are the position of "horizontal" and "vertical" scroll. If that's the part you want to move, first declare and assign variable to "ui.adjustment()". Than you can assign value and put them in:

Code: Select all

default y_adjustment = ui.adjustment()

screen choice(items):
    style_prefix "choice"

    python:
        y_adjustment.value = float("inf")    # start scrollbar at the bottom.

    if len(items) >= 10:
        viewport:
            draggable True
            mousewheel True
            scrollbars "vertical"

            yadjustment y_adjustment

            xsize gui.choice_button_width
            ysize config.screen_height - 180

            xalign 0.5
            yalign 0.5

            vbox:
                for i in items:
                    textbutton i.caption action i.action
    else:
        vbox:
            for i in items:
                textbutton i.caption action i.action
Completed:
Image

tcassat
Newbie
Posts: 24
Joined: Tue Oct 03, 2017 7:32 pm
Contact:

Re: Add a vertical bar when there are too many choices?

#5 Post by tcassat » Thu Nov 09, 2017 1:10 pm

Divona wrote:
Thu Nov 09, 2017 11:41 am
"xalign" and "yalign" both set to 0.5 so viewport should appear in the middle of the screen. Does that not the case?
No, viewport appears in 0x0.

Using xpos and ypos instead xaling and yalign changes the viewport position, but not the scrollbar position. By the way, I found exactly the same question resolved in this topic:

viewtopic.php?f=8&t=39275&p=420893&hili ... en#p420893

Apparently the problem was solved when the topic author sets xfill parameter for the vbox to True. I tried adding "xfill True" to your code's vbox but nothing happened. I still do not have enough knowledge to understand where I have to change the "xfill" to True.

User avatar
Imperf3kt
Eileen-Class Veteran
Posts: 1683
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: Add a vertical bar when there are too many choices?

#6 Post by Imperf3kt » Thu Nov 09, 2017 4:05 pm

What happens if you remove 'vbox' and replace it with 'has vbox'?

Remember to correct indentation.
Image

Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

tcassat
Newbie
Posts: 24
Joined: Tue Oct 03, 2017 7:32 pm
Contact:

Re: Add a vertical bar when there are too many choices?

#7 Post by tcassat » Fri Nov 10, 2017 10:00 am

Imperf3kt wrote:
Thu Nov 09, 2017 4:05 pm
What happens if you remove 'vbox' and replace it with 'has vbox'?

Remember to correct indentation.
Nothing changes.

I solved the problem by changing xalign and yalign to xpos and ypos and centering according to the resolution I am using. The bar is half misaligned, as much as I try to adjust the size of the viewport, the bar is not aligned right, but I think it will be the only way to solve this, since xalign and yalign, for some reason that escapes me, has no effect in viewport.

Post Reply

Who is online

Users browsing this forum: No registered users