From 310ca8b333bd7b3263b2c117b20a083fe8d7c6f3 Mon Sep 17 00:00:00 2001 From: Michael Werle Date: Mon, 25 Nov 2024 12:18:01 +0900 Subject: [PATCH] feat(radar): improve checking when mouse is over radar area 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. --- data/pigui/modules/radar.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/data/pigui/modules/radar.lua b/data/pigui/modules/radar.lua index 4bf2d8ecd3..7692140ba9 100644 --- a/data/pigui/modules/radar.lua +++ b/data/pigui/modules/radar.lua @@ -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