@@ -24,7 +24,7 @@ local planetwarsLevelRequired = false
2424local IMG_LINK = LUA_DIRNAME .. " images/link.png"
2525
2626local panelInterface
27- local PLANET_NAME_LENGTH = 350
27+ local PLANET_NAME_LENGTH = 450
2828local FACTION_SPACING = 134
2929local LIST_PHASE_FRACTIONS = false
3030
@@ -49,6 +49,14 @@ local DoUnMatchedActivityUpdate -- Activity update function
4949---- ----------------------------------------------------------------------------
5050-- Utilities
5151
52+ local function HexToColorString (hex )
53+ local r = string.format (" %03d" , tonumber (string.sub (hex , 2 , 3 ) or " ff" , 16 ))
54+ local g = string.format (" %03d" , tonumber (string.sub (hex , 4 , 5 ) or " ff" , 16 ))
55+ local b = string.format (" %03d" , tonumber (string.sub (hex , 6 , 7 ) or " ff" , 16 ))
56+ local postfunc , err = loadstring ([[ return "\255\]] .. r .. [[ \]] .. g .. [[ \]] .. b .. [[ "]] )
57+ return postfunc ()
58+ end
59+
5260local function HaveRightEngineVersion ()
5361 local configuration = WG .Chobby .Configuration
5462 if configuration .useWrongEngine then
@@ -99,7 +107,7 @@ local function GetAttackingOrDefending(lobby, attackerFactions, defenderFactions
99107 local myFaction = lobby :GetMyFaction ()
100108 if defenderFactions and # defenderFactions > 0 then
101109 return false , true
102- else
110+ elseif attackerFactions and # attackerFactions > 0 then
103111 return true , false
104112 end
105113 -- local attackPhase = false
@@ -121,6 +129,7 @@ local function GetAttackingOrDefending(lobby, attackerFactions, defenderFactions
121129 -- end
122130 -- end
123131 -- return attackPhase, defendPhase
132+ return false , false
124133end
125134
126135local function IsPhaseUrgent ()
@@ -681,11 +690,16 @@ local function MakePlanetControl(planetData, DeselectOtherFunc, attackPhase, def
681690 parent = holder ,
682691 }
683692
684- local function SetPlanetName (newPlanetName , faction )
685- local factionData = faction lobby : GetFactionData ( faction )
693+ local function SetPlanetName (planet )
694+ local newPlanetName = planet . PlanetName
686695 newPlanetName = StringUtilities .GetTruncatedStringWithDotDot (newPlanetName , tbPlanetName .font , PLANET_NAME_LENGTH - 24 )
687- if factionData and factionData .Name then
688- newPlanetName = newPlanetName .. " (" .. factionData .Name .. " )"
696+ if defendPhase and planet .AttackerAvgWhr then
697+ local skill = math.floor ((planet .AttackerAvgWhr + 50 )/ 100 )* 100
698+ newPlanetName = newPlanetName .. string.format (" (skill %d)" , skill )
699+ end
700+ local factionData = planet .OwnerFaction and lobby :GetFactionData (planet .OwnerFaction )
701+ if factionData and factionData .Color then
702+ newPlanetName = HexToColorString (factionData .Color ) .. newPlanetName
689703 end
690704 tbPlanetName :SetText (newPlanetName )
691705 local length = tbPlanetName .font :GetTextWidth (newPlanetName )
@@ -791,7 +805,7 @@ local function MakePlanetControl(planetData, DeselectOtherFunc, attackPhase, def
791805 }
792806
793807 -- Initialization
794- SetPlanetName (planetData . PlanetName , planetData . OwnerFaction )
808+ SetPlanetName (planetData )
795809 UpdateJoinButton ()
796810
797811 local externalFunctions = {}
@@ -820,7 +834,7 @@ local function MakePlanetControl(planetData, DeselectOtherFunc, attackPhase, def
820834 imMinimap :ResetImageLoadTimer ()
821835 imMinimap :Invalidate ()
822836
823- SetPlanetName (newPlanetData . PlanetName , newPlanetData . OwnerFaction )
837+ SetPlanetName (newPlanetData )
824838 end
825839 planetID = newPlanetData .PlanetID
826840
@@ -1254,7 +1268,7 @@ local function InitializeControls(window)
12541268 y = 134 ,
12551269 height = 50 ,
12561270 objectOverrideFont = Configuration :GetFont (2 ),
1257- text = " asdf " ,
1271+ text = " " ,
12581272 parent = window
12591273 }
12601274 end
@@ -1327,12 +1341,12 @@ local function InitializeControls(window)
13271341 if rechargeTime then
13281342 local difference , inTheFuture , isNow = Spring .Utilities .GetTimeDifference (rechargeTime , false , true )
13291343 if inTheFuture then
1330- text = text .. " - Regain by defending or passively in " .. difference
1344+ text = text .. " - Gain more by defending or waiting for " .. difference
13311345 else
1332- text = text .. " - Regain by defending or passively in 0 seconds"
1346+ text = text .. " - Gain more by defending or waiting for 0 seconds"
13331347 end
13341348 elseif charges < pwData .maxCharges then
1335- text = text .. " - Regain by defending"
1349+ text = text .. " - Gain more by defending"
13361350 end
13371351 chargesText :SetText (text )
13381352 end
@@ -1355,7 +1369,7 @@ local function InitializeControls(window)
13551369 end
13561370 end
13571371
1358- local function UpdateStatusText (attackPhase , defending , currentMode , planets )
1372+ local function UpdateStatusText (attackPhase , defendPhase , currentMode , planets )
13591373 if not CheckPlanetwarsRequirements () or missingResources then
13601374 return
13611375 end
@@ -1364,7 +1378,7 @@ local function InitializeControls(window)
13641378 if charges == 0 then
13651379 statusText :SetText (" You are out of attack charges. Regain charges by defending or waiting for the recharge timer." )
13661380 else
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. " )
1381+ statusText :SetText (" Select a planet to attack, it will launch when the timer runs out if enough allies join you." )
13681382 end
13691383 if planets then
13701384 UpdatePlanetStatusData (attackPhase , planets )
@@ -1375,58 +1389,23 @@ local function InitializeControls(window)
13751389 planetStatusText [planetStatusNames [i ]]:SetVisibility (true )
13761390 end
13771391 end
1378-
1379- -- else
1380- -- local planets = lobby.planetwarsData.planets
1381- -- local noPlanets = not (planets and planets[1])
1382- -- local planetName = planets and (FindMyattackPhasePlanet(planets) or (planets[1] and not planets[2] and planets[1].PlanetName))
1383- -- if lobby.planetwarsData.attackPhasePlanet then
1384- -- if planetName then
1385- -- statusText:SetText("You are attacking " .. planetName .. ". The defenders have limited time to respond.")
1386- -- else
1387- -- statusText:SetText("You are attacking a planet. Wait for the defenders have limited time to respond.")
1388- -- end
1389- -- elseif noPlanets then
1390- -- statusText:SetText("Your faction has launched an attack. The defenders have limited time to respond")
1391- --
1392- -- elseif planetName then
1393- -- statusText:SetText("Your faction is attacking " .. planetName .. ". The defenders have limited time to respond")
1394- -- else
1395- -- statusText:SetText("Your faction is attacking multiple planets. The defenders have limited time to respond")
1396- -- end
1397- -- end
1398- else
1392+ elseif defendPhase then
13991393 local myAttack , myFactionAttack = GetAttackingPlanet ()
14001394 if myAttack then
1401- statusText :SetText (" You are attacking " .. myAttack .. " , the battle will start at the end of the phase." )
1402- elseif myFactionAttack then
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." )
1395+ statusText :SetText (" You are attacking " .. myAttack .. " , the battle will start if there are any defenders at the end of the phase (or they forfeit)." )
14041396 else
1405- statusText :SetText (" Join any planets that need defenders. Participating in defense generates an attack charge" )
1397+ statusText :SetText (" Join planets that need defenders. Participating in defense generates an attack charge charge. " )
14061398 end
14071399
14081400 for i = 1 , # planetStatusNames do
14091401 planetStatusText [planetStatusNames [i ]]:SetVisibility (false )
14101402 end
1403+ else
1404+ statusText :SetText (" Error fetching Planetwars state. Try logging out then in again." )
14111405
1412- -- if currentMode == lobby.PW_ATTACK then
1413- -- statusText:SetText("Waiting for another faction to launch an attack.")
1414- -- elseif defending then
1415- -- local planets = lobby.planetwarsData.planets
1416- -- local planetName = planets and planets[1] and not planets[2] and planets[1].PlanetName
1417- -- if planetName then
1418- -- planetName = " " .. planetName
1419- -- end
1420- -- if planetName then
1421- -- statusText:SetText("Your planet " .. planetName .. " is under attack. Join the defence before it is too late!")
1422- -- else
1423- -- statusText:SetText("Your planets are under attack. Join the defence before it is too late!")
1424- -- end
1425- -- elseif currentMode == lobby.PW_DEFEND then
1426- -- statusText:SetText("Another faction is preparing their response to an invasion.")
1427- -- else
1428- -- statusText:SetText("Planetwars is either offline or loading.")
1429- -- end
1406+ for i = 1 , # planetStatusNames do
1407+ planetStatusText [planetStatusNames [i ]]:SetVisibility (false )
1408+ end
14301409 end
14311410 end
14321411
@@ -1473,6 +1452,7 @@ local function InitializeControls(window)
14731452 lobby :AddListener (" OnUpdateUserStatus" , OnUpdateUserStatus )
14741453
14751454 local function OnPwAttackCharges (listener , newCharges , newRechargeTime )
1455+ local attackPhase , defendPhase = GetAttackingOrDefending (lobby , oldAttackerFaction , oldDefenderFactions , oldMode )
14761456 charges , rechargeTime = newCharges , newRechargeTime
14771457 UpdateChargesText ()
14781458 UpdateStatusText (attackPhase , defendPhase , oldMode )
0 commit comments