How to change ui.input into a button?

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
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: How to change ui.input into a button?

#31 Post by xela » Sat Mar 14, 2015 11:59 pm

Aah, ok, they are just using the enable on hover... hold on.
Like what we're doing? Support us at:
Image

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How to change ui.input into a button?

#32 Post by namastaii » Sun Mar 15, 2015 12:49 am

XD ahh okay :) lool

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

Re: How to change ui.input into a button?

#33 Post by xela » Sun Mar 15, 2015 1:08 am

Sadly, there is no simple way of doing this with more than one input field. I did not anticipate that Ren'Py will only allow to edit last input field rendered. What they're doing in Magic diary is basically creating new input instance every time you hover over the button...
Like what we're doing? Support us at:
Image

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How to change ui.input into a button?

#34 Post by namastaii » Sun Mar 15, 2015 8:07 am

Hmm interesting. I think it's fine the way it is then. I hope xD

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How to change ui.input into a button?

#35 Post by namastaii » Sun Mar 15, 2015 1:17 pm

Okay, so now the problem (that I realize) is that whenever I push a button to change the characters hair or eyes or anything, it resets the text entry buttons XD omg This is a pain

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How to change ui.input into a button?

#36 Post by namastaii » Sun Mar 15, 2015 1:17 pm

I might have to have the name screen separate or something x.x

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How to change ui.input into a button?

#37 Post by namastaii » Sun Mar 15, 2015 1:26 pm

It's not even storing the names. hmm

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

Re: How to change ui.input into a button?

#38 Post by xela » Sun Mar 15, 2015 1:35 pm

Input in Ren'Py seems to be coded in a way that expects input to be called, not shown. Even so I did not anticipate the issue that you describe... but then again, I didn't anticipate a lot of issues in this topic :(

What they did in Magic Diary (I decrypted their code out of curiosity) is to create a class called SmartInput inheriting from the Button that creates an input field. Then they constantly redraw the ui (game was coded in a prescreen language environment) through a whileloop instantiating the class in every loop. Code is a bit clumsy but it definitely gets the job done, there might be something else at work there as well, I didn't look at it too deeply.

My own approach would be to have buttons create input fields in it, inherit from the Input class and override the event method to work like a text editor or input fields in the browser (main issue that I see is that clicking Enter does not terminate input field or move the next next input like (like second name), it should be very easy to get done right). If you have the skill to do that it would make an excellent cookbook entry...
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: How to change ui.input into a button?

#39 Post by xela » Sun Mar 15, 2015 1:36 pm

namastaii wrote:It's not even storing the names. hmm
Post your full code, this should not happen.
Like what we're doing? Support us at:
Image

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How to change ui.input into a button?

#40 Post by namastaii » Sun Mar 15, 2015 1:48 pm

Oh my goodness XD This is so complicated. Okay here's the code:

Code: Select all

init python:
    dressup_button_show = False
    skinColor, hair, hairColor, top, topColor, bottom, bottomColor, eyes, eyesColor = 1, 1, 1, 1, 1, 1, 1, 1, 1 # default dressup items
    skin_color_num, hair_styles_num, hair_color_num, top_num, top_color_num, bottom_num, bottom_color_num, eyes_num, eyes_color_num = 1, 4, 15, 5, 5, 5, 5, 3, 10 # number of styles (files) for each dressup item
    

    
    def draw_char(st, at): 
       
        
            
            
            return LiveComposite(
            (100, 630), # image size
            (0, 0), "create_character/base_female.png",
            (0, 0), "create_character/bottoms_female/bottom%s_%s.png"%(bottom, bottomColor),
            (0, 0), "create_character/tops_female/top%s_%s.png"%(top, topColor),
            (0, 0), "create_character/eyes_female/eyes%s_%s.png"%(eyes, eyesColor),
            (0, 0), "create_character/eyebrows_female/eyebrows_1.png",
            (0, 0), "create_character/mouth_female/mouth_2.png",
            (0, 0), "create_character/hair_female/hair%s_%s.png"%(hair, hairColor),
            
           
            
            ),.1

    def draw_char_side(st, at): 
        return LiveComposite(
            (100, 630),
            (2, 500), im.FactorScale("create_character/base_female.png", .45, .45),
            (2, 500), im.FactorScale("create_character/bottoms_female/bottom%s_%s.png"%(bottom, bottomColor), .45, .45),
            (2, 500), im.FactorScale("create_character/tops_female/top%s_%s.png"%(top, topColor), .45, .45),
            (2, 500), im.FactorScale("create_character/eyes_female/eyes%s_%s.png"%(eyes, eyesColor), .45, .45),
            (2, 500), im.FactorScale("create_character/eyebrows_female/eyebrows_1.png", .45, .45),
            (2, 500), im.FactorScale("create_character/mouth_female/mouth_2.png", .45, .45),
            
            (2, 500), im.FactorScale("create_character/hair_female/hair%s_%s.png"%(hair, hairColor), .45, .45),
            
            ),.1
 
init:
    image char = DynamicDisplayable(draw_char) # using DynamicDisplayable ensures that any changes are visible immedietly
    $ character = Character('Koma', color="#c8ffc8", window_left_padding=180, show_side_image=DynamicDisplayable(draw_char_side))
    image bg create_character_background = "create_character/create_character_background.jpg"
label start:
   show screen dressup_button
   $ dressup_button_show = True


screen dressup_button: # a button to call the dressup game
    if dressup_button_show:
        vbox xalign 0.1 yalign 0.01:
            textbutton "Create Character." action ui.callsinnewcontext("create_character")

####

init python:
    def name_func(newstring):
        
        store.var = newstring

        

screen name_input():
    button xalign 0.3 yalign 0.12:
        id "name_input"
        xysize (250, 25)
        action NullAction()
        add Input(size=30,color="#ff0066",changed=name_func,length=10,button=renpy.get_widget("name_input","name_input")) yalign 1.0 
    
    button xalign 0.3 yalign 0.213:
        id "name_input"
        xysize (250, 25)
        action NullAction()
        add Input(size=30,color="#ff0066",default=lastName,changed=name_func,length=15,button=renpy.get_widget("name_input","name_input")) yalign 1.0     

label create_character:
    scene bg create_character_background
    show char:
        xpos 830
        ypos -20
    
    hide screen dressup_button
    $ firstName =""
    $ lastName = ""
    $ player = firstName
    show screen name_input()

  
    python:
        y = 20 
        
        ui.text("[hair]",size=25,color="#330033", ypos=277,xpos=310)
        ui.text("[hairColor]",size=25,color="#330033", ypos=325,xpos=364) 
        ui.text("[top]",size=25,color="#330033", ypos=553,xpos=428)
        ui.text("[topColor]",size=25,color="#330033", ypos=553,xpos=732)
        ui.text("[bottom]",size=25,color="#330033", ypos=598,xpos=486)
        ui.text("[bottomColor]",size=25,color="#330033", ypos=598,xpos=732)
        ui.text("[eyes]",size=25,color="#330033", ypos=425,xpos=276)
        ui.text("[eyesColor]",size=25,color="#330033", ypos=425,xpos=502)
        
        
        

       
        ui.imagebutton("create_character/arrowL.png", "create_character/arrowLhover.png", clicked=ui.returns("topL"), ypos=550, xpos=377)
        ui.imagebutton("create_character/arrowR.png", "create_character/arrowRhover.png", clicked=ui.returns("topR"), ypos=550, xpos=457)
        y += 80
        ui.imagebutton("create_character/arrowL.png", "create_character/arrowLhover.png", clicked=ui.returns("bottomL"), ypos=591, xpos=434)
        ui.imagebutton("create_character/arrowR.png", "create_character/arrowRhover.png", clicked=ui.returns("bottomR"), ypos=591, xpos=514)
        
        ui.imagebutton("create_character/arrowL.png", "create_character/arrowLhover.png", clicked=ui.returns("topColorL"), ypos=550, xpos=680)
        ui.imagebutton("create_character/arrowR.png", "create_character/arrowRhover.png", clicked=ui.returns("topColorR"), ypos=550, xpos=760)
       
        ui.imagebutton("create_character/arrowL.png", "create_character/arrowLhover.png", clicked=ui.returns("bottomColorL"), ypos=591, xpos=680)
        ui.imagebutton("create_character/arrowR.png", "create_character/arrowRhover.png", clicked=ui.returns("bottomColorR"), ypos=591, xpos=760)
        
        ui.imagebutton("create_character/arrowL.png", "create_character/arrowLhover.png", clicked=ui.returns("hairL"), ypos=274, xpos=256)
        ui.imagebutton("create_character/arrowR.png", "create_character/arrowRhover.png", clicked=ui.returns("hairR"), ypos=274, xpos=336)
        
        ui.imagebutton("create_character/arrowL.png", "create_character/arrowLhover.png", clicked=ui.returns("hairColorL"), ypos=320, xpos=310)
        ui.imagebutton("create_character/arrowR.png", "create_character/arrowRhover.png", clicked=ui.returns("hairColorR"), ypos=320, xpos=410)
        
        ui.imagebutton("create_character/arrowDown.png", "create_character/arrowDownhover.png", clicked=ui.returns("eyesL"), ypos=460, xpos=262)
        ui.imagebutton("create_character/arrowUp.png", "create_character/arrowUphover.png", clicked=ui.returns("eyesR"), ypos=380, xpos=262)
        
        ui.imagebutton("create_character/arrowDown.png", "create_character/arrowDownhover.png", clicked=ui.returns("eyesColorL"), ypos=460, xpos=498)
        ui.imagebutton("create_character/arrowUp.png", "create_character/arrowUphover.png", clicked=ui.returns("eyesColorR"), ypos=380, xpos=498)
        

        
        
        ui.textbutton("Return", clicked=ui.returns("goback")) # image button version: ui.imagebutton("return.png", "return_hover.png", clicked=ui.returns("goback"), ypos=0, xpos=0)
        ui.textbutton("Continue", clicked=ui.returns("continue_toStart"), ypos=100, xpos=800)
        
    $ picked = ui.interact()

    if picked == "hairColorR":
        $ hairColor += 1
    if picked == "hairColorL":
        $ hairColor -= 1

          
    if hairColor < 1:
        $ hairColor = 1
    if hairColor > hair_color_num:
        $ hairColor = hair_color_num
        
    if picked == "hairL":
        $ hair -= 1
    if picked == "hairR":
        $ hair += 1 
    if hair < 1: 
        $ hair = 1
    if hair > hair_styles_num: 
        $ hair = hair_styles_num
    
    
    if picked == "topR":
        $ top += 1
    if picked == "topL":
        $ top -= 1

          
    if top < 1:
        $ top = 1
    if top > top_num:
        $ top = top_num 

    
    if picked == "topColorR":
        $ topColor += 1
    if picked == "topColorL":
        $ topColor -= 1

          
    if topColor < 1:
        $ topColor = 1
    if topColor > top_color_num:
        $ topColor = top_color_num 
    
    if picked == "bottomR":
        $ bottom += 1
    if picked == "bottomL":
        $ bottom -= 1

          
    if bottom < 1:
        $ bottom = 1
    if bottom > bottom_num:
        $ bottom = bottom_num 
        
    if picked == "bottomColorR":
        $ bottomColor += 1
    if picked == "bottomColorL":
        $ bottomColor -= 1

          
    if bottomColor < 1:
        $ bottomColor = 1
    if bottomColor > bottom_color_num:
        $ bottomColor = bottom_color_num 
        
        
    
    if picked == "eyesR":
        $ eyes += 1
    if picked == "eyesL":
        $ eyes -= 1

          
    if eyes < 1:
        $ eyes = 1
    if eyes > eyes_num:
        $ eyes = eyes_num 
        
    if picked == "eyesColorR":
        $ eyesColor += 1
    if picked == "eyesColorL":
        $ eyesColor -= 1

          
    if eyesColor < 1:
        $ eyesColor = 1
    if eyesColor > eyes_color_num:
        $ eyesColor = eyes_color_num 
        
    if picked == "goback":
        return    
    
    if picked == "continue_toStart":
        jump begin_story
        
   
    jump create_character # we don't want to return on every click, this jump loops until we click on "back" button

    return
On the next page, in the dialogue, I tested to see if the name was printed and it's blank (which is the initial value) so the input fields haven't been storing it like it's supposed to. Maybe I did something wrong.

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

Re: How to change ui.input into a button?

#41 Post by xela » Sun Mar 15, 2015 2:22 pm

This does work. Variable do update, but it is not visible anywhere else on the screen except for text strings themselves until interaction is restarted.

Code: Select all

init python:
    def name_func(newstring):
        store.firstname = newstring

    def lastname_func(newstring):
        store.lastname = newstring
        
screen name_input():
    button xalign 0.3 yalign 0.12:
        id "name_input1"
        xysize (250, 25)
        action NullAction()
        add Input(size=30, color="#ff0066", default=firstname, changed=name_func, length=10, button=renpy.get_widget("name_input","name_input1")) yalign 1.0
   
    button xalign 0.3 yalign 0.213:
        id "name_input2"
        xysize (250, 25)
        action NullAction()
        add Input(size=30, color="#ff0066", default=lastname, changed=lastname_func, length=15, button=renpy.get_widget("name_input","name_input2")) yalign 1.0


label start:
    $ firstname = "Curious"
    $ lastname = "Cat"
    show screen name_input()
    "[firstname] [lastname]"
    "[firstname] [lastname]"
    "[firstname] [lastname]"
    "[firstname] [lastname]"
Like what we're doing? Support us at:
Image

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How to change ui.input into a button?

#42 Post by namastaii » Sun Mar 15, 2015 2:25 pm

I actually tried something just like that. But I'll try again.

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How to change ui.input into a button?

#43 Post by namastaii » Sun Mar 15, 2015 2:27 pm

It does work for you? the strings aren't showing up for me. They don't update

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How to change ui.input into a button?

#44 Post by namastaii » Sun Mar 15, 2015 2:32 pm

Okay, I got it to work. I didn't realize that you didn't capitalize it like firstName, I just had to change it XD

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How to change ui.input into a button?

#45 Post by namastaii » Sun Mar 15, 2015 2:35 pm

The only thing that bothers me is that when you push to change her appearance, it gets rid of the text and you can't edit it anymore.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]