204 lines
5.9 KiB
Lua
204 lines
5.9 KiB
Lua
require("PGBase")
|
|
require("GameManager/Constants")
|
|
|
|
---@class GUIManager
|
|
---@field TacticalGame TacticalGameClass|nil The local Tactical Game state.
|
|
---@field SkirmishGame SkirmishGameClass|nil The local Skirmish Game state.
|
|
---@field ShowTeamId integer The Team ID units to display.
|
|
GUIManager = {}
|
|
GUIManager.__index = GUIManager
|
|
|
|
---Creates a new GUI Manager.
|
|
---@return GUIManager
|
|
function GUIManager:New()
|
|
local self = setmetatable({}, GUIManager)
|
|
|
|
self.TacticalGame = nil
|
|
self.SkirmishGame = nil
|
|
self.ShowTeamId = 0
|
|
|
|
return self
|
|
end
|
|
|
|
---Initializes the GUI Manager for Skirmish mode.
|
|
---@param game SkirmishGameClass The Skirmish Game state.
|
|
function GUIManager:InitSkirmish(game)
|
|
self.SkirmishGame = game
|
|
self.TacticalGame = game.TacticalGame
|
|
|
|
GUI_Component_Visibility(UI_GameTime, true)
|
|
|
|
if self.SkirmishGame.IsLocalSpectator then
|
|
GUI_Component_Visibility(UI_CreditsT1, true)
|
|
GUI_Component_Visibility(UI_IconT1, true)
|
|
|
|
GUI_Component_Visibility(UI_CreditsT2, true)
|
|
GUI_Component_Visibility(UI_IconT2, true)
|
|
|
|
GUI_Component_Visibility(UI_PlanetaryPop, false)
|
|
GUI_Component_Visibility(UI_CreditsTactical, false)
|
|
end
|
|
end
|
|
|
|
---Initializes the GUI Manager for Tactical mode.
|
|
---@param game TacticalGameClass The Tactical Game state.
|
|
function GUIManager:InitTactical(game)
|
|
self.TacticalGame = game
|
|
|
|
GUI_Component_Visibility(UI_GameTime, true)
|
|
end
|
|
|
|
---Resets the GUI Manager.
|
|
function GUIManager:Reset()
|
|
self.SkirmishGame = nil
|
|
self.TacticalGame = nil
|
|
|
|
GUI_Component_Text(UI_GameTime, "")
|
|
GUI_Text_Color(UI_GameTime, 1, 1, 1, 1)
|
|
GUI_Component_Visibility(UI_GameTime, false)
|
|
|
|
GUI_Component_Text(UI_CreditsT1, "")
|
|
GUI_Text_Color(UI_CreditsT1, 1, 1, 1, 1)
|
|
GUI_Component_Visibility(UI_CreditsT1, false)
|
|
|
|
GUI_Button_Icon(UI_IconT1, "", 1, 1, 1, 1)
|
|
GUI_Component_Visibility(UI_IconT1, false)
|
|
|
|
GUI_Component_Text(UI_CreditsT2, "")
|
|
GUI_Text_Color(UI_CreditsT2, 1, 1, 1, 1)
|
|
GUI_Component_Visibility(UI_CreditsT2, false)
|
|
|
|
GUI_Button_Icon(UI_IconT2, "", 1, 1, 1, 1)
|
|
GUI_Component_Visibility(UI_IconT2, false)
|
|
|
|
GUI_Component_Visibility(UI_PlanetaryPop, true)
|
|
GUI_Component_Visibility(UI_CreditsTactical, true)
|
|
end
|
|
|
|
---Services the GUI Manager.
|
|
function GUIManager:Service()
|
|
if not self.TacticalGame then
|
|
-- Nothing to service
|
|
return
|
|
end
|
|
|
|
ScriptMessage("Servicing GUI Updates...")
|
|
ServiceGameTime(self.TacticalGame)
|
|
ServiceTeamCredits(self.SkirmishGame)
|
|
--ServiceUnitDisplay(self.SkirmishGame, self.ShowTeamId)
|
|
ServiceScreenText(self.SkirmishGame)
|
|
end
|
|
|
|
---Services Game Time display.
|
|
---@param tacticalGame TacticalGameClass The current Tactical Game state
|
|
function ServiceGameTime(tacticalGame)
|
|
if not tacticalGame then
|
|
return
|
|
end
|
|
|
|
local gameTime = Dirty_Floor(GetCurrentTime()) - tacticalGame.StartTime
|
|
local minutes = Dirty_Floor(gameTime / 60)
|
|
local minutesText = tostring(minutes)
|
|
|
|
if tonumber(minutes) < 10 then
|
|
minutesText = "0" .. minutesText
|
|
end
|
|
|
|
local seconds = gameTime - (minutes * 60)
|
|
local secondsText = tostring(seconds)
|
|
|
|
if tonumber(seconds) < 10 then
|
|
secondsText = "0" .. secondsText
|
|
end
|
|
|
|
local text = string.format("Time: %s:%s", minutesText, secondsText)
|
|
|
|
GUI_Component_Text(UI_GameTime, text)
|
|
end
|
|
|
|
---Services Team Credits display.
|
|
---@param skirmishGame SkirmishGameClass The current Skirmish Game state.
|
|
function ServiceTeamCredits(skirmishGame)
|
|
if not skirmishGame then
|
|
return
|
|
end
|
|
|
|
if not skirmishGame.IsLocalSpectator then
|
|
return
|
|
end
|
|
|
|
---Displays credits for the specified team
|
|
---@param team TeamStruct The team to service.
|
|
---@param uiText string The name of the UI Component to display Team credits in.
|
|
---@param uiIcon string The name of the UI Component to display the Faction icon in.
|
|
local function DisplayTeamCredits(team, uiText, uiIcon)
|
|
local teamCredits = skirmishGame:CalculateTeamTotalCredits(team.Id)
|
|
local teamIncome = skirmishGame:CalculateTeamTotalIncome(team.Id)
|
|
local positiveText = "+"
|
|
|
|
if teamIncome < 0 then
|
|
positiveText = ""
|
|
end
|
|
|
|
local text = string.format("Team %d: $%d (%s%d)", team.Number, teamCredits, positiveText, teamIncome)
|
|
local icon = team.Faction.Icon
|
|
local color = team.Faction.Color
|
|
|
|
GUI_Button_Icon(uiIcon, icon, color.R, color.G, color.B, 1)
|
|
GUI_Component_Text(uiText, text)
|
|
GUI_Text_Color(uiText, color.R, color.G, color.B, 1)
|
|
end
|
|
|
|
for _, team in pairs(skirmishGame.Teams) do
|
|
if team.Number == 1 then
|
|
DisplayTeamCredits(team, UI_CreditsT1, UI_IconT1)
|
|
elseif team.Number == 2 then
|
|
DisplayTeamCredits(team, UI_CreditsT2, UI_IconT2)
|
|
end
|
|
end
|
|
end
|
|
|
|
---Services Team Units display.
|
|
---@param skirmishGame SkirmishGameClass The current Skirmish Game state.
|
|
---@param teamId integer The Team ID's units to display.
|
|
function ServiceUnitDisplay(skirmishGame, teamId)
|
|
if not skirmishGame then
|
|
return
|
|
end
|
|
|
|
if not skirmishGame.IsLocalSpectator then
|
|
return
|
|
end
|
|
|
|
local localPlayer = Find_Player("local")
|
|
|
|
if not localPlayer then
|
|
return
|
|
end
|
|
|
|
local function DisplayTeamUnit(unit, uiComponent)
|
|
|
|
end
|
|
|
|
local players = skirmishGame:GetPlayersOnTeam(teamId)
|
|
---@type table<string, integer> Units Table by name with alive count.
|
|
local units = {}
|
|
|
|
for _, player in pairs(players) do
|
|
local playerUnits = player:GetAliveUnits()
|
|
|
|
for _, playerUnit in pairs(playerUnits) do
|
|
localPlayer.Select_Object(playerUnit.GameObjectWrapper)
|
|
|
|
if not units[playerUnit.Name] then
|
|
units[playerUnit.Name] = 1
|
|
else
|
|
units[playerUnit.Name] = units[playerUnit.Name] + 1
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function ServiceScreenText(skirmishGame)
|
|
end
|