[SOLVED] Textbutton with State-Dependent Text

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
KnotUntied
Newbie
Posts: 23
Joined: Mon Jan 04, 2016 5:36 am
Projects: Acheron
IRC Nick: Knot
Contact:

[SOLVED] Textbutton with State-Dependent Text

#1 Post by KnotUntied »

I plan on creating textbuttons with text that varies between states, something like:
Insensitive - [cantclickdis]
Selected - [youclickeddis]
Standard - [nothinghappened]

Is this possible? Did I miss some documentation concerning such? Has this question been asked already?

I will try to clarify if required.
Last edited by KnotUntied on Mon May 23, 2016 7:54 pm, edited 1 time in total.
I don't always make something, but when I do, I never fini

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Textbutton with State-Dependent Text

#2 Post by xela »

KnotUntied wrote:Did I miss some documentation concerning such?
Yes...
KnotUntied wrote:Has this question been asked already?
Chances are that it was.

You can create styles or pass style properties to you buttons directly.
Like what we're doing? Support us at:
Image

User avatar
saguaro
Miko-Class Veteran
Posts: 560
Joined: Sun Feb 12, 2012 9:17 am
Completed: Locked-In, Sunrise, The Censor
Organization: Lucky Special Games
itch: saguarofoo
Location: USA
Contact:

Re: Textbutton with State-Dependent Text

#3 Post by saguaro »

I think you'll want to use imagebuttons for this. You can assign a different image based on button state as insensitive, sensitive, or selected by using styling. If you want it to look like a textbutton you can use text displayables.

Edit to add: ok you can use a button, you can change the child displayable based on state.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Textbutton with State-Dependent Text

#4 Post by xela »

saguaro wrote:I think you'll want to use imagebuttons for this. You can assign a different image based on button state as insensitive, sensitive, or selected by using styling. If you want it to look like a textbutton you can use text displayables.
...?
Like what we're doing? Support us at:
Image

User avatar
KnotUntied
Newbie
Posts: 23
Joined: Mon Jan 04, 2016 5:36 am
Projects: Acheron
IRC Nick: Knot
Contact:

Re: Textbutton with State-Dependent Text

#5 Post by KnotUntied »

Is there a way to allow strings instead of file locations in imagebuttons, then?
I don't always make something, but when I do, I never fini

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Textbutton with State-Dependent Text

#6 Post by xela »

KnotUntied wrote:Is there a way to allow strings instead of file locations in imagebuttons, then?
I have no idea why imagebuttons were suggested to be used instead of textbuttons for buttons that are used to display text :( Ask the other guy...
Like what we're doing? Support us at:
Image

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Textbutton with State-Dependent Text

#7 Post by xela »

Basically some form of this, you don't need style, I misunderstood your question at first:

Code: Select all

style meow_button_text:
    idle_color "FFF"
    hover_color "F00"
    selected_color "000"
    selected_hover_color "F0F"

screen test():
    
    default meow = ":)"
    
    textbutton "[meow]":
        align .5, .5
        style "meow_button"
        action SetScreenVariable("meow", ":("), SensitiveIf(not meow == ":(")
        hovered SetScreenVariable("meow", "Cliiiiick me noooooooow!")
        unhovered SetScreenVariable("meow", ":)")

label start:
    call screen test
Like what we're doing? Support us at:
Image

User avatar
korova
Veteran
Posts: 217
Joined: Sat Jun 27, 2009 5:15 pm
Completed: Ivy, Chocolate, Time, Clair Obscur
Projects: Writing exercises, The House [Nano18]
Tumblr: korova08
itch: korova
Location: Normandie, France
Contact:

Re: Textbutton with State-Dependent Text

#8 Post by korova »

This is what I use in my scripts to achieve that effect

Code: Select all

    imagebutton:
        style "accueil_button"
        idle Text("Text idle",style = "accueil_icone")
        hover Text("Text hover"), style = "accueil_texte")
        selected Text("Text selected"), style = "accueil_texte")
        action Start()

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Textbutton with State-Dependent Text

#9 Post by xela »

korova wrote:This is what I use in my scripts to achieve that effect

Code: Select all

    imagebutton:
        style "accueil_button"
        idle Text("Text idle",style = "accueil_icone")
        hover Text("Text hover"), style = "accueil_texte")
        selected Text("Text selected"), style = "accueil_texte")
        action Start()
Good one, in the past you could only assign Displayable to buttons (imagebuttons threw errors)... "image"button is not really a correct name anymore :D Usually with image in Ren'Py, reference is made either to tagging system or to image like displayable.
Like what we're doing? Support us at:
Image

User avatar
KnotUntied
Newbie
Posts: 23
Joined: Mon Jan 04, 2016 5:36 am
Projects: Acheron
IRC Nick: Knot
Contact:

Re: Textbutton with State-Dependent Text

#10 Post by KnotUntied »

I implemented korova's method, which did what I wanted, except for the text displaying insensitive color all the time.

UPDATE: I also tried implementing saguaro's alternate idea, which involved buttons and children, and it did provide a lighter footprint, but went insane with "child Text("Test", etc)" not registering and having the unselected button cover the area with void.

Code: Select all

button:
    child Text("Testing...", style = "pref_button_text") # Does nothing, eats display space
    selected_child Text("SUCCESS!", style = "pref_button_text") # Works except for color, same issue with imagebutton attempt
    action Preference("skip", "seen")
I don't always make something, but when I do, I never fini

User avatar
korova
Veteran
Posts: 217
Joined: Sat Jun 27, 2009 5:15 pm
Completed: Ivy, Chocolate, Time, Clair Obscur
Projects: Writing exercises, The House [Nano18]
Tumblr: korova08
itch: korova
Location: Normandie, France
Contact:

Re: Textbutton with State-Dependent Text

#11 Post by korova »

KnotUntied wrote:I implemented korova's method, which did what I wanted, except for the text displaying insensitive color all the time.

Unfortunately, you have to assign a specific text-style to each text.
I know this is heavy, but I found no other easier alternative.

So you have to define a "text_idle" style, to assign to your idle version of the button, s "selected_text" style for the selected version and such.
I'm not very happy with this either, but as for now, this is the best I can do...

Code: Select all

    imagebutton:
        style "accueil_button"
        idle Text("Text idle",style = "idle_text")
        hover Text("Text hover"), style = "hover_text")
        selected Text("Text selected"), style = "selected_text")
        action Start()

Code: Select all

style idle_text:
     color my_idle_color

style hover_text:
     color my_hover_color

User avatar
saguaro
Miko-Class Veteran
Posts: 560
Joined: Sun Feb 12, 2012 9:17 am
Completed: Locked-In, Sunrise, The Censor
Organization: Lucky Special Games
itch: saguarofoo
Location: USA
Contact:

Re: Textbutton with State-Dependent Text

#12 Post by saguaro »

Re: Button: I tried but could do no better unfortunately. It has to do with how the Text displayable handles styles?

Code: Select all

screen button_test():    
    default select = False
    button:        
        xsize 120 ysize 20
        idle_child Text("Idle", style="test_text")
        hover_child Text("Hover", style="test_text")           
        selected_child Text("Selected", style="selected_text")        
        action ToggleScreenVariable("select")
            
style test_text:
    color "#000"
    
style selected_text:
    color "#088"

User avatar
KnotUntied
Newbie
Posts: 23
Joined: Mon Jan 04, 2016 5:36 am
Projects: Acheron
IRC Nick: Knot
Contact:

Re: Textbutton with State-Dependent Text

#13 Post by KnotUntied »

After some graphical adjustments, I finally obtained my desired results.

Despite the barbarous length of code required, I guess I'll have to sit with saguaro's solution.

Thanks for your help, gents!
I don't always make something, but when I do, I never fini

Post Reply

Who is online

Users browsing this forum: Semrush [Bot]