Skip to content

Commit

Permalink
feat(radar): add tooltip for targets to scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
mwerle committed Nov 7, 2024
1 parent 9a8b0e1 commit d3be2fa
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions data/pigui/modules/radar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,21 @@ local function display2DRadar(cntr, size)
-- local textsize = ui.addStyledText(textcenter, ui.anchor.left, ui.anchor.bottom, distance, colors.frame, pionillium.small, lui.HUD_RADAR_DISTANCE, colors.lightBlackBackground)
end

-- Return tooltip for target
local function drawTarget(target, scale, center, color)
local pos = target.rel_position
local basePos = Vector2(pos.x * scale.x + center.x, pos.z * scale.y + center.y)
local blobPos = Vector2(basePos.x, basePos.y - pos.y * scale.y);
local blobHalfSize = Vector2(blobSize / 2)
local tooltip = {}

ui.addLine(basePos, blobPos, color:shade(0.1), 2)
ui.addRectFilled(blobPos - blobHalfSize, blobPos + blobHalfSize, color, 0, 0)
local mouse_position = ui.getMousePos()
if (mouse_position - blobPos):length() < 4 then
table.insert(tooltip, target.label)
end
return tooltip
end

local radar = require 'PiGui.Modules.RadarWidget'()
Expand All @@ -119,6 +126,7 @@ radar.maxZoom = MAX_RADAR_SIZE

local function display3DRadar(center, size)
local targets = ui.getTargetsNearby(MAX_RADAR_SIZE)
local tooltip = {}

local combatTarget = player:GetCombatTarget()
local navTarget = player:GetNavTarget()
Expand All @@ -144,7 +152,7 @@ local function display3DRadar(center, size)

if v.distance < current_radar_size and v.rel_position.y < 0.0 then
local color = (v.body == navTarget and colors.navTarget) or (v.body == combatTarget and colors.combatTarget) or getColorFor(v)
drawTarget(v, scale, center, color)
table.append(tooltip, drawTarget(v, scale, center, color))
end
end

Expand All @@ -161,10 +169,14 @@ local function display3DRadar(center, size)
for k, v in pairs(targets) do
if v.distance < current_radar_size and v.rel_position.y >= 0.0 then
local color = (v.body == navTarget and colors.navTarget) or (v.body == combatTarget and colors.combatTarget) or getColorFor(v)
drawTarget(v, scale, center, color)
table.append(tooltip, drawTarget(v, scale, center, color))
end
end

if #tooltip > 0 then
ui.setTooltip(table.concat(tooltip, "\n"))
end

-- handle automatic radar zoom based on player surroundings
if not manual_zoom then
local maxDist = maxBodyDist
Expand Down

0 comments on commit d3be2fa

Please sign in to comment.