Pushed down the MouseInput handling to the OrderGenerators and made a base class for handling the basic logic

This commit is contained in:
teinarss
2019-03-30 20:07:11 +01:00
committed by reaperrr
parent 9ec8d25dff
commit 1dd90a1d7b
13 changed files with 120 additions and 77 deletions

View File

@@ -13,6 +13,7 @@ using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Mods.Common.Orders;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
@@ -61,7 +62,7 @@ namespace OpenRA.Mods.Cnc.Traits
}
}
public class SelectAttackPowerTarget : IOrderGenerator
public class SelectAttackPowerTarget : OrderGenerator
{
readonly SupportPowerManager manager;
readonly SupportPowerInstance instance;
@@ -94,7 +95,7 @@ namespace OpenRA.Mods.Cnc.Traits
return world.Map.Contains(cell) && instance.Instances.Any(a => !a.IsTraitPaused && (a.Self.CenterPosition - pos).HorizontalLengthSquared < range);
}
IEnumerable<Order> IOrderGenerator.Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
protected override IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi)
{
world.CancelInputMode();
if (mi.Button == expectedButton && IsValidTarget(world, cell))
@@ -104,16 +105,16 @@ namespace OpenRA.Mods.Cnc.Traits
};
}
void IOrderGenerator.Tick(World world)
protected override void Tick(World world)
{
// Cancel the OG if we can't use the power
if (!manager.Powers.ContainsKey(order))
world.CancelInputMode();
}
IEnumerable<IRenderable> IOrderGenerator.Render(WorldRenderer wr, World world) { yield break; }
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
IEnumerable<IRenderable> IOrderGenerator.RenderAboveShroud(WorldRenderer wr, World world)
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
{
foreach (var a in instance.Instances.Where(i => !i.IsTraitPaused))
{
@@ -133,7 +134,7 @@ namespace OpenRA.Mods.Cnc.Traits
}
}
string IOrderGenerator.GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
{
return IsValidTarget(world, cell) ? cursor : cursorBlocked;
}