Hello there! This script actually works, but... I think it would be even greater if we "changed" it a tiny bit so it can:
The hard part now is:
Or does there exist a simpler way of doing this? Still I don't think much can beat this great mouse over tooltip script...
- co-exist with the "new" version of it
- co-exist with other versions of it
The hard part now is:
- How do we hack the code so it will use "images"
- How and where do we define the images in the code.
PHP:
################################################################################
# RUN - Hovering tooltip code that follow mouse movment
################################################################################
#-------------------------------------------------------------------------------
# INSTRUCTIONS
#
# If the item you want a tooltip on looks like this:
# imagebutton:
# idle "placeholder"
# Then:
# imagebutton:
# idle "placeholder" tooltip "Now you see me"
# add mousetooltip
#
# You don't need to add "add mousetooltip" under each box, just add it when all
# is done. See more examples down in the document.
# define d = Character("The poor developer")
# define c = Character("Cat")
init python:
class MouseTooltip(renpy.Displayable):
def __init__(self, **kwargs):
super(renpy.Displayable, self).__init__(**kwargs)
self.text = Text("")
#-------------------------------------------------------------------------------
# RUN - Change text style of the tooltip here
#-------------------------------------------------------------------------------
# self.text.style.bold = True
# self.text.style.size = 46
self.text.style.bold = False
self.text.style.size = 20
#-------------------------------------------------------------------------------
# END - Change text style of the tooltip here
#-------------------------------------------------------------------------------
self.x = 0
self.y = 0
def render(self, width, height, st, at):
w, h = self.text.size()
render = renpy.Render(w, h)
# if tooltip is close to the top or right side make sure it stays on the screen
x = self.x
if x > config.screen_width - w:
x = config.screen_width - w
y = self.y-h # -h to place text above cursor
if y < 0:
y = 0
#-------------------------------------------------------------------------------
# END - Tooltip box color
#-------------------------------------------------------------------------------
fixed = Fixed(Color("#7777")) # fixed = transparent background rectangle
# fixed = Fixed(Color("#000000")) # fixed = transparent background rectangle
#-------------------------------------------------------------------------------
# END - Tooltip box color
#-------------------------------------------------------------------------------
fixed.add(self.text)
#fixed.add(Text("UNCOMMENT TO SEE WHEN TOOLTIP REDRAWS"))
render.place(fixed, x, y)
return render
def event(self, ev, x, y, st):
import pygame
# ignore all events except MOUSEMOTION
# not sure whether events like MOUSEBUTTONDOWN update the position too and should therefore be added here?!
if ev.type != pygame.MOUSEMOTION:
return None
self.x = x
self.y = y
tooltip = GetTooltip()
if tooltip:
#self.text.text = tooltip # does not work, won't update the text
self.text = Text(tooltip)
renpy.redraw(self, 0)
elif self.text.text != [""]: # avoid unnecessary redraw calls
self.text = Text("") # if there is no tooltip then clear the text just once
renpy.redraw(self, 0)
define mousetooltip = MouseTooltip()
################################################################################
# END - Hovering tooltip code that follow mouse movment
################################################################################
#-------------------------------------------------------------------------------
# EXAMPLE CODE FOR: - Hovering tooltip code that follow mouse movment
#
# Just add anywhere on a item at end ---> tooltip "Chair"
# and under all items an ---> add mousetooltip
#
#-------------------------------------------------------------------------------
# screen s_room():
# layer "master"
# textbutton "object to test top right corner":
# xpos 1420 ypos 0 action Return("picture") tooltip "Picture"
# textbutton "object" xpos 1200 ypos 800 action Return("cat") tooltip "Cat"
# textbutton "object" xpos 500 ypos 600 action Return("keys") tooltip "Keys"
# textbutton "object" xpos 400 ypos 800 action Return("switch") tooltip "Switch"
# textbutton "object" xpos 1200 ypos 900 action Return("chair") tooltip "Chair"
# add mousetooltip
# label start:
# d "Damn it! It's midnight and they cut the power! I couldn't afford to pay the powerbill ..."
# d "I need to find the garage keys! I will set up my giant hamsterwheel as powergenerator! That's the only way I can keep working on my Visual Novel."
# label find_keys:
# call screen s_room()
# if _return == "keys":
# d "Wohoo! I found them!"
# return
# elif _return == "picture":
# d "My poster of Miss Super Sexy World Mega Champion Over the Max 9000! ... to bad I can't see sh*t!"
# elif _return == "cat":
# c "Meeeooooww! ... Feed me!"
# d "Did you just say 'feed me'? ... Cats don't speak!"
# c "Okay ... Meow!"
# d "Just wait until I find my whip and the hamsterwheel!"
# elif _return == "switch":
# d "It's not working ..."
# jump find_keys