Added: StrategicProgressWidget to show the capturing progress (including custom gfx)
Fixed: Sync on unsyncable field type Added: StrategicProgressWidget to both cnc & ra
This commit is contained in:
@@ -263,6 +263,7 @@
|
|||||||
<Compile Include="Widgets\PowerBinWidget.cs" />
|
<Compile Include="Widgets\PowerBinWidget.cs" />
|
||||||
<Compile Include="Widgets\RadarBinWidget.cs" />
|
<Compile Include="Widgets\RadarBinWidget.cs" />
|
||||||
<Compile Include="Widgets\SpecialPowerBinWidget.cs" />
|
<Compile Include="Widgets\SpecialPowerBinWidget.cs" />
|
||||||
|
<Compile Include="Widgets\StrategicProgressWidget.cs" />
|
||||||
<Compile Include="Widgets\WorldCommandWidget.cs" />
|
<Compile Include="Widgets\WorldCommandWidget.cs" />
|
||||||
<Compile Include="Widgets\WorldTooltipWidget.cs" />
|
<Compile Include="Widgets\WorldTooltipWidget.cs" />
|
||||||
<Compile Include="WithMuzzleFlash.cs" />
|
<Compile Include="WithMuzzleFlash.cs" />
|
||||||
|
|||||||
@@ -31,12 +31,12 @@ namespace OpenRA.Mods.RA
|
|||||||
public class StrategicVictoryConditions : ITick
|
public class StrategicVictoryConditions : ITick
|
||||||
{
|
{
|
||||||
[Sync] public Actor Self;
|
[Sync] public Actor Self;
|
||||||
[Sync] public StrategicVictoryConditionsInfo Info;
|
public StrategicVictoryConditionsInfo Info;
|
||||||
|
|
||||||
[Sync] public int TicksToHold;
|
[Sync] public int TicksToHold;
|
||||||
[Sync] public bool ResetOnHoldLost;
|
[Sync] public bool ResetOnHoldLost;
|
||||||
[Sync] public float RatioRequired;
|
public float RatioRequired;
|
||||||
[Sync] public float CriticalRatioRequired;
|
public float CriticalRatioRequired;
|
||||||
[Sync] public bool SplitHolds;
|
[Sync] public bool SplitHolds;
|
||||||
[Sync] public int TicksLeft = 0;
|
[Sync] public int TicksLeft = 0;
|
||||||
[Sync] public int CriticalTicksLeft = 0;
|
[Sync] public int CriticalTicksLeft = 0;
|
||||||
|
|||||||
116
OpenRA.Mods.RA/Widgets/StrategicProgressWidget.cs
Normal file
116
OpenRA.Mods.RA/Widgets/StrategicProgressWidget.cs
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.RA.Widgets
|
||||||
|
{
|
||||||
|
public class StrategicProgressWidget : Widget
|
||||||
|
{
|
||||||
|
bool Initialised = false;
|
||||||
|
|
||||||
|
public StrategicProgressWidget() { IsVisible = () => true; }
|
||||||
|
|
||||||
|
public override void DrawInner(WorldRenderer wr)
|
||||||
|
{
|
||||||
|
if (!Initialised)
|
||||||
|
Init(wr);
|
||||||
|
|
||||||
|
if (!IsVisible()) return;
|
||||||
|
int2 offset = int2.Zero;
|
||||||
|
|
||||||
|
var svc = wr.world.players.Select(p => p.Value.PlayerActor.TraitOrDefault<StrategicVictoryConditions>()).FirstOrDefault();
|
||||||
|
|
||||||
|
var totalWidth = (svc.Total + svc.TotalCritical)*32;
|
||||||
|
int curX = -(totalWidth / 2);
|
||||||
|
|
||||||
|
foreach (var a in wr.world.Actors.Where(a => !a.Destroyed && a.HasTrait<StrategicPoint>() && !a.TraitOrDefault<StrategicPoint>().Critical))
|
||||||
|
{
|
||||||
|
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("strategic", "unowned"), offset + new float2(RenderBounds.Left + curX, RenderBounds.Top));
|
||||||
|
|
||||||
|
if (a.Owner == wr.world.LocalPlayer || (a.Owner.Stances[wr.world.LocalPlayer] == Stance.Ally && wr.world.LocalPlayer.Stances[a.Owner] == Stance.Ally))
|
||||||
|
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("strategic", "player_owned"), offset + new float2(RenderBounds.Left + curX, RenderBounds.Top));
|
||||||
|
else if (!a.Owner.NonCombatant)
|
||||||
|
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("strategic", "enemy_owned"), offset + new float2(RenderBounds.Left + curX, RenderBounds.Top));
|
||||||
|
curX += 32;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var a in wr.world.Actors.Where(a => !a.Destroyed && a.HasTrait<StrategicPoint>() && a.TraitOrDefault<StrategicPoint>().Critical))
|
||||||
|
{
|
||||||
|
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("strategic", "critical_unowned"), offset + new float2(RenderBounds.Left + curX, RenderBounds.Top));
|
||||||
|
|
||||||
|
if (a.Owner == wr.world.LocalPlayer || (a.Owner.Stances[wr.world.LocalPlayer] == Stance.Ally && wr.world.LocalPlayer.Stances[a.Owner] == Stance.Ally))
|
||||||
|
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("strategic", "player_owned"), offset + new float2(RenderBounds.Left + curX, RenderBounds.Top));
|
||||||
|
else if (!a.Owner.NonCombatant)
|
||||||
|
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("strategic", "enemy_owned"), offset + new float2(RenderBounds.Left + curX, RenderBounds.Top));
|
||||||
|
|
||||||
|
curX += 32;
|
||||||
|
}
|
||||||
|
offset += new int2(0, 32);
|
||||||
|
|
||||||
|
var pendingWinner = FindFirstWinningPlayer(wr.world);
|
||||||
|
if (pendingWinner == null) return;
|
||||||
|
svc = pendingWinner.PlayerActor.TraitOrDefault<StrategicVictoryConditions>();
|
||||||
|
|
||||||
|
if (wr.world.LocalPlayer == null)
|
||||||
|
{
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
var tc = "";
|
||||||
|
|
||||||
|
if (pendingWinner != wr.world.LocalPlayer && (pendingWinner.Stances[wr.world.LocalPlayer] != Stance.Ally || wr.world.LocalPlayer.Stances[pendingWinner] != Stance.Ally))
|
||||||
|
{
|
||||||
|
// losing
|
||||||
|
tc = "Strategic defeat in " + ((svc.CriticalTicksLeft > svc.TicksLeft) ? svc.CriticalTicksLeft / 25 : svc.TicksLeft / 25) + " second(s)";
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
// winning
|
||||||
|
tc = "Strategic victory in " + ((svc.CriticalTicksLeft > svc.TicksLeft) ? svc.CriticalTicksLeft / 25 : svc.TicksLeft / 25) + " second(s)";
|
||||||
|
}
|
||||||
|
|
||||||
|
var size = Game.Renderer.BoldFont.Measure(tc);
|
||||||
|
|
||||||
|
Game.Renderer.BoldFont.DrawText(tc, offset + new float2(RenderBounds.Left - size.X / 2 + 1, RenderBounds.Top + 1), Color.Black);
|
||||||
|
Game.Renderer.BoldFont.DrawText(tc, offset + new float2(RenderBounds.Left - size.X / 2, RenderBounds.Top), Color.WhiteSmoke);
|
||||||
|
offset += new int2(0, size.Y + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player FindFirstWinningPlayer(World world)
|
||||||
|
{
|
||||||
|
// loop through all players, see who is 'winning' and get the one with the shortest 'time to win'
|
||||||
|
int shortest = int.MaxValue;
|
||||||
|
Player shortestPlayer = null;
|
||||||
|
|
||||||
|
foreach (var p in world.players.Select(p => p.Value).Where(p => !p.NonCombatant))
|
||||||
|
{
|
||||||
|
var svc = p.PlayerActor.TraitOrDefault<StrategicVictoryConditions>();
|
||||||
|
|
||||||
|
if (svc.HoldingCritical && svc.CriticalTicksLeft > 0 && svc.CriticalTicksLeft < shortest)
|
||||||
|
{
|
||||||
|
shortest = svc.CriticalTicksLeft;
|
||||||
|
shortestPlayer = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (svc.Holding && svc.TicksLeft > 0 && svc.TicksLeft < shortest)
|
||||||
|
{
|
||||||
|
shortest = svc.CriticalTicksLeft;
|
||||||
|
shortestPlayer = p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return shortestPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Init(WorldRenderer wr)
|
||||||
|
{
|
||||||
|
IsVisible = () => (wr.world.Actors.Where(a => a.HasTrait<StrategicVictoryConditions>()).Any() && wr.world.Actors.Where(a => a.HasTrait<StrategicPoint>()).Any());
|
||||||
|
Initialised = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -209,4 +209,12 @@
|
|||||||
<collection name="checkbox" src="buttons.png">
|
<collection name="checkbox" src="buttons.png">
|
||||||
<image name="checked" x="0" y="112" width="16" height="16" />
|
<image name="checked" x="0" y="112" width="16" height="16" />
|
||||||
</collection>
|
</collection>
|
||||||
|
<collection name="strategic" src="strategic.png">
|
||||||
|
<image name="unowned" x="0" y="0" width="32" height="32" />
|
||||||
|
<!-- <image name="owned" x="32" y="0" width="32" height="32" /> -->
|
||||||
|
<image name="critical_unowned" x="0" y="32" width="32" height="32" />
|
||||||
|
<image name="enemy_owned" x="32" y="32" width="32" height="32" />
|
||||||
|
<!-- <image name="unused_unowned" x="0" y="32" width="32" height="32" /> -->
|
||||||
|
<image name="player_owned" x="96" y="0" width="32" height="32" />
|
||||||
|
</collection>
|
||||||
</chrome>
|
</chrome>
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ Container@INGAME_ROOT:
|
|||||||
Id:GAME_TIMER
|
Id:GAME_TIMER
|
||||||
X: WINDOW_RIGHT/2
|
X: WINDOW_RIGHT/2
|
||||||
Y: 10
|
Y: 10
|
||||||
|
StrategicProgress@STRATEGIC_PROGRESS:
|
||||||
|
Id:STRATEGIC_PROGRESS
|
||||||
|
X: WINDOW_RIGHT/2
|
||||||
|
Y: 40
|
||||||
Background@POSTGAME_BG:
|
Background@POSTGAME_BG:
|
||||||
Id:POSTGAME_BG
|
Id:POSTGAME_BG
|
||||||
X:(WINDOW_RIGHT - WIDTH)/2
|
X:(WINDOW_RIGHT - WIDTH)/2
|
||||||
|
|||||||
BIN
mods/cnc/uibits/strategic.png
Normal file
BIN
mods/cnc/uibits/strategic.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
@@ -174,6 +174,14 @@
|
|||||||
<image name="unowned" x="528" y="128" width="16" height="16" />
|
<image name="unowned" x="528" y="128" width="16" height="16" />
|
||||||
<image name="owned" x="512" y="128" width="16" height="16" />
|
<image name="owned" x="512" y="128" width="16" height="16" />
|
||||||
</collection>
|
</collection>
|
||||||
|
<collection name="strategic" src="strategic.png">
|
||||||
|
<image name="unowned" x="0" y="0" width="32" height="32" />
|
||||||
|
<!-- <image name="owned" x="32" y="0" width="32" height="32" /> -->
|
||||||
|
<image name="critical_unowned" x="0" y="32" width="32" height="32" />
|
||||||
|
<image name="enemy_owned" x="32" y="32" width="32" height="32" />
|
||||||
|
<!-- <image name="unused_unowned" x="0" y="32" width="32" height="32" /> -->
|
||||||
|
<image name="player_owned" x="96" y="0" width="32" height="32" />
|
||||||
|
</collection>
|
||||||
<collection name="sell-button" src="buttons.png">
|
<collection name="sell-button" src="buttons.png">
|
||||||
<image name="normal" x="0" y="0" width="34" height="28" />
|
<image name="normal" x="0" y="0" width="34" height="28" />
|
||||||
<image name="pressed" x="34" y="0" width="34" height="28" />
|
<image name="pressed" x="34" y="0" width="34" height="28" />
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ Container@INGAME_ROOT:
|
|||||||
Id:GAME_TIMER
|
Id:GAME_TIMER
|
||||||
X: WINDOW_RIGHT/2
|
X: WINDOW_RIGHT/2
|
||||||
Y: 10
|
Y: 10
|
||||||
|
StrategicProgress@STRATEGIC_PROGRESS:
|
||||||
|
Id:STRATEGIC_PROGRESS
|
||||||
|
X: WINDOW_RIGHT/2
|
||||||
|
Y: 40
|
||||||
Background@POSTGAME_BG:
|
Background@POSTGAME_BG:
|
||||||
Id:POSTGAME_BG
|
Id:POSTGAME_BG
|
||||||
X:(WINDOW_RIGHT - WIDTH)/2
|
X:(WINDOW_RIGHT - WIDTH)/2
|
||||||
|
|||||||
BIN
mods/ra/uibits/strategic.png
Normal file
BIN
mods/ra/uibits/strategic.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
Reference in New Issue
Block a user