Skip to content

Commit

Permalink
Additional fixes - will be squashed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Gliese852 committed Apr 10, 2021
1 parent f32efbe commit 88d7c05
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 17 deletions.
4 changes: 3 additions & 1 deletion data/modules/TradeShips/Debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -200,6 +201,7 @@ debugView.registerTab('debug-trade-ships', function()
end
end
end
end

if ui.collapsingHeader("All ships") then
local ships = {}
Expand Down
17 changes: 12 additions & 5 deletions data/modules/TradeShips/Flow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions data/pigui/baseui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/lua/LuaPiGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ static LuaFlags<ImGuiWindowFlags_> imguiWindowFlagsTable = {
{ "NoScrollWithMouse", ImGuiWindowFlags_NoScrollWithMouse },
{ "NoCollapse", ImGuiWindowFlags_NoCollapse },
{ "AlwaysAutoResize", ImGuiWindowFlags_AlwaysAutoResize },
{ "NoBackground", ImGuiWindowFlags_NoBackground },
{ "NoSavedSettings", ImGuiWindowFlags_NoSavedSettings },
{ "NoInputs", ImGuiWindowFlags_NoInputs },
{ "MenuBar", ImGuiWindowFlags_MenuBar },
Expand Down
2 changes: 1 addition & 1 deletion src/lua/LuaShip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*
Expand Down

0 comments on commit 88d7c05

Please sign in to comment.