Preference bar step value

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
15nick
Regular
Posts: 33
Joined: Thu Oct 17, 2013 2:46 am
Contact:

Preference bar step value

#1 Post by 15nick »

I was wondering if there was a way to use the step value you use with a variable or field bar, but with the music/sound/autoplay preference bars. I have a hotbar for my preference screen imagemap that looks similar to this
remotecenter-6-big.jpg
but with thicker "blocks."
Rather than the player being able to move the slider until it's in the middle of a block, I'd like to have it go up in even increments so it shows the blocks in their entirety if that makes sense.

If I can't do it with a preference bar, does anyone know code to make a VariableValue bar able to change the preference values I want instead?

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Preference bar step value

#2 Post by Asceai »

auto-forward time and text speed are easy:

Code: Select all

bar FieldValue(_preferences, "afm_time", range=30.0, max_is_zero=True, style="slider", step=1.0)
bar FieldValue(_preferences, "text_cps", range=200, max_is_zero=True, style="slider", step=10)
for volume, you need to reimplement MixerValue:

Code: Select all

init python:
    class SteppedMixerValue(BarValue):
        """
         :doc: value

         The value of an audio mixer.

         `mixer`
             The name of the mixer to adjust. This is usually one of
             "music", "sfx", or "voice", but user code can create new
             mixers.
         `step`
             The amount to change the bar by. If None, defaults to 1/10th of
             the bar.
         """

        def __init__(self, mixer, step=None):
            self.mixer = mixer
            self.step = step

        def set_mixer(self, value):
            _preferences.set_volume(self.mixer, value)

        def get_adjustment(self):
            return ui.adjustment(
                range=1.0,
                value=_preferences.get_volume(self.mixer),
                changed=self.set_mixer,
                step=self.step)

        def get_style(self):
            return "slider", "vslider"
then use it:

Code: Select all

bar value SteppedMixerValue('music', step=0.1)
bar value SteppedMixerValue('sfx', step=0.1)

User avatar
15nick
Regular
Posts: 33
Joined: Thu Oct 17, 2013 2:46 am
Contact:

Re: Preference bar step value

#3 Post by 15nick »

While it certainly works, it doesn't replicate the effect I wanted where it only shows whole blocks when it's adjusted by mouse. I think I might just wait a while and see if I can live with users being able to put 3.5 blocks for music, but it's weird because I remember making a slider for something else and the player could only move it in certain size increments even when using the mouse. Thank you for your help none the less, though.

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Preference bar step value

#4 Post by Asceai »

I'm confused. Isn't this precisely what you asked for?

This is clearly something that you can achieve with using VariableValue, so I assumed it was just the step property you needed so I provided an approach that allows you to specify a step property when putting in these bars.

So what's the problem? What does this approach not do that using VariableValue does do?

User avatar
15nick
Regular
Posts: 33
Joined: Thu Oct 17, 2013 2:46 am
Contact:

Re: Preference bar step value

#5 Post by 15nick »

It's only going in set increments when you use the arrow keys, not the mouse. I've done a slider before where I used VariableValue although it was for an in-game variable, not a preference or anything important, and got that effect with both mouse and keys which is why I'm trying for that effect.

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Preference bar step value

#6 Post by Asceai »

All VariableValue is is FieldValue but with 'renpy.store' as the object- everything just gets passed along, including those 'step' values, so if that doesn't work I don't see how VariableValue would work.

User avatar
15nick
Regular
Posts: 33
Joined: Thu Oct 17, 2013 2:46 am
Contact:

Re: Preference bar step value

#7 Post by 15nick »

I promise it did. It was a height slider, and it would only go up by inches so whenever the player played around with the bar it would go up by set amounts until it hit the cap. The only difference I can see between the two other than one being VariableValue is that one had an offset for the minimum height though I don't know why that would cause it to work or not. I guess I'll just have to mess around and see.

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Preference bar step value

#8 Post by Asceai »

I did some tests with VariableValue and I can't get step to produce the behaviour you described. I also had a look at ui.adjustment and it doesn't actually seem to allow for that, at least by default.

Anyway, here's a new SteppedMixerValue. This ugly mess is probably the best I can do:

Code: Select all

    class SteppedMixerValue(BarValue):
        """
         :doc: value

         The value of an audio mixer.

         `mixer`
             The name of the mixer to adjust. This is usually one of
             "music", "sfx", or "voice", but user code can create new
             mixers.
         `step`
             The amount to change the bar by. If None, defaults to 1/10th of
             the bar.
         """

        def __init__(self, mixer, step=None):
            self.mixer = mixer
            self.step = step
            self.adjustment = ui.adjustment(
                range=1.0,
                value=_preferences.get_volume(self.mixer),
                changed=self.set_mixer,
                step=self.step)
        def set_mixer(self, value):
            roundedvalue = round(value / self.step) * self.step
            if roundedvalue != value:
                self.adjustment.change(roundedvalue)
                return
            _preferences.set_volume(self.mixer, value)

        def get_adjustment(self):
            return self.adjustment

        def get_style(self):
            return "slider", "vslider"
Something like this could be done for the text and auto sliders too (in which you'd create a custom Value class like that, only instead of adjusting the mixers, it would change _preferences variables.

User avatar
15nick
Regular
Posts: 33
Joined: Thu Oct 17, 2013 2:46 am
Contact:

Re: Preference bar step value

#9 Post by 15nick »

Here, this is what I did basically. You see what I mean about the increments?
I'll definitely try what you just posted, though.
Attachments
step_slider.rpy
(1.72 KiB) Downloaded 125 times

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Preference bar step value

#10 Post by Asceai »

Aha, yep, I suspected what it was after mulling over your earlier posts for a bit.
It has nothing to do with step and everything to do with height being an integer. This isn't too valuable to you unless you use a separate integer variable and update the preferences with that variable multiplied by something to get it into the right range. Although it might be useful for a tidie4 implementation, since you'd just need a custom ui.adjustment for each bar and do the conversiin in the changed function.

User avatar
15nick
Regular
Posts: 33
Joined: Thu Oct 17, 2013 2:46 am
Contact:

Re: Preference bar step value

#11 Post by 15nick »

Yeah, that's what I was thinking when I changed the step and it didn't change anything that I could see but in the end it's just a nice effect I liked so I'll probably put seeing if I can do it to the back of the list.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Dark12ose, Google [Bot]