Skip to content

Commit 09f0a7c

Browse files
committed
Simplify PW UI.
1 parent c5467e7 commit 09f0a7c

1 file changed

Lines changed: 103 additions & 87 deletions

File tree

LuaMenu/widgets/gui_planetwars_list_window.lua

Lines changed: 103 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,30 @@ end
9797

9898
local function GetattackPhaseOrDefending(lobby, attackerFactions, defenderFactions, currentMode)
9999
local myFaction = lobby:GetMyFaction()
100-
local attackPhase = false
101-
local defendPhase = false
102-
if attackerFactions then
103-
for i = 1, #attackerFactions do
104-
if myFaction == attackerFactions[i] then
105-
attackPhase = true
106-
break
107-
end
108-
end
109-
end
110-
if defenderFactions then
111-
for i = 1, #defenderFactions do
112-
if myFaction == defenderFactions[i] then
113-
defendPhase = true
114-
break
115-
end
116-
end
117-
end
118-
return attackPhase, defendPhase
100+
if defenderFactions and #defenderFactions > 0 then
101+
return false, true
102+
else
103+
return true, false
104+
end
105+
--local attackPhase = false
106+
--local defendPhase = false
107+
--if attackerFactions then
108+
-- for i = 1, #attackerFactions do
109+
-- if myFaction == attackerFactions[i] then
110+
-- attackPhase = true
111+
-- break
112+
-- end
113+
-- end
114+
--end
115+
--if defenderFactions then
116+
-- for i = 1, #defenderFactions do
117+
-- if myFaction == defenderFactions[i] then
118+
-- defendPhase = true
119+
-- break
120+
-- end
121+
-- end
122+
--end
123+
--return attackPhase, defendPhase
119124
end
120125

121126
local function IsAttackUrgent()
@@ -203,6 +208,25 @@ local function HasAttackCharges()
203208
return (WG.LibLobby.lobby:GetPlanetwarsData().charges or 0) > 0
204209
end
205210

211+
local function GetAttackingPlanet()
212+
local myAttack, myFactionAttack = false, false
213+
local planets = WG.LibLobby.lobby:GetPlanetwarsData().planets
214+
local myFaction = WG.LibLobby.lobby:GetMyFaction()
215+
if not (planets and myFaction) then
216+
return false, false
217+
end
218+
for i = 1, #planets do
219+
local planetData = planets[i]
220+
if planetData.AttackerFaction == myFaction then
221+
myFactionAttack = true
222+
end
223+
if planetData.PlayerIsAttacker then
224+
myAttack = planetData.PlanetName
225+
end
226+
end
227+
return myAttack, myFactionAttack
228+
end
229+
206230
--------------------------------------------------------------------------------
207231
--------------------------------------------------------------------------------
208232
-- Timing
@@ -660,17 +684,6 @@ local function MakePlanetControl(planetData, DeselectOtherFunc, attackPhase, def
660684
text = "0/0",
661685
parent = holder,
662686
}
663-
local attackingCaption = TextBox:New {
664-
name = "attacking",
665-
x = 238,
666-
y = 55,
667-
width = 350,
668-
height = 20,
669-
valign = 'center',
670-
objectOverrideFont = Configuration:GetFont(3),
671-
text = "",
672-
parent = holder,
673-
}
674687

675688
local function SetPlanetName(newPlanetName)
676689
newPlanetName = StringUtilities.GetTruncatedStringWithDotDot(newPlanetName, tbPlanetName.font, PLANET_NAME_LENGTH - 24)
@@ -681,40 +694,29 @@ local function MakePlanetControl(planetData, DeselectOtherFunc, attackPhase, def
681694
end
682695

683696
local function UpdateCaptions()
684-
if joinedBattle and not (myAttacking and defendPhase) then
697+
if myAttacking and defendPhase then
698+
playerCaption:SetText("You are attacking this planet - Defenders: " .. currentPlayers .. "/" .. maxPlayers)
699+
elseif joinedBattle and not (myAttacking and defendPhase) then
685700
playerCaption:SetText("Joined - Waiting for players: " .. currentPlayers .. "/" .. maxPlayers)
686701
else
687702
playerCaption:SetText(currentPlayers .. "/" .. maxPlayers)
688703
end
689-
if myAttacking and defendPhase then
690-
attackingCaption:SetText("** You are attacking **")
691-
else
692-
attackingCaption:SetText("")
693-
end
694704
end
695705

696706
local function UpdateJoinButton()
697-
local haveCharge = HasAttackCharges()
698-
local needMap = not VFS.HasArchive(mapName)
699-
if not (canSelectPlanet and haveCharge) or (canSelectPlanet and needMap) then
700-
playerCaption:SetPos(104)
701-
UpdateCaptions()
702-
btnJoin:SetVisibility(false)
703-
btnLeave:SetVisibility(false)
704-
return
705-
end
706-
707-
if joinedBattle then
708-
playerCaption:SetPos(104)
709-
else
707+
local showButton = false
708+
if not joinedBattle then
710709
playerCaption:SetPos(270)
710+
local needMap = not VFS.HasArchive(mapName)
711711
if needMap then
712+
showButton = true
712713
if downloading then
713714
btnJoin:SetCaption(i18n("downloading"))
714715
else
715716
btnJoin:SetCaption(i18n("download_map"))
716717
end
717-
elseif canSelectPlanet and haveCharge then
718+
elseif canSelectPlanet and HasAttackCharges() then
719+
showButton = true
718720
if attackPhase then
719721
btnJoin:SetCaption(i18n("attack_planet"))
720722
elseif defendPhase then
@@ -724,8 +726,10 @@ local function MakePlanetControl(planetData, DeselectOtherFunc, attackPhase, def
724726
end
725727
end
726728
end
729+
727730
UpdateCaptions()
728-
btnJoin:SetVisibility(not joinedBattle)
731+
playerCaption:SetPos(showButton and 270 or 104)
732+
btnJoin:SetVisibility(showButton)
729733
btnLeave:SetVisibility(joinedBattle)
730734
end
731735

@@ -1314,7 +1318,7 @@ local function InitializeControls(window)
13141318
text = text .. " - Passive recharge in 0 seconds"
13151319
end
13161320
end
1317-
text = text .. "\nSpend charges to attack and regain them by defending planets."
1321+
text = text .. "\nSpend charges to attack and regain them by defending."
13181322
chargesText:SetText(text)
13191323
end
13201324

@@ -1326,46 +1330,56 @@ local function InitializeControls(window)
13261330
if attackPhase then
13271331
if charges == 0 then
13281332
statusText:SetText("You are out of attack charges. You need to defend a planet or wait for passive recharge.")
1329-
elseif currentMode == lobby.PW_ATTACK then
1330-
statusText:SetText("Choose a planet to attack. All attacks that reach the player threshold are launched when the timer reaches zero.")
13311333
else
1332-
local planets = lobby.planetwarsData.planets
1333-
local noPlanets = not (planets and planets[1])
1334-
local planetName = planets and (FindMyattackPhasePlanet(planets) or (planets[1] and not planets[2] and planets[1].PlanetName))
1335-
if lobby.planetwarsData.attackPhasePlanet then
1336-
if planetName then
1337-
statusText:SetText("You are attacking " .. planetName .. ". The defenders have limited time to respond.")
1338-
else
1339-
statusText:SetText("You are attacking a planet. Wait for the defenders have limited time to respond.")
1340-
end
1341-
elseif noPlanets then
1342-
statusText:SetText("Your faction has launched an attack. The defenders have limited time to respond")
1343-
1344-
elseif planetName then
1345-
statusText:SetText("Your faction is attacking " .. planetName .. ". The defenders have limited time to respond")
1346-
else
1347-
statusText:SetText("Your faction is attacking multiple planets. The defenders have limited time to respond")
1348-
end
1334+
statusText:SetText("Choose a planet to attack. All attacks that reach the player threshold are launched when the timer reaches zero.")
13491335
end
1336+
--else
1337+
-- local planets = lobby.planetwarsData.planets
1338+
-- local noPlanets = not (planets and planets[1])
1339+
-- local planetName = planets and (FindMyattackPhasePlanet(planets) or (planets[1] and not planets[2] and planets[1].PlanetName))
1340+
-- if lobby.planetwarsData.attackPhasePlanet then
1341+
-- if planetName then
1342+
-- statusText:SetText("You are attacking " .. planetName .. ". The defenders have limited time to respond.")
1343+
-- else
1344+
-- statusText:SetText("You are attacking a planet. Wait for the defenders have limited time to respond.")
1345+
-- end
1346+
-- elseif noPlanets then
1347+
-- statusText:SetText("Your faction has launched an attack. The defenders have limited time to respond")
1348+
--
1349+
-- elseif planetName then
1350+
-- statusText:SetText("Your faction is attacking " .. planetName .. ". The defenders have limited time to respond")
1351+
-- else
1352+
-- statusText:SetText("Your faction is attacking multiple planets. The defenders have limited time to respond")
1353+
-- end
1354+
--end
13501355
else
1351-
if currentMode == lobby.PW_ATTACK then
1352-
statusText:SetText("Waiting for another faction to launch an attack.")
1353-
elseif defending then
1354-
local planets = lobby.planetwarsData.planets
1355-
local planetName = planets and planets[1] and not planets[2] and planets[1].PlanetName
1356-
if planetName then
1357-
planetName = " " .. planetName
1358-
end
1359-
if planetName then
1360-
statusText:SetText("Your planet " .. planetName .. " is under attack. Join the defence before it is too late!")
1361-
else
1362-
statusText:SetText("Your planets are under attack. Join the defence before it is too late!")
1363-
end
1364-
elseif currentMode == lobby.PW_DEFEND then
1365-
statusText:SetText("Another faction is preparing their response to an invasion.")
1356+
local myAttack, myFactionAttack = GetAttackingPlanet()
1357+
if myAttack then
1358+
statusText:SetText("You are attacking " .. myAttack .. " wait for defenders to muster.")
1359+
elseif myFactionAttack then
1360+
statusText:SetText("Your faction is attacking but may also be under attack. Join planets that need defenders.")
13661361
else
1367-
statusText:SetText("Planetwars is either offline or loading.")
1362+
statusText:SetText("Join any planets that need defenders.")
13681363
end
1364+
1365+
--if currentMode == lobby.PW_ATTACK then
1366+
-- statusText:SetText("Waiting for another faction to launch an attack.")
1367+
--elseif defending then
1368+
-- local planets = lobby.planetwarsData.planets
1369+
-- local planetName = planets and planets[1] and not planets[2] and planets[1].PlanetName
1370+
-- if planetName then
1371+
-- planetName = " " .. planetName
1372+
-- end
1373+
-- if planetName then
1374+
-- statusText:SetText("Your planet " .. planetName .. " is under attack. Join the defence before it is too late!")
1375+
-- else
1376+
-- statusText:SetText("Your planets are under attack. Join the defence before it is too late!")
1377+
-- end
1378+
--elseif currentMode == lobby.PW_DEFEND then
1379+
-- statusText:SetText("Another faction is preparing their response to an invasion.")
1380+
--else
1381+
-- statusText:SetText("Planetwars is either offline or loading.")
1382+
--end
13691383
end
13701384
end
13711385

@@ -1418,6 +1432,7 @@ local function InitializeControls(window)
14181432
planetList.UpdateJoinCheck()
14191433
end
14201434
lobby:AddListener("OnPwAttackCharges", OnPwAttackCharges)
1435+
14211436
local externalFunctions = {}
14221437

14231438
function externalFunctions.CheckDownloads()
@@ -1446,6 +1461,7 @@ local function InitializeControls(window)
14461461
if timeRemaining then
14471462
lblTitle:SetCaption(title .. Spring.Utilities.FormatTime(timeRemaining, true))
14481463
end
1464+
UpdateChargesText()
14491465
end
14501466

14511467
function externalFunctions.SetPlanetJoined(planetID)

0 commit comments

Comments
 (0)