Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implemented trait defined Rollovers.
  • Loading branch information
IceReaper committed Nov 12, 2018
1 parent cd82382 commit 5ec5aee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions OpenRA.Game/Traits/TraitsInterfaces.cs
Expand Up @@ -287,6 +287,8 @@ public interface IPips { IEnumerable<PipType> GetPips(Actor self); }
[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);
Expand Down
8 changes: 7 additions & 1 deletion OpenRA.Mods.Common/Traits/Render/SelectionDecorations.cs
Expand Up @@ -34,7 +34,7 @@ public class SelectionDecorationsInfo : ITraitInfo, Requires<IDecorationBoundsIn
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" };
Expand Down Expand Up @@ -121,6 +121,12 @@ IEnumerable<IRenderable> DrawDecorations(Actor self, WorldRenderer wr)
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)
Expand Down
12 changes: 5 additions & 7 deletions OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs
Expand Up @@ -14,7 +14,6 @@
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;
Expand Down Expand Up @@ -48,12 +47,11 @@ public WorldInteractionControllerWidget(World world, WorldRenderer worldRenderer

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()
Expand Down

0 comments on commit 5ec5aee

Please sign in to comment.