[SOLVED] Adjust volume bar with left/ right arrow key

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
Kinmoku
Veteran
Posts: 407
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: Love IRL, Memories
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

[SOLVED] Adjust volume bar with left/ right arrow key

#1 Post by Kinmoku » Fri Jun 07, 2019 4:07 am

Hi all,

On controller, I noticed to adjust the volume bars, you need to select them first, then press left or right. Since there is nothing left or right of my bars, is it possible to remove the select and just press left or right? It feels more intuitive to do it that way but I'm not sure if it's possible in Ren'Py?

Thanks :D
Last edited by Kinmoku on Tue Jun 11, 2019 11:44 am, edited 1 time in total.

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

Re: Adjust volume bar with left/ right arrow key

#2 Post by Alex » Fri Jun 07, 2019 9:37 am

Try to set actions like

Code: Select all

key "focus_left" action SetDict (_preferences.volumes,'music', max (0.0, (_preferences.volumes['music'] - 0.1) ) )
key "focus_right" action SetDict (_preferences.volumes,'music', min (1.0, (_preferences.volumes['music'] + 0.1) ) )

User avatar
Kinmoku
Veteran
Posts: 407
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: Love IRL, Memories
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: Adjust volume bar with left/ right arrow key

#3 Post by Kinmoku » Sat Jun 08, 2019 8:46 am

Alex wrote:
Fri Jun 07, 2019 9:37 am
Try to set actions like

Code: Select all

key "focus_left" action SetDict (_preferences.volumes,'music', max (0.0, (_preferences.volumes['music'] - 0.1) ) )
key "focus_right" action SetDict (_preferences.volumes,'music', min (1.0, (_preferences.volumes['music'] + 0.1) ) )
Thanks Alex. This works but only for the music bar (not sound). I also only want it to work when I'm hovered over the music volume bar. Even if I am somewhere else on the settings UI, pressing left/ right will still adjust the volume, which I don't want as I cannot select other buttons left and right beneath the bars.

How can I have it focus only on the volume bar?

Code: Select all

        hbox:
            style_group "pref"
            spacing 50
            xalign 0.5
            
            text _("Music Volume") ypos 10
            
            bar value Preference("music volume") ypos 12
            key "focus_left" action SetDict (_preferences.volumes,'music', max (0.0, (_preferences.volumes['music'] - 0.1) ) )
            key "focus_right" action SetDict (_preferences.volumes,'music', min (1.0, (_preferences.volumes['music'] + 0.1) ) )

        hbox:
            style_group "pref"
            spacing 50
            xalign 0.5
            
            text _("Sound Volume") ypos 35

            bar value Preference("sound volume") ypos 35
            key "focus_left" action SetDict (_preferences.volumes,'sound', max (0.0, (_preferences.volumes['sound'] - 0.1) ) )
            key "focus_right" action SetDict (_preferences.volumes,'sound', min (1.0, (_preferences.volumes['sound'] + 0.1) ) )

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

Re: Adjust volume bar with left/ right arrow key

#4 Post by Alex » Sat Jun 08, 2019 9:47 am

Kinmoku wrote:
Sat Jun 08, 2019 8:46 am
... Even if I am somewhere else on the settings UI, pressing left/ right will still adjust the volume, which I don't want as I cannot select other buttons left and right beneath the bars. ...
I thought it was what your were looking for...

Well, then try to make a separate screen to reassign keys actions and show it while bar is hovered.

Code: Select all

screen my_keys_operate_scr(mixer):
    key "focus_left" action SetDict (_preferences.volumes, mixer, max (0.0, (_preferences.volumes[mixer] - 0.1) ) )
    key "focus_right" action SetDict (_preferences.volumes, mixer, min (1.0, (_preferences.volumes[mixer] + 0.1) ) )
and in preferences screen

Code: Select all

bar value Preference("music volume") hovered Show("my_keys_operate_scr", mixer='music') unhovered Hide("my_keys_operate_scr")

bar value Preference("sound volume") hovered Show("my_keys_operate_scr", mixer='sfx') unhovered Hide("my_keys_operate_scr")

bar value Preference("voice volume") hovered Show("my_keys_operate_scr", mixer='voice') unhovered Hide("my_keys_operate_scr")

User avatar
SypherZent
Veteran
Posts: 266
Joined: Fri Sep 02, 2016 3:14 am
Completed: Multiverse Heroes, Space Hamster in Turmoil
Projects: Working on WWTDAA
Soundcloud: Chrysopoeist
Location: Puerto Rico
Contact:

Re: Adjust volume bar with left/ right arrow key

#5 Post by SypherZent » Sat Jun 08, 2019 12:32 pm

You can try setting multiple actions, too.

Code: Select all

screen my_keys_operate_scr(mixer):
    key "focus_left" action [
                                    SetDict (_preferences.volumes,'music', max (0.0, (_preferences.volumes['music'] - 0.1) ) ),
                                    SetDict (_preferences.volumes,'sound', max (0.0, (_preferences.volumes['sound'] - 0.1) ) )
                                      ]

User avatar
Kinmoku
Veteran
Posts: 407
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: Love IRL, Memories
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: Adjust volume bar with left/ right arrow key

#6 Post by Kinmoku » Tue Jun 11, 2019 11:44 am

Thank you both for your help :)

I went with:

Code: Select all

        hbox:
            style_group "pref"
            spacing 50
            xalign 0.5
            
            text _("Music Volume") ypos 10
            
            bar value Preference("music volume") hovered Show("my_keys_operate_scr", mixer='music') unhovered Hide("my_keys_operate_scr") ypos 10

        hbox:
            style_group "pref"
            spacing 50
            xalign 0.5
            
            text _("Sound Volume") ypos 35

            bar value Preference("sound volume") hovered Show("my_keys_operate_scr", mixer='sfx') unhovered Hide("my_keys_operate_scr") ypos 40
I had to adjust the y position (space them out more) because the buttons were interfering slightly. Seems to work well now, though! :D

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Hiddenwall, jack_norton