Adding a the choice to change the textbox in preferences.

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.
Message
Author
User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Adding a the choice to change the textbox in preferences

#31 Post by SinnyROM » Wed Jul 01, 2015 4:53 pm

I'm not sure - I haven't seen any style.window properties other than the textbox background here:

Code: Select all

    $style.window.background = Frame("Textbox1.png", 12, 12)
You can copy what's done for the textbox background and select other style properties from the documentation if they're not passing through. If the textbox of style 1 has different margins than style 1A for instance, then you can copy the background ConditionSwitch(...) and change it to xmargin ConditionSwitch(...), or ymargin. For character-specific changes, use the window_ prefix in the character definition.

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Adding a the choice to change the textbox in preferences

#32 Post by crimsonnight » Wed Jul 01, 2015 5:05 pm

Whereabouts would I place that code though? Currently it's all set in options.rpy:

Code: Select all

style.window.background = Frame("Textbox1.png", 12, 12)
    
    ## Margin is space surrounding the window, where the background
    ## is not drawn.

    style.window.left_margin = 385
    style.window.right_margin = 385
    style.window.top_margin = 0
    style.window.bottom_margin = 15

    ## Padding is space inside the window, where the background is
    ## drawn.

    style.window.left_padding = 20
    style.window.right_padding = 20
    style.window.top_padding = 15
    style.window.bottom_padding = 14

    ## This is the minimum height of the window, including the margins
    ## and padding.

    style.window.yminimum = 132
Both textboxes share the same properties if that makes things any easier? And apologies for being dense, I appreciate your help >_<
alwaysthesamebluesky.com

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Adding a the choice to change the textbox in preferences

#33 Post by SinnyROM » Wed Jul 01, 2015 5:31 pm

Sorry, I completely forgot about those in options.rpy! I don't use them so my mind went blank.
However, I tried to change those values and it still applied them. What I noticed is that the first line isn't indented like the rest. Since options.rpy is almost entirely an init python block, and that statement is in Python, indentation is part of the structure. Try indenting it and see if it registers?

Code: Select all

    # indented and aligned with the rest
    style.window.background = Frame("Textbox1.png", 12, 12)

    ## Margin is space surrounding the window, where the background
    ## is not drawn.

    style.window.left_margin = 385
    # rest of code
    # ...

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Adding a the choice to change the textbox in preferences

#34 Post by crimsonnight » Wed Jul 01, 2015 5:39 pm

SinnyROM wrote:Sorry, I completely forgot about those in options.rpy! I don't use them so my mind went blank.
However, I tried to change those values and it still applied them. What I noticed is that the first line isn't indented like the rest. Since options.rpy is almost entirely an init python block, and that statement is in Python, indentation is part of the structure. Try indenting it and see if it registers?

Code: Select all

    # indented and aligned with the rest
    style.window.background = Frame("Textbox1.png", 12, 12)

    ## Margin is space surrounding the window, where the background
    ## is not drawn.

    style.window.left_margin = 385
    # rest of code
    # ...
Oh sorry, it is indented, I just copied it from the beginning of the word! It's strange, the properties set in options apply when I comment out the new code, so for some reason the new code is bypassing them my end...
alwaysthesamebluesky.com

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Adding a the choice to change the textbox in preferences

#35 Post by SinnyROM » Wed Jul 01, 2015 9:07 pm

Well, then I have no idea why that could be. Could you post your code and what you commented to make the properties work again?

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Adding a the choice to change the textbox in preferences

#36 Post by crimsonnight » Thu Jul 02, 2015 3:20 am

Sure!

Script:

Code: Select all

init python:
    persistent.style = ""

Code: Select all

define narrator = Character(None, what_outlines=my_n)
define stw = Character(None, show_two_window=True)
define k = Character("Kira", color="#ffffff", kind=stw, what_outlines=my_k, who_outlines=[(3, "#b6a472", 0, 0)],
    # styling the namebox
    # default is namebox1, change if otherwise
    show_custom_who_background=ConditionSwitch(
          "persistent.style == 'A'", "Namebox1A.png",
          "True", "Namebox1.png",
        )
    )
define k2 = Character(None, what_outlines=my_k)
define r = DynamicCharacter("player_name", color="#ffffff", show_two_window=True, what_outlines=my_r, who_outlines = [(3, "#79003f", 0, 0)],
    # styling the namebox
    # default is namebox1, change if otherwise
    show_custom_who_background=ConditionSwitch(
          "persistent.style == 'A'", "Namebox2A.png",
          "True", "Namebox2.png",
        )
    )
define g = Character("Grant", color="#ffffff", kind=stw, what_outlines=my_g, who_outlines = [(3, "#50697f", 0, 0)],
    # styling the namebox
    # default is namebox1, change if otherwise
    show_custom_who_background=ConditionSwitch(
          "persistent.style == 'A'", "Namebox2A.png",
          "True", "Namebox2.png",
        )
    )
define gs = Character("Kimmy", color="#ffffff", kind=stw, what_outlines=my_gs, who_outlines = [(3, "#c95f8c", 0, 0)],
    # styling the namebox
    # default is namebox1, change if otherwise
    show_custom_who_background=ConditionSwitch(
          "persistent.style == 'A'", "Namebox2A.png",
          "True", "Namebox2.png",
        )
    )
Screns (say):

Code: Select all

screen say(who, what, side_image=None, two_window=False,  # the usual arguments
    custom_who_background="say_who_window_background"  # for the custom namebox
):

    # Defaults for side_image and two_window
    default side_image = None
    default two_window = False

    # Decide if we want to use the one-window or two-window varaint.
    if not two_window:

        # The one window variant.        
        window:
            id "window"
            
            # change textbox style
            background ConditionSwitch(
                "persistent.style == 'A'", "Textbox2.png",
                "True", "Textbox1.png"
            )

            has vbox:
                style "say_vbox"

            if who:
                text who id "who"

            text what id "what"

    else:

        # The two window variant.
        vbox:
            style "say_two_window_vbox"

            if who:            
                window:
                    style "say_who_window"
                    background custom_who_background

                    text who:
                        id "who"
                        
            window:
                id "window"
                
                # change textbox style
                background ConditionSwitch(
                    "persistent.style == 'A'", "Textbox2.png",
                    "True", "Textbox1.png"
                )

                has vbox:
                    style "say_vbox"

                text what id "what"
              
    # If there's a side image, display it above the text.
    if side_image:
        add side_image
    else:
        add SideImage() xalign 0.0 yalign 1.0

    # Use the quick menu.
    use quick_menu
Screens (pref):

Code: Select all

frame:
                style_group "pref"
                has vbox
                label _("Textbox Style")
                textbutton "Standard" action SetField(persistent, "style", "")
                textbutton "Plain" action SetField(persistent, "style", "A")
Options:

Code: Select all

    style.window.background = Frame("Textbox1.png", 12, 12)
    
    ## Margin is space surrounding the window, where the background
    ## is not drawn.

    style.window.left_margin = 385
    style.window.right_margin = 385
    style.window.top_margin = 0
    style.window.bottom_margin = 15

    ## Padding is space inside the window, where the background is
    ## drawn.

    style.window.left_padding = 20
    style.window.right_padding = 20
    style.window.top_padding = 15
    style.window.bottom_padding = 14

    ## This is the minimum height of the window, including the margins
    ## and padding.

    style.window.yminimum = 132

    #Namebox

    style.say_who_window.background = Frame("namebox1.png", 8, 8)
    
    style.say_who_window.ypos = 102
    
    style.say_who_window.left_margin = 384
    
    style.say_who_window.xminimum = 25
    style.say_who_window.yminimum = 10
    
    #Input Prompt
    
    style.input_prompt.outlines = [(3.3, "#2d2d2d", 0, 0)]
    
    style.input.color = '#ffffff'
    style.input.outlines = [(3.3, "#79003f", 0, 0)]
If I comment out this for example:

Code: Select all

#            # change textbox style
#            background ConditionSwitch(
#                "persistent.style == 'A'", "Textbox2.png",
#                "True", "Textbox1.png"
#            )
Then the textbox will be sized correctly.

Apologies if I've missed anything!
alwaysthesamebluesky.com

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Adding a the choice to change the textbox in preferences

#37 Post by SinnyROM » Thu Jul 02, 2015 8:23 am

I looked over your code, and it looks like it should work fine, since that line is only changing the background. I may be missing something as well haha.
Does it work if it's just an if statement?

Code: Select all

# replace conditionswitch with if statement
            if persistent.style == "A":
                background "Textbox2.png"
            else:
                background "Textbox1.png"

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Adding a the choice to change the textbox in preferences

#38 Post by crimsonnight » Thu Jul 02, 2015 8:40 am

SinnyROM wrote:I looked over your code, and it looks like it should work fine, since that line is only changing the background. I may be missing something as well haha.
Does it work if it's just an if statement?

Code: Select all

# replace conditionswitch with if statement
            if persistent.style == "A":
                background "Textbox2.png"
            else:
                background "Textbox1.png"
Like this?:

Code: Select all

        window:
            id "window"
            
            # change textbox style
            if persistent.style == "A":
                background "Textbox2.png"
            else:
                background "Textbox1.png"

            has vbox:
                style "say_vbox"

            if who:
                text who id "who"

            text what id "what"

    else:

        # The two window variant.
        vbox:
            style "say_two_window_vbox"

            if who:            
                window:
                    style "say_who_window"
                    background custom_who_background

                    text who:
                        id "who"
                        
            window:
                id "window"
                
                # change textbox style
                if persistent.style == "A":
                    background "Textbox2.png"
                else:
                    background "Textbox1.png"

                has vbox:
                    style "say_vbox"

                text what id "what"
I get an error message when trying to launch the game saying
File "game/screens.rpy", line 30: The has statement may not be given after a child has been supplied.
has vbox:
^
alwaysthesamebluesky.com

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Adding a the choice to change the textbox in preferences

#39 Post by SinnyROM » Thu Jul 02, 2015 9:11 am

Sorry about that, you need to change the vbox too:

Code: Select all

#                has vbox:
#                    style "say_vbox"
#
#                text what id "what"

                vbox:
                    style "say_vbox"

                    text what id "what"

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Adding a the choice to change the textbox in preferences

#40 Post by crimsonnight » Thu Jul 02, 2015 9:37 am

So that it ends up like this?

Code: Select all

screen say(who, what, side_image=None, two_window=False,  # the usual arguments
    custom_who_background="say_who_window_background"  # for the custom namebox
):

    # Defaults for side_image and two_window
    default side_image = None
    default two_window = False

    # Decide if we want to use the one-window or two-window varaint.
    if not two_window:

        # The one window variant.        
        window:
            id "window"
            
            # change textbox style
            if persistent.style == "A":
                background "Textbox2.png"
            else:
                background "Textbox1.png"

            vbox:
                style "say_vbox"

                if who:
                    text who id "who"

                text what id "what"

    else:

        # The two window variant.
        vbox:
            style "say_two_window_vbox"

            if who:            
                window:
                    style "say_who_window"
                    background custom_who_background

                    text who:
                        id "who"
                        
            window:
                id "window"
                
                # change textbox style
                if persistent.style == "A":
                    background "Textbox2.png"
                else:
                    background "Textbox1.png"

                vbox:
                    style "say_vbox"

                    text what id "what"
              
    # If there's a side image, display it above the text.
    if side_image:
        add side_image
    else:
        add SideImage() xalign 0.0 yalign 1.0

    # Use the quick menu.
    use quick_menu
It's still not adopting it's style properties :(
alwaysthesamebluesky.com

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Adding a the choice to change the textbox in preferences

#41 Post by SinnyROM » Thu Jul 02, 2015 10:09 pm

Yeah, that way should work too. I can't figure it out, even after running a diff on our scripts and seeing if there's anything inherently different. Sorry I couldn't help you there. Maybe try Delete Persistent from the Ren'Py window? Or Check Script (Lint) and see if it says anything?

If it's any help to you, I've attached what I have to this post. It's very similar to what you have only with using coloured Frames, which can be replaced with images easily. You can try it as a new game first to see if it works, and hopefully if you integrate your current code into this - or the other way around - the issue will be gone. Hopefully!
Attachments
script.rpy
(2.16 KiB) Downloaded 17 times
screens.rpy
(15.02 KiB) Downloaded 14 times
options.rpy
(10.05 KiB) Downloaded 13 times

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Adding a the choice to change the textbox in preferences

#42 Post by crimsonnight » Fri Jul 03, 2015 5:58 pm

I've try clearing the lint and deleting the persistent, no joy I'm afraid. It's weird the issue is occurring my end and not yours. I've also looked through your files (cheers for attaching them) and compared them to mine but only saw a couple of minor differences which I tested but it didn't make a difference.

Is there any way to have it reapply the style during the condition switch? If not, I have a backup plan!

So we know although not perfect, this method works to switch the textbox:

Code: Select all

label pick_style1:
    $style.window.background = Frame("background1.png", 12, 12)
    $style.rebuild()
    return
label pick_style2:
    $style.window.background = Frame("background2.png", 12, 12)
    $style.rebuild()
    return
Combined with:

Code: Select all

frame:
                style_group "pref"
                has vbox

                label _("Style")
                textbutton _("Style 1") action Jump('pick_style1')
                textbutton _("Style 2") action Jump('pick_style2')
So! It seems to work as intended when I just combine the two actions:

Code: Select all

frame:
                style_group "pref"
                has vbox
                label _("Textbox Style")
                textbutton "Standard" action [SetField(persistent, "style", ""), Jump('pick_style1')]
                textbutton "Plain" action [SetField(persistent, "style", "A"), Jump('pick_style2')]
Hopefully that's a decent enough solution. Thanks again for all your assistance :)
alwaysthesamebluesky.com

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Adding a the choice to change the textbox in preferences

#43 Post by SinnyROM » Fri Jul 03, 2015 9:23 pm

I was hoping it would work somehow. As long as this backup plan works for you! I don't know about reapplying the style during the conditionswitch - maybe someone else might know.

Post Reply

Who is online

Users browsing this forum: Google [Bot], Ocelot, zyric