From ed15020bc1be7e4d7cc94c49e04f25af84c1ed7e Mon Sep 17 00:00:00 2001 From: Webster Sheets Date: Tue, 18 Jun 2024 18:34:38 -0400 Subject: [PATCH 1/2] Fix scenegraph labels not clearing text mesh - If a model skin is applied to a model which replaces a valid text string with an empty string, the old string would continue to render because the text mesh was still valid. --- src/scenegraph/Label3D.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/scenegraph/Label3D.cpp b/src/scenegraph/Label3D.cpp index 00244018c46..3af8d9092f1 100644 --- a/src/scenegraph/Label3D.cpp +++ b/src/scenegraph/Label3D.cpp @@ -52,6 +52,8 @@ namespace SceneGraph { { //regenerate geometry m_geometry->Clear(); + m_textMesh.reset(); + if (!text.empty()) { m_font->GetGeometry(*m_geometry, text, vector2f(0.f)); From d38f8ea843b890ef73e5b89bea877b528fcaff25 Mon Sep 17 00:00:00 2001 From: Webster Sheets Date: Tue, 18 Jun 2024 18:56:35 -0400 Subject: [PATCH 2/2] Ensure ship skins have appropriate labels - Player ship skin was created (and subsequently serialized) without a label. - Labels were not visible on ships in the new game window. - Labels also not visible in the ship market. - Labels should correctly be visible in the paint shop now. - SearchRescue target ships should now display labels on their skins as well (setting the label on the ship mutates the set skin object). - Adjusted new game window inputText widget API to support returning a changed value from the randomize function. --- data/libs/SpaceStation.lua | 5 +++-- data/modules/SearchRescue/SearchRescue.lua | 2 +- data/pigui/modules/new-game-window/class.lua | 1 + data/pigui/modules/new-game-window/crew.lua | 2 +- data/pigui/modules/new-game-window/ship.lua | 10 +++++++--- data/pigui/modules/new-game-window/widgets.lua | 5 ++++- data/pigui/modules/station-view/06-shipRepairs.lua | 2 +- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/data/libs/SpaceStation.lua b/data/libs/SpaceStation.lua index 0fcf3b22bb5..66b3030ebea 100644 --- a/data/libs/SpaceStation.lua +++ b/data/libs/SpaceStation.lua @@ -576,11 +576,12 @@ local function addRandomShipAdvert(station, num) local def = avail[Engine.rand:Integer(1,#avail)] local model = Engine.GetModel(def.modelName) local pattern = model.numPatterns ~= 0 and Engine.rand:Integer(1,model.numPatterns) or nil + local label = Ship.MakeRandomLabel() addShipOnSale(station, { def = def, - skin = ModelSkin.New():SetRandomColors(Engine.rand):SetDecal(def.manufacturer), + skin = ModelSkin.New():SetRandomColors(Engine.rand):SetDecal(def.manufacturer):SetLabel(label), pattern = pattern, - label = Ship.MakeRandomLabel(), + label = label, }) end end diff --git a/data/modules/SearchRescue/SearchRescue.lua b/data/modules/SearchRescue/SearchRescue.lua index 0d8f27fae41..039f257ae13 100644 --- a/data/modules/SearchRescue/SearchRescue.lua +++ b/data/modules/SearchRescue/SearchRescue.lua @@ -711,9 +711,9 @@ local createTargetShip = function (mission) end -- set ship looks (label, skin, pattern) - ship:SetLabel(mission.shiplabel) local skin = ModelSkin.New():SetRandomColors(rand):SetDecal(shipdef.manufacturer) ship:SetSkin(skin) + ship:SetLabel(mission.shiplabel) local model = Engine.GetModel(shipdef.modelName) local pattern if model.numPatterns <= 1 then diff --git a/data/pigui/modules/new-game-window/class.lua b/data/pigui/modules/new-game-window/class.lua index 64ec53db223..565fb601805 100644 --- a/data/pigui/modules/new-game-window/class.lua +++ b/data/pigui/modules/new-game-window/class.lua @@ -125,6 +125,7 @@ local function startGame(gameParams) local skin = ModelSkin.New() skin:SetColors({ primary = colors[1], secondary = colors[2], trim = colors[3] }) skin:SetDecal(shipDef.manufacturer) + skin:SetLabel(gameParams.ship.label) player:SetSkin(skin) -- setup player character diff --git a/data/pigui/modules/new-game-window/crew.lua b/data/pigui/modules/new-game-window/crew.lua index 4499ddb6f7f..e9c1a8c4d3d 100644 --- a/data/pigui/modules/new-game-window/crew.lua +++ b/data/pigui/modules/new-game-window/crew.lua @@ -325,7 +325,7 @@ function Crew:drawMember(memberEntry) Widgets.verticalCenter(self.layout, function() Widgets.alignLabel(lui.NAME_PERSON, self.layout, function() local txt, changed = Widgets.inputText(lock, memberEntry:isValid(), "##charname" .. tostring(memberEntry), tostring(memberEntry.value.name), function() - memberEntry.value.name = NameGen.FullName(memberEntry.value.female) + return NameGen.FullName(memberEntry.value.female) end) if changed then memberEntry.value.name = txt diff --git a/data/pigui/modules/new-game-window/ship.lua b/data/pigui/modules/new-game-window/ship.lua index 71c128ffe51..778bfb12599 100644 --- a/data/pigui/modules/new-game-window/ship.lua +++ b/data/pigui/modules/new-game-window/ship.lua @@ -99,7 +99,7 @@ ShipName.layout = {} function ShipName:draw() Widgets.alignLabel(lui.SHIP_NAME, self.layout, function() local txt, changed = Widgets.inputText(self.lock, self:isValid(), "##shipname", self.value, function() - self.value = ShipNames.generateRandom() + return ShipNames.generateRandom() end) if changed then self.value = txt end end) @@ -135,9 +135,12 @@ ShipLabel.value = "" function ShipLabel:draw() Widgets.oneLiner(lui.REGISTRATION_NUMBER, self.layout, function() local txt, changed = Widgets.inputText(self.lock, self:isValid(), "##ShipLabel", self.value, function() - self.value = ShipObject.MakeRandomLabel() + return ShipObject.MakeRandomLabel() end) - if changed then self.value = txt end + if changed then + self.value = txt + ShipModel:updateModel() + end end) end @@ -218,6 +221,7 @@ function ShipModel:updateModel() if not self.skin then return end local c = self.value.colors self.skin:SetColors({ primary = c[1], secondary = c[2], trim = c[3] }) + self.skin:SetLabel(ShipLabel.value) self.spinner:setModel(modelName, self.skin, self.value.pattern) end diff --git a/data/pigui/modules/new-game-window/widgets.lua b/data/pigui/modules/new-game-window/widgets.lua index 4dafc6a35c7..f13a250709b 100644 --- a/data/pigui/modules/new-game-window/widgets.lua +++ b/data/pigui/modules/new-game-window/widgets.lua @@ -109,7 +109,10 @@ Widgets.inputText = function(lock, valid, id, text, randomFnc) local txt, changed = ui.inputText(id, text) ui.sameLine() if ui.iconButton(ui.theme.icons.random, Vector2(size, size), tostring(id) .. "_random_button") then - randomFnc() + local newtxt = randomFnc() + if newtxt and newtxt ~= txt then + txt, changed = newtxt, true + end end return txt, changed else diff --git a/data/pigui/modules/station-view/06-shipRepairs.lua b/data/pigui/modules/station-view/06-shipRepairs.lua index 1cc87e29c19..10f3802d27b 100644 --- a/data/pigui/modules/station-view/06-shipRepairs.lua +++ b/data/pigui/modules/station-view/06-shipRepairs.lua @@ -141,7 +141,7 @@ local function changeColor() local player = Game.player local shipDef = ShipDef[player.shipId] local newColor = reformatColor(previewColors) - previewSkin = ModelSkin.New():SetColors(newColor):SetDecal(shipDef.manufacturer) + previewSkin = ModelSkin.New():SetColors(newColor):SetDecal(shipDef.manufacturer):SetLabel(player.label) refreshModelSpinner() end