[Tutorial] Customizing the NVL Textbox

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Message
Author
User avatar
OokamiKasumi
Eileen-Class Veteran
Posts: 1775
Joined: Thu Oct 14, 2010 3:53 am
Completed: 14 games released -- and Counting.
Organization: DarkErotica Games
Deviantart: OokamiKasumi
Location: NC, USA
Contact:

Re: [Tutorial] Customizing the NVL Textbox

#16 Post by OokamiKasumi » Tue Apr 01, 2014 9:33 am

PyTom wrote:You could also set a variable, and then modify the nvl screen to check that variable and lay itself out appropriately.
Could you show an example of how that would work?
Ookami Kasumi ~ Purveyor of fine Smut.
Most recent Games Completed: For ALL my completed games visit: DarkErotica Games

"No amount of great animation will save a bad story." -- John Lasseter of Pixar

User avatar
PyTom
Ren'Py Creator
Posts: 15445
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: [Tutorial] Customizing the NVL Textbox

#17 Post by PyTom » Tue Apr 01, 2014 1:50 pm

Without actually indenting properly, the code would look like:

Code: Select all

screen nvl:

  if nvl_style == 1:

    window:
        style "nvl_window"

        has vbox:
            style "nvl_vbox"

        # Display dialogue.
        for who, what, who_id, what_id, window_id in dialogue:
            window:
                id window_id

                has hbox:
                    spacing 10

                if who is not None:
                    text who id who_id

                text what id what_id

        # Display a menu, if given.
        if items:

            vbox:
                id "menu"

                for caption, action, chosen in items:

                    if action:

                        button:
                            style "nvl_menu_choice_button"
                            action action

                            text caption style "nvl_menu_choice"

                    else:

                        text caption style "nvl_dialogue"
  else:

    window:
        style "nvl_window"

        has vbox:
            style "nvl_vbox"

        # Display dialogue.
        for who, what, who_id, what_id, window_id in dialogue:
            window:
                id window_id

                has hbox:
                    spacing 10

                if who is not None:
                    text who id who_id

                text what id what_id

        # Display a menu, if given.
        if items:

            vbox:
                id "menu"

                for caption, action, chosen in items:

                    if action:

                        button:
                            style "nvl_menu_choice_button"
                            action action

                            text caption style "nvl_menu_choice"

                    else:

                        text caption style "nvl_dialogue"
You could change the top and bottom parts to use different styles, etc.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
OokamiKasumi
Eileen-Class Veteran
Posts: 1775
Joined: Thu Oct 14, 2010 3:53 am
Completed: 14 games released -- and Counting.
Organization: DarkErotica Games
Deviantart: OokamiKasumi
Location: NC, USA
Contact:

Re: [Tutorial] Customizing the NVL Textbox

#18 Post by OokamiKasumi » Wed Apr 02, 2014 2:44 pm

PyTom wrote:Without actually indenting properly, the code would look like: You could change the top and bottom parts to use different styles, etc.
I can't make it work because options.rpy will not accept 2 different nvl styles.
Ookami Kasumi ~ Purveyor of fine Smut.
Most recent Games Completed: For ALL my completed games visit: DarkErotica Games

"No amount of great animation will save a bad story." -- John Lasseter of Pixar

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

Re: [Tutorial] Customizing the NVL Textbox

#19 Post by saguaro » Wed Apr 02, 2014 3:44 pm

I have used Levrex's method to have multiple NVL screens, it uses a modified nvl screen like PyTom's example but also has a callback function:
http://lemmasoft.renai.us/forums/viewto ... vl#p229973

I used the callback in that post and was able to style size/background properties like so:

Code: Select all

  
    style.nar_nvl = Style(style.nvl_window, properties=dict(xpadding=100,ypadding=100))    
   
    style.ims = Style(style.nvl_window, properties=dict(background = "terminal_box", left_padding = 10, right_padding = 10, top_padding = 10, bottom_padding = 10, left_margin = 200, right_margin = 200, top_margin = 100, bottom_margin = 100))
Then I modified the nvl screen directly for things like font, text color, etc.

User avatar
OokamiKasumi
Eileen-Class Veteran
Posts: 1775
Joined: Thu Oct 14, 2010 3:53 am
Completed: 14 games released -- and Counting.
Organization: DarkErotica Games
Deviantart: OokamiKasumi
Location: NC, USA
Contact:

Re: [Tutorial] Customizing the NVL Textbox

#20 Post by OokamiKasumi » Wed Apr 02, 2014 7:35 pm

saguaro wrote:I have used Levrex's method to have multiple NVL screens, it uses a modified nvl screen like PyTom's example but also has a callback function:
http://lemmasoft.renai.us/forums/viewto ... vl#p229973

I used the callback in that post and was able to style size/background properties like so:

Then I modified the nvl screen directly for things like font, text color, etc.
I've been trying this method, but I keep getting errors.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While executing init code:
  File "game/script.rpy", line 50, in script
  File "game/script.rpy", line 52, in python
NameError: name 'st1' is not defined

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "L:\Library\!Kenetic Novels\RenPy\renpy-6.15.5-sdk\renpy\bootstrap.py", line 286, in bootstrap
    renpy.main.main()
  File "L:\Library\!Kenetic Novels\RenPy\renpy-6.15.5-sdk\renpy\main.py", line 264, in main
    game.context().run(node)
  File "L:\Library\!Kenetic Novels\RenPy\renpy-6.15.5-sdk\renpy\execution.py", line 294, in run
    node.execute()
  File "L:\Library\!Kenetic Novels\RenPy\renpy-6.15.5-sdk\renpy\ast.py", line 732, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "L:\Library\!Kenetic Novels\RenPy\renpy-6.15.5-sdk\renpy\python.py", line 1358, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/script.rpy", line 52, in <module>
    nvl_var = st1,
NameError: name 'st1' is not defined

Windows-7-6.1.7601-SP1
Ren'Py 6.17.3.327
1280x720 Template 0.0
The errors are addressing this part:

Code: Select all

    $ story1 = Character(None, 
        kind=nvl,
        nvl_var = st1,
        callback=speaker("story1"),
        ctc="ctc_blinkNVL",
        ctc_position="fixed", 
        )

    $ story2 = Character(None, 
        kind=nvl,
        what_color="ffffff",
        callback=speaker("story2"), 
        ctc="ctc_blinkNVL",
        ctc_position="fixed", 
        )
However, I suspect that the cause is actually here:

Code: Select all

init -1 python hide:
    nvl_var = None

    def st1(name, event, **kwargs):
        global nvl_var
        nvl_var = st1           
    speaker = renpy.curry(st1)

    def st2(name, event, **kwargs):
        global nvl_var
        nvl_var = st2           
    speaker = renpy.curry(st2)
This is from the link you posted:
This is the simplest function that goes into "init python" block:
Code:

Code: Select all

        nvl_var = None

        def blahblah(name, event, **kwargs):
            global nvl_var
           
            nvl_var = name
           
        speaker = renpy.curry(blahblah)
Ookami Kasumi ~ Purveyor of fine Smut.
Most recent Games Completed: For ALL my completed games visit: DarkErotica Games

"No amount of great animation will save a bad story." -- John Lasseter of Pixar

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

Re: [Tutorial] Customizing the NVL Textbox

#21 Post by saguaro » Wed Apr 02, 2014 9:16 pm

You only need one callback function. 'name' is the parameter you want, as opposed to the function name. Try:

Code: Select all

init -1 python hide:
    nvl_var = None

    def st1(name, event, **kwargs):
        global nvl_var
        nvl_var = name          
    speaker = renpy.curry(st1)
And assuming "story1" is the name of the style you want to use:

Code: Select all

    $ story1 = Character(None, 
        kind=nvl,
        callback=speaker("story1"),
        ctc="ctc_blinkNVL",
        ctc_position="fixed", 
        )
See if the above changes work for you. I last worked with this stuff during last years Nano, so someone else may be able to chime in with a better solution.

User avatar
OokamiKasumi
Eileen-Class Veteran
Posts: 1775
Joined: Thu Oct 14, 2010 3:53 am
Completed: 14 games released -- and Counting.
Organization: DarkErotica Games
Deviantart: OokamiKasumi
Location: NC, USA
Contact:

Re: [Tutorial] Customizing the NVL Textbox

#22 Post by OokamiKasumi » Wed Apr 02, 2014 11:21 pm

saguaro wrote:You only need one callback function. 'name' is the parameter you want, as opposed to the function name. Try:

Code: Select all

init -1 python hide:
    nvl_var = None

    def st1(name, event, **kwargs):
        global nvl_var
        nvl_var = name          
    speaker = renpy.curry(st1)
The function name doesn't matter? Okay, I changed it to:

Code: Select all

init -1 python hide:
    nvl_type = None

    def st1(name, event, **kwargs):
        global nvl_var
        nvl_var = name         

    speaker = renpy.curry(nvl_type)
And assuming "story1" is the name of the style you want to use:
Actually, the style names are nvl1 and nvl2.

Code: Select all

    style.nvl1 = Style(style.nvl_window, properties=dict(
        ## ----------- Framed NVL box -------------------
        # style.nvl_window.background = Frame("ui/NVLbox.png", 0, 0), 
         
        ## ---------- No Frame Nvl Box--------------------
        background = "ui/NVLbox.png",
         
        # margins ---------------------------------
        top_margin = 80,
        bottom_margin = 0,
        left_margin = 0,
        right_margin = 0,

        # padding ---------------------------------
        top_padding = 80,
        bottom_padding = 30,
        left_padding = 780,
        right_padding = 80,
))
# --------------------------------------------------------------------------------------
    style.nvl2 = Style(style.nvl_window, properties=dict(
        ## ----------- Framed NVL box -------------------
        background = Frame("ui/NVLbox2.png", 0, 0),
         
        ## ---------- No Frame Nvl Box--------------------
        # background = "ui/NVLbox.png", 
         
        # margins ---------------------------------
        top_margin = 80,
        bottom_margin = 0,
        left_margin = 0,
        right_margin = 0,

        # padding ---------------------------------
        top_padding = 80,
        bottom_padding = 30,
        left_padding = 780,
        right_padding = 80,
))
So I changed those to:

Code: Select all

    $ story1 = Character(None,
        kind=nvl,
        callback=speaker("nvl1"),
        ctc="ctc_blinkNVL",
        ctc_position="fixed",
        )

    $ story2 = Character(None, 
        kind=nvl,
        callback=speaker("nvl2"),
        what_color="ffffff",
        ctc="ctc_blinkNVL",
        ctc_position="fixed", 
        )
However I am still getting the same error:

Code: Select all

While executing init code:
  File "game/script.rpy", line 50, in script
  File "game/script.rpy", line 52, in python
NameError: name 'speaker' is not defined

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "L:\Library\!Kenetic Novels\RenPy\renpy-6.15.5-sdk\renpy\bootstrap.py", line 286, in bootstrap
    renpy.main.main()
  File "L:\Library\!Kenetic Novels\RenPy\renpy-6.15.5-sdk\renpy\main.py", line 264, in main
    game.context().run(node)
  File "L:\Library\!Kenetic Novels\RenPy\renpy-6.15.5-sdk\renpy\execution.py", line 294, in run
    node.execute()
  File "L:\Library\!Kenetic Novels\RenPy\renpy-6.15.5-sdk\renpy\ast.py", line 732, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "L:\Library\!Kenetic Novels\RenPy\renpy-6.15.5-sdk\renpy\python.py", line 1358, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/script.rpy", line 52, in <module>
    callback=speaker("nvl1"),
NameError: name 'speaker' is not defined

Windows-7-6.1.7601-SP1
Ren'Py 6.17.3.327
1280x720 Template 0.0
Ookami Kasumi ~ Purveyor of fine Smut.
Most recent Games Completed: For ALL my completed games visit: DarkErotica Games

"No amount of great animation will save a bad story." -- John Lasseter of Pixar

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

Re: [Tutorial] Customizing the NVL Textbox

#23 Post by saguaro » Thu Apr 03, 2014 8:25 am

While I was messing with this I found the new version of Ren'Py throws a RevertableDict error for me that I think is related to the python styling, so head's up? But below works for me in 6.15, just also include the styles you posted.

Code: Select all

init python:
    nvl_var = None

    def st1(name, event, **kwargs):
        global nvl_var       
        nvl_var = name       
    speaker = renpy.curry(st1)

# Declare characters used by this game.
define story1 = Character(None, kind=nvl, callback=speaker("nvl1"))
define story2 = Character(None, kind=nvl, callback=speaker("nvl2"),what_color="#c8ffc8")

##############################################################################
# Nvl
#
# Screen used for nvl-mode dialogue and menus.
# http://www.renpy.org/doc/html/screen_special.html#nvl

screen nvl:

    if nvl_var == "nvl1":
        window:
            style "nvl1"

            has vbox:
                style "nvl_vbox"

            # Display dialogue.
            for who, what, who_id, what_id, window_id in dialogue:
                window:
                    id window_id

                    has hbox:
                        spacing 10

                    if who is not None:
                        text who id who_id

                    text what id what_id

            # Display a menu, if given.
            if items:

                vbox:
                    id "menu"

                    for caption, action, chosen in items:

                        if action:

                            button:
                                style "nvl_menu_choice_button"
                                action action

                                text caption style "nvl_menu_choice"

                        else:

                            text caption style "nvl_dialogue"

        add SideImage() xalign 0.0 yalign 1.0
        
        use quick_menu             
        
    else:
    
        window:
            style "nvl2"

            has vbox:
                style "nvl_vbox"

            # Display dialogue.
            for who, what, who_id, what_id, window_id in dialogue:
                window:
                    id window_id

                    has hbox:
                        spacing 10

                    if who is not None:
                        text who id who_id

                    text what id what_id

            # Display a menu, if given.
            if items:

                vbox:
                    id "menu"

                    for caption, action, chosen in items:

                        if action:

                            button:
                                style "nvl_menu_choice_button"
                                action action

                                text caption style "nvl_menu_choice"

                        else:

                            text caption style "nvl_dialogue"

        add SideImage() xalign 0.0 yalign 1.0
        
        use quick_menu    

User avatar
OokamiKasumi
Eileen-Class Veteran
Posts: 1775
Joined: Thu Oct 14, 2010 3:53 am
Completed: 14 games released -- and Counting.
Organization: DarkErotica Games
Deviantart: OokamiKasumi
Location: NC, USA
Contact:

Re: [Tutorial] Customizing the NVL Textbox

#24 Post by OokamiKasumi » Thu Apr 03, 2014 12:15 pm

saguaro wrote:While I was messing with this I found the new version of Ren'Py throws a RevertableDict error for me that I think is related to the python styling, so head's up? But below works for me in 6.15, just also include the styles you posted.
So... In other words, it used to work, but not anymore? (Back to square one...) LOL!
-- Thank you for trying so hard, but I don't think we can call this a viable solution. It Does work, but I seriously doubt anyone wants to go back to using a previous version of renpy just to do this. It's also a lot more complicated than the solution I originally suggested, (using a blank png for the nvl background, setting up the text padding in the nvl character definitions then showing the individual nvl boxes as needed.) It may not be so...automated, but it's easier for a beginner to actually use without messing something up.
Ookami Kasumi ~ Purveyor of fine Smut.
Most recent Games Completed: For ALL my completed games visit: DarkErotica Games

"No amount of great animation will save a bad story." -- John Lasseter of Pixar

dmasterxd
Regular
Posts: 158
Joined: Wed Feb 19, 2014 5:05 pm
Completed: Mage Wars
Projects: Falling Star
Organization: Star Guide
Contact:

Re: [Tutorial] Customizing the NVL Textbox

#25 Post by dmasterxd » Tue Feb 03, 2015 12:43 am

Hey thanks for this, it's helpful! But I just have one issue. An error occurred which said it expected a 'word' between style and .nvl_windows.background.

Also am I supposed to put the code in the game folder or was that just for the image?

User avatar
OokamiKasumi
Eileen-Class Veteran
Posts: 1775
Joined: Thu Oct 14, 2010 3:53 am
Completed: 14 games released -- and Counting.
Organization: DarkErotica Games
Deviantart: OokamiKasumi
Location: NC, USA
Contact:

Re: [Tutorial] Customizing the NVL Textbox

#26 Post by OokamiKasumi » Tue Feb 03, 2015 7:12 am

dmasterxd wrote:Hey thanks for this, it's helpful! But I just have one issue. An error occurred which said it expected a 'word' between style and .nvl_windows.background.
I'll need to see your code and the error message to tell you what isn't working right.
dmasterxd wrote:Also am I supposed to put the code in the game folder or was that just for the image?
The code goes in the same folder all your other code goes in. The image goes in the same folder your other images go in.
Ookami Kasumi ~ Purveyor of fine Smut.
Most recent Games Completed: For ALL my completed games visit: DarkErotica Games

"No amount of great animation will save a bad story." -- John Lasseter of Pixar

dmasterxd
Regular
Posts: 158
Joined: Wed Feb 19, 2014 5:05 pm
Completed: Mage Wars
Projects: Falling Star
Organization: Star Guide
Contact:

Re: [Tutorial] Customizing the NVL Textbox

#27 Post by dmasterxd » Tue Feb 03, 2015 12:05 pm

Okay here it is.
Capture.PNG
Capture.PNG (8.1 KiB) Viewed 2670 times
Capturex.PNG
Capture1.PNG
Capture1.PNG (10.39 KiB) Viewed 2670 times

User avatar
OokamiKasumi
Eileen-Class Veteran
Posts: 1775
Joined: Thu Oct 14, 2010 3:53 am
Completed: 14 games released -- and Counting.
Organization: DarkErotica Games
Deviantart: OokamiKasumi
Location: NC, USA
Contact:

Re: [Tutorial] Customizing the NVL Textbox

#28 Post by OokamiKasumi » Wed Feb 04, 2015 5:19 am

You have two problems here.
1) You cannot have style.nvl_window.background under a plain ordinary init: for the same reason you can't have config under one -- they're both written in Python. Copy/paste that whole line into your options.rpy page right under the rest of your textbox styles.

2) those numbers at the end of your code stand for space allowance for the CORNERS of a frame.

Example:
frame.png
frame.png (28.8 KiB) Viewed 2658 times
This frame's corners need 51 pixels of allowance to keep the corners from stretching along with the rest of the frame.

Code: Select all

init -1 python hide:
    ## Frames ----------------------------------------------
    style.frame.background = Frame("ui/frame.png",51,51) # numbers are size of corners, 'ui' is the name of the folder the image is in. 
1366x768_VictorianSS_01.jpg
Unless your textbox image has a Design on the corners, use '0' for both those numbers.

Code: Select all

init -1 python hide:
    ## Frame ------------------------
    style.nvl_window.background = Frame("ui/NVLbox.png", 0, 0) # ui/ is the name of the folder the image is in. 
If you don't want the box to stretch at all, write it this way:

Code: Select all

init -1 python hide:
    ## No Frame --------------------
    style.nvl_window.background = "ui/NVLbox.png" # ui/ is the name of the folder the image is in. 
Ookami Kasumi ~ Purveyor of fine Smut.
Most recent Games Completed: For ALL my completed games visit: DarkErotica Games

"No amount of great animation will save a bad story." -- John Lasseter of Pixar

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

Re: [Tutorial] Customizing the NVL Textbox

#29 Post by Ryue » Tue Nov 22, 2016 11:50 am

As this thread has been a livesaver time and again for me: Many of the things mentioned here won't work any longer in the current version of renpy, as nvl has changed a lot there. A new file: gui.rpy has been introduced which defines the values and many of the old style. need to be replaced with gui. in order to work again.

code example in the gui.rpy:

Code: Select all

## The borders of the background of the NVL-mode background window.
define gui.nvl_borders = Borders(0, 10, 0, 20)

## The height of an NVL-mode entry. Set this to None to have the entries
## dynamically adjust height.
define gui.nvl_height = 115

## The spacing between NVL-mode entries when gui.nvl_height is None, and between
## NVL-mode entries and an NVL-mode menu.
define gui.nvl_spacing = 10

## The position, width, and alignment of the label giving the name of the
## speaking character.
define gui.nvl_name_xpos = 430
define gui.nvl_name_ypos = 0
define gui.nvl_name_width = 150
define gui.nvl_name_xalign = 1.0

## The position, width, and alignment of the dialogue text.
define gui.nvl_text_xpos = 450
define gui.nvl_text_ypos = 8
define gui.nvl_text_width = 590
define gui.nvl_text_xalign = 0.0

## The position, width, and alignment of nvl_thought text (the text said by the
## nvl_narrator character.)
define gui.nvl_thought_xpos = 240
define gui.nvl_thought_ypos = 0
define gui.nvl_thought_width = 780
define gui.nvl_thought_xalign = 0.0

## The position of nvl menu_buttons.
define gui.nvl_button_xpos = 450
define gui.nvl_button_xalign = 0.0

User avatar
OokamiKasumi
Eileen-Class Veteran
Posts: 1775
Joined: Thu Oct 14, 2010 3:53 am
Completed: 14 games released -- and Counting.
Organization: DarkErotica Games
Deviantart: OokamiKasumi
Location: NC, USA
Contact:

Re: [Tutorial] Customizing the NVL Textbox

#30 Post by OokamiKasumi » Tue Nov 22, 2016 3:31 pm

Ryue wrote:As this thread has been a livesaver time and again for me...
Glad to be of service!
Ryue wrote:Many of the things mentioned here won't work any longer in the current version of renpy, as nvl has changed a lot there. A new file: gui.rpy, has been introduced which defines the values and many of the old style. need to be replaced with gui. in order to work again.
Thank you so much for this!
-- I haven't bothered to figure out the adjustments to the New GUI style because: Laziness. The default style allows me to adjust just about everything I generally mess with. I have about half a dozen or so working Test games that I copy-paste all my coding from. So yeah: Laziness.
Ookami Kasumi ~ Purveyor of fine Smut.
Most recent Games Completed: For ALL my completed games visit: DarkErotica Games

"No amount of great animation will save a bad story." -- John Lasseter of Pixar

Post Reply

Who is online

Users browsing this forum: No registered users