[SOLVED] How can I draw a specific textbox whenever the namebox is hovered?

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
Aureus
Veteran
Posts: 278
Joined: Sun Aug 06, 2017 4:49 am
Completed: The Tavern, Tales From Windy Meadow
Projects: Roadwarden
Organization: Moral Anxiety Studio
itch: moral-anxiety
Location: Breslau, Poland
Contact:

[SOLVED] How can I draw a specific textbox whenever the namebox is hovered?

#1 Post by Aureus »

Hi there! I started using Ren'Py engine three days ago and there is this little thing that I really need to implement to the game, but I don't believe there are any tutorials focused on this topic yet. I'm not a programmer, so I find this idea quite confusing to develop.

What I want to achieve:
1) Whenever the player hovers the mouse pointer over the namebox (nearby the dialogue box), 2) a text shows up 3) (with a png shown behind it) 4) which is referencing to the name shown in the namebox itself (the character description) 5) allowing player to read some unique description of every character shown in the game. 6) When the namebox stops being hovered, the box disappears.

So, basically, if player doesn't remember or know who a specific character is, they can point the mouse at the namebox to read this character's description.
Any ideas how can I make it? I assume this would be a good step to take?
Last edited by Aureus on Mon Feb 19, 2018 5:22 am, edited 1 time in total.
Tales From Windy Meadow - slice of life, pixel art Visual Novel set in a fantasy village. now available on Steam.

User avatar
Andredron
Miko-Class Veteran
Posts: 714
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: How can I draw a specific textbox whenever the namebox is hovered?

#2 Post by Andredron »

Aureus wrote: Fri Feb 16, 2018 8:37 am Hi there! I started using Ren'Py engine three days ago and there is this little thing that I really need to implement to the game, but I don't believe there are any tutorials focused on this topic yet. I'm not a programmer, so I find this idea quite confusing to develop.

What I want to achieve:
1) Whenever the player hovers the mouse pointer over the namebox (nearby the dialogue box), 2) a text shows up 3) (with a png shown behind it) 4) which is referencing to the name shown in the namebox itself (the character description) 5) allowing player to read some unique description of every character shown in the game. 6) When the namebox stops being hovered, the box disappears.

So, basically, if player doesn't remember or know who a specific character is, they can point the mouse at the namebox to read this character's description.
Any ideas how can I make it? I assume this would be a good step to take?

Code: Select all

init:
    $ config.mouse = {"default": [("images / cursorarrow.png", 0, 0)],
                                     "hand": [("images / cursorhand.png", 2, 8)],
                                    "finger": [("images / cursorfinger.png", 2, 2)]}

screen test:
     vbox:
         align (.5, .35)
         textbutton _ ("Finger"):
             xminimum 300
             mouse "finger"
             action NullAction ()
        textbutton _ ("Hand"):
             xminimum 300
             mouse "hand"
action NullAction ()

label start:
    scene expression "# 001"
    show screen test
    "Use the mouse to move the cursor to the button."
    return
1) you can register as a cursor image.
2) As the button which when hovering calls the screen where everything is specified.

Code: Select all

screen button_hover_example():

frame:

    xalign 0.5 ypos 50

    button:

        action Notify(_("Ты нажал на кнопку"))

        hovered Notify(_("Ты навел на кнопку"))

        unhovered Notify(_("Ты отвел кнопку"))
        text _("Кликни на меня")

label start:

    show screen button_hover_example

User avatar
Andredron
Miko-Class Veteran
Posts: 714
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: How can I draw a specific textbox whenever the namebox is hovered?

#3 Post by Andredron »

You in the Russian textbook to throw off on renpy?)) My)

User avatar
Aureus
Veteran
Posts: 278
Joined: Sun Aug 06, 2017 4:49 am
Completed: The Tavern, Tales From Windy Meadow
Projects: Roadwarden
Organization: Moral Anxiety Studio
itch: moral-anxiety
Location: Breslau, Poland
Contact:

Re: How can I draw a specific textbox whenever the namebox is hovered?

#4 Post by Aureus »

Andredron wrote: Fri Feb 16, 2018 10:00 am You in the Russian textbook to throw off on renpy?)) My)
I'm sorry, I have no idea what do you mean. Also, I'm not from Russia.

I tried to apply your first version of the code. I was able to solve various issues with additional spaces, but I can't pass the issue with "expected statement. action NullAction :arrow: ()

The second code works great (I only had to push one module beneath the "screen"), I think I should be able to trick it into showing where the namebox is. I don't know yet how to connect it with the specific texts, but I'm going to try to build upon it. Thank you.
Tales From Windy Meadow - slice of life, pixel art Visual Novel set in a fantasy village. now available on Steam.

User avatar
Aureus
Veteran
Posts: 278
Joined: Sun Aug 06, 2017 4:49 am
Completed: The Tavern, Tales From Windy Meadow
Projects: Roadwarden
Organization: Moral Anxiety Studio
itch: moral-anxiety
Location: Breslau, Poland
Contact:

Re: How can I draw a specific textbox whenever the namebox is hovered?

#5 Post by Aureus »

So here is what I was able to make for now using the code from Andredron. : ) I'm going to experiment some more, but if you have an idea how to refer the "hovered" text to the description of the character shown in the namebox, it would make my day.

Code: Select all

screen button_hover_example():
    button:
        xpos gui.name_xpos
        xanchor gui.name_xalign
        xsize gui.namebox_width
        ypos 865
        ysize gui.namebox_height
        action Notify(_(""))
        hovered Notify(_("text"))
        unhovered Notify(_(""))
Tales From Windy Meadow - slice of life, pixel art Visual Novel set in a fantasy village. now available on Steam.

User avatar
Andredron
Miko-Class Veteran
Posts: 714
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: How can I draw a specific textbox whenever the namebox is hovered?

#6 Post by Andredron »

if that, google translate to help you :)

https://yadi.sk/i/ps3F6blo3PZdRc

in the training app that goes to the renpy's launcher, almost everything is shown

online wordends there on the Yandex are terrible, and the codes do not show clearly)

User avatar
Aureus
Veteran
Posts: 278
Joined: Sun Aug 06, 2017 4:49 am
Completed: The Tavern, Tales From Windy Meadow
Projects: Roadwarden
Organization: Moral Anxiety Studio
itch: moral-anxiety
Location: Breslau, Poland
Contact:

Re: How can I draw a specific textbox whenever the namebox is hovered?

#7 Post by Aureus »

So, I almost finished making the working system, but I'm confused how to order the code to draw this "notify" box only when the namebox itself is drawn by the game...
Tales From Windy Meadow - slice of life, pixel art Visual Novel set in a fantasy village. now available on Steam.

User avatar
Andredron
Miko-Class Veteran
Posts: 714
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: How can I draw a specific textbox whenever the namebox is hovered?

#8 Post by Andredron »

Aureus wrote: Sat Feb 17, 2018 11:00 am So, I almost finished making the working system, but I'm confused how to order the code to draw this "notify" box only when the namebox itself is drawn by the game...
I'm very badly sorted out, you're sort of like what you want "Notyfi" Was shown only when the screen booted? If so, see the Tutorial application in the Ripping Lounge, select the section screens. There will be a code using on show when the screen is loaded. And on hide, when the screen closes. If I was mistaken then please clarify

Code: Select all

screen on_screen ():

    on "show" action Notify (_ ("The screen has appeared"))

    on "hide" action Notify (_ ("Screen removed"))

label start:

    schow screen on_screen

    "Hi"

    hide screen on_screen

    "Till"

irredeemable
Regular
Posts: 78
Joined: Thu Feb 08, 2018 7:57 am
Contact:

Re: How can I draw a specific textbox whenever the namebox is hovered?

#9 Post by irredeemable »

Change the say screen in screens.rpy so that the text for 'who' is a textbutton and set the hovered, unhovered, and action properties:

Code: Select all

screen say(who, what):
    style_prefix "say"

    window:
        id "window"

        if who is not None:

            window:
                id "namebox"
                style "namebox"
                textbutton who id "who" hovered Show('character_tooltip', who=who) unhovered Hide('character_tooltip') action NullAction()
Then your screen/script would be something like this, just adapted to style it however you like and take into consideration how your images and descriptions are stored:

Code: Select all

image foo_bg = "#eee"
default description = {"foo" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}

screen character_tooltip(who):
    frame background who + "_bg" xysize (500, 200) align (0.5, 0.5):
        text description[who]

label start:
    $ renpy.say('foo', "Hello.")

User avatar
Aureus
Veteran
Posts: 278
Joined: Sun Aug 06, 2017 4:49 am
Completed: The Tavern, Tales From Windy Meadow
Projects: Roadwarden
Organization: Moral Anxiety Studio
itch: moral-anxiety
Location: Breslau, Poland
Contact:

Re: How can I draw a specific textbox whenever the namebox is hovered?

#10 Post by Aureus »

Thank you, irredeemable. I really, really tried applying your code and I also tried various variations, but I was unable to make it work.
However, right now I only need one thing to make... And I don't know how to make it. I would like to have something like this:

(repeat the following code through the entire game)
if (text shown in the 'namebox') == something:
$ npcdescription = "somethingsomething"

Do you have any tips how to make it?
Tales From Windy Meadow - slice of life, pixel art Visual Novel set in a fantasy village. now available on Steam.

irredeemable
Regular
Posts: 78
Joined: Thu Feb 08, 2018 7:57 am
Contact:

Re: How can I draw a specific textbox whenever the namebox is hovered?

#11 Post by irredeemable »

What wasn't working exactly? In this case I would create a new class to handle all of this, but keeping things simple you should at least have a dictionary that maps the name of the speaker to the description. So if you have characters 'Jack' and 'Jill' you might define the dictionary like this:

Code: Select all

default npcs = {"Jack" : "This is Jack.", "Jill" : "This is Jill."}
The part before the colon is the key the part after the colon is the value. To access the value from a line of python you use square brackets, so npcs["Jack"] is equal to "This is Jack." If you don't want to use the hovered thing I posted earlier then you still need to get the name of the current speaker. Apparently it's not saved in any documented variable so you'll still need to change the say screen. I tried using on 'show' action SetVariable here but it was always one entry behind for some reason, though SetField worked (if anyone has an explanation for that I am curious). So what I ended up doing was adding a field to the variable npcs and then updating that field in the say screen. A basic script.rpy would look like:

Code: Select all

define jack = Character("Jack")
define jill = Character("Jill")

default npcs = {"Jack" : "This is Jack.", "Jill" : "This is Jill."}
default npcs.speaker = None

label start:
    jack "Hello world."
    $ renpy.say(None, "Last speakers name: " + npcs.speaker + ".\nLast speaker's description: " + npcs[npcs.speaker])
And change screens.rpy so that the say screen declaration starts like this (leave the rest of it intact):

Code: Select all

screen say(who, what):
    style_prefix "say"

    if who is not None:
        on 'show' action SetField(npcs, 'speaker', who)
Now you can use those variables ( npcs.speaker and npcs[npcs.speaker]) in any screen you may already have in place.

User avatar
Aureus
Veteran
Posts: 278
Joined: Sun Aug 06, 2017 4:49 am
Completed: The Tavern, Tales From Windy Meadow
Projects: Roadwarden
Organization: Moral Anxiety Studio
itch: moral-anxiety
Location: Breslau, Poland
Contact:

Re: How can I draw a specific textbox whenever the namebox is hovered?

#12 Post by Aureus »

Dear irredeemable, you made my day. I was able to transfer it into Notify screen and combine it with hovering, it works perfect. Thank you so much for taking your time to explain these things to me.
Tales From Windy Meadow - slice of life, pixel art Visual Novel set in a fantasy village. now available on Steam.

Post Reply

Who is online

Users browsing this forum: Google [Bot]