Fix filenames of capture related traits.

This commit is contained in:
Mustafa Alperen Seki
2019-03-12 12:18:43 +03:00
committed by reaperrr
parent 00b8576edf
commit 35ad33e8be
4 changed files with 31 additions and 31 deletions

View File

@@ -311,9 +311,9 @@
<Compile Include="Traits\Buildings\RepairableBuilding.cs" /> <Compile Include="Traits\Buildings\RepairableBuilding.cs" />
<Compile Include="Traits\Buildings\RequiresBuildableArea.cs" /> <Compile Include="Traits\Buildings\RequiresBuildableArea.cs" />
<Compile Include="Traits\Buildings\Reservable.cs" /> <Compile Include="Traits\Buildings\Reservable.cs" />
<Compile Include="Traits\CapturableProgressBar.cs" />
<Compile Include="Traits\CaptureProgressBar.cs" /> <Compile Include="Traits\CaptureProgressBar.cs" />
<Compile Include="Traits\CaptureProgressBlink.cs" /> <Compile Include="Traits\CapturableProgressBar.cs" />
<Compile Include="Traits\CapturableProgressBlink.cs" />
<Compile Include="Traits\Conditions\GrantConditionOnPlayerResources.cs" /> <Compile Include="Traits\Conditions\GrantConditionOnPlayerResources.cs" />
<Compile Include="Traits\GrantExternalConditionToProduced.cs" /> <Compile Include="Traits\GrantExternalConditionToProduced.cs" />
<Compile Include="Traits\Multipliers\CreatesShroudMultiplier.cs" /> <Compile Include="Traits\Multipliers\CreatesShroudMultiplier.cs" />

View File

@@ -9,45 +9,48 @@
*/ */
#endregion #endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Primitives; using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Visualize the progress of this actor being captured.")] [Desc("Visualize capture progress.")]
class CaptureProgressBarInfo : ITraitInfo, Requires<CapturesInfo> class CapturableProgressBarInfo : ITraitInfo, Requires<CapturableInfo>
{ {
public readonly Color Color = Color.Orange; public readonly Color Color = Color.Orange;
public object Create(ActorInitializer init) { return new CaptureProgressBar(init.Self, this); } public object Create(ActorInitializer init) { return new CapturableProgressBar(init.Self, this); }
} }
class CaptureProgressBar : ISelectionBar, ICaptureProgressWatcher class CapturableProgressBar : ISelectionBar, ICaptureProgressWatcher
{ {
readonly CaptureProgressBarInfo info; readonly CapturableProgressBarInfo info;
int current; Dictionary<Actor, Pair<int, int>> progress = new Dictionary<Actor, Pair<int, int>>();
int total;
public CaptureProgressBar(Actor self, CaptureProgressBarInfo info) public CapturableProgressBar(Actor self, CapturableProgressBarInfo info)
{ {
this.info = info; this.info = info;
} }
void ICaptureProgressWatcher.Update(Actor self, Actor captor, Actor target, int current, int total) void ICaptureProgressWatcher.Update(Actor self, Actor captor, Actor target, int current, int total)
{ {
if (self != captor) if (self != target)
return; return;
this.current = current; if (total == 0)
this.total = total; progress.Remove(captor);
else
progress[captor] = Pair.New(current, total);
} }
float ISelectionBar.GetValue() float ISelectionBar.GetValue()
{ {
if (total == 0) if (!progress.Any())
return 0f; return 0f;
return (float)current / total; return progress.Values.Max(p => (float)p.First / p.Second);
} }
Color ISelectionBar.GetColor() { return info.Color; } Color ISelectionBar.GetColor() { return info.Color; }

View File

@@ -9,48 +9,45 @@
*/ */
#endregion #endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Primitives; using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Visualize capture progress.")] [Desc("Visualize the progress of this actor being captured.")]
class CapturableProgressBarInfo : ITraitInfo, Requires<CapturableInfo> class CaptureProgressBarInfo : ITraitInfo, Requires<CapturesInfo>
{ {
public readonly Color Color = Color.Orange; public readonly Color Color = Color.Orange;
public object Create(ActorInitializer init) { return new CapturableProgressBar(init.Self, this); } public object Create(ActorInitializer init) { return new CaptureProgressBar(init.Self, this); }
} }
class CapturableProgressBar : ISelectionBar, ICaptureProgressWatcher class CaptureProgressBar : ISelectionBar, ICaptureProgressWatcher
{ {
readonly CapturableProgressBarInfo info; readonly CaptureProgressBarInfo info;
Dictionary<Actor, Pair<int, int>> progress = new Dictionary<Actor, Pair<int, int>>(); int current;
int total;
public CapturableProgressBar(Actor self, CapturableProgressBarInfo info) public CaptureProgressBar(Actor self, CaptureProgressBarInfo info)
{ {
this.info = info; this.info = info;
} }
void ICaptureProgressWatcher.Update(Actor self, Actor captor, Actor target, int current, int total) void ICaptureProgressWatcher.Update(Actor self, Actor captor, Actor target, int current, int total)
{ {
if (self != target) if (self != captor)
return; return;
if (total == 0) this.current = current;
progress.Remove(captor); this.total = total;
else
progress[captor] = Pair.New(current, total);
} }
float ISelectionBar.GetValue() float ISelectionBar.GetValue()
{ {
if (!progress.Any()) if (total == 0)
return 0f; return 0f;
return progress.Values.Max(p => (float)p.First / p.Second); return (float)current / total;
} }
Color ISelectionBar.GetColor() { return info.Color; } Color ISelectionBar.GetColor() { return info.Color; }