Skip to content

Commit

Permalink
Merge pull request #5948 from mwerle/feat/radar_autozoom
Browse files Browse the repository at this point in the history
Improvement: Radar auto-zoom on cargo cannisters
  • Loading branch information
Webster Sheets authored Nov 4, 2024
2 parents 628f39c + 60491c8 commit b15d937
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion data/pigui/modules/radar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ local function display3DRadar(center, size)
local navTarget = player:GetNavTarget()
local maxBodyDist = 0.0
local maxShipDist = 0.0
local maxCargoDist = 0.0

radar.size = size
radar.zoom = currentZoomDist
Expand All @@ -136,6 +137,9 @@ local function display3DRadar(center, size)
-- only snap to ships if they're less than 50km away (arbitrary constant based on crime range)
if v.body:IsShip() and v.distance < 50000 then maxShipDist = math.max(maxShipDist, v.distance) end

-- only snap to cargo containers if they're less than 25km away (arbitrary)
if v.body:IsCargoContainer() and v.distance < 25000 then maxCargoDist = math.max(maxCargoDist, v.distance) end

if v.distance < currentZoomDist 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)
Expand Down Expand Up @@ -165,6 +169,8 @@ local function display3DRadar(center, size)
maxDist = combatTarget:GetPositionRelTo(player):length() * 1.4
elseif maxShipDist > 0 then
maxDist = maxShipDist * 1.4
elseif maxCargoDist > 0 then
maxDist = maxCargoDist * 1.4
elseif navTarget then
local dist = navTarget:GetPositionRelTo(player):length()
maxDist = dist > MAX_RADAR_SIZE and maxBodyDist or dist * 1.4
Expand Down Expand Up @@ -233,6 +239,13 @@ require 'Serializer':Register("PiguiRadar",
function () return { shouldDisplay2DRadar = shouldDisplay2DRadar } end,
function (data) shouldDisplay2DRadar = data.shouldDisplay2DRadar end)

ui.registerModule("game", displayRadar)
ui.registerModule("game", {
id = "game-view-radar-module",
draw = displayRadar,
debugReload = function()
print("Radar module reloading..")
package.reimport()
end
})

return {}

0 comments on commit b15d937

Please sign in to comment.