Skip to content

Commit

Permalink
Merge pull request pioneerspacesim#5932 from mwerle/feat/scan_manager
Browse files Browse the repository at this point in the history
feat: fix completion display of scan manager
  • Loading branch information
Webster Sheets authored Oct 24, 2024
2 parents 9cf9a6b + b8d008b commit fe95f23
Show file tree
Hide file tree
Showing 23 changed files with 215 additions and 115 deletions.
16 changes: 16 additions & 0 deletions data/lang/core/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,22 @@
"description": "Mass unit: one petatonne",
"message": "Pt"
},
"UNIT_HECTARES": {
"description": "Area unit: one hectare (ha) -10,000 m²",
"message": "ha"
},
"UNIT_SQUARE_KILOMETERS": {
"description": "Area unit: square kilometer (km²) - 1,000,000 m²",
"message": "km²"
},
"UNIT_SQUARE_MEGAMETERS": {
"description": "Area unit: square megameter (Mm²) - 10^12 m²",
"message": "Mm²"
},
"UNIT_SQUARE_METERS": {
"description": "Area unit: square meter (m²)",
"message": ""
},
"UNIT_PRESSURE_ATMOSPHERES": {
"description": "Pressure unit: one earth atmosphere (atm)",
"message": "atm"
Expand Down
4 changes: 4 additions & 0 deletions data/lang/module-scout/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@
"description": "",
"message": "Danger:"
},
"DATA_COLLECTED_PROGRESS": {
"description": "Label for scan card progress bar",
"message": "Data Collected: {percent_completed}%"
},
"DEADLINE": {
"description": "",
"message": "Deadline:"
Expand Down
2 changes: 1 addition & 1 deletion data/libs/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ end
--
local object = {}

object.meta = { __index = object, class="object", inherits = { ["object"] = true } }
object.meta = { __index = object, class="object", inherits = { object = true } }

--
-- Function: New
Expand Down
29 changes: 20 additions & 9 deletions data/modules/Scout/ScanDisplay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -182,36 +182,45 @@ function scanDisplay:drawScanInfo(scan, isHighlighted)

-- displayed when the active scanner cannot carry out the scan
local altitude = string.upper(ls.INVALID_SCANNER)
local target = ""

local params = scanMgr:GetScanParameters(sBody, scan.minResolution, scan.orbital)
if params and params.canScan then
altitude = ui.Format.Distance(params.maxAltitude)
end

if scan.orbital then
target = string.format("%.1f%%", scan.targetCoverage * 100.0)
else
target = ui.Format.Distance(scan.targetCoverage * 1000.0, "%.1f")
end

local completion = math.min(1.0, scan.coverage / scan.targetCoverage)
local target = ui.Format.Area(scan.targetCoverage * 1e6)

local data = {
title = sBody.name .. ", " .. scan.bodyPath:GetStarSystem().name,
target = target,
completion = string.format("%2.1f%%", completion * 100.0),
completion = ui.Format.Area(scan.coverage * 1e6),
isActive = self.scanMgr:GetActiveScan() == scan,
scan = scan,
icon = scan.orbital and icons.map or icons.scanner,
{ icons.comms, target, ls.SCAN_TARGET_COVERAGE },
{ icons.scanner, ui.Format.Distance(scan.minResolution, "%.1f"), ls.SCAN_MAXIMUM_SPATIAL_RESOLUTION },
{ icons.altitude, altitude, ls.SCAN_MAXIMUM_ALTITUDE },
progress = (scan.targetCoverage / scan.coverage) * 100
}

return ScanCard:draw(data, isHighlighted)
end

---@param scan ScanData
function scanDisplay:drawScanProgress(scan)
local completion = math.min(1.0, scan.coverage / scan.targetCoverage)
local width = ui.getContentRegion().x
-- The default progress bar colour style is yellow which is very jarring
-- for this display. So instead lets use a more suitable colour style.
local progressBarColor = colors.uiPrimaryLight
local progressBarText = ls.DATA_COLLECTED_PROGRESS % {
percent_completed = string.format("%.2f", completion * 100.0)
}
ui.withStyleColors({ PlotHistogram = progressBarColor }, function()
ui.progressBar(completion, Vector2(width, 0), progressBarText)
end)
end

-- Return a sorted copy of the given scan list for display
---@param scanList ScanData[]
function scanDisplay:sortScanList(scanList)
Expand Down Expand Up @@ -283,6 +292,8 @@ function scanDisplay:drawBody()

if clicked then
self.scanMgr:ClearActiveScan()
else
self:drawScanProgress(activeScan)
end
else
self:drawEmptyActiveScan()
Expand Down
6 changes: 4 additions & 2 deletions data/modules/Scout/ScanGauge.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ local ls = Lang.GetResource('module-scout')
gauges.registerGauge(10, {
value = function()
local scanMgr = Game.player:GetComponent("ScanManager")

local scan = scanMgr and scanMgr:GetActiveScan()
if not scan then return nil end

Expand All @@ -24,5 +23,8 @@ gauges.registerGauge(10, {
end,
unit = '%', format = '%.2f', min = 0, max = 100,
icon = icons.scanner, color = colors.gaugeScanner,
tooltip = ls.HUD_SCAN_PROGRESS
tooltip = ls.HUD_SCAN_PROGRESS,
debugReload = function()
package.reimport()
end
})
20 changes: 8 additions & 12 deletions data/modules/Scout/ScanManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@ end
--=============================================================================

-- Update different scan types at different rates
-- TODO: these update rates cause excessive updates at high timewarp factors.
-- This especially impacts the Orbial Scans. It is proposed to replace
-- this mechanism with a timewarp-invariant timer instead.
-- See : https://github.com/pioneerspacesim/pioneer/pull/5932#discussion_r1800544550
local SURFACE_SCAN_UPDATE_RATE = 1
local ORBITAL_SCAN_UPDATE_RATE = 60
local ORBITAL_SCAN_UPDATE_RATE = 1

-- Square meters to square kilometers
local SQUARE_KILOMETERS = 10^6
Expand Down Expand Up @@ -595,17 +599,9 @@ function ScanManager:OnUpdateScan(scan)
local coverage
local beamWidth = self.activeSensor.apertureWidth * altitude

if scan.orbital then
-- percent of total coverage gained per orbit, calculated at the widest point of the body
local covPctPerOrbit = beamWidth / (radius * math.pi)
local orbitPercent = dS / (math.pi * 2)

coverage = covPctPerOrbit * orbitPercent
else
local distance = dS * radius
-- total coverage gain in square kilometers
coverage = beamWidth * distance / SQUARE_KILOMETERS
end
local distance = dS * radius
-- total coverage gain in square kilometers
coverage = beamWidth * distance / SQUARE_KILOMETERS

scan.coverage = scan.coverage + coverage

Expand Down
Loading

0 comments on commit fe95f23

Please sign in to comment.