Pushed down the MouseInput handling to the OrderGenerators and made a base class for handling the basic logic
This commit is contained in:
@@ -15,9 +15,9 @@ using OpenRA.Traits;
|
||||
|
||||
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();
|
||||
|
||||
@@ -25,10 +25,10 @@ namespace OpenRA.Mods.Common.Orders
|
||||
yield return new Order("PlaceBeacon", world.LocalPlayer.PlayerActor, Target.FromCell(world, cell), false) { SuppressVisualFeedback = true };
|
||||
}
|
||||
|
||||
public virtual void Tick(World world) { }
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||
public IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world) { yield break; }
|
||||
public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
protected override void Tick(World world) { }
|
||||
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world) { yield break; }
|
||||
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
return "ability";
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ using OpenRA.Mods.Common.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Orders
|
||||
{
|
||||
public abstract class GlobalButtonOrderGenerator<T> : IOrderGenerator
|
||||
public abstract class GlobalButtonOrderGenerator<T> : OrderGenerator
|
||||
{
|
||||
string order;
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Orders
|
||||
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)
|
||||
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 &&
|
||||
world.LocalPlayer.WinState != WinState.Undefined)
|
||||
world.CancelInputMode();
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||
public IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world) { yield break; }
|
||||
protected override IEnumerable<IRenderable> Render(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>
|
||||
@@ -76,7 +76,7 @@ namespace OpenRA.Mods.Common.Orders
|
||||
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;
|
||||
return OrderInner(world, mi).Any() ? "powerdown" : "powerdown-blocked";
|
||||
@@ -87,7 +87,7 @@ namespace OpenRA.Mods.Common.Orders
|
||||
{
|
||||
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;
|
||||
|
||||
|
||||
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
|
||||
{
|
||||
public class PlaceBuildingOrderGenerator : IOrderGenerator
|
||||
public class PlaceBuildingOrderGenerator : OrderGenerator
|
||||
{
|
||||
[Flags]
|
||||
enum CellType { Valid = 0, Invalid = 1, LineBuild = 2 }
|
||||
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Orders
|
||||
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)
|
||||
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))
|
||||
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));
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||
public IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
|
||||
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
|
||||
{
|
||||
var topLeft = viewport.ViewToWorld(Viewport.LastMousePos + topLeftScreenOffset);
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -17,9 +17,9 @@ using OpenRA.Traits;
|
||||
|
||||
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)
|
||||
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) };
|
||||
}
|
||||
|
||||
public void Tick(World world)
|
||||
protected override void Tick(World world)
|
||||
{
|
||||
if (world.LocalPlayer != null &&
|
||||
world.LocalPlayer.WinState != WinState.Undefined)
|
||||
world.CancelInputMode();
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||
public IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world) { yield break; }
|
||||
protected override IEnumerable<IRenderable> Render(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;
|
||||
return OrderInner(world, mi).Any()
|
||||
|
||||
Reference in New Issue
Block a user