Tooltip improvements

* Moved calculations into a transform function.
* Reduced overhead
This commit is contained in:
LoafyLemon 2022-05-31 16:03:20 +01:00
parent 91f44064dc
commit 108475316d

View File

@ -4,32 +4,12 @@ screen tooltip():
zorder 5
style_prefix "tooltip"
default last_tooltip = ""
if settings.get("tooltip"):
$ mouseclick = any(pygame.mouse.get_pressed()[:3])
# Do not remove the empty string from the statement below,
# it is a rare case when the save file gets updated but the old tooltip
# and its scope defaults last_tooltip to None value
# because it was previously unknown at the runtime,
# and we cannot hide the screen fast enough, causing a hard crash.
# This ensures it never happens.
$ tooltip = GetTooltip() or last_tooltip or ""
$ last_tooltip = tooltip
showif GetTooltip() and not mouseclick:
$ x, y = renpy.get_mouse_pos()
$ xflip = x > 980
$ yflip = y > 500
$ xanchor = 1.0 if xflip else 0.0
$ yanchor = 1.0 if yflip else 0.0
$ xoffset = 11 if xflip else 0
$ yoffset = 14 if yflip else 0
$ tooltip = GetTooltip()
if settings.get("tooltip") and tooltip:
window:
id tooltip
at tooltip_follow((x+xoffset, y+yoffset), (xanchor, yanchor))
at tooltip_follow
text "[tooltip]"
style tooltip_window is empty:
@ -42,17 +22,20 @@ style tooltip_text is default:
size 10
outlines [(1, "#00000080", 1, 0)]
transform tooltip_follow:
events False
function tooltip_func
init python:
config.per_frame_screens.append("tooltip")
transform tooltip_follow(pos, anchor):
on start:
alpha 0.0
def tooltip_func(trans, st, at):
x, y = renpy.get_mouse_pos()
xanchor = 1.0 if (x > 980) else 0.0
yanchor = 1.0 if (y > 500) else 0.0
xoffset = 11 if xanchor else 0
yoffset = 14 if yanchor else 0
trans.pos = (x, y)
trans.anchor = (xanchor, yanchor)
trans.offset = (xoffset, yoffset)
on show:
anchor anchor
pos pos
linear 0.1 alpha 1.0
on hide:
linear 0.1 alpha 0.0
return 0