From 84886f71c634e8b15b74794c395479997845fc02 Mon Sep 17 00:00:00 2001 From: Michael Werle Date: Tue, 22 Oct 2024 16:17:58 +0900 Subject: [PATCH 1/7] refactor: don't quote table identifiers As per [this discussion](https://github.com/pioneerspacesim/pioneer/pull/5932#discussion_r1803793025), all instances of quoted table identifiers are replaced with the identifiers directly. --- data/libs/utils.lua | 2 +- data/modules/TradeShips/Debug.lua | 2 +- data/pigui/libs/commodity-market.lua | 2 +- data/pigui/libs/window-layout.lua | 4 ++-- data/pigui/modules/autopilot-window.lua | 2 +- data/pigui/modules/flight-ui/reticule.lua | 24 +++++++++---------- data/pigui/modules/fx-window.lua | 4 ++-- data/pigui/modules/hyperjump-planner.lua | 2 +- .../pigui/modules/new-game-window/widgets.lua | 2 +- data/pigui/modules/settings-window.lua | 12 +++++----- .../modules/station-view/06-shipRepairs.lua | 2 +- data/pigui/views/init.lua | 6 ++--- data/pigui/views/mainmenu.lua | 8 +++---- data/pigui/views/map-sector-view.lua | 2 +- data/pigui/views/tab-view.lua | 4 ++-- 15 files changed, 39 insertions(+), 39 deletions(-) diff --git a/data/libs/utils.lua b/data/libs/utils.lua index a30fc5f44ea..90088189692 100644 --- a/data/libs/utils.lua +++ b/data/libs/utils.lua @@ -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 diff --git a/data/modules/TradeShips/Debug.lua b/data/modules/TradeShips/Debug.lua index 3503d5e5c54..9bc4f3854f1 100644 --- a/data/modules/TradeShips/Debug.lua +++ b/data/modules/TradeShips/Debug.lua @@ -61,7 +61,7 @@ debugView.registerTab('debug-trade-ships', { draw = function() local function property(key, value) - ui.withStyleColors({["Text"] = ui.theme.colors.fontDark}, function() + ui.withStyleColors({Text = ui.theme.colors.fontDark}, function() ui.text(key) end) ui.sameLine() diff --git a/data/pigui/libs/commodity-market.lua b/data/pigui/libs/commodity-market.lua index 39b7489f426..1287b86e274 100644 --- a/data/pigui/libs/commodity-market.lua +++ b/data/pigui/libs/commodity-market.lua @@ -430,7 +430,7 @@ function CommodityMarketWidget:TradeMenu() if ui.button("+100", self.style.widgetSizes.smallButton) then self:ChangeTradeAmount(100) end ui.dummy(self.style.itemSpacing/2) - ui.withStyleColors({["Text"] = self.tradeTextColor }, function() + ui.withStyleColors({Text = self.tradeTextColor }, function() ui.withFont(pionillium.heading, function() ui.text(self.tradeText) end) diff --git a/data/pigui/libs/window-layout.lua b/data/pigui/libs/window-layout.lua index 2df105d172b..b052198922b 100644 --- a/data/pigui/libs/window-layout.lua +++ b/data/pigui/libs/window-layout.lua @@ -29,13 +29,13 @@ function layout.NewWindow(name, bgColor, flags) pos = Vector2(0.0, 0.0), visible = true, name = name, - style_colors = {["WindowBg"] = bgColor or ui.theme.colors.lightBlackBackground}, + style_colors = {WindowBg = bgColor or ui.theme.colors.lightBlackBackground}, params = flags or defaultWindowFlags, } --- func desc ---@param collapse boolean|nil If not present or true, collapse this window, else expand it function new_window:Collapse( collapse ) - if collapse == nil then collapse = true end + if collapse == nil then collapse = true end self.to_collapse = collapse end return new_window diff --git a/data/pigui/modules/autopilot-window.lua b/data/pigui/modules/autopilot-window.lua index 9eeaa68f3be..f2e8f445765 100644 --- a/data/pigui/modules/autopilot-window.lua +++ b/data/pigui/modules/autopilot-window.lua @@ -189,7 +189,7 @@ local speed_limiter = (function() local step = math.max(0.01, speed_limit / 1000 / 500) local value, changed - ui.withStyleColors( {["FrameBg"] = colors.uiBackground}, function() + ui.withStyleColors( {FrameBg = colors.uiBackground}, function() value, changed = ui.dragFloat("##speed_limiter_drag", speed_limit / 1000, step, 0.0, MAX_SPEED_LIMIT, "%.2f " .. lc.UNIT_KILOMETERS_PER_SECOND) end) if ui.isItemHovered() then diff --git a/data/pigui/modules/flight-ui/reticule.lua b/data/pigui/modules/flight-ui/reticule.lua index 0769ab3e4d4..f080a6d703b 100644 --- a/data/pigui/modules/flight-ui/reticule.lua +++ b/data/pigui/modules/flight-ui/reticule.lua @@ -462,24 +462,24 @@ local function displayManeuverData(radius) end local aicommand_info = { - ["CMD_DOCK"] = { icon = icons.autopilot_dock, tooltip = lui.HUD_BUTTON_AUTOPILOT_DOCKING }, - ["CMD_FLYTO"] = { icon = icons.autopilot_fly_to, tooltip = lui.HUD_BUTTON_AUTOPILOT_FLYING_TO_TARGET }, - ["CMD_FORMATION"] = { icon = icons.autopilot_fly_to, tooltip = lui.HUD_BUTTON_AUTOPILOT_FLYING_TO_TARGET }, - ["CMD_FLYAROUND"] = { icon = icons.autopilot_medium_orbit, tooltip = lui.HUD_BUTTON_AUTOPILOT_ENTERING_ORBIT }, + CMD_DOCK = { icon = icons.autopilot_dock, tooltip = lui.HUD_BUTTON_AUTOPILOT_DOCKING }, + CMD_FLYTO = { icon = icons.autopilot_fly_to, tooltip = lui.HUD_BUTTON_AUTOPILOT_FLYING_TO_TARGET }, + CMD_FORMATION = { icon = icons.autopilot_fly_to, tooltip = lui.HUD_BUTTON_AUTOPILOT_FLYING_TO_TARGET }, + CMD_FLYAROUND = { icon = icons.autopilot_medium_orbit, tooltip = lui.HUD_BUTTON_AUTOPILOT_ENTERING_ORBIT }, } local flightstate_info = { - ["CONTROL_MANUAL"] = { icon = icons.empty, tooltip = lui.HUD_BUTTON_MANUAL_CONTROL }, + CONTROL_MANUAL = { icon = icons.empty, tooltip = lui.HUD_BUTTON_MANUAL_CONTROL }, -- "CONTROL_AUTOPILOT" - depends on the current command -- "CONTROL_FIXSPEED" - depends on the cruise mode - ["CONTROL_FIXHEADING_FORWARD"] = { icon = icons.prograde_thin, tooltip = lui.HUD_BUTTON_FIX_PROGRADE }, - ["CONTROL_FIXHEADING_BACKWARD"] = { icon = icons.retrograde_thin , tooltip = lui.HUD_BUTTON_FIX_RETROGRADE }, - ["CONTROL_FIXHEADING_NORMAL"] = { icon = icons.normal_thin, tooltip = lui.HUD_BUTTON_FIX_NORMAL }, - ["CONTROL_FIXHEADING_ANTINORMAL"] = { icon = icons.antinormal_thin, tooltip = lui.HUD_BUTTON_FIX_ANTINORMAL }, - ["CONTROL_FIXHEADING_RADIALLY_INWARD"] = { icon = icons.radial_in_thin, tooltip = lui.HUD_BUTTON_FIX_RADIAL_IN }, - ["CONTROL_FIXHEADING_RADIALLY_OUTWARD"] = { icon = icons.radial_out_thin, tooltip = lui.HUD_BUTTON_FIX_RADIAL_OUT }, + CONTROL_FIXHEADING_FORWARD = { icon = icons.prograde_thin, tooltip = lui.HUD_BUTTON_FIX_PROGRADE }, + CONTROL_FIXHEADING_BACKWARD = { icon = icons.retrograde_thin , tooltip = lui.HUD_BUTTON_FIX_RETROGRADE }, + CONTROL_FIXHEADING_NORMAL = { icon = icons.normal_thin, tooltip = lui.HUD_BUTTON_FIX_NORMAL }, + CONTROL_FIXHEADING_ANTINORMAL = { icon = icons.antinormal_thin, tooltip = lui.HUD_BUTTON_FIX_ANTINORMAL }, + CONTROL_FIXHEADING_RADIALLY_INWARD = { icon = icons.radial_in_thin, tooltip = lui.HUD_BUTTON_FIX_RADIAL_IN }, + CONTROL_FIXHEADING_RADIALLY_OUTWARD = { icon = icons.radial_out_thin, tooltip = lui.HUD_BUTTON_FIX_RADIAL_OUT }, -- "CONTROL_FIXHEADING_KILLROT" uses the same icon as rotation damping on - ["CONTROL_FIXHEADING_KILLROT"] = { icon = icons.rotation_damping_on , tooltip = lui.HUD_BUTTON_KILL_ROTATION } + CONTROL_FIXHEADING_KILLROT = { icon = icons.rotation_damping_on , tooltip = lui.HUD_BUTTON_KILL_ROTATION } } local radial_menu_actions_orbital = { diff --git a/data/pigui/modules/fx-window.lua b/data/pigui/modules/fx-window.lua index 4da8d86ec9c..57d8a050d93 100644 --- a/data/pigui/modules/fx-window.lua +++ b/data/pigui/modules/fx-window.lua @@ -12,8 +12,8 @@ local icons = ui.theme.icons local mainButtonSize = ui.theme.styles.MainButtonSize -local next_cam_type = { ["internal"] = "external", ["external"] = "sidereal", ["sidereal"] = "internal", ["flyby"] = "internal" } -local cam_tooltip = { ["internal"] = lui.HUD_BUTTON_INTERNAL_VIEW, ["external"] = lui.HUD_BUTTON_EXTERNAL_VIEW, ["sidereal"] = lui.HUD_BUTTON_SIDEREAL_VIEW, ["flyby"] = lui.HUD_BUTTON_FLYBY_VIEW } +local next_cam_type = { internal = "external", external = "sidereal", sidereal = "internal", flyby = "internal" } +local cam_tooltip = { internal = lui.HUD_BUTTON_INTERNAL_VIEW, external = lui.HUD_BUTTON_EXTERNAL_VIEW, sidereal = lui.HUD_BUTTON_SIDEREAL_VIEW, flyby = lui.HUD_BUTTON_FLYBY_VIEW } local function button_world(current_view) local camtype = Game.GetWorldCamType() local view_icon = camtype and "view_" .. camtype or "view_internal" diff --git a/data/pigui/modules/hyperjump-planner.lua b/data/pigui/modules/hyperjump-planner.lua index 01f36d99e4f..5dcb46c01ad 100644 --- a/data/pigui/modules/hyperjump-planner.lua +++ b/data/pigui/modules/hyperjump-planner.lua @@ -229,7 +229,7 @@ local function showJumpRoute() local clicked ui.child("routelist", function() for jumpIndex, jump in pairs(hyperjump_route) do - ui.withStyleColors({["Text"] = jump.color}, function() + ui.withStyleColors({Text = jump.color}, function() if ui.selectable(jump.textLine, jumpIndex == selected_jump) then clicked = jumpIndex end diff --git a/data/pigui/modules/new-game-window/widgets.lua b/data/pigui/modules/new-game-window/widgets.lua index f1e8622f0b4..d03ab188ac6 100644 --- a/data/pigui/modules/new-game-window/widgets.lua +++ b/data/pigui/modules/new-game-window/widgets.lua @@ -140,7 +140,7 @@ Widgets.incrementDrag = function(lock, label, value, v_speed, v_min, v_max, form local indent = (itemWidth - txtWidth) * 0.5 local cur = ui.getCursorPos() if draw_progress_bar then - ui.withStyleColors({ ["PlotHistogram"] = Defs.progressBarColor }, function() + ui.withStyleColors({ PlotHistogram = Defs.progressBarColor }, function() ui.progressBar((value - v_min) / (v_max - v_min), Vector2(0,0), "") end) else diff --git a/data/pigui/modules/settings-window.lua b/data/pigui/modules/settings-window.lua index cafd582697c..c1dfeb7348c 100644 --- a/data/pigui/modules/settings-window.lua +++ b/data/pigui/modules/settings-window.lua @@ -39,7 +39,7 @@ local starFieldStarSizeFactor = Engine.GetStarFieldStarSizeFactor() * 100 local function combo(label, selected, items, tooltip) local color = colors.buttonBlue local changed, ret = 0, nil - ui.withStyleColors({["Button"]=color,["ButtonHovered"]=color:tint(0.1),["ButtonActive"]=color:tint(0.2)},function() + ui.withStyleColors({Button=color,ButtonHovered=color:tint(0.1),ButtonActive=color:tint(0.2)},function() changed, ret = ui.combo(label, selected, items) end) if ui.isItemHovered() and tooltip then @@ -648,11 +648,11 @@ local function showGameOptions() end local optionsTabs = { - ["video"]=showVideoOptions, - ["sound"]=showSoundOptions, - ["language"]=showLanguageOptions, - ["controls"]=showControlsOptions, - ["game"]=showGameOptions + video=showVideoOptions, + sound=showSoundOptions, + language=showLanguageOptions, + controls=showControlsOptions, + game=showGameOptions } ui.optionsWindow = ModalWindow.New("Options", function() diff --git a/data/pigui/modules/station-view/06-shipRepairs.lua b/data/pigui/modules/station-view/06-shipRepairs.lua index 10f3802d27b..5d4d1818dca 100644 --- a/data/pigui/modules/station-view/06-shipRepairs.lua +++ b/data/pigui/modules/station-view/06-shipRepairs.lua @@ -327,7 +327,7 @@ local function drawPaintshop() ui.dummy(verticalDummy) - ui.withStyleColors({["Text"] = priceColor }, function() + ui.withStyleColors({Text = priceColor }, function() ui.text(l.PRICE.. ": " ..Format.Money(price, false)) end) if ui.button(l.PURCHASE_PAINTJOB, Vector2(200, 36)) then diff --git a/data/pigui/views/init.lua b/data/pigui/views/init.lua index 3f4ca984264..42b606bc810 100644 --- a/data/pigui/views/init.lua +++ b/data/pigui/views/init.lua @@ -25,7 +25,7 @@ ui.registerHandler( ui.setNextWindowPos(Vector2(ui.screenWidth / 2 - window_width / 2, ui.screenHeight/3*2), "Always") ui.setNextWindowSize(Vector2(window_width,200), "Always") ui.withFont("orbiteer", 18, function() - ui.withStyleColors( {["WindowBg"] = transparent }, function () + ui.withStyleColors( {WindowBg = transparent }, function () ui.window("test", {"NoTitleBar", "NoResize", "NoMove"}, function() local age = string.format("%.1f", 13.7 * progress) local agestring = string.interp(lui.SIMULATING_UNIVERSE_EVOLUTION_N_BYEARS, { age = age }) @@ -36,7 +36,7 @@ ui.registerHandler( ui.dummy(Vector2(15,15)) - ui.withStyleColors({ ["PlotHistogram"] = highlight, ["FrameBg"] = base }, function() + ui.withStyleColors({ PlotHistogram = highlight, FrameBg = base }, function() ui.progressBar(progress, Vector2(window_width - 20, ui.screenHeight / 43), "") -- 1080 / 43 -> 25 end) end) @@ -46,7 +46,7 @@ ui.registerHandler( local leftup = Vector2(ui.screenWidth/2 - logosize/2, ui.screenHeight/7) ui.setNextWindowPos(leftup, "Always") ui.setNextWindowSize(Vector2(logosize, logosize), "Always") - ui.withStyleColors( {["WindowBg"] = transparent }, function () + ui.withStyleColors( {WindowBg = transparent }, function () ui.window("logo", {"NoTitleBar", "NoResize", "NoMove"}, function () local size = Vector2(logosize,logosize) local pos = Vector2(0,0) -- Vector2(ui.screenWidth / 2, ui.screenHeight / 3 * 2) diff --git a/data/pigui/views/mainmenu.lua b/data/pigui/views/mainmenu.lua index c2356cc9107..088222b0a07 100644 --- a/data/pigui/views/mainmenu.lua +++ b/data/pigui/views/mainmenu.lua @@ -137,7 +137,7 @@ local function showMainMenu() local winPos = Vector2(ui.screenWidth - mainButtonSize.x - 100, ui.screenHeight/2 - (buttons * mainButtonSize.y)/2 - (2*mainButtonSize.y)/2 - 8) ui.setNextWindowPos(Vector2(110,65),'Always') - ui.withStyleColors({["WindowBg"]=colors.transparent}, function() + ui.withStyleColors({WindowBg=colors.transparent}, function() ui.window("headingWindow", overlayWindowFlags, function() ui.withFont(orbiteer.xlarge, function() ui.text("Pioneer") end) end) @@ -145,7 +145,7 @@ local function showMainMenu() if Engine.IsIntroZooming() then ui.setNextWindowPos(Vector2(0,0),'Always') ui.setNextWindowSize(Vector2(ui.screenWidth, ui.screenHeight), 'Always') - ui.withStyleColors({["WindowBg"]=colors.transparent}, function() + ui.withStyleColors({WindowBg=colors.transparent}, function() ui.window("shipinfoWindow", overlayWindowFlags, function() local mn = Engine.GetIntroCurrentModelName() if mn then @@ -162,7 +162,7 @@ local function showMainMenu() ui.withFont(orbiteer.medium, function() ui.setNextWindowPos(Vector2(ui.screenWidth - ui.calcTextSize(build_text).x * 1.2,ui.screenHeight - 50), 'Always') - ui.withStyleColors({["WindowBg"] = colors.transparent}, function() + ui.withStyleColors({WindowBg = colors.transparent}, function() ui.window("buildLabel", overlayWindowFlags, function() ui.text(build_text) end) @@ -171,7 +171,7 @@ local function showMainMenu() ui.setNextWindowPos(winPos,'Always') ui.setNextWindowSize(Vector2(0,0), 'Always') - ui.withStyleColors({["WindowBg"] = colors.lightBlackBackground}, function() + ui.withStyleColors({WindowBg = colors.lightBlackBackground}, function() ui.window("MainMenuButtons", mainMenuFlags, function() mainTextButton(lui.CONTINUE_GAME, nil, showContinue, continueGame) diff --git a/data/pigui/views/map-sector-view.lua b/data/pigui/views/map-sector-view.lua index b4d62089e5a..50a5cb60f65 100644 --- a/data/pigui/views/map-sector-view.lua +++ b/data/pigui/views/map-sector-view.lua @@ -410,7 +410,7 @@ function Windows.factions.Show() local factions = sectorView:GetMap():GetFactions() for _,f in pairs(factions) do local changed, value - ui.withStyleColors({ ["Text"] = Color(f.faction.colour.r, f.faction.colour.g, f.faction.colour.b) }, function() + ui.withStyleColors({ Text = Color(f.faction.colour.r, f.faction.colour.g, f.faction.colour.b) }, function() changed, value = ui.checkbox(f.faction.name, f.visible) end) if changed then diff --git a/data/pigui/views/tab-view.lua b/data/pigui/views/tab-view.lua index 858eb170d7e..f06764bf154 100644 --- a/data/pigui/views/tab-view.lua +++ b/data/pigui/views/tab-view.lua @@ -113,8 +113,8 @@ function PiGuiTabView.renderTabView(self) end local styleColors = { - ["WindowBg"] = colors.windowBackground, - ["Border"] = colors.windowFrame, + WindowBg = colors.windowBackground, + Border = colors.windowFrame, } local styleVars = { WindowRounding = 0, From 6d408ab0d802f8bf1bacd69883e9001be460291a Mon Sep 17 00:00:00 2001 From: Michael Werle Date: Tue, 15 Oct 2024 01:48:58 +0900 Subject: [PATCH 2/7] feat: add area formatter and descriptions --- data/lang/core/en.json | 16 ++++++++++++++++ data/pigui/libs/text.lua | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/data/lang/core/en.json b/data/lang/core/en.json index ad2b64753ab..2b2a8deeedc 100644 --- a/data/lang/core/en.json +++ b/data/lang/core/en.json @@ -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": "m²" + }, "UNIT_PRESSURE_ATMOSPHERES": { "description": "Pressure unit: one earth atmosphere (atm)", "message": "atm" diff --git a/data/pigui/libs/text.lua b/data/pigui/libs/text.lua index cc1bc7eb0fa..76270555a93 100644 --- a/data/pigui/libs/text.lua +++ b/data/pigui/libs/text.lua @@ -339,6 +339,42 @@ ui.Format = { Volume = function(number, places) return ui.Format.Number(number, places or 1) .. lc.UNIT_CUBIC_METERS end, + -- Format an Area quantity, scaling from square meters to square megameters + -- Returns the formatted value, the units, and the number of digits following the decimal point + AreaUnit= function(area, digits) + local a = math.abs(area) + local d = 0 + local u = lc.UNIT_SQUARE_METERS + local div = 1 + if a < 1e2 then + d = 2 + u = lc.UNIT_SQUARE_METERS + elseif a < 1e4 then + d = 0 + u = lc.UNIT_SQUARE_METERS + elseif a < 1e8 then + d = 2 + u = lc.UNIT_SQUARE_KILOMETERS + div = 1e6 + elseif a < 1e10 then + d = 0 + u = lc.UNIT_SQUARE_KILOMETERS + div = 1e6 + elseif a < 1e14 then + d = 2 + u = lc.UNIT_SQUARE_MEGAMETERS + div = 1e12 + else + d = 0 + u = lc.UNIT_SQUARE_MEGAMETERS + div = 1e12 + end + return ui.Format.Number(area / div, digits or d), u + end, + Area = function(area, digits) + local a, u = ui.Format.AreaUnit(area, digits) + return a .. ' ' .. u + end, SystemPath = function(path) local sectorString = "("..path.sectorX..", "..path.sectorY..", "..path.sectorZ..")" if path:IsSectorPath() then From e31f128c10896a72a5817b46c45707e4a2c6d6cc Mon Sep 17 00:00:00 2001 From: Michael Werle Date: Wed, 9 Oct 2024 08:23:50 +0900 Subject: [PATCH 3/7] feat: implemenent onDebugReload for ScanGauge Other gauges reload as part of the gauges module, but the ScanGuage does not as it's implemented in a different module. This commit adds an option 'onDebugReload' member to all guages, and the gauges module now invokes it if it is implemented. The ScanGauge is now properly reloaded when the Lua debug reload keystroke is invoked. --- data/modules/Scout/ScanGauge.lua | 8 ++++++-- data/pigui/modules/flight-ui/gauges.lua | 13 ++++++++++++- data/pigui/views/game.lua | 2 ++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/data/modules/Scout/ScanGauge.lua b/data/modules/Scout/ScanGauge.lua index 13e89833ee3..b0197b7dc8c 100644 --- a/data/modules/Scout/ScanGauge.lua +++ b/data/modules/Scout/ScanGauge.lua @@ -12,10 +12,13 @@ local colors = ui.theme.colors local ls = Lang.GetResource('module-scout') +local function onDebugReload() + package.reimport() +end + gauges.registerGauge(10, { value = function() local scanMgr = Game.player:GetComponent("ScanManager") - local scan = scanMgr and scanMgr:GetActiveScan() if not scan then return nil end @@ -24,5 +27,6 @@ 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 = onDebugReload, }) diff --git a/data/pigui/modules/flight-ui/gauges.lua b/data/pigui/modules/flight-ui/gauges.lua index 825acedd092..82a3e9460a6 100644 --- a/data/pigui/modules/flight-ui/gauges.lua +++ b/data/pigui/modules/flight-ui/gauges.lua @@ -111,10 +111,21 @@ gauges.registerGauge(5, { icon = icons.hull, color = colors.gaugeHull, tooltip = lui.HUD_HULL_STRENGTH }) +local function onDebugReload() + package.reimport() + + -- invoke debugReload for all gauages; required for gauges not defined in this file + for i,v in ipairs(gauges) do + if v.debugReload then + v.debugReload() + end + end +end + gameView.registerHudModule("gauges", { side = "left", showInHyperspace = false, - debugReload = function() package.reimport() end, + debugReload = onDebugReload, draw = function(_, min, max) colors = ui.theme.colors icons = ui.theme.icons diff --git a/data/pigui/views/game.lua b/data/pigui/views/game.lua index cb2efa74084..780b722b7b9 100644 --- a/data/pigui/views/game.lua +++ b/data/pigui/views/game.lua @@ -309,6 +309,8 @@ ui.registerHandler('game', function(delta_t) debugReload(gameView.modules) debugReload(gameView.hudModules) debugReload(gameView.sidebarModules) + + Event.Queue("onDebugReload"); end end) From ef9255e93c7dcecdbc46381cf92cea2d0a297deb Mon Sep 17 00:00:00 2001 From: Michael Werle Date: Tue, 15 Oct 2024 01:51:10 +0900 Subject: [PATCH 4/7] feat(scout): Scan manager use square kilometres for completion The Scan manager used by Scout missions shows the completion percentage of the current scan target while performing a scan. This is potentially confusing for players when performing orbital scan missions which require less than 100% of the planet to be scanned. For example, the mission might request that 42% of the target planet needs to be scanned, but the completion percentage always goes from 0..100% - confusing the player when it goes past 42%. Surface scan missions do not have this issue as the scan target is displayed in kilometres, so having a 0..100% completion is understandable. This change modifies both displays to show both the scan target as well as the completion in square kilometres, eliminating the potentially confusing percentages. It also adds a progress bar for the currently active scan. This is to both show a more intuitive way to show to the player how far along they are in completing the scan target, as well as to provide faster feedback as the current completion amount can be slow to update. While these changes should not have impacted the time required to complete a mission, additional play-testing is required to compare the changes against the original implementation and ensure that all missions remain achievable. Also tweak the reward calculations and parameters following these changes as suggested by Web-eWorks. --- data/lang/module-scout/en.json | 4 +++ data/modules/Scout/ScanDisplay.lua | 29 +++++++++++++++------- data/modules/Scout/ScanGauge.lua | 8 +++--- data/modules/Scout/ScanManager.lua | 20 ++++++--------- data/modules/Scout/Scout.lua | 39 ++++++++++++++++++------------ data/pigui/views/game.lua | 2 -- 6 files changed, 59 insertions(+), 43 deletions(-) diff --git a/data/lang/module-scout/en.json b/data/lang/module-scout/en.json index 55ea7601328..b34e3e136cb 100644 --- a/data/lang/module-scout/en.json +++ b/data/lang/module-scout/en.json @@ -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:" diff --git a/data/modules/Scout/ScanDisplay.lua b/data/modules/Scout/ScanDisplay.lua index fc40c29ff65..fdb2b88f08b 100644 --- a/data/modules/Scout/ScanDisplay.lua +++ b/data/modules/Scout/ScanDisplay.lua @@ -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) @@ -283,6 +292,8 @@ function scanDisplay:drawBody() if clicked then self.scanMgr:ClearActiveScan() + else + self:drawScanProgress(activeScan) end else self:drawEmptyActiveScan() diff --git a/data/modules/Scout/ScanGauge.lua b/data/modules/Scout/ScanGauge.lua index b0197b7dc8c..36252e994fb 100644 --- a/data/modules/Scout/ScanGauge.lua +++ b/data/modules/Scout/ScanGauge.lua @@ -12,10 +12,6 @@ local colors = ui.theme.colors local ls = Lang.GetResource('module-scout') -local function onDebugReload() - package.reimport() -end - gauges.registerGauge(10, { value = function() local scanMgr = Game.player:GetComponent("ScanManager") @@ -28,5 +24,7 @@ gauges.registerGauge(10, { unit = '%', format = '%.2f', min = 0, max = 100, icon = icons.scanner, color = colors.gaugeScanner, tooltip = ls.HUD_SCAN_PROGRESS, - debugReload = onDebugReload, + debugReload = function() + package.reimport() + end }) diff --git a/data/modules/Scout/ScanManager.lua b/data/modules/Scout/ScanManager.lua index 86697fa40e8..fbc26d9f456 100644 --- a/data/modules/Scout/ScanManager.lua +++ b/data/modules/Scout/ScanManager.lua @@ -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 @@ -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 diff --git a/data/modules/Scout/Scout.lua b/data/modules/Scout/Scout.lua index c340fbc6a74..7137e0039d0 100644 --- a/data/modules/Scout/Scout.lua +++ b/data/modules/Scout/Scout.lua @@ -43,17 +43,17 @@ local orbital_params = { resolution_min = 35, -- scan coverage values generated, relative to the nominal radius - coverage_max = 0.8, - coverage_min = 0.1, + coverage_max = 0.08, + coverage_min = 0.01, -- approximate "normal" body radius used to scale coverage to the body being scanned nominal_radius = 2500, -- reward per kilometer-width of body coverage - reward_per_km = 0.08, + reward_per_km = 0.11, -- reward scaling by resolution reward_resolution_max = 1.0, - reward_resolution_min = 8.0, + reward_resolution_min = 12.0, } local surface_params = { @@ -169,8 +169,8 @@ local ads = {} local missions = {} local missionKey = {} -local format_coverage = function(orbital, val) - return orbital and string.format("%.2f%%", val * 100) or ui.Format.Distance(val * 1000) +local format_coverage = function(val) + return ui.Format.Area(val * 1e6) end local format_resolution = function(val) @@ -226,7 +226,7 @@ local onChat = function (form, ref, option) elseif option == 4 then local details = l.SCAN_DETAILS % { - coverage = format_coverage(ad.orbital, ad.coverage), + coverage = format_coverage(ad.coverage), resolution = string.format("%.1f", ad.resolution), body = ad.location:GetSystemBody().name, type = ad.orbital and l.AN_ORBITAL_SCAN or l.A_SURFACE_SCAN @@ -303,24 +303,30 @@ local function calcOrbitalScanMission(sBody, difficulty, reward) local resolutionScalar = math.invlerp(p.resolution_min, p.resolution_max, resolution) + local body_coverage = coverage if radiusScalar > 1.0 then -- body is small, increase coverage of the scan - coverage = math.min(coverage, 1.0) * (radiusScalar ^ 0.9) + body_coverage = math.min(coverage, 1.0) * (radiusScalar ^ 0.9) else -- body is large, reduce coverage of the scan proportionally - coverage = math.min(coverage, 1.0) * radiusScalar + body_coverage = math.min(coverage, 1.0) * radiusScalar -- similarly increase the resolution of the scan to ensure we can scan at higher altitudes resolution = resolution * (1.0 + math.log(radiusKm / p.nominal_radius, 10)) end - coverage = math.min(coverage * realDifficulty, 1.0) + -- adjust coverage against difficulty and clamp to a maximum of 100% + body_coverage = math.min(body_coverage * realDifficulty, 1.0) + + -- finally, convert the coverage into km2 and limit the number of decimals + local body_area = 4 * math.pi * radiusKm^2 + local coverageKm2 = utils.round(body_area * body_coverage, 0.0001) local rewardAmount = reward - * p.reward_per_km * (math.pi * radiusKm * coverage) + * p.reward_per_km * math.sqrt(coverageKm2) * math.lerp(p.reward_resolution_min, p.reward_resolution_max, resolutionScalar) return { - coverage = coverage, + coverage = coverageKm2, minResolution = resolution, reward = rewardAmount } @@ -365,8 +371,11 @@ local function calcSurfaceScanMission(sBody, difficulty, reward) + p.reward_interesting * bodyReward + -- finally, convert the coverage into km2 and limit the number of decimals + local coverageKm2 = utils.round(coverage, 0.0001) + return { - coverage = coverage, + coverage = coverageKm2, minResolution = resolution, reward = rewardAmount, } @@ -658,7 +667,7 @@ local onShipDocked = function (player, station) mission.status = "FAILED" end - if station.path == mission.location and mission.status == "FAILED" or mission.status == "COMPLETED" then + if station.path == mission.station and mission.status == "FAILED" or mission.status == "COMPLETED" then local flavour = flavours[mission.flavour] local failed = mission.status == "FAILED" local scan = scanMgr:AcceptScanComplete(mission.scanId) @@ -775,7 +784,7 @@ local buildMissionDescription = function (mission) {l.DISTANCE, dist .. lc.UNIT_LY}, {l.DEADLINE, Format.Date(mission.due)}, {luc.TYPE..":", mission.orbital and l.ORBITAL_SCAN or l.SURFACE_SCAN}, - {l.COVERAGE, format_coverage(mission.orbital, mission.coverage) }, + {l.COVERAGE, format_coverage(mission.coverage) }, {l.RESOLUTION, format_resolution(mission.resolution) }, {luc.STATUS, luc[mission.status]}, } diff --git a/data/pigui/views/game.lua b/data/pigui/views/game.lua index 780b722b7b9..cb2efa74084 100644 --- a/data/pigui/views/game.lua +++ b/data/pigui/views/game.lua @@ -309,8 +309,6 @@ ui.registerHandler('game', function(delta_t) debugReload(gameView.modules) debugReload(gameView.hudModules) debugReload(gameView.sidebarModules) - - Event.Queue("onDebugReload"); end end) From 4dba12a9fb35c8a962b12e7a43c1f998ee30de66 Mon Sep 17 00:00:00 2001 From: Michael Werle Date: Thu, 10 Oct 2024 13:00:21 +0900 Subject: [PATCH 5/7] fix(scout): Scout missions completing at any station The check to see whether the mission can be completed had a bad logical operation and completed the first time the player docks anywhere. This fixes the check and missions now complete as expected only when the player returns to the station at which the mission was issued. --- data/modules/Scout/Scout.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/modules/Scout/Scout.lua b/data/modules/Scout/Scout.lua index 7137e0039d0..49b3e428b63 100644 --- a/data/modules/Scout/Scout.lua +++ b/data/modules/Scout/Scout.lua @@ -667,7 +667,7 @@ local onShipDocked = function (player, station) mission.status = "FAILED" end - if station.path == mission.station and mission.status == "FAILED" or mission.status == "COMPLETED" then + if station.path == mission.station and (mission.status == "FAILED" or mission.status == "COMPLETED") then local flavour = flavours[mission.flavour] local failed = mission.status == "FAILED" local scan = scanMgr:AcceptScanComplete(mission.scanId) From 6db624efc5195d9f08f66409b8420c53d366f755 Mon Sep 17 00:00:00 2001 From: Michael Werle Date: Tue, 15 Oct 2024 01:06:32 +0900 Subject: [PATCH 6/7] feat(scout): improve return location for scan missions Set the "desc.returnLocation" field on mission completion to show the "Set Return Route" button once the mission is finished, and continue to show the mission description. Also show the return location, if known, as part of the mission description. TODO: Further improve the display by breaking out the return location text based on whether "dropoff" is set. --- data/modules/Scout/Scout.lua | 67 ++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/data/modules/Scout/Scout.lua b/data/modules/Scout/Scout.lua index 49b3e428b63..608a374bf5d 100644 --- a/data/modules/Scout/Scout.lua +++ b/data/modules/Scout/Scout.lua @@ -643,14 +643,14 @@ local onScanComplete = function (player, scanId) Comms.ImportantMessage(l.YOU_WILL_BE_PAID_ON_MY_BEHALF_AT_NEW_DESTINATION, mission.client.name) end + mission.station = newlocation end - mission.location = newlocation - - if Game.system and mission.location:IsSameSystem(Game.system.path) then - Game.player:SetNavTarget(mission.location) + -- Set navigation target to the station + if Game.system and mission.station:IsSameSystem(Game.system.path) then + Game.player:SetNavTarget(mission.station) else - Game.player:SetHyperspaceTarget(mission.location:SystemOnly()) + Game.player:SetHyperspaceTarget(mission.station:SystemOnly()) end end @@ -746,41 +746,33 @@ end local buildMissionDescription = function (mission) local desc = {} local dist = Game.system and string.format("%.2f", Game.system:DistanceTo(mission.location)) or "???" - local finished = mission.status == "COMPLETED" or mission.status == "FAILED" - - -- Main body intro text - if finished then - desc.description = string.interp(l.DROP_OFF_DATA, - {date = Format.Date(mission.due), - location = mission.location:GetSystemBody().name}) - else - desc.description = - flavours[mission.flavour].introtext:interp( - { - name = mission.client.name, - systembody = mission.location:GetSystemBody().name, - system = ui.Format.SystemPath(mission.location:SystemOnly()), - dist = dist, - cash = Format.Money(mission.reward), - }) - desc.location = mission.location + local returnLocationDesc = "" + + if finished or not mission.dropoff or flavours[mission.flavour].localscout then + returnLocationDesc = "\n\n" .. string.interp(l.DROP_OFF_DATA, + { + date = Format.Date(mission.due), + location = mission.station:GetSystemBody().name + .. "," .. mission.station:GetStarSystem().name + }) end - desc.client = mission.client - local coordinates = "("..mission.location.sectorX.."," - ..mission.location.sectorY.."," - ..mission.location.sectorZ..")" - - -- station is shown for return station, after mission is completed - local destination = not finished and - { l.TARGET_BODY, mission.location:GetSystemBody().name } or - { l.DESTINATION, mission.location:GetSystemBody().name } + desc.description = + flavours[mission.flavour].introtext:interp( + { + name = mission.client.name, + systembody = mission.location:GetSystemBody().name, + system = ui.Format.SystemPath(mission.location:SystemOnly()), + dist = dist, + cash = Format.Money(mission.reward), + }) + .. returnLocationDesc desc.details = { "Mapping", - {lc.SYSTEM..":", mission.location:GetStarSystem().name.." "..coordinates}, - destination, + {lc.SYSTEM..":", ui.Format.SystemPath(mission.location) }, + {l.TARGET_BODY, mission.location:GetSystemBody().name }, {l.DISTANCE, dist .. lc.UNIT_LY}, {l.DEADLINE, Format.Date(mission.due)}, {luc.TYPE..":", mission.orbital and l.ORBITAL_SCAN or l.SURFACE_SCAN}, @@ -789,6 +781,13 @@ local buildMissionDescription = function (mission) {luc.STATUS, luc[mission.status]}, } + desc.client = mission.client + if finished then + desc.returnLocation = mission.station + else + desc.location = mission.location + end + return desc end From b8d008bd3efb92b527a5ed552d95926996383300 Mon Sep 17 00:00:00 2001 From: Michael Werle Date: Thu, 24 Oct 2024 16:08:38 +0900 Subject: [PATCH 7/7] doc(scout): add additional mission ideas as a comment Raised in https://github.com/pioneerspacesim/pioneer/pull/5932#discussion_r1813922824 some additional mission / risk ideas. Adding them as a comment so they don't get lost for now. These could be added when the overall mission difficulty/reward structure is overhauled following completion of the equipment overhaul. --- data/modules/Scout/Scout.lua | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/data/modules/Scout/Scout.lua b/data/modules/Scout/Scout.lua index 608a374bf5d..5f4383d040b 100644 --- a/data/modules/Scout/Scout.lua +++ b/data/modules/Scout/Scout.lua @@ -92,19 +92,35 @@ MissionCalc:SetParams({ }) local flavours = { + -- Additional mission flavour ideas (originally raised in + -- https://github.com/pioneerspacesim/pioneer/pull/5932#discussion_r1813922824) + -- + -- * prospecting for mining claims - the mission-giver would be a mining + -- company. There might be rival companies or environmental groups who + -- wish to prevent mining on the target body and send a vessel to + -- "dissuade" you from mapping the body. This could be an actual firefight + -- (simple), or an offer to sell the data to them instead (might affect + -- reputation?). + -- * Claims (family in race to claim): again, might add a risk factor with + -- the rival group(s) sending their own ship(s) to map/stake the claim + -- with potential firefight between the rivals. + -- * In-system data returns could transmit the data once the mapping + -- is complete (possibly for a lower reward?) instead of having to return + -- to a station. + -- -- localscout: if in same system or not -- days: simply the hard deadline for this type of contract -- difficulty: used to set altitude in scanner -- reward: used as multiplier in reward calculation -- dropoff: data needs to be delivered to another station than where the mission was accepted from - { -- flavour 1 + { -- 1 - Galactic Geographic Society localscout = false, -- is in same system? days = 60, -- days until deadline, from accepting it difficulty = 1, -- altitude, [0,1] reward = 1, -- reward multiplier, 1=none. (unrelated to "urgency") dropoff = false, }, { - localscout = false, -- 2 Galactic Geographic Society + localscout = false, -- 2 - Low altitude mapping days = 60, difficulty = 2, -- low altitude flying reward = 1, @@ -140,7 +156,7 @@ local flavours = { reward = 2, -- because urgent dropoff = false, }, { - localscout = true, -- 8 geographical society + localscout = true, -- 8 geographical society, low-flying days = 80, difficulty = 2, reward = 2,