From 88d7c0558fbe871c4760da75256943cd5ef1e087 Mon Sep 17 00:00:00 2001 From: Gliese852 Date: Sun, 11 Apr 2021 00:11:10 +0300 Subject: [PATCH] Additional fixes - will be squashed Add a truncated display of debug information in a system with no trade Add NILing of Core.params if the calculation of the system parameters failed Add NoBackground flag for fullscreen UI window options Add a Log::Verbose when the body changes frame Add const to GetRotFrame() function --- data/modules/TradeShips/Debug.lua | 4 +++- data/modules/TradeShips/Flow.lua | 17 ++++++++++++----- data/pigui/baseui.lua | 12 +++++------- src/Body.cpp | 4 ++-- src/Frame.h | 2 +- src/lua/LuaPiGui.cpp | 1 + src/lua/LuaShip.cpp | 2 +- 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/data/modules/TradeShips/Debug.lua b/data/modules/TradeShips/Debug.lua index a2246a5adc3..b92a371dba1 100644 --- a/data/modules/TradeShips/Debug.lua +++ b/data/modules/TradeShips/Debug.lua @@ -54,7 +54,7 @@ local statuses = { } debugView.registerTab('debug-trade-ships', function() - if not Core.ships or not Core.params then return end + if not Core.ships and not Core.params then return end if not ui.beginTabItem("Tradeships") then return end local function property(key, value) @@ -66,6 +66,7 @@ debugView.registerTab('debug-trade-ships', function() end ui.child("tradeships_as_child", Vector2(-1, -infosize), {"NoSavedSettings", "HorizontalScrollbar"}, function() + if Core.params then if ui.collapsingHeader("System summary", {"DefaultOpen"}) then local precalculated = {} if Core.params.spawn_in then @@ -200,6 +201,7 @@ debugView.registerTab('debug-trade-ships', function() end end end + end if ui.collapsingHeader("All ships") then local ships = {} diff --git a/data/modules/TradeShips/Flow.lua b/data/modules/TradeShips/Flow.lua index f7a4ef8024f..a4ce346d406 100644 --- a/data/modules/TradeShips/Flow.lua +++ b/data/modules/TradeShips/Flow.lua @@ -84,6 +84,13 @@ local function getImportsExports(system) return imports, exports end +-- we do this if the calculation of the system parameters failed, and we need +-- to return nil, and also execute some code +local function noSystemParams() + Core.params = nil + return nil +end + -- we collect all the information necessary for the module to work in this system: -- valid ship models -- import / export goods @@ -95,12 +102,12 @@ Flow.calculateSystemParams = function() local system = Game.system -- dont spawn tradeships in unpopulated systems - if system.population == 0 then return nil end + if system.population == 0 then return noSystemParams() end -- all ports in the system local ports = Space.GetBodies(function (body) return body.superType == 'STARPORT' end) -- check if the current system can be traded in - if #ports == 0 then return nil end + if #ports == 0 then return noSystemParams() end -- all routes in the system -- routes are laid from the nearest star @@ -118,12 +125,12 @@ Flow.calculateSystemParams = function() -- get ships listed as tradeships, if none - give up local ship_names = getAcceptableShips() - if #ship_names == 0 then return nil end + if #ship_names == 0 then return noSystemParams() end local imports, exports = getImportsExports(system) -- if there is no market then there is no trade - if #imports == 0 or #exports == 0 then return nil end + if #imports == 0 or #exports == 0 then return noSystemParams() end -- all tradeship models array -- these are real ship objects, they are needed for calculations @@ -193,7 +200,7 @@ Flow.calculateSystemParams = function() end -- as a result, not a single ship might remain - if #ship_names == 0 then return nil end + if #ship_names == 0 then return noSystemParams() end -- now we have only those ships that can jump from somewhere and land somewhere -- now set the flow on the most popular route to MAX_ROUTE_FLOW diff --git a/data/pigui/baseui.lua b/data/pigui/baseui.lua index d05c995bb3a..2138a3599b2 100644 --- a/data/pigui/baseui.lua +++ b/data/pigui/baseui.lua @@ -25,19 +25,17 @@ ui.pi_4 = pi_4 ui.pi = pi ui.anchor = { left = 1, right = 2, center = 3, top = 4, bottom = 5, baseline = 6 } -ui.fullScreenWindowFlags = ui.WindowFlags {"NoTitleBar", "NoResize", "NoMove", "NoInputs", "NoSavedSettings", "NoFocusOnAppearing", "NoBringToFrontOnFocus"} +ui.fullScreenWindowFlags = ui.WindowFlags { "NoTitleBar", "NoResize", "NoMove", "NoInputs", "NoSavedSettings", "NoFocusOnAppearing", "NoBringToFrontOnFocus", "NoBackground" } -- make all the necessary preparations for displaying the full-screen UI, launch the drawing function function ui.makeFullScreenHandler(window_name, window_fnc) return function() ui.setNextWindowPos(Vector2(0, 0), "Always") ui.setNextWindowSize(Vector2(ui.screenWidth, ui.screenHeight), "Always") - ui.withStyleColors({ ["WindowBg"] = ui.theme.colors.transparent }, function() - ui.window(window_name, ui.fullScreenWindowFlags, function() - if ui.shouldDrawUI() then - window_fnc() - end - end) + ui.window(window_name, ui.fullScreenWindowFlags, function() + if ui.shouldDrawUI() then + window_fnc() + end end) end end diff --git a/src/Body.cpp b/src/Body.cpp index e71cb139e40..32d392408ce 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -234,7 +234,7 @@ void Body::UpdateFrame() FrameId parent = frame->GetParent(); Frame *newFrame = Frame::GetFrame(parent); if (newFrame) { // don't fall out of root frame - // Output("%s leaves frame %s\n", GetLabel().c_str(), frame->GetLabel().c_str()); + Log::Verbose("{} leaves frame{}\n", GetLabel(), frame->GetLabel()); SwitchToFrame(parent); return; } @@ -246,7 +246,7 @@ void Body::UpdateFrame() const vector3d pos = GetPositionRelTo(kid); if (pos.Length() >= kid_frame->GetRadius()) continue; SwitchToFrame(kid); - // Output("%s enters frame %s\n", GetLabel().c_str(), kid_frame->GetLabel().c_str()); + Log::Verbose("{} enters frame{}\n", GetLabel(), frame->GetLabel()); break; } } diff --git a/src/Frame.h b/src/Frame.h index 6438f0974d9..ad36d6ac189 100644 --- a/src/Frame.h +++ b/src/Frame.h @@ -83,7 +83,7 @@ class Frame { FrameId GetParent() const { return m_parent; } FrameId GetNonRotFrame() const { return IsRotFrame() ? m_parent : m_thisId; } - FrameId GetRotFrame() { return HasRotFrame() ? m_children.front() : m_thisId; } + FrameId GetRotFrame() const { return HasRotFrame() ? m_children.front() : m_thisId; } void SetBodies(SystemBody *s, Body *b) { diff --git a/src/lua/LuaPiGui.cpp b/src/lua/LuaPiGui.cpp index 6f8d2015bfd..80b9c3408e3 100644 --- a/src/lua/LuaPiGui.cpp +++ b/src/lua/LuaPiGui.cpp @@ -317,6 +317,7 @@ static LuaFlags imguiWindowFlagsTable = { { "NoScrollWithMouse", ImGuiWindowFlags_NoScrollWithMouse }, { "NoCollapse", ImGuiWindowFlags_NoCollapse }, { "AlwaysAutoResize", ImGuiWindowFlags_AlwaysAutoResize }, + { "NoBackground", ImGuiWindowFlags_NoBackground }, { "NoSavedSettings", ImGuiWindowFlags_NoSavedSettings }, { "NoInputs", ImGuiWindowFlags_NoInputs }, { "MenuBar", ImGuiWindowFlags_MenuBar }, diff --git a/src/lua/LuaShip.cpp b/src/lua/LuaShip.cpp index d9ab709b2ad..1d9aa3663c9 100644 --- a/src/lua/LuaShip.cpp +++ b/src/lua/LuaShip.cpp @@ -668,7 +668,7 @@ static int l_ship_is_ecm_ready(lua_State *l) * Calculating the duration of the flight of a given ship at a specified distance. * Assumed that at the beginning and at the end of the travel the speed is 0. * - * > duration = ship:GetDurationForDistancel(distance) + * > duration = ship:GetDurationForDistance(distance) * * Parameters: *