How can I do a disabled textbutton that is not clickable?

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
Ryue
Miko-Class Veteran
Posts: 745
Joined: Fri Nov 02, 2012 8:41 am
Projects: Red eyes in the darkness
Contact:

How can I do a disabled textbutton that is not clickable?

#1 Post by Ryue » Thu Aug 13, 2015 9:12 am

I've got the following code that I'm trying to optimize in terms of usability:

Code: Select all

screen RedEyesRPGEngine_CombatChooseTurnAction(turnNumber, minimumDistanceEnemy, maximumDistanceEnemy, isEnemyInCloseCombat, isEnemyAtMaxRange):
    window:
        xanchor 0.0
        yanchor 0.0
        xpos 0.3
        ypos 0.4
        vbox:
            text "Turn: " + str(turnNumber)
            textbutton "Fight" action Return("Fight")
            if (not isEnemyInCloseCombat):
                textbutton "Advance" action Return("Advance")
            if (not isEnemyAtMaxRange):
                textbutton "Back off" action Return("BackOff")
            textbutton "Flee" action Return("Flee")
Now if:

Code: Select all

            if (not isEnemyInCloseCombat):
                textbutton "Advance" action Return("Advance")
results in true instead of false I want the Advance textbutton to show up but grayed out and to do nothing at all if it is pressed (the screen itsel is called with renpy.call_screen thus it should be as if no button had been pressed).

Is that possible? and if so how?

synedraacus
Regular
Posts: 58
Joined: Tue Jun 09, 2015 8:10 am
Github: synedraacus
Contact:

Re: How can I do a disabled textbutton that is not clickable

#2 Post by synedraacus » Thu Aug 13, 2015 9:21 am

You need to create a custom Action subclass for your button. It should have a method called get_sensitive that returns True when the button should pressable and False otherwise. Renpy will do the rest for you; colours of active/inactive buttons can be customised somewhere in styles, but I don't remember where exactly.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: How can I do a disabled textbutton that is not clickable

#3 Post by nyaatrap » Thu Aug 13, 2015 9:39 am

Isn't it just order of if clause?

Code: Select all

textbutton "Advance":
    if something:
        action Return

Ryue
Miko-Class Veteran
Posts: 745
Joined: Fri Nov 02, 2012 8:41 am
Projects: Red eyes in the darkness
Contact:

Re: How can I do a disabled textbutton that is not clickable

#4 Post by Ryue » Thu Aug 13, 2015 11:47 am

ok didnt think of that constellation. And how can I make a "disabled / grayed out" look on the button?

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: How can I do a disabled textbutton that is not clickable

#5 Post by nyaatrap » Fri Aug 14, 2015 1:39 pm

Code: Select all

button:
    if something:
        background "image" #or style e.t.c.
It's same. If clause can control almost anything in screens.

Ryue
Miko-Class Veteran
Posts: 745
Joined: Fri Nov 02, 2012 8:41 am
Projects: Red eyes in the darkness
Contact:

Re: How can I do a disabled textbutton that is not clickable

#6 Post by Ryue » Fri Aug 14, 2015 2:22 pm

mhm tnx

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: How can I do a disabled textbutton that is not clickable

#7 Post by trooper6 » Fri Aug 14, 2015 2:34 pm

Wolf wrote:ok didnt think of that constellation. And how can I make a "disabled / grayed out" look on the button?
Also note, if the button has no action, will look "disables/grayed out."
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
octacon100
Regular
Posts: 163
Joined: Thu Sep 12, 2013 11:23 pm
Projects: Regeria Hope
Organization: Golden Game Barn
IRC Nick: Octacon100
Location: Boston, MA
Contact:

Re: How can I do a disabled textbutton that is not clickable

#8 Post by octacon100 » Fri Aug 14, 2015 2:41 pm

Yeah, without an action the button will be disabled. Usually I have a variable and use an if statement to either show a button that is active or a button that is disabled.

Code: Select all

if presentMode == True:
                            imagebutton:
                                idle "GUI/presentButton_idle.png" 
                                hover "GUI/presentButton_hover.png"
                                activate_sound buttonSFX 
                                action [ Jump("handle_Present") ]     
                        else: 
                            imagebutton:
                                idle im.MatrixColor( "GUI/presentButton_idle.png", im.matrix.desaturate())
                                hover im.MatrixColor( "GUI/presentButton_idle.png", im.matrix.desaturate())
                                activate_sound None
                                action None

You might find that helpful.
Image
Current Digital Projects -
Image
Regiera Hope Completed Game Forum Post

Ryue
Miko-Class Veteran
Posts: 745
Joined: Fri Nov 02, 2012 8:41 am
Projects: Red eyes in the darkness
Contact:

Re: How can I do a disabled textbutton that is not clickable

#9 Post by Ryue » Sat Aug 15, 2015 12:46 am

Tnx again and tnx for the no action comment that was just what I was looking for in terms of disabled look

Post Reply

Who is online

Users browsing this forum: zyric