Skip to content

Commit

Permalink
Merge branch 'second_footer_for_capacity', #3238
Browse files Browse the repository at this point in the history
  • Loading branch information
impaktor committed Nov 7, 2014
2 parents 67a7113 + ee52387 commit bd83d9f
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 66 deletions.
4 changes: 4 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ November 2014
* Script and UI API changes
* Added random number from Poisson distribution (#3242)

* Minor changes and tweaks
* Introduce special footer when player is in equipment market,
fixes #3117 (#3238)

October 2014
* Art
* Lunar Shuttle facelift (#3230)
Expand Down
4 changes: 4 additions & 0 deletions data/lang/ui-core/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
"description" : "",
"message" : "Cargo space"
},
"CARGO_SPACE_USED" : {
"description" : "",
"message" : "Cargo space used"
},
"CARGO_T_FREE" : {
"description" : "",
"message" : "{amount}t free"
Expand Down
5 changes: 5 additions & 0 deletions data/libs/ui/TabView.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ function TabView.AddTab (self, args)
local title = args.title
local icon = args.icon
local template = args.template
local footer = args.footer

local tab = {
group = self,
id = id,
icon = icon,
title = title,
template = template,
footer = footer
}

self:RemoveTab(id)
Expand Down Expand Up @@ -126,6 +128,9 @@ function TabView.SwitchToNum (self, num)
self.title:SetText(tab.title)

self.body:SetInnerWidget(tab.template(tab, self))
if tab.footer then
self:SetFooter(tab.footer)
end
end

function TabView.SwitchTo (self, id)
Expand Down
2 changes: 2 additions & 0 deletions data/ui/InfoView/ShipInfo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ local shipInfo = function (args)
"",
{ l.WEIGHT_EMPTY..":", string.format("%dt", player.totalMass - player.usedCapacity) },
{ l.CAPACITY_USED..":", string.format("%dt (%dt "..l.FREE..")", player.usedCapacity, player.freeCapacity) },
{ l.CARGO_SPACE..":", string.format("%dt (%dt "..l.MAX..")", player.totalCargo, shipDef.equipSlotCapacity.cargo) },
{ l.CARGO_SPACE_USED..":", string.format("%dt (%dt "..l.FREE..")", player.usedCargo, player.totalCargo - player.usedCargo) },
{ l.FUEL_WEIGHT..":", string.format("%dt (%dt "..l.MAX..")", player.fuelMassLeft, shipDef.fuelTankMass ) },
{ l.ALL_UP_WEIGHT..":", string.format("%dt", mass_with_fuel ) },
"",
Expand Down
151 changes: 85 additions & 66 deletions data/ui/StationView.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,74 +34,89 @@ ui.templates.StationView = function (args)

local player = Game.player

local cashLabel = ui:NumberLabel("MONEY")
cashLabel:Bind("value", player, "cash")

local cargoGauge = ui:Gauge()
local cargoUsedLabel = ui:Label("")
local cargoFreeLabel = ui:Label("")
local function cargoUpdate ()
cargoGauge:SetUpperValue(player.totalCargo)
cargoGauge:SetValue(player.usedCargo)
cargoUsedLabel:SetText(string.interp(l.CARGO_T_USED, { amount = player.usedCargo }))
cargoFreeLabel:SetText(string.interp(l.CARGO_T_FREE, { amount = player.totalCargo-player.usedCargo }))
local function createCashLabel()
local cashLabel = ui:NumberLabel("MONEY")
cashLabel:Bind("value", player, "cash")
return cashLabel
end
player:Connect("usedCargo", cargoUpdate)
player:Connect("totalCargo", cargoUpdate)
cargoUpdate()

local cabinGauge = ui:Gauge()
local cabinUsedLabel = ui:Label("")
local cabinFreeLabel = ui:Label("")
local function cabinUpdate ()
local cap = player.cabin_cap or 0
local count = player:GetEquipCountOccupied("cabin")
cabinGauge:SetUpperValue(count)
cabinGauge:SetValue(count-cap)
cabinUsedLabel:SetText(string.interp(l.CABIN_USED, { amount = count-cap }))
cabinFreeLabel:SetText(string.interp(l.CABIN_FREE, { amount = cap}))

local function cargoUpdate (fields)
fields["gauge"]:SetUpperValue(player.totalCargo)
fields["gauge"]:SetValue(player.usedCargo)
fields["usedLabel"]:SetText(string.interp(l.CARGO_T_USED, { amount = player.usedCargo }))
fields["freeLabel"]:SetText(string.interp(l.CARGO_T_FREE, { amount = player.totalCargo-player.usedCargo }))
end

local function capacityUpdate (fields)
local totalCapacity = player.usedCapacity + player.freeCapacity
fields["gauge"]:SetUpperValue(totalCapacity)
fields["gauge"]:SetValue(player.usedCapacity)
fields["usedLabel"]:SetText(string.interp(l.CARGO_T_USED, { amount = player.usedCapacity }))
fields["freeLabel"]:SetText(string.interp(l.CARGO_T_FREE, { amount = player.freeCapacity }))
end

local function cabinUpdate (fields)
local cap = player.cabin_cap or 0
local count = player:GetEquipCountOccupied("cabin")
fields["gauge"]:SetUpperValue(count)
fields["gauge"]:SetValue(count-cap)
fields["usedLabel"]:SetText(string.interp(l.CABIN_USED, { amount = count-cap }))
fields["freeLabel"]:SetText(string.interp(l.CABIN_FREE, { amount = cap}))
end
player:Connect("cabin_cap", cabinUpdate)
cabinUpdate()

local footer =
ui:Margin(15, "TOP",
local function createGauge(text, connectTo, funcUpdate)
local gauge = ui:Gauge()
local usedLabel = ui:Label("")
local freeLabel = ui:Label("")
local fields = {}
fields["gauge"] = gauge;
fields["usedLabel"] = usedLabel;
fields["freeLabel"] = freeLabel;
local function innerFuncUpdate()
funcUpdate(fields);
end
for k,v in pairs(connectTo) do
player:Connect(v, innerFuncUpdate)
end
innerFuncUpdate()

return ui:Margin(10, "HORIZONTAL",
ui:HBox(10):PackEnd({
ui:Align("MIDDLE",
ui:HBox(10):PackEnd({
text..":",
gauge,
})
),
ui:VBox():PackEnd({
usedLabel,
freeLabel,
}):SetFont("XSMALL"),
})
)
end

local function createFooter(type)
type = type or "default"

local leftGauge = nil
if type == "default" then
leftGauge = createGauge(l.CARGO, { "usedCargo", "totalCargo" }, cargoUpdate)
elseif type == "equip" then
leftGauge = createGauge(l.CAPACITY, { "usedCapacity", "freeCapacity" }, capacityUpdate)
end

return ui:Margin(15, "TOP",
ui:Margin(5, "VERTICAL",
ui:Grid({15,30,30,15},1):SetRow(0, {
ui:Margin(10, "HORIZONTAL",
ui:HBox():PackEnd({
l.CASH..": ",
cashLabel,
})
),
ui:Margin(10, "HORIZONTAL",
ui:HBox(10):PackEnd({
ui:Align("MIDDLE",
ui:HBox(10):PackEnd({
l.CARGO..":",
cargoGauge,
})
),
ui:VBox():PackEnd({
cargoUsedLabel,
cargoFreeLabel,
}):SetFont("XSMALL"),
})
),
ui:Margin(10, "HORIZONTAL",
ui:HBox(10):PackEnd({
ui:Align("MIDDLE",
ui:HBox(10):PackEnd({
l.CABINS..":",
cabinGauge,
})
),
ui:VBox():PackEnd({
cabinUsedLabel,
cabinFreeLabel,
}):SetFont("XSMALL"),
createCashLabel(),
})
),
leftGauge,
createGauge(l.CABINS, { "cabin_cap" }, cabinUpdate),
ui:Margin(10, "HORIZONTAL",
ui:Align("RIGHT",
l.LEGAL_STATUS..": "..l.CLEAN
Expand All @@ -110,16 +125,20 @@ ui.templates.StationView = function (args)
})
)
)
end

local footerDefault = createFooter()
local footerEquip = createFooter("equip")

tabGroup:AddTab({ id = "lobby", title = l.LOBBY, icon = "Info", template = lobby })
tabGroup:AddTab({ id = "bulletinBoard", title = l.BULLETIN_BOARD, icon = "Clipboard", template = bulletinBoard })
tabGroup:AddTab({ id = "commodityMarket", title = l.COMMODITY_MARKET, icon = "Cart", template = commodityMarket })
tabGroup:AddTab({ id = "shipMarket", title = l.SHIP_MARKET, icon = "Rocketship", template = shipMarket })
tabGroup:AddTab({ id = "equipmentMarket", title = l.EQUIPMENT_MARKET, icon = "Radio", template = equipmentMarket })
tabGroup:AddTab({ id = "shipRepairs", title = l.SHIP_REPAIRS, icon = "Tools", template = shipRepairs })
tabGroup:AddTab({ id = "police", title = l.POLICE, icon = "Shield", template = police })
tabGroup:AddTab({ id = "lobby", title = l.LOBBY, icon = "Info", template = lobby, footer = footerDefault})
tabGroup:AddTab({ id = "bulletinBoard", title = l.BULLETIN_BOARD, icon = "Clipboard", template = bulletinBoard, footer = footerDefault})
tabGroup:AddTab({ id = "commodityMarket", title = l.COMMODITY_MARKET, icon = "Cart", template = commodityMarket, footer = footerDefault})
tabGroup:AddTab({ id = "shipMarket", title = l.SHIP_MARKET, icon = "Rocketship", template = shipMarket, footer = footerDefault})
tabGroup:AddTab({ id = "equipmentMarket", title = l.EQUIPMENT_MARKET, icon = "Radio", template = equipmentMarket, footer = footerEquip})
tabGroup:AddTab({ id = "shipRepairs", title = l.SHIP_REPAIRS, icon = "Tools", template = shipRepairs, footer = footerDefault})
tabGroup:AddTab({ id = "police", title = l.POLICE, icon = "Shield", template = police, footer = footerDefault})

tabGroup:SetFooter(footer)
tabGroup:SetFooter(footerDefault)

return tabGroup.widget
end
Expand Down

0 comments on commit bd83d9f

Please sign in to comment.