Skip to content

Commit 05742dd

Browse files
committed
More PW UI.
1 parent c9f6bb0 commit 05742dd

1 file changed

Lines changed: 71 additions & 21 deletions

File tree

LuaMenu/widgets/gui_planetwars_list_window.lua

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ local planetwarsLevelRequired = false
2424
local IMG_LINK = LUA_DIRNAME .. "images/link.png"
2525

2626
local panelInterface
27-
local PLANET_NAME_LENGTH = 210
27+
local PLANET_NAME_LENGTH = 350
2828
local FACTION_SPACING = 134
2929
local LIST_PHASE_FRACTIONS = false
3030

@@ -128,7 +128,7 @@ local function IsPhaseUrgent()
128128
return timeRemaining and timeRemaining < URGENT_ATTACK_TIME
129129
end
130130

131-
local function FindMyAttackPhasePlanet(planets)
131+
local function FindMyAttackPhasePlanet(lobby, planets)
132132
local planetID = lobby.planetwarsData.attackPhasePlanet
133133
if not planetID then
134134
return false
@@ -148,13 +148,12 @@ local function GetActivityToPrompt(lobby, attackerFactions, defenderFactions, cu
148148
end
149149

150150
if lobby.planetwarsData.attackingPlanet and planets then
151-
local myPlanet = FindMyAttackPhasePlanet(planets)
151+
local myPlanet = FindMyAttackPhasePlanet(lobby, planets)
152152
if myPlanet then
153153
return myPlanet, true, true, false
154154
end
155155
return false
156156
end
157-
158157
local attackPhase, defendPhase = GetAttackingOrDefending(lobby, attackerFactions, defenderFactions)
159158
if lobby.planetwarsData.joinPlanet and planets then
160159
local planetID = lobby.planetwarsData.joinPlanet
@@ -513,7 +512,7 @@ local function InitializeActivityPromptHandler()
513512
PossiblyPlayWarning(isAttacker)
514513
if alreadyJoined then
515514
if isAttacker then
516-
planetStatusTextBox:SetText("Attack: " .. planetData.PlanetName)
515+
planetStatusTextBox:SetText("Attacking: " .. planetData.PlanetName)
517516
if waitingForAllies then
518517
battleStatusText = "Attackers " .. newPlanetData.Count .. "/" .. newPlanetData.Needed .. ", "
519518
else
@@ -682,8 +681,12 @@ local function MakePlanetControl(planetData, DeselectOtherFunc, attackPhase, def
682681
parent = holder,
683682
}
684683

685-
local function SetPlanetName(newPlanetName)
684+
local function SetPlanetName(newPlanetName, faction)
685+
local factionData = faction lobby:GetFactionData(faction)
686686
newPlanetName = StringUtilities.GetTruncatedStringWithDotDot(newPlanetName, tbPlanetName.font, PLANET_NAME_LENGTH - 24)
687+
if factionData and factionData.Name then
688+
newPlanetName = newPlanetName .. " (" .. factionData.Name .. ")"
689+
end
687690
tbPlanetName:SetText(newPlanetName)
688691
local length = tbPlanetName.font:GetTextWidth(newPlanetName)
689692
imgPlanetLink:SetPos(length + 7)
@@ -788,7 +791,7 @@ local function MakePlanetControl(planetData, DeselectOtherFunc, attackPhase, def
788791
}
789792

790793
-- Initialization
791-
SetPlanetName(planetData.PlanetName)
794+
SetPlanetName(planetData.PlanetName, planetData.OwnerFaction)
792795
UpdateJoinButton()
793796

794797
local externalFunctions = {}
@@ -817,7 +820,7 @@ local function MakePlanetControl(planetData, DeselectOtherFunc, attackPhase, def
817820
imMinimap:ResetImageLoadTimer()
818821
imMinimap:Invalidate()
819822

820-
SetPlanetName(newPlanetData.PlanetName)
823+
SetPlanetName(newPlanetData.PlanetName, newPlanetData.OwnerFaction)
821824
end
822825
planetID = newPlanetData.PlanetID
823826

@@ -1176,9 +1179,9 @@ local function InitializeControls(window)
11761179
}
11771180

11781181
local listHolder = Control:New {
1179-
x = 5,
1180-
right = 5,
1181-
y = 170,
1182+
x = 12,
1183+
right = 12,
1184+
y = 152,
11821185
bottom = 46,
11831186
padding = {5, 5, 5, 5},
11841187
parent = window,
@@ -1235,13 +1238,27 @@ local function InitializeControls(window)
12351238
local chargesText = TextBox:New {
12361239
x = 20,
12371240
right = 16,
1238-
y = 116,
1241+
y = 112,
12391242
height = 50,
12401243
objectOverrideFont = Configuration:GetFont(2),
12411244
text = "",
12421245
parent = window
12431246
}
12441247

1248+
local planetStatusText = {}
1249+
local planetStatusNames = {"attackers", "incoming", "neutral"}
1250+
for i = 1, #planetStatusNames do
1251+
planetStatusText[planetStatusNames[i]] = TextBox:New {
1252+
x = 20 + (i - 1) * 180 + math.max(0, i - 2)*25,
1253+
right = 16,
1254+
y = 134,
1255+
height = 50,
1256+
objectOverrideFont = Configuration:GetFont(2),
1257+
text = "asdf",
1258+
parent = window
1259+
}
1260+
end
1261+
12451262
local function CheckPlanetwarsRequirements()
12461263
local myUserInfo = lobby:GetMyInfo()
12471264
if not (planetwarsSoon or planetwarsEnabled) then
@@ -1310,26 +1327,55 @@ local function InitializeControls(window)
13101327
if rechargeTime then
13111328
local difference, inTheFuture, isNow = Spring.Utilities.GetTimeDifference(rechargeTime, false, true)
13121329
if inTheFuture then
1313-
text = text.. " - Passive recharge in " .. difference
1330+
text = text.. " - Regain by defending or passively in " .. difference
13141331
else
1315-
text = text .. " - Passive recharge in 0 seconds"
1332+
text = text .. " - Regain by defending or passively in 0 seconds"
13161333
end
1334+
elseif charges < pwData.maxCharges then
1335+
text = text .. " - Regain by defending"
13171336
end
1318-
text = text .. "\nSpend charges to attack and regain them by defending."
13191337
chargesText:SetText(text)
13201338
end
13211339

1322-
local function UpdateStatusText(attackPhase, defending, currentMode)
1340+
local planetStatusData = {}
1341+
local function UpdatePlanetStatusData(attackPhase, planets)
1342+
local myFaction = lobby:GetMyFaction()
1343+
planetStatusData.myAttackers = 0
1344+
planetStatusData.myIncoming = 0
1345+
planetStatusData.neutralDefense = 0
1346+
for i = 1, #planets do
1347+
local planet = planets[i]
1348+
if planet.AttackerFaction == myFaction then
1349+
planetStatusData.myAttackers = planetStatusData.myAttackers + planet.Count
1350+
elseif planet.OwnerFaction == myFaction then
1351+
planetStatusData.myIncoming = planetStatusData.myIncoming + planet.Count
1352+
elseif not planet.OwnerFaction then
1353+
planetStatusData.neutralDefense = planetStatusData.neutralDefense + planet.Count
1354+
end
1355+
end
1356+
end
1357+
1358+
local function UpdateStatusText(attackPhase, defending, currentMode, planets)
13231359
if not CheckPlanetwarsRequirements() or missingResources then
13241360
return
13251361
end
13261362

13271363
if attackPhase then
13281364
if charges == 0 then
1329-
statusText:SetText("You are out of attack charges. You need to defend a planet or wait for passive recharge.")
1365+
statusText:SetText("You are out of attack charges. Regain charges by defending or waiting for the recharge timer.")
13301366
else
1331-
statusText:SetText("Choose a planet to attack. All attacks that reach the player threshold are launched when the timer reaches zero.")
1367+
statusText:SetText("Select a planet to attack, it will launch when the timer runs out if enough allies join you. This costs an attack charge.")
1368+
end
1369+
if planets then
1370+
UpdatePlanetStatusData(attackPhase, planets)
1371+
planetStatusText.attackers:SetText("Fellow attackers: " .. planetStatusData.myAttackers)
1372+
planetStatusText.incoming:SetText("Incoming attackers: " .. planetStatusData.myIncoming)
1373+
planetStatusText.neutral:SetText("Neutrals to defend: " .. planetStatusData.neutralDefense)
1374+
for i = 1, #planetStatusNames do
1375+
planetStatusText[planetStatusNames[i]]:SetVisibility(true)
1376+
end
13321377
end
1378+
13331379
--else
13341380
-- local planets = lobby.planetwarsData.planets
13351381
-- local noPlanets = not (planets and planets[1])
@@ -1354,9 +1400,13 @@ local function InitializeControls(window)
13541400
if myAttack then
13551401
statusText:SetText("You are attacking " .. myAttack .. ", the battle will start at the end of the phase.")
13561402
elseif myFactionAttack then
1357-
statusText:SetText("Your faction is attacking but may also be under attack. Join planets that need defenders.")
1403+
statusText:SetText("Your faction is attacking but may also be under attack. Join planets that need defenders. Participating in defense generates an attack charge charge.")
13581404
else
1359-
statusText:SetText("Join any planets that need defenders.")
1405+
statusText:SetText("Join any planets that need defenders. Participating in defense generates an attack charge")
1406+
end
1407+
1408+
for i = 1, #planetStatusNames do
1409+
planetStatusText[planetStatusNames[i]]:SetVisibility(false)
13601410
end
13611411

13621412
--if currentMode == lobby.PW_ATTACK then
@@ -1399,7 +1449,7 @@ local function InitializeControls(window)
13991449

14001450
local attackPhase, defendPhase = GetAttackingOrDefending(lobby, attackerFactions, defenderFactions, currentMode)
14011451
UpdateChargesText()
1402-
UpdateStatusText(attackPhase, defendPhase, currentMode)
1452+
UpdateStatusText(attackPhase, defendPhase, currentMode, planets)
14031453

14041454
planetList.SetPlanetList(planets, attackPhase, defendPhase, modeSwitched)
14051455
end

0 commit comments

Comments
 (0)