Skip to content

Commit

Permalink
feat(radar): improve checking when mouse is over radar area
Browse files Browse the repository at this point in the history
The 2D radar is trivial as it is a circle, but the 3D scanner is an
ellipse. For now we check if the mouse is in a rectangle surrounding
the scanner, which is an improvement but not a complete fix.

TODO: if the mouse leaves the radar area while the popup for selecting
between the radar modes is displayed, the popup disappears. The
mouse-area-check should be disabled while the popup is displayed.
  • Loading branch information
mwerle committed Nov 30, 2024
1 parent db4f213 commit 310ca8b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions data/pigui/modules/radar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,18 @@ local function displayRadar()
end

-- Handle mouse if it is in the radar area
local mp = ui.getMousePos()
-- TODO: adjust properly for 3D radar; bit more challenging as its an ellipse
if (mp - center):length() < radar2d.getRadius(radar2d) then
local isMouseOverRadar = function()
if shouldDisplay2DRadar then
local mp = ui.getMousePos()
return (mp - center):length() < radar2d.getRadius(radar2d)
end
return ui.isMouseHoveringRect(
Vector2(center.x - ui.reticuleCircleRadius * 0.9,
center.y - ui.reticuleCircleRadius * 0.7),
Vector2(center.x + ui.reticuleCircleRadius * 0.9,
center.y + ui.reticuleCircleRadius * 0.7))
end
if isMouseOverRadar() then
ui.popup("radarselector", function()
if ui.selectable(lui.HUD_2D_RADAR, shouldDisplay2DRadar, {}) then
toggle_radar = true
Expand Down

0 comments on commit 310ca8b

Please sign in to comment.