Skip to content

Commit

Permalink
HUD and GUI updated
Browse files Browse the repository at this point in the history
  • Loading branch information
scfmod committed Dec 19, 2023
1 parent a8a07bb commit d4f4296
Show file tree
Hide file tree
Showing 16 changed files with 551 additions and 916 deletions.
42 changes: 12 additions & 30 deletions scripts/gui/InGameMenuConstructionsFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
---@field inputListLayout BitmapElement
---@field inputList SmoothListElement
---@field statusLayout BitmapElement
---@field statusIcon BitmapElement
---@field statusText TextElement
---@field statusProgressBar InputProgressElement
---@field statusProgressBar ProgressBarElement
---@field backButtonInfo table
---
---@field superClass fun(): TabbedMenuFrameElement
Expand All @@ -27,8 +25,6 @@ InGameMenuConstructionsFrame.CONTROLS = {
'inputListLayout',
'inputList',
'statusLayout',
'statusIcon',
'statusText',
'statusProgressBar'
}

Expand Down Expand Up @@ -145,7 +141,6 @@ function InGameMenuConstructionsFrame:initialize()
end
}

self.statusIcon:setImageUVs(nil, unpack(Construction.STATUS_ICON_UVS[Construction.STATE_ACTIVE]))
self.statusLayout:setVisible(false)
end

Expand Down Expand Up @@ -229,26 +224,8 @@ function InGameMenuConstructionsFrame:updateStatus()
else
local state = placeable:getActiveState()

local isAwaitingDelivery = state:getIsAwaitingDelivery()
local isProcessing = state:getIsProcessing()

if isAwaitingDelivery then
self.statusIcon:setImageUVs(nil, unpack(Construction.STATUS_ICON_UVS[Construction.STATE_ACTIVE]))

local text = Construction.STATUS_L10N[Construction.STATE_ACTIVE]

if isProcessing then
text = text .. '\n' .. Construction.STATUS_L10N[Construction.STATE_PROCESSING]
end

self.statusText:setText(text)
else
self.statusIcon:setImageUVs(nil, unpack(Construction.STATUS_ICON_UVS[Construction.STATE_PROCESSING]))
self.statusText:setText(Construction.STATUS_L10N[Construction.STATE_PROCESSING])
end

self.statusProgressBar:setDeliveryValue(state:getDeliveryProgress())
self.statusProgressBar:setProcessValue(state:getProcessingProgress())
self.statusProgressBar:setPrimary(state:getDeliveryProgress())
self.statusProgressBar:setSecondary(state:getProcessingProgress())

self.statusLayout:setVisible(true)
end
Expand Down Expand Up @@ -387,14 +364,19 @@ function InGameMenuConstructionsFrame:populateCellForItemInSection(list, section

if state == activeState then
cell:getAttribute('fillLevel'):setText(('%s / %s'):format(ConstructionUtils.formatNumber(input.deliveredAmount), ConstructionUtils.formatNumber(input.amount)))
cell:getAttribute('progress'):setDeliveryValue(1 / input.amount * input.deliveredAmount)
cell:getAttribute('progress'):setProcessValue(1 / input.amount * input.processedAmount)
cell:getAttribute('progress'):setVisible(true)
cell:getAttribute('progressBar'):setPrimary(1 / input.amount * input.deliveredAmount)
cell:getAttribute('progressBar'):setSecondary(1 / input.amount * input.processedAmount)

cell:setDisabled(false)
else
cell:getAttribute('fillLevel'):setText(ConstructionUtils.formatNumber(input.amount))
cell:getAttribute('progress'):setVisible(false)

if state.index < activeState.index then
cell:getAttribute('progressBar'):setSecondary(1)
else
cell:getAttribute('progressBar'):setSecondary(0)
end

cell:setDisabled(true)
end
end
Expand Down
2 changes: 1 addition & 1 deletion scripts/gui/dialogs/ConstructionInputsDialog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function ConstructionInputsDialog:populateCellForItemInSection(list, sectionInde
if input ~= nil then
cell:getAttribute('title'):setText(input.title)
cell:getAttribute('icon'):setImageFilename(input.icon)
cell:getAttribute('progress'):setValue(1 / input.totalAmount * input.deliveredAmount)
cell:getAttribute('progressBar'):setPrimary(1 / input.totalAmount * input.deliveredAmount)
cell:getAttribute('progressText'):setText(('%s / %s'):format(ConstructionUtils.formatNumber(input.deliveredAmount), ConstructionUtils.formatNumber(input.totalAmount)))
end
end
Expand Down
71 changes: 0 additions & 71 deletions scripts/gui/elements/InputProgressElement.lua

This file was deleted.

146 changes: 146 additions & 0 deletions scripts/gui/elements/ProgressBarElement.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
---@class ProgressBarElement : BitmapElement
---@field fullWidth number
---@field fullHeight number
---@field active boolean
---
---@field primaryElement BitmapElement
---@field secondaryElement BitmapElement
---
---@field primaryColor number[]
---@field secondaryColor number[]
---@field frameColor number[]
---@field frameDisabledColor number[]
---
---@field superClass fun(): BitmapElement
ProgressBarElement = {}

local ProgressBarElement_mt = Class(ProgressBarElement, BitmapElement)

function ProgressBarElement.new(target, custom_mt)
---@type ProgressBarElement
local self = BitmapElement.new(target, custom_mt or ProgressBarElement_mt)

self.active = true

self.primaryColor = { 1, 1, 1, 1 }
self.secondaryColor = { 0, 0, 1, 1 }
self.frameColor = { 0, 0, 1, 1 }
self.frameDisabledColor = { 1, 0, 0, 1 }

return self
end

function ProgressBarElement:loadFromXML(xmlFile, key)
self:superClass().loadFromXML(self, xmlFile, key)

self.primaryColor = GuiUtils.getColorArray(getXMLString(xmlFile, key .. '#primaryColor'), self.primaryColor)
self.secondaryColor = GuiUtils.getColorArray(getXMLString(xmlFile, key .. '#secondaryColor'), self.secondaryColor)

self.frameColor = GuiUtils.getColorArray(getXMLString(xmlFile, key .. '#frameColor'), self.frameColor)
self.frameDisabledColor = GuiUtils.getColorArray(getXMLString(xmlFile, key .. '#frameDisabledColor'), self.frameDisabledColor)
end

function ProgressBarElement:loadProfile(profile, applyProfile)
self:superClass().loadProfile(self, profile, applyProfile)

self.primaryColor = GuiUtils.getColorArray(profile:getValue('primaryColor'), self.primaryColor)
self.secondaryColor = GuiUtils.getColorArray(profile:getValue('secondaryColor'), self.secondaryColor)

self.frameColor = GuiUtils.getColorArray(profile:getValue('frameColor'), self.frameColor)
self.frameDisabledColor = GuiUtils.getColorArray(profile:getValue('frameDisabledColor'), self.frameDisabledColor)
end

function ProgressBarElement:onGuiSetupFinished()
self:superClass().onGuiSetupFinished(self)

self.fullWidth = self.absSize[1]
self.fullHeight = self.absSize[2]

self:registerElements()

self:setBorderColor(self:getIsDisabled() and self.frameDisabledColor or self.frameColor)
end

function ProgressBarElement:registerElements()
self.primaryElement = self.elements[1]
self.secondaryElement = self.elements[2]

if self.primaryElement then
self.primaryElement:setImageColor(nil, unpack(self.primaryColor))
else
Logging.warning('ProgressBarElement:registerElements() primaryElement not found')
end

if self.secondaryElement then
self.secondaryElement:setImageColor(nil, unpack(self.secondaryColor))
end
end

function ProgressBarElement:clone(parent, includeId, suppressOnCreate)
local clone = self:superClass().clone(self, parent, includeId, suppressOnCreate)

clone.primaryColor = table.copy(self.primaryColor)
clone.secondaryColor = table.copy(self.secondaryColor)

clone.frameColor = table.copy(self.frameColor)
clone.frameDisabledColor = table.copy(self.frameDisabledColor)

clone:registerElements()

return clone
end

---@param disabled boolean
---@param doNotUpdateChildren boolean | nil
function ProgressBarElement:setDisabled(disabled, doNotUpdateChildren)
self:superClass().setDisabled(self, disabled, doNotUpdateChildren)

self:setBorderColor(disabled and self.frameDisabledColor or self.frameColor)
end

---@param color number[]
function ProgressBarElement:setBorderColor(color)
if self.hasFrame then
self.frameColors[GuiElement.FRAME_LEFT] = color
self.frameColors[GuiElement.FRAME_TOP] = color
self.frameColors[GuiElement.FRAME_RIGHT] = color
self.frameColors[GuiElement.FRAME_BOTTOM] = color
end
end

---@param element BitmapElement
---@param value number
function ProgressBarElement:updateElementSize(element, value)
---@diagnostic disable-next-line: cast-local-type
value = MathUtil.round(value or 0, 4)

if value <= 0 then
element:setVisible(false)
else
local width = self.absSize[1]

value = math.min(1, value)

element:setSize(width * value, self.absSize[2])
element:setVisible(true)
end
end

---@param value number
function ProgressBarElement:setPrimary(value)
if self.primaryElement then
self:updateElementSize(self.primaryElement, value)

self:setDisabled(value <= 0)
end
end

---@param value number
function ProgressBarElement:setSecondary(value)
if self.secondaryElement then
self:updateElementSize(self.secondaryElement, value)
end
end

-- Register custom GUI element
Gui.CONFIGURATION_CLASS_MAPPING['constructionProgressBar'] = ProgressBarElement
84 changes: 0 additions & 84 deletions scripts/gui/elements/ProgressElement.lua

This file was deleted.

Loading

0 comments on commit d4f4296

Please sign in to comment.