InputValue and Editing Values on a Screen

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
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

InputValue and Editing Values on a Screen

#1 Post by trooper6 »

So, here is my vision.

There is dict. The dict has a key that is a title and a value that is a list of words.
I want a screen that uses the key as the label and then has the words in the value list in a vbox.
This I can do no problem.
But now i want to turn those words into input values so the user can change the individual words if necessary. I think I might need to make a custom ValueInput...but maybe not? Any idea how to do what I'm thinking? I'll give you the basic shell in code and ask if any of you all know how to turn the words into inputs that would be amazing.

Code: Select all


screen codepoem():
    frame:
        xalign 1.0
        yalign 0.0
        vbox:
                label "".join(currentpoem.keys())
                text "-----"
                for v in currentpoem.values():
                    $n = len(v)
                    for x in range(n):
                        text "{0}: {1}".format(x, v[x]) #I'd like to turn this into an Input, but how do work this?
                        
default currentpoem = {"Szabo": ["The", "live", "that", "I", "have", "is", "all", "that", "I", "have"]

label start:
    show screen codepoem()
    "Testing"
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

strayerror
Regular
Posts: 159
Joined: Fri Jan 04, 2019 3:44 pm
Contact:

Re: InputValue and Editing Values on a Screen

#2 Post by strayerror »

I think this is what you were aiming for, we'll see.

First problem is multiple inputs on one screen. You can only ever edit one at a time, so we need some kind of focus control - in this case the active var. We also modulus this when using it to ensure we loop around the inputs in both directions. This is a really basic hacky version, but for this simple case in a screen containing nothing else it works well enough, just a heads up that you may need to revisit it depending on how you use it. Those key definitions should probably be in a proper keymap too, but we'll leave it there for now. :P

The words we're not currently editing, we may wish to click so we can edit them, so we use a button with similar styling to the frame we put out active input into. This minimises the visual difference while still keeping apparent which is currently being edited.

Finally we abuse the fact that the DictInputValue is just implicitly using the __getitem__/__setitem__ methods on the var we hand it, so it doesn't matter that what we're really giving it is a list, so long as the index is valid. It also results in the data being updated in place since we're giving it a reference to the list in the original data structure (rather than a copy), so there's no worry about needing to return the updated values.

End result is a vertical list of values that may be edited, and tab/shift+tab can be used to navigate up and down the list, as well as clicking the specific item you wish to edit. The Enter or NumpadEnter keys will progress forward from the screen and display the contents of the newly updated data structure.

Code: Select all

screen codepoem():
    default active = 1
    frame:
        align 1., 0.
        for k, v in currentpoem.items():
            vbox:
                label k
                text "-----"
                for i in xrange(len(v)):
                    if i == active % len(v):
                        frame:
                            background '#fff6'
                            padding 2, 2
                            xysize 100, 20
                            input:
                                value DictInputValue(v, i)
                    else:
                        button:
                            action SetScreenVariable('active', i)
                            hover_background '#fff3'
                            padding 2, 2
                            xysize 100, 20
                            text v[i]

        key 'K_TAB' action SetScreenVariable('active', active + 1)
        key 'repeat_K_TAB' action SetScreenVariable('active', active + 1)

        key 'shift_K_TAB' action SetScreenVariable('active', active - 1)
        key 'repeat_shift_K_TAB' action SetScreenVariable('active', active - 1)

        key 'input_enter' action Return()

default currentpoem = {"Szabo": ["The", "live", "that", "I", "have", "is", "all", "that", "I", "have"]}

label start:
    call screen codepoem()
    "Testing [currentpoem!q]"
    return

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: InputValue and Editing Values on a Screen

#3 Post by trooper6 »

Thank you for this! Studying your code, I can tell I'm already going to learn a lot from this! And my little strange side project will be much improved.
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
qirien
Miko-Class Veteran
Posts: 541
Joined: Thu Jul 31, 2003 10:06 pm
Organization: Metasepia Games
Deviantart: qirien
Github: qirien
itch: qirien
Location: New Mexico, USA
Discord: qirien
Contact:

Re: InputValue and Editing Values on a Screen

#4 Post by qirien »

Great code sample! I learned from it, too (and now I'm curious about this "side project"...). :-)
Finished games:
Image
Image
Image

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: InputValue and Editing Values on a Screen

#5 Post by trooper6 »

I’m creating a program that allows you encode and decode text via the code poem method used by resistance members during WW2. The core of the project is basic done, now I’m doing the code polish that will make it more convenient...then I’ll do the GUI improvements to make it look cool. Then I’ll decide it I need to make any other little tweaks.
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
qirien
Miko-Class Veteran
Posts: 541
Joined: Thu Jul 31, 2003 10:06 pm
Organization: Metasepia Games
Deviantart: qirien
Github: qirien
itch: qirien
Location: New Mexico, USA
Discord: qirien
Contact:

Re: InputValue and Editing Values on a Screen

#6 Post by qirien »

That sounds awesome; I would love to see it when it's done or help test it if you need betas. :-)
Finished games:
Image
Image
Image

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: InputValue and Editing Values on a Screen

#7 Post by trooper6 »

Certainly! I’ll message you when I’m done with it!
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

Post Reply

Who is online

Users browsing this forum: Google [Bot]