[Solved]Tooltip box that moves with mouse?
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.
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.
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3794
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
[Solved]Tooltip box that moves with mouse?
I've added a tooltip to a recent project and its working nicely, but I'd like to try and place the text in a vbox or something that only shows while a button is hovered, and gets its positioning based on where the mouse currently is.
I looked into renpy.get_mouse_pos(), but I don't know how I could use this to achieve what I want, if I even can.
I can make the screen appear easily enough by just using "if tooltip", but how do I make it follow the mouse or even just change position based on the mouse? I don't know how to use a tuple as x/y positioning. Is this even possible?
Sorry about not supplying further info, the project isn't my own, so I'm not sure how much information about it I can freely share.
I looked into renpy.get_mouse_pos(), but I don't know how I could use this to achieve what I want, if I even can.
I can make the screen appear easily enough by just using "if tooltip", but how do I make it follow the mouse or even just change position based on the mouse? I don't know how to use a tuple as x/y positioning. Is this even possible?
Sorry about not supplying further info, the project isn't my own, so I'm not sure how much information about it I can freely share.
Last edited by Imperf3kt on Tue Jan 29, 2019 8:13 am, edited 1 time in total.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Twitter
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
- Kia
- Eileen-Class Veteran
- Posts: 1040
- Joined: Fri Aug 01, 2014 7:49 am
- Deviantart: KiaAzad
- Discord: Kia#6810
- Contact:
Re: Tooltip box that moves with mouse?
I would use a timer that get's the position of the mouse in short intervals and stores it in variables that are used for positioning the tooltip frame, from the top of my head:
Code: Select all
timer .02 repeat True action [SetScreenVariable("ttxp", get_mouse[0]), SetScreenVariable("ttyp", get_mouse[1])]
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3794
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Tooltip box that moves with mouse?
Thanks, but I'm not sure I am using it correctly.Kia wrote: ↑Fri Jan 25, 2019 1:15 pm I would use a timer that get's the position of the mouse in short intervals and stores it in variables that are used for positioning the tooltip frame, from the top of my head:Code: Select all
timer .02 repeat True action [SetScreenVariable("ttxp", get_mouse[0]), SetScreenVariable("ttyp", get_mouse[1])]
I placed the code in a screen:
Code: Select all
screen mopos():
timer .02 repeat True action [SetScreenVariable("ttxp", get_mouse[0]), SetScreenVariable("ttyp", get_mouse[1])]
vbox:
xpos [ttxp]
ypos [ttyp]
text "[tooltip]"
Code: Select all
screen ret():
fixed:
xpos 270
ypos 882
imagebutton:
idle "images/Buttons & Graphics/Text Buttons/Return_Select_Off.png"
hover "images/Buttons & Graphics/Text Buttons/Return_Select_On.png"
action Return(), ToggleScreen("mopos")
tooltip "Return to the previous menu"
So I put the code in my existing tooltip screen:
Code: Select all
screen ttp():
$ tooltip = GetTooltip()
timer .02 repeat True action [SetScreenVariable("ttxp", get_mouse[0]), SetScreenVariable("ttyp", get_mouse[1])]
fixed:
# xmaximum 1000
# xpos 300
# ypos 1030
xpos [ttxp]
ypos [ttyp]
if tooltip:
text "[tooltip]"
If I define get_mouse, I am told "module has no attribute __get_mouse__"
If I use renpy.get_mouse, I am told the same thing as if I defined get_mouse.
I'm really confused here and honestly don't know what I'm doing.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Twitter
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
- Kia
- Eileen-Class Veteran
- Posts: 1040
- Joined: Fri Aug 01, 2014 7:49 am
- Deviantart: KiaAzad
- Discord: Kia#6810
- Contact:
Re: Tooltip box that moves with mouse?
oh, the code I've gave you was from the top of my head, the things you need to add are:
two screen variables, and you need to replace the "get_mouse" with the function you get the mouse position from.
something like this should work, though, I haven't had chance to test it, there might be mistakes you'll have to track down and fix.
two screen variables, and you need to replace the "get_mouse" with the function you get the mouse position from.
something like this should work, though, I haven't had chance to test it, there might be mistakes you'll have to track down and fix.
Code: Select all
screen mopos():
default = ttxp
default = ttyp
timer .02 repeat True action [SetScreenVariable("ttxp", renpy.get_mouse_pos()[0]), SetScreenVariable("ttyp",renpy.get_mouse_pos()[1])]
vbox:
xpos [ttxp]
ypos [ttyp]
text "[tooltip]"
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3794
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Tooltip box that moves with mouse?
I give up. Thanks for trying
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Twitter
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
- Kia
- Eileen-Class Veteran
- Posts: 1040
- Joined: Fri Aug 01, 2014 7:49 am
- Deviantart: KiaAzad
- Discord: Kia#6810
- Contact:
Re: Tooltip box that moves with mouse?
this one works, I tested it and it follows the mouse around, all you have to do is showing it on hover, hiding it on unhover and passing the text to it.
Code: Select all
screen tt:
default ttx = 0
default tty = 0
timer .02 repeat True action [SetScreenVariable("ttx", renpy.get_mouse_pos()[0]), SetScreenVariable("tty",renpy.get_mouse_pos()[1])]
frame:
offset(10,10) anchor(0.0,0.0)
xpos ttx
ypos tty
text "codex"
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3794
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Tooltip box that moves with mouse?
Oh cool thanks.
I spent so many hours yesterday trying so many different things that I thought I'd never work it out, so I really appreciate the help.
I spent so many hours yesterday trying so many different things that I thought I'd never work it out, so I really appreciate the help.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Twitter
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
- Kia
- Eileen-Class Veteran
- Posts: 1040
- Joined: Fri Aug 01, 2014 7:49 am
- Deviantart: KiaAzad
- Discord: Kia#6810
- Contact:
Re: Tooltip box that moves with mouse?
from my experience, it's always something small that we miss and cause frustration. ^_^
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3794
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Tooltip box that moves with mouse?
Edit 2: Not as useful as I thought, it appears to cause unintended behaviour. Back to the drawing board.
Original post:
That almost works perfectly, but I don't seem to be able to get the screen to go away without clicking. Any idea what I might have missed?
Code: Select all
screen ret():
fixed:
xpos 270
ypos 882
imagebutton:
idle "images/Buttons & Graphics/Text Buttons/Return_Select_Off.png"
hover "images/Buttons & Graphics/Text Buttons/Return_Select_On.png"
action Return()
hovered Show("tt", transition=dissolve)
unhovered Hide("tt", transition=dissolve)
tooltip "Return to the previous menu"
screen tt:
default ttx = 0
default tty = 0
$ tooltip = GetTooltip()
timer .02 repeat True action [SetScreenVariable("ttx", renpy.get_mouse_pos()[0]), SetScreenVariable("tty",renpy.get_mouse_pos()[1])]
if tooltip:
frame:
offset(10,10) anchor(0.0,0.0)
xpos ttx
ypos tty
text "[tooltip]"
I'll put this aside for now and go have some breakfast before I throw my mouse at something xD
I added a Return("None") to the timer action, but that makes the game jump to the start label lol
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Twitter
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Re: Tooltip box that moves with mouse?
Have you seen this thread - viewtopic.php?f=51&t=47205#p472810 ?
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3794
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Tooltip box that moves with mouse?
Thanks for the link. Will try it soon.Alex wrote: ↑Sun Jan 27, 2019 5:42 pm Have you seen this thread - viewtopic.php?f=51&t=47205#p472810 ?
Last edited by Imperf3kt on Tue Jan 29, 2019 7:28 am, edited 1 time in total.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Twitter
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3794
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Tooltip box that moves with mouse?
Thats great!Alex wrote: ↑Sun Jan 27, 2019 5:42 pm Have you seen this thread - viewtopic.php?f=51&t=47205#p472810 ?
Thank you so much for the link, and a huge thanks to Human Bolt Diary for coming up with it.
Edit: Or it does, until you try to put it in a screens.rpy
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/screens.rpy", line 88, in script
init -1500 python:
File "game/screens.rpy", line 90, in <module>
class MouseTooltip(Tooltip, renpy.Displayable):
NameError: name 'Tooltip' is not defined
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/screens.rpy", line 88, in script
init -1500 python:
File "C:\Program Files (x86)\renpy\renpy\ast.py", line 881, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "C:\Program Files (x86)\renpy\renpy\python.py", line 1913, in py_exec_bytecode
exec bytecode in globals, locals
File "game/screens.rpy", line 90, in <module>
class MouseTooltip(Tooltip, renpy.Displayable):
NameError: name 'Tooltip' is not defined
Windows-8-6.2.9200
Ren'Py 7.1.3.1092
Tue Jan 29 22:37:35 2019
I got it, found a feature of Ren'Py and decided to just put it in and see if it works, and it did!
For example:
Code: Select all
hovered mtt.Action(VBox(Text("Continue\nLine break test"), xmaximum=50))
#or
hovered mtt.Action(Frame(Text("Continue\nLine break test"), xmaximum=250, ymaximum=250))
#Or even
hovered mtt.Action(Fixed(Image("images/bg3.jpg"), Text("Begin a new game"), xmaximum=250, ymaximum=250))
Thanks again for the massive help.
Any idea how to bring it in front of other displayables?
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Twitter
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Who is online
Users browsing this forum: Ahrefs [Bot]