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,33 +4,13 @@ screen tooltip():
zorder 5 zorder 5
style_prefix "tooltip" style_prefix "tooltip"
default last_tooltip = "" $ tooltip = GetTooltip()
if settings.get("tooltip"): if settings.get("tooltip") and tooltip:
$ mouseclick = any(pygame.mouse.get_pressed()[:3]) window:
id tooltip
# Do not remove the empty string from the statement below, at tooltip_follow
# it is a rare case when the save file gets updated but the old tooltip text "[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
window:
id tooltip
at tooltip_follow((x+xoffset, y+yoffset), (xanchor, yanchor))
text "[tooltip]"
style tooltip_window is empty: style tooltip_window is empty:
background "#00000080" background "#00000080"
@ -42,17 +22,20 @@ style tooltip_text is default:
size 10 size 10
outlines [(1, "#00000080", 1, 0)] outlines [(1, "#00000080", 1, 0)]
transform tooltip_follow:
events False
function tooltip_func
init python: init python:
config.per_frame_screens.append("tooltip")
transform tooltip_follow(pos, anchor): def tooltip_func(trans, st, at):
on start: x, y = renpy.get_mouse_pos()
alpha 0.0 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: return 0
anchor anchor
pos pos
linear 0.1 alpha 1.0
on hide:
linear 0.1 alpha 0.0