Implemented trait defined Rollovers.
This commit is contained in:
@@ -286,6 +286,8 @@ namespace OpenRA.Traits
|
||||
[RequireExplicitImplementation]
|
||||
public interface ISelectionBar { float GetValue(); Color GetColor(); bool DisplayWhenEmpty { get; } }
|
||||
|
||||
public interface ISelectionDecorations { void DrawRollover(Actor self, WorldRenderer worldRenderer); }
|
||||
|
||||
public interface IOccupySpaceInfo : ITraitInfoInterface
|
||||
{
|
||||
IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any);
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
public object Create(ActorInitializer init) { return new SelectionDecorations(init.Self, this); }
|
||||
}
|
||||
|
||||
public class SelectionDecorations : IRenderAboveShroud, INotifyCreated, ITick
|
||||
public class SelectionDecorations : ISelectionDecorations, IRenderAboveShroud, INotifyCreated, ITick
|
||||
{
|
||||
// depends on the order of pips in TraitsInterfaces.cs!
|
||||
static readonly string[] PipStrings = { "pip-empty", "pip-green", "pip-yellow", "pip-red", "pip-gray", "pip-blue", "pip-ammo", "pip-ammoempty" };
|
||||
@@ -121,6 +121,12 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
yield return r;
|
||||
}
|
||||
|
||||
public void DrawRollover(Actor self, WorldRenderer worldRenderer)
|
||||
{
|
||||
var bounds = decorationBounds.FirstNonEmptyBounds(self, worldRenderer);
|
||||
new SelectionBarsRenderable(self, bounds, true, true).Render(worldRenderer);
|
||||
}
|
||||
|
||||
IEnumerable<IRenderable> DrawPips(Actor self, Rectangle bounds, WorldRenderer wr)
|
||||
{
|
||||
if (pipSources.Length == 0)
|
||||
|
||||
@@ -14,7 +14,6 @@ using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Mods.Common.Graphics;
|
||||
using OpenRA.Orders;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
@@ -48,12 +47,11 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
void DrawRollover(Actor unit)
|
||||
{
|
||||
// TODO: Integrate this with SelectionDecorations to unhardcode the *Renderable
|
||||
if (unit.Info.HasTraitInfo<SelectableInfo>())
|
||||
{
|
||||
var bounds = unit.TraitsImplementing<IDecorationBounds>().FirstNonEmptyBounds(unit, worldRenderer);
|
||||
new SelectionBarsRenderable(unit, bounds, true, true).Render(worldRenderer);
|
||||
}
|
||||
var selectionDecorations = unit.TraitOrDefault<ISelectionDecorations>();
|
||||
if (selectionDecorations == null)
|
||||
return;
|
||||
|
||||
selectionDecorations.DrawRollover(unit, worldRenderer);
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
|
||||
Reference in New Issue
Block a user