Skip to content

Commit

Permalink
Ensure ship skins have appropriate labels
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
sturnclaw committed Jun 18, 2024
1 parent ed15020 commit d38f8ea
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 9 deletions.
5 changes: 3 additions & 2 deletions data/libs/SpaceStation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion data/modules/SearchRescue/SearchRescue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions data/pigui/modules/new-game-window/class.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion data/pigui/modules/new-game-window/crew.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions data/pigui/modules/new-game-window/ship.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion data/pigui/modules/new-game-window/widgets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion data/pigui/modules/station-view/06-shipRepairs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d38f8ea

Please sign in to comment.