(Solved) How to Automatically Scroll Viewport when using Controller / Keyboard?

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
SypherZent
Veteran
Posts: 362
Joined: Fri Sep 02, 2016 3:14 am
Completed: Multiverse Heroes, Space Hamster in Turmoil
Location: Puerto Rico
Contact:

(Solved) How to Automatically Scroll Viewport when using Controller / Keyboard?

#1 Post by SypherZent »

I have a viewport with a scrollbar and 5 rows of items. If you use left/right/down/up, it works perfectly fine, except only two of the 5 rows are visible. To see more, you'd have to normally scroll. However, I want the viewport to automatically scroll if I press DOWN and there are still rows below not being displayed.

For example...

I have 5 rows of items in a viewport.

XXXXXX
XXXXXX
-------------- Screen ends here
XXXXXX
XXXXXX
XXXXXX

There is a scrollbar where you can use a mouse to manually click and scroll.
You can also use mousewheel to scroll down the viewport.

HOWEVER, if you are using controller, and you press DOWN the selection only goes up to Row 2 and then stops, even if there are three more rows.

XXXXXX
[X]XXXXX <--- Selection stops here even if I press DOWN, the viewport won't automatically scroll to display the next row.
-------------- Screen ends here
XXXXXX
XXXXXX
XXXXXX

How can I make this possible? I want the game to auto-scroll the viewport and display the next row.
It should only scroll to display the next row, not more than this, just enough to show the next row of entries.

I feel like this should be normal functionality for Ren'Py but it seems the quality of controller support is lacking, so I will need to code this myself.

Any help is appreciated, thanks.


Solved
I worked around this using ui.adjustment and the screen function to change the value when the button is pressed:

Code: Select all

key CONTROLLER_BUTTON action Function(yadj.change, yadj.value - VAL_TO_MOVE), renpy.restart_interaction
I set the VAL_TO_MOVE to be exactly 1 row in height, since it doesn't smoothly scroll when holding down the right analog stick on controller, so a single tap moves a full row.

User avatar
komehara
Regular
Posts: 36
Joined: Fri Jan 31, 2020 10:08 pm
Projects: Spirit Link
Tumblr: hsandt
Deviantart: hsandt
Github: hsandt
itch: komehara
Contact:

Re: (Solved) How to Automatically Scroll Viewport when using Controller / Keyboard?

#2 Post by komehara »

Hey, would you mind sharing the full code that worked so far? I'm trying to make smooth continuous scrolling work with gamepad right stick vertical axis (instead of per page scrolling).

Currently I'm doing this:

Code: Select all

init python:
    config.pad_bindings['pad_righty_neg'].append('viewport_pageup')
    config.pad_bindings['pad_righty_pos'].append('viewport_pagedown')
which causes instant page scroll on controller right stick vertical motion, as they are perceived like buttons, but I wonder if there is a way to obtain continuous scrolling. Setting increment to 1 is a solution, but the increment is taken from self.yadjustment.page in renpy-sdk > viewport.py and even if I force-modified this, then it would affect other pageup/down from keyboard too - and would still not be continuous (player would have to repeatedly press the button to advance).

Post Reply

Who is online

Users browsing this forum: Ocelot