Page 1 of 1

[SOLVED] Toggling two preferences at once with textbuttons

Posted: Sat Apr 30, 2022 1:12 pm
by Ana
Hello, I have an issue where I want to move the textbox window slightly to the side depending on if the side images are on or off. I was able to manage making it three separate buttons, but I would like to combine these somehow where if the side images are toggled on, the window is "offsettotheside" and if the side images are toggled off, the window is "centeredinthemiddle".

Here is my current code:

Code: Select all

vbox:
	textbutton _("Show Side Images") action [ToggleField(persistent, 'side_images'), SelectedIf(persistent.side_images)]
vbox:
	style_group "pref"
	label _("Side Images Window")
	textbutton _("Window is centred in the middle") action StylePreference("window", "centeredinmiddle")
	textbutton _("Window is offset to the side") action StylePreference("window", "offsettotheside")

Re: Toggling two preferences at once

Posted: Tue May 10, 2022 6:51 am
by m_from_space
I read your text many times and still don't quite understand what it is you really want to do. Could you rephrase it please?

You can make a button make multiple things at once by just comma-separating the commands.

Code: Select all

textbutton _("Show Side Images"):
   action ToggleField(...), StylePreference(...), etc.

Re: Toggling two preferences at once

Posted: Sun May 15, 2022 4:10 pm
by Ana
m_from_space wrote:
Tue May 10, 2022 6:51 am
I read your text many times and still don't quite understand what it is you really want to do. Could you rephrase it please?

You can make a button make multiple things at once by just comma-separating the commands.

Code: Select all

textbutton _("Show Side Images"):
   action ToggleField(...), StylePreference(...), etc.
Hi, thanks for the reply. The problem is, the ToggleField is a button that sets the side image to on or off through one click, but the other button, the style preference (which moves the textbox either [1] to the center or [2] to the side) has two options and needs two separate buttons right now. I can't think of a way to change between
Image

If I set the StylePreference to the center and side image off/on, the textbox will remain in the center. I want it to go:
- side image on, set the textbox off to the side (top image)
- side image off, set the textbox centered in the middle (bottom image)

Can style preference alternate between 2 separate styles with one command?

Edit: alternatively, I'm following this post here regarding turning side images on/off:
viewtopic.php?t=50213
Is there any way to split the toggle button into two separate buttons: an "on" button and an "off" button?

Re: Toggling two preferences at once

Posted: Sun May 15, 2022 4:35 pm
by Ocelot
You can make a function which does what you want:

Code: Select all

init python:
    def set_window_style():
        if persistent.side_images:
            renpy.set_style_preference("window", "centeredinmiddle")
        else:
            renpy.set_style_preference("window", "offsettotheside")

# . . .
textbutton _("Show Side Images") selected persistent.side_images action [ToggleField(persistent, 'side_images'), Function(set_window_style)]
Or, if you wish, you can use SetField action instead of ToggleField

Re: Toggling two preferences at once

Posted: Sun May 15, 2022 4:51 pm
by Ana
Ocelot wrote:
Sun May 15, 2022 4:35 pm
You can make a function which does what you want:

Code: Select all

init python:
    def set_window_style():
        if persistent.side_images:
            renpy.set_style_preference("window", "centeredinmiddle")
        else:
            renpy.set_style_preference("window", "offsettotheside")

# . . .
textbutton _("Show Side Images") selected persistent.side_images action [ToggleField(persistent, 'side_images'), Function(set_window_style)]
Or, if you wish, you can use SetField action instead of ToggleField
It works perfectly!! Thank you so much!