Skip to content

Commit 744db2c

Browse files
committed
Display tooltips on highlighted mods in Manage Installed Mods
1 parent a0c6782 commit 744db2c

File tree

6 files changed

+141
-10
lines changed

6 files changed

+141
-10
lines changed

changelog.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ and only contains the latest changes.
33
Its purpose is to be shown in Olympus when updating.
44

55
#changelog#
6-
Touch-ups to French translation
6+
Display tooltips on highlighted mods in Manage Installed Mods

src/lang.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ Press the manage button below.]],
285285
Do you want to enable %s as well?]],
286286
mod1 = [[mod]],
287287
mods1 = [[mods]],
288+
tooltip_favorite = [[Favorite]],
289+
tooltip_dependency_of_favorite = [[Dependency of one of your favorites]],
290+
tooltip_dependency = [[Dependency of one of your enabled mods]],
288291
it = [[it]],
289292
them = [[them]],
290293
s_other_s_no_longer_required_for_any_ena = [[%s other %s no longer required for any enabled mod.
@@ -670,6 +673,9 @@ Appuie sur le bouton "Gérer" ci-dessous.]],
670673
Veux-tu aussi activer %s ?]],
671674
mod1 = [[mod non activé]],
672675
mods1 = [[mods non activés]],
676+
tooltip_favorite = [[Favori]],
677+
tooltip_dependency_of_favorite = [[Requis par l'un de tes mods favoris]],
678+
tooltip_dependency = [[Requis par l'un des mods que tu as activés]],
673679
it = [[celui-ci]],
674680
them = [[ceux-ci]],
675681
s_other_s_no_longer_required_for_any_ena = [[%s %s pour aucun mod activé.

src/main.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,9 @@ function love.load(args)
438438
interactive = -1
439439
}):with(function(el)
440440
table.remove(el.children, 1).parent = el
441-
end):as("logWindow")
441+
end):as("logWindow"),
442442

443+
require("tooltip").getTooltipWindow()
443444
}):with({
444445
style = {
445446
spacing = 0
@@ -903,6 +904,10 @@ function love.keypressed(key, scancode, isrepeat)
903904
error("SHIFT + F9")
904905
elseif love.keyboard.isDown("lctrl") or love.keyboard.isDown("rctrl") then
905906
sharp.crash()
907+
elseif love.keyboard.isDown("lalt") or love.keyboard.isDown("ralt") then
908+
threader.routine(function()
909+
error("You successfully killed the threader, good job!")
910+
end)
906911
else
907912
collectgarbage("collect")
908913
collectgarbage("collect")

src/scenes/modlist.lua

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,10 @@ local function getLabelTextFor(info)
184184
local themeColors = uie.modNameLabelColors().style
185185
local color = themeColors.normalColor
186186

187+
local tooltip = nil
187188
if info.IsFavorite then
188189
color = themeColors.favoriteColor
190+
tooltip = lang.get("tooltip_favorite")
189191
else
190192
local isDependencyOfFavorite = false
191193
local isDependency = false
@@ -202,12 +204,15 @@ local function getLabelTextFor(info)
202204

203205
if isDependencyOfFavorite then
204206
color = themeColors.dependencyOfFavoriteColor
207+
tooltip = lang.get("tooltip_dependency_of_favorite")
205208
elseif isDependency then
206209
color = themeColors.dependencyColor
210+
tooltip = lang.get("tooltip_dependency")
207211
end
208212
end
209213

210214
color = {color[1], color[2], color[3], info.IsBlacklisted and 0.5 or 1}
215+
tooltip = tooltip and { color, tooltip } or nil
211216

212217
if info.Name then
213218
if info.GameBananaTitle then
@@ -218,7 +223,7 @@ local function getLabelTextFor(info)
218223
info.GameBananaTitle .. "\n",
219224
themeColors.disabledColor,
220225
info.Name .. " " .. (info.Version or "?.?.?.?") .. "" .. fs.filename(info.Path)
221-
}
226+
}, tooltip
222227
else
223228
-- MaxHelpingHand
224229
-- 1.4.5 ∙ Filename.zip
@@ -227,7 +232,7 @@ local function getLabelTextFor(info)
227232
info.Name .. "\n",
228233
themeColors.disabledColor,
229234
(info.Version or "?.?.?.?") .. "" .. fs.filename(info.Path)
230-
}
235+
}, tooltip
231236
end
232237
else
233238
-- Filename.zip
@@ -236,7 +241,7 @@ local function getLabelTextFor(info)
236241
fs.filename(info.Path) .. "\n",
237242
themeColors.disabledColor,
238243
lang.get("no_mod_info_available")
239-
}
244+
}, tooltip
240245
end
241246
end
242247

@@ -282,7 +287,11 @@ local function findDependenciesToEnable(mod)
282287
end
283288

284289
local function updateLabelTextForMod(mod)
285-
mod.row:findChild("title"):setText(getLabelTextFor(mod.info))
290+
local label, tooltip = getLabelTextFor(mod.info)
291+
mod.row:findChild("title"):with({
292+
tooltipText = tooltip,
293+
interactive = tooltip and 1 or 0
294+
}):setText(label)
286295
end
287296

288297
local function updateLabelTextForDependencies(mod)
@@ -906,8 +915,12 @@ function scene.item(info)
906915
return nil
907916
end
908917

918+
local label, tooltip = getLabelTextFor(info)
909919
local item = uie.paneled.row({
910-
uie.label(getLabelTextFor(info)):as("title"),
920+
uie.label(label):with({
921+
tooltipText = tooltip,
922+
interactive = tooltip and 1 or 0
923+
}):as("title"),
911924

912925
uie.row({
913926
uie.warning(false, function(warning, newState)

src/threader.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ function threader.routine(fun, ...)
490490
return {fun(unpack(args))}
491491
end,
492492
function(err)
493-
logger.error(id, err)
493+
log.error(id, err)
494494
if type(err) == "userdata" or type(err) == "table" then
495495
return err
496496
end
@@ -533,9 +533,9 @@ function threader.update()
533533
if running then
534534
local status = coroutine.status(running.routine)
535535
if status ~= "running" then
536-
logger.warning("threader.update called from within a " .. (running.waiting and "waiting " or "") .. " ZOMBIE threader coroutine (" .. running.id .. ", " .. status .. "), possibly via a native callback during coroutine.yield")
536+
log.warning("threader.update called from within a " .. (running.waiting and "waiting " or "") .. " ZOMBIE threader coroutine (" .. running.id .. ", " .. status .. "), possibly via a native callback during coroutine.yield")
537537
else
538-
logger.warning("threader.update called from within a " .. (running.waiting and "waiting " or "") .. "threader coroutine (" .. running.id .. "), possibly via a native callback during coroutine.yield")
538+
log.warning("threader.update called from within a " .. (running.waiting and "waiting " or "") .. "threader coroutine (" .. running.id .. "), possibly via a native callback during coroutine.yield")
539539
end
540540
end
541541

src/tooltip.lua

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
-- adapted from the Lönn map editor, also based on OlympUI: https://github.com/CelestialCartographers/Loenn/blob/ui-olympUI/src/ui/tooltip.lua
2+
3+
local ui = require("ui")
4+
local uie = require("ui.elements")
5+
local uiu = require("ui.utils")
6+
7+
local log = require("logger")("tooltip")
8+
9+
local tooltipWaitDuration = 0.5
10+
local lastX, lastY = 0, 0
11+
local waitedDuration = 0
12+
13+
local targetElement
14+
local tooltipExists = false
15+
local tooltipWindow
16+
17+
local tooltipHandler = {}
18+
19+
local function getUsableSize()
20+
local root = ui.root
21+
return root.width - 32, root.height - 32
22+
end
23+
24+
local function moveWindow(window, newX, newY, clamp)
25+
local usableWidth, usableHeight = getUsableSize()
26+
local currentX, currentY = window.x, window.y
27+
28+
if clamp ~= false then
29+
newX = math.max(math.min(usableWidth - window.width + 16, newX), 16)
30+
newY = math.max(math.min(usableHeight - window.height + 16, newY), 16)
31+
end
32+
33+
if math.abs(currentX - newX) > 4 or math.abs(currentY - newY) > 4 then
34+
window.x = newX
35+
window.realX = newX
36+
window.y = newY
37+
window.realY = newY
38+
39+
if window.parent then
40+
window.parent:reflow()
41+
end
42+
43+
ui.root:recollect(false, true)
44+
end
45+
end
46+
47+
function tooltipHandler.tooltipWindowUpdate(orig, self, dt)
48+
orig(self, dt)
49+
50+
local cursorX, cursorY = love.mouse.getPosition()
51+
local hovered = ui.hovering
52+
local waitedEnough = waitedDuration >= tooltipWaitDuration
53+
54+
if not waitedEnough then
55+
if cursorX == lastX and cursorY == lastY then
56+
waitedDuration = waitedDuration + dt
57+
58+
else
59+
lastX, lastY = cursorX, cursorY
60+
waitedDuration = 0
61+
end
62+
end
63+
64+
if hovered ~= targetElement then
65+
waitedDuration = 0
66+
67+
if hovered then
68+
local tooltipText = rawget(hovered, "tooltipText")
69+
70+
if tooltipText then
71+
tooltipWindow.children[1]:setText(tooltipText)
72+
log.debug("Hovering over element with tooltip", tooltipText)
73+
end
74+
75+
targetElement = hovered
76+
tooltipExists = not not tooltipText
77+
78+
else
79+
targetElement = false
80+
tooltipExists = false
81+
end
82+
end
83+
84+
if tooltipExists and waitedEnough then
85+
moveWindow(tooltipWindow, cursorX, cursorY - tooltipWindow.height)
86+
87+
elseif tooltipWindow.x ~= -1024 or tooltipWindow.y ~= -1024 then
88+
moveWindow(tooltipWindow, -1024, -1024, false)
89+
end
90+
end
91+
92+
function tooltipHandler.getTooltipWindow()
93+
if not tooltipWindow then
94+
tooltipWindow = uie.panel({
95+
uie.label("Test")
96+
}):with({
97+
interactive = -2,
98+
updateHidden = true
99+
}):hook({
100+
update = tooltipHandler.tooltipWindowUpdate
101+
})
102+
end
103+
104+
return tooltipWindow
105+
end
106+
107+
return tooltipHandler

0 commit comments

Comments
 (0)