Pushed down the MouseInput handling to the OrderGenerators and made a base class for handling the basic logic
This commit is contained in:
@@ -155,7 +155,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
|
|
||||||
bool IRenderAboveShroudWhenSelected.SpatiallyPartitionable { get { return false; } }
|
bool IRenderAboveShroudWhenSelected.SpatiallyPartitionable { get { return false; } }
|
||||||
|
|
||||||
class MinefieldOrderGenerator : IOrderGenerator
|
class MinefieldOrderGenerator : OrderGenerator
|
||||||
{
|
{
|
||||||
readonly List<Actor> minelayers;
|
readonly List<Actor> minelayers;
|
||||||
readonly Sprite tileOk;
|
readonly Sprite tileOk;
|
||||||
@@ -179,7 +179,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
minelayers.Add(a);
|
minelayers.Add(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
protected override IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == Game.Settings.Game.MouseButtonPreference.Cancel)
|
if (mi.Button == Game.Settings.Game.MouseButtonPreference.Cancel)
|
||||||
{
|
{
|
||||||
@@ -201,15 +201,15 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(World world)
|
protected override void Tick(World world)
|
||||||
{
|
{
|
||||||
minelayers.RemoveAll(minelayer => !minelayer.IsInWorld || minelayer.IsDead);
|
minelayers.RemoveAll(minelayer => !minelayer.IsInWorld || minelayer.IsDead);
|
||||||
if (!minelayers.Any())
|
if (!minelayers.Any())
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||||
public IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
|
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
|
||||||
{
|
{
|
||||||
var minelayer = minelayers.FirstOrDefault(m => m.IsInWorld && !m.IsDead);
|
var minelayer = minelayers.FirstOrDefault(m => m.IsInWorld && !m.IsDead);
|
||||||
if (minelayer == null)
|
if (minelayer == null)
|
||||||
@@ -230,7 +230,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
return "ability";
|
return "ability";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PortableChronoOrderGenerator : IOrderGenerator
|
class PortableChronoOrderGenerator : OrderGenerator
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
readonly PortableChronoInfo info;
|
readonly PortableChronoInfo info;
|
||||||
@@ -191,7 +191,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
this.info = info;
|
this.info = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
protected override IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == Game.Settings.Game.MouseButtonPreference.Cancel)
|
if (mi.Button == Game.Settings.Game.MouseButtonPreference.Cancel)
|
||||||
{
|
{
|
||||||
@@ -207,18 +207,18 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(World world)
|
protected override void Tick(World world)
|
||||||
{
|
{
|
||||||
if (!self.IsInWorld || self.IsDead)
|
if (!self.IsInWorld || self.IsDead)
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world)
|
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world)
|
||||||
{
|
{
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
|
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
|
||||||
{
|
{
|
||||||
if (!self.IsInWorld || self.Owner != self.World.LocalPlayer)
|
if (!self.IsInWorld || self.Owner != self.World.LocalPlayer)
|
||||||
yield break;
|
yield break;
|
||||||
@@ -234,7 +234,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
Color.FromArgb(96, Color.Black));
|
Color.FromArgb(96, Color.Black));
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (self.IsInWorld && self.Location != cell
|
if (self.IsInWorld && self.Location != cell
|
||||||
&& self.Trait<PortableChrono>().CanTeleport && self.Owner.Shroud.IsExplored(cell))
|
&& self.Trait<PortableChrono>().CanTeleport && self.Owner.Shroud.IsExplored(cell))
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Mods.Common.Graphics;
|
using OpenRA.Mods.Common.Graphics;
|
||||||
|
using OpenRA.Mods.Common.Orders;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
@@ -61,7 +62,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SelectAttackPowerTarget : IOrderGenerator
|
public class SelectAttackPowerTarget : OrderGenerator
|
||||||
{
|
{
|
||||||
readonly SupportPowerManager manager;
|
readonly SupportPowerManager manager;
|
||||||
readonly SupportPowerInstance instance;
|
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);
|
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();
|
world.CancelInputMode();
|
||||||
if (mi.Button == expectedButton && IsValidTarget(world, cell))
|
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
|
// Cancel the OG if we can't use the power
|
||||||
if (!manager.Powers.ContainsKey(order))
|
if (!manager.Powers.ContainsKey(order))
|
||||||
world.CancelInputMode();
|
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))
|
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;
|
return IsValidTarget(world, cell) ? cursor : cursorBlocked;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Mods.Common.Graphics;
|
using OpenRA.Mods.Common.Graphics;
|
||||||
|
using OpenRA.Mods.Common.Orders;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
@@ -120,7 +121,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
class SelectChronoshiftTarget : IOrderGenerator
|
class SelectChronoshiftTarget : OrderGenerator
|
||||||
{
|
{
|
||||||
readonly ChronoshiftPower power;
|
readonly ChronoshiftPower power;
|
||||||
readonly int range;
|
readonly int range;
|
||||||
@@ -143,7 +144,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
tile = world.Map.Rules.Sequences.GetSequence(info.OverlaySpriteGroup, info.SourceTileSequence).GetSprite(0);
|
tile = world.Map.Rules.Sequences.GetSequence(info.OverlaySpriteGroup, info.SourceTileSequence).GetSprite(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
protected override IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
if (mi.Button == MouseButton.Left)
|
if (mi.Button == MouseButton.Left)
|
||||||
@@ -152,14 +153,14 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(World world)
|
protected override void Tick(World world)
|
||||||
{
|
{
|
||||||
// Cancel the OG if we can't use the power
|
// Cancel the OG if we can't use the power
|
||||||
if (!manager.Powers.ContainsKey(order))
|
if (!manager.Powers.ContainsKey(order))
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
|
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
|
||||||
{
|
{
|
||||||
var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
|
var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
|
||||||
var targetUnits = power.UnitsInRange(xy).Where(a => !world.FogObscures(a));
|
var targetUnits = power.UnitsInRange(xy).Where(a => !world.FogObscures(a));
|
||||||
@@ -174,7 +175,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world)
|
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world)
|
||||||
{
|
{
|
||||||
var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
|
var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
|
||||||
var tiles = world.Map.FindTilesInCircle(xy, range);
|
var tiles = world.Map.FindTilesInCircle(xy, range);
|
||||||
@@ -183,13 +184,13 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
yield return new SpriteRenderable(tile, wr.World.Map.CenterOfCell(t), WVec.Zero, -511, palette, 1f, true);
|
yield return new SpriteRenderable(tile, wr.World.Map.CenterOfCell(t), WVec.Zero, -511, palette, 1f, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
return ((ChronoshiftPowerInfo)power.Info).SelectionCursor;
|
return ((ChronoshiftPowerInfo)power.Info).SelectionCursor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SelectDestination : IOrderGenerator
|
class SelectDestination : OrderGenerator
|
||||||
{
|
{
|
||||||
readonly ChronoshiftPower power;
|
readonly ChronoshiftPower power;
|
||||||
readonly CPos sourceLocation;
|
readonly CPos sourceLocation;
|
||||||
@@ -214,7 +215,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
sourceTile = world.Map.Rules.Sequences.GetSequence(info.OverlaySpriteGroup, info.SourceTileSequence).GetSprite(0);
|
sourceTile = world.Map.Rules.Sequences.GetSequence(info.OverlaySpriteGroup, info.SourceTileSequence).GetSprite(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
protected override IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Right)
|
if (mi.Button == MouseButton.Right)
|
||||||
{
|
{
|
||||||
@@ -241,14 +242,14 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(World world)
|
protected override void Tick(World world)
|
||||||
{
|
{
|
||||||
// Cancel the OG if we can't use the power
|
// Cancel the OG if we can't use the power
|
||||||
if (!manager.Powers.ContainsKey(order))
|
if (!manager.Powers.ContainsKey(order))
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
|
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
|
||||||
{
|
{
|
||||||
var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
|
var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
|
||||||
var palette = wr.Palette(power.Info.IconPalette);
|
var palette = wr.Palette(power.Info.IconPalette);
|
||||||
@@ -289,7 +290,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world)
|
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world)
|
||||||
{
|
{
|
||||||
var palette = wr.Palette(power.Info.IconPalette);
|
var palette = wr.Palette(power.Info.IconPalette);
|
||||||
|
|
||||||
@@ -322,7 +323,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
return canTeleport;
|
return canTeleport;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
var powerInfo = (ChronoshiftPowerInfo)power.Info;
|
var powerInfo = (ChronoshiftPowerInfo)power.Info;
|
||||||
return IsValidTarget(cell) ? powerInfo.TargetCursor : powerInfo.TargetBlockedCursor;
|
return IsValidTarget(cell) ? powerInfo.TargetCursor : powerInfo.TargetBlockedCursor;
|
||||||
|
|||||||
@@ -117,6 +117,7 @@
|
|||||||
<Compile Include="Activities\WaitForTransport.cs" />
|
<Compile Include="Activities\WaitForTransport.cs" />
|
||||||
<Compile Include="ActorExts.cs" />
|
<Compile Include="ActorExts.cs" />
|
||||||
<Compile Include="AIUtils.cs" />
|
<Compile Include="AIUtils.cs" />
|
||||||
|
<Compile Include="Orders\OrderGenerator.cs" />
|
||||||
<Compile Include="TargetExtensions.cs" />
|
<Compile Include="TargetExtensions.cs" />
|
||||||
<Compile Include="Traits\BotModules\Squads\AttackOrFleeFuzzy.cs" />
|
<Compile Include="Traits\BotModules\Squads\AttackOrFleeFuzzy.cs" />
|
||||||
<Compile Include="Traits\BotModules\BotModuleLogic\BaseBuilderQueueManager.cs" />
|
<Compile Include="Traits\BotModules\BotModuleLogic\BaseBuilderQueueManager.cs" />
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Orders
|
namespace OpenRA.Mods.Common.Orders
|
||||||
{
|
{
|
||||||
public class BeaconOrderGenerator : IOrderGenerator
|
public class BeaconOrderGenerator : OrderGenerator
|
||||||
{
|
{
|
||||||
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
protected override IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
|
|
||||||
@@ -25,10 +25,10 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
yield return new Order("PlaceBeacon", world.LocalPlayer.PlayerActor, Target.FromCell(world, cell), false) { SuppressVisualFeedback = true };
|
yield return new Order("PlaceBeacon", world.LocalPlayer.PlayerActor, Target.FromCell(world, cell), false) { SuppressVisualFeedback = true };
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Tick(World world) { }
|
protected override void Tick(World world) { }
|
||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||||
public IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world) { yield break; }
|
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world) { yield break; }
|
||||||
public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
return "ability";
|
return "ability";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ using OpenRA.Mods.Common.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Orders
|
namespace OpenRA.Mods.Common.Orders
|
||||||
{
|
{
|
||||||
public abstract class GlobalButtonOrderGenerator<T> : IOrderGenerator
|
public abstract class GlobalButtonOrderGenerator<T> : OrderGenerator
|
||||||
{
|
{
|
||||||
string order;
|
string order;
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
this.order = order;
|
this.order = order;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
protected override IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Right)
|
if (mi.Button == MouseButton.Right)
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
@@ -54,17 +54,17 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(World world)
|
protected override void Tick(World world)
|
||||||
{
|
{
|
||||||
if (world.LocalPlayer != null &&
|
if (world.LocalPlayer != null &&
|
||||||
world.LocalPlayer.WinState != WinState.Undefined)
|
world.LocalPlayer.WinState != WinState.Undefined)
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||||
public IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world) { yield break; }
|
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world) { yield break; }
|
||||||
|
|
||||||
public abstract string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi);
|
protected abstract override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PowerDownOrderGenerator : GlobalButtonOrderGenerator<ToggleConditionOnOrder>
|
public class PowerDownOrderGenerator : GlobalButtonOrderGenerator<ToggleConditionOnOrder>
|
||||||
@@ -76,7 +76,7 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
return !t.IsTraitDisabled && !t.IsTraitPaused;
|
return !t.IsTraitDisabled && !t.IsTraitPaused;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
mi.Button = MouseButton.Left;
|
mi.Button = MouseButton.Left;
|
||||||
return OrderInner(world, mi).Any() ? "powerdown" : "powerdown-blocked";
|
return OrderInner(world, mi).Any() ? "powerdown" : "powerdown-blocked";
|
||||||
@@ -87,7 +87,7 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
{
|
{
|
||||||
public SellOrderGenerator() : base("Sell") { }
|
public SellOrderGenerator() : base("Sell") { }
|
||||||
|
|
||||||
public override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
mi.Button = MouseButton.Left;
|
mi.Button = MouseButton.Left;
|
||||||
|
|
||||||
|
|||||||
39
OpenRA.Mods.Common/Orders/OrderGenerator.cs
Normal file
39
OpenRA.Mods.Common/Orders/OrderGenerator.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2019 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation, either version 3 of
|
||||||
|
* the License, or (at your option) any later version. For more
|
||||||
|
* information, see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenRA.Graphics;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Orders
|
||||||
|
{
|
||||||
|
public abstract class OrderGenerator : IOrderGenerator
|
||||||
|
{
|
||||||
|
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
|
{
|
||||||
|
if ((mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Down) || (mi.Button == MouseButton.Right && mi.Event == MouseInputEvent.Up))
|
||||||
|
return OrderInner(world, cell, worldPixel, mi);
|
||||||
|
|
||||||
|
return Enumerable.Empty<Order>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IOrderGenerator.Tick(World world) { Tick(world); }
|
||||||
|
IEnumerable<IRenderable> IOrderGenerator.Render(WorldRenderer wr, World world) { return Render(wr, world); }
|
||||||
|
IEnumerable<IRenderable> IOrderGenerator.RenderAboveShroud(WorldRenderer wr, World world) { return RenderAboveShroud(wr, world); }
|
||||||
|
string IOrderGenerator.GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { return GetCursor(world, cell, worldPixel, mi); }
|
||||||
|
|
||||||
|
protected abstract void Tick(World world);
|
||||||
|
protected abstract IEnumerable<IRenderable> Render(WorldRenderer wr, World world);
|
||||||
|
protected abstract IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world);
|
||||||
|
protected abstract string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi);
|
||||||
|
protected abstract IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Orders
|
namespace OpenRA.Mods.Common.Orders
|
||||||
{
|
{
|
||||||
public class PlaceBuildingOrderGenerator : IOrderGenerator
|
public class PlaceBuildingOrderGenerator : OrderGenerator
|
||||||
{
|
{
|
||||||
[Flags]
|
[Flags]
|
||||||
enum CellType { Valid = 0, Invalid = 1, LineBuild = 2 }
|
enum CellType { Valid = 0, Invalid = 1, LineBuild = 2 }
|
||||||
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
protected override IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Right)
|
if (mi.Button == MouseButton.Right)
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
@@ -147,7 +147,7 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(World world)
|
protected override void Tick(World world)
|
||||||
{
|
{
|
||||||
if (queue.AllQueued().All(i => !i.Done || i.Item != actorInfo.Name))
|
if (queue.AllQueued().All(i => !i.Done || i.Item != actorInfo.Name))
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
@@ -169,8 +169,8 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
return host.TraitsImplementing<Pluggable>().Any(p => location + p.Info.Offset == cell && p.AcceptsPlug(host, plug.Type));
|
return host.TraitsImplementing<Pluggable>().Any(p => location + p.Info.Offset == cell && p.AcceptsPlug(host, plug.Type));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||||
public IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
|
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
|
||||||
{
|
{
|
||||||
var topLeft = viewport.ViewToWorld(Viewport.LastMousePos + topLeftScreenOffset);
|
var topLeft = viewport.ViewToWorld(Viewport.LastMousePos + topLeftScreenOffset);
|
||||||
var centerPosition = world.Map.CenterOfCell(topLeft) + centerOffset;
|
var centerPosition = world.Map.CenterOfCell(topLeft) + centerOffset;
|
||||||
@@ -250,7 +250,7 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { return "default"; }
|
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { return "default"; }
|
||||||
|
|
||||||
IEnumerable<Order> ClearBlockersOrders(World world, CPos topLeft)
|
IEnumerable<Order> ClearBlockersOrders(World world, CPos topLeft)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Orders
|
namespace OpenRA.Mods.Common.Orders
|
||||||
{
|
{
|
||||||
public class RepairOrderGenerator : IOrderGenerator
|
public class RepairOrderGenerator : OrderGenerator
|
||||||
{
|
{
|
||||||
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
protected override IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Right)
|
if (mi.Button == MouseButton.Right)
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
@@ -73,17 +73,17 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
yield return new Order(orderId, underCursor, Target.FromActor(repairBuilding), false) { VisualFeedbackTarget = Target.FromActor(underCursor) };
|
yield return new Order(orderId, underCursor, Target.FromActor(repairBuilding), false) { VisualFeedbackTarget = Target.FromActor(underCursor) };
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(World world)
|
protected override void Tick(World world)
|
||||||
{
|
{
|
||||||
if (world.LocalPlayer != null &&
|
if (world.LocalPlayer != null &&
|
||||||
world.LocalPlayer.WinState != WinState.Undefined)
|
world.LocalPlayer.WinState != WinState.Undefined)
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||||
public IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world) { yield break; }
|
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world) { yield break; }
|
||||||
|
|
||||||
public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
mi.Button = MouseButton.Left;
|
mi.Button = MouseButton.Left;
|
||||||
return OrderInner(world, mi).Any()
|
return OrderInner(world, mi).Any()
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Mods.Common.Graphics;
|
using OpenRA.Mods.Common.Graphics;
|
||||||
|
using OpenRA.Mods.Common.Orders;
|
||||||
using OpenRA.Mods.Common.Traits.Render;
|
using OpenRA.Mods.Common.Traits.Render;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
@@ -101,7 +102,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class SelectConditionTarget : IOrderGenerator
|
class SelectConditionTarget : OrderGenerator
|
||||||
{
|
{
|
||||||
readonly GrantExternalConditionPower power;
|
readonly GrantExternalConditionPower power;
|
||||||
readonly int range;
|
readonly int range;
|
||||||
@@ -122,21 +123,21 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
tile = world.Map.Rules.Sequences.GetSequence("overlay", "target-select").GetSprite(0);
|
tile = world.Map.Rules.Sequences.GetSequence("overlay", "target-select").GetSprite(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
protected override IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
if (mi.Button == MouseButton.Left && power.UnitsInRange(cell).Any())
|
if (mi.Button == MouseButton.Left && power.UnitsInRange(cell).Any())
|
||||||
yield return new Order(order, manager.Self, Target.FromCell(world, cell), false) { SuppressVisualFeedback = true };
|
yield return new Order(order, manager.Self, Target.FromCell(world, cell), false) { SuppressVisualFeedback = true };
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(World world)
|
protected override void Tick(World world)
|
||||||
{
|
{
|
||||||
// Cancel the OG if we can't use the power
|
// Cancel the OG if we can't use the power
|
||||||
if (!manager.Powers.ContainsKey(order))
|
if (!manager.Powers.ContainsKey(order))
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
|
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
|
||||||
{
|
{
|
||||||
var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
|
var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
|
||||||
foreach (var unit in power.UnitsInRange(xy))
|
foreach (var unit in power.UnitsInRange(xy))
|
||||||
@@ -146,7 +147,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world)
|
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world)
|
||||||
{
|
{
|
||||||
var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
|
var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
|
||||||
var pal = wr.Palette(TileSet.TerrainPaletteInternalName);
|
var pal = wr.Palette(TileSet.TerrainPaletteInternalName);
|
||||||
@@ -155,7 +156,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
yield return new SpriteRenderable(tile, wr.World.Map.CenterOfCell(t), WVec.Zero, -511, pal, 1f, true);
|
yield return new SpriteRenderable(tile, wr.World.Map.CenterOfCell(t), WVec.Zero, -511, pal, 1f, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
return power.UnitsInRange(cell).Any() ? power.info.Cursor : power.info.BlockedCursor;
|
return power.UnitsInRange(cell).Any() ? power.info.Cursor : power.info.BlockedCursor;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Mods.Common.Orders;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
@@ -258,7 +259,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SelectGenericPowerTarget : IOrderGenerator
|
public class SelectGenericPowerTarget : OrderGenerator
|
||||||
{
|
{
|
||||||
readonly SupportPowerManager manager;
|
readonly SupportPowerManager manager;
|
||||||
readonly string order;
|
readonly string order;
|
||||||
@@ -279,23 +280,23 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
expectedButton = button;
|
expectedButton = button;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
protected override IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
if (mi.Button == expectedButton && world.Map.Contains(cell))
|
if (mi.Button == expectedButton && world.Map.Contains(cell))
|
||||||
yield return new Order(order, manager.Self, Target.FromCell(world, cell), false) { SuppressVisualFeedback = true };
|
yield return new Order(order, manager.Self, Target.FromCell(world, cell), false) { SuppressVisualFeedback = true };
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Tick(World world)
|
protected override void Tick(World world)
|
||||||
{
|
{
|
||||||
// Cancel the OG if we can't use the power
|
// Cancel the OG if we can't use the power
|
||||||
if (!manager.Powers.ContainsKey(order))
|
if (!manager.Powers.ContainsKey(order))
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||||
public IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world) { yield break; }
|
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world) { yield break; }
|
||||||
public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
return world.Map.Contains(cell) ? cursor : "generic-blocked";
|
return world.Map.Contains(cell) ? cursor : "generic-blocked";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,6 +82,14 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
|
|
||||||
var multiClick = mi.MultiTapCount >= 2;
|
var multiClick = mi.MultiTapCount >= 2;
|
||||||
|
|
||||||
|
if (!(World.OrderGenerator is UnitOrderGenerator))
|
||||||
|
{
|
||||||
|
ApplyOrders(World, mi);
|
||||||
|
isDragging = false;
|
||||||
|
YieldMouseFocus(mi);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Down)
|
if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Down)
|
||||||
{
|
{
|
||||||
if (!TakeMouseFocus(mi))
|
if (!TakeMouseFocus(mi))
|
||||||
@@ -89,15 +97,6 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
|
|
||||||
dragStart = mousePos;
|
dragStart = mousePos;
|
||||||
isDragging = true;
|
isDragging = true;
|
||||||
|
|
||||||
// Place buildings, use support powers, and other non-unit things
|
|
||||||
if (!(World.OrderGenerator is UnitOrderGenerator))
|
|
||||||
{
|
|
||||||
ApplyOrders(World, mi);
|
|
||||||
isDragging = false;
|
|
||||||
YieldMouseFocus(mi);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Up)
|
if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Up)
|
||||||
|
|||||||
Reference in New Issue
Block a user