Replace MouseButtonPreference with MouseActionType.
This commit is contained in:
committed by
Gustas Kažukauskas
parent
c588c3ef8d
commit
962e7e911d
@@ -17,12 +17,15 @@ namespace OpenRA.Mods.Common.Orders
|
||||
{
|
||||
public class BeaconOrderGenerator : OrderGenerator
|
||||
{
|
||||
protected override MouseActionType ActionType => MouseActionType.PlaceBuilding;
|
||||
|
||||
public BeaconOrderGenerator(World world)
|
||||
: base(world) { }
|
||||
|
||||
protected override IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
world.CancelInputMode();
|
||||
|
||||
if (mi.Button == MouseButton.Left)
|
||||
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 };
|
||||
}
|
||||
|
||||
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||
|
||||
@@ -15,10 +15,12 @@ namespace OpenRA.Mods.Common.Orders
|
||||
{
|
||||
public class ForceModifiersOrderGenerator : UnitOrderGenerator
|
||||
{
|
||||
protected override MouseActionType ActionType => MouseActionType.ConfirmOrder;
|
||||
public readonly Modifiers Modifiers;
|
||||
readonly bool cancelOnFirstUse;
|
||||
|
||||
public ForceModifiersOrderGenerator(Modifiers modifiers, bool cancelOnFirstUse)
|
||||
public ForceModifiersOrderGenerator(World world, Modifiers modifiers, bool cancelOnFirstUse)
|
||||
: base(world)
|
||||
{
|
||||
Modifiers = modifiers;
|
||||
this.cancelOnFirstUse = cancelOnFirstUse;
|
||||
@@ -27,8 +29,7 @@ namespace OpenRA.Mods.Common.Orders
|
||||
public override IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
mi.Modifiers |= Modifiers;
|
||||
|
||||
if (cancelOnFirstUse)
|
||||
if ((cancelOnFirstUse && !mi.Modifiers.HasModifier(Modifiers.Shift)) || mi.Button == CancelButton)
|
||||
world.CancelInputMode();
|
||||
|
||||
return base.Order(world, cell, worldPixel, mi);
|
||||
|
||||
@@ -20,38 +20,30 @@ namespace OpenRA.Mods.Common.Orders
|
||||
{
|
||||
readonly string order;
|
||||
|
||||
protected GlobalButtonOrderGenerator(string order)
|
||||
protected override MouseActionType ActionType => MouseActionType.GlobalCommand;
|
||||
|
||||
protected GlobalButtonOrderGenerator(World world, string order)
|
||||
: base(world)
|
||||
{
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
protected override IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
if (mi.Button == MouseButton.Right)
|
||||
world.CancelInputMode();
|
||||
|
||||
return OrderInner(world, mi);
|
||||
}
|
||||
|
||||
protected virtual bool IsValidTrait(T t)
|
||||
{
|
||||
return t.IsTraitEnabled();
|
||||
}
|
||||
|
||||
protected IEnumerable<Order> OrderInner(World world, MouseInput mi)
|
||||
protected override IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
if (mi.Button == MouseButton.Left)
|
||||
{
|
||||
var underCursor = world.ScreenMap.ActorsAtMouse(mi)
|
||||
.Select(a => a.Actor)
|
||||
.FirstOrDefault(a => a.Owner == world.LocalPlayer && a.TraitsImplementing<T>()
|
||||
.Any(IsValidTrait));
|
||||
var underCursor = world.ScreenMap.ActorsAtMouse(mi)
|
||||
.Select(a => a.Actor)
|
||||
.FirstOrDefault(a => a.Owner == world.LocalPlayer && a.TraitsImplementing<T>()
|
||||
.Any(IsValidTrait));
|
||||
|
||||
if (underCursor == null)
|
||||
yield break;
|
||||
if (underCursor == null)
|
||||
yield break;
|
||||
|
||||
yield return new Order(order, underCursor, false);
|
||||
}
|
||||
yield return new Order(order, underCursor, false);
|
||||
}
|
||||
|
||||
protected override void Tick(World world)
|
||||
@@ -70,8 +62,8 @@ namespace OpenRA.Mods.Common.Orders
|
||||
|
||||
public class PowerDownOrderGenerator : GlobalButtonOrderGenerator<ToggleConditionOnOrder>
|
||||
{
|
||||
public PowerDownOrderGenerator()
|
||||
: base("PowerDown") { }
|
||||
public PowerDownOrderGenerator(World world)
|
||||
: base(world, "PowerDown") { }
|
||||
|
||||
protected override bool IsValidTrait(ToggleConditionOnOrder t)
|
||||
{
|
||||
@@ -80,21 +72,18 @@ namespace OpenRA.Mods.Common.Orders
|
||||
|
||||
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
mi.Button = MouseButton.Left;
|
||||
return OrderInner(world, mi).Any() ? "powerdown" : "powerdown-blocked";
|
||||
return OrderInner(world, cell, worldPixel, mi).Any() ? "powerdown" : "powerdown-blocked";
|
||||
}
|
||||
}
|
||||
|
||||
public class SellOrderGenerator : GlobalButtonOrderGenerator<Sellable>
|
||||
{
|
||||
public SellOrderGenerator()
|
||||
: base("Sell") { }
|
||||
public SellOrderGenerator(World world)
|
||||
: base(world, "Sell") { }
|
||||
|
||||
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
mi.Button = MouseButton.Left;
|
||||
|
||||
var cursor = OrderInner(world, mi)
|
||||
var cursor = OrderInner(world, cell, worldPixel, mi)
|
||||
.SelectMany(o => o.Subject.TraitsImplementing<Sellable>())
|
||||
.Where(t => !t.IsTraitDisabled)
|
||||
.Select(si => si.Info.Cursor)
|
||||
|
||||
@@ -20,27 +20,25 @@ namespace OpenRA.Mods.Common.Orders
|
||||
{
|
||||
readonly string orderName;
|
||||
readonly string cursor;
|
||||
readonly MouseButton expectedButton;
|
||||
IEnumerable<Actor> subjects;
|
||||
protected override MouseActionType ActionType => MouseActionType.ConfirmOrder;
|
||||
|
||||
public GuardOrderGenerator(IEnumerable<Actor> subjects, string order, string cursor, MouseButton button)
|
||||
public GuardOrderGenerator(World world, IEnumerable<Actor> subjects, string order, string cursor)
|
||||
: base(world)
|
||||
{
|
||||
orderName = order;
|
||||
this.cursor = cursor;
|
||||
expectedButton = button;
|
||||
this.subjects = subjects;
|
||||
}
|
||||
|
||||
public override IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
if (mi.Button != expectedButton)
|
||||
if (mi.Button != ActionButton)
|
||||
{
|
||||
world.CancelInputMode();
|
||||
yield break;
|
||||
}
|
||||
|
||||
return OrderInner(world, mi);
|
||||
}
|
||||
|
||||
IEnumerable<Order> OrderInner(World world, MouseInput mi)
|
||||
{
|
||||
var target = FriendlyGuardableUnits(world, mi).FirstOrDefault();
|
||||
if (target == null)
|
||||
yield break;
|
||||
|
||||
@@ -17,11 +17,27 @@ namespace OpenRA.Mods.Common.Orders
|
||||
{
|
||||
public abstract class OrderGenerator : IOrderGenerator
|
||||
{
|
||||
protected abstract MouseActionType ActionType { get; }
|
||||
readonly GameSettings gameSettings;
|
||||
|
||||
protected OrderGenerator(World world, bool classicClearSelection = true)
|
||||
{
|
||||
gameSettings = Game.Settings.Game;
|
||||
if (classicClearSelection && gameSettings.UseClassicMouseStyle)
|
||||
world.Selection.Clear();
|
||||
}
|
||||
|
||||
public MouseButton ActionButton => gameSettings.ResolveActionButton(ActionType);
|
||||
public MouseButton CancelButton => gameSettings.ResolveCancelButton(ActionType);
|
||||
|
||||
public virtual 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))
|
||||
if (mi.Button == ActionButton && mi.Event == MouseInputEvent.Down)
|
||||
return OrderInner(world, cell, worldPixel, mi);
|
||||
|
||||
if (mi.Button == CancelButton && mi.Event == MouseInputEvent.Up)
|
||||
world.CancelInputMode();
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@ namespace OpenRA.Mods.Common.Orders
|
||||
readonly PlaceBuildingInfo placeBuildingInfo;
|
||||
readonly Viewport viewport;
|
||||
readonly VariantWrapper[] variants;
|
||||
readonly GameSettings gameSettings;
|
||||
int variant;
|
||||
|
||||
public PlaceBuildingOrderGenerator(ProductionQueue queue, string name, WorldRenderer worldRenderer)
|
||||
@@ -98,9 +99,9 @@ namespace OpenRA.Mods.Common.Orders
|
||||
world = queue.Actor.World;
|
||||
placeBuildingInfo = queue.Actor.Owner.PlayerActor.Info.TraitInfo<PlaceBuildingInfo>();
|
||||
viewport = worldRenderer.Viewport;
|
||||
gameSettings = Game.Settings.Game;
|
||||
|
||||
// Clear selection if using Left-Click Orders
|
||||
if (Game.Settings.Game.UseClassicMouseStyle)
|
||||
if (gameSettings.UseClassicMouseStyle)
|
||||
world.Selection.Clear();
|
||||
|
||||
var variants = new List<VariantWrapper>()
|
||||
@@ -115,6 +116,8 @@ namespace OpenRA.Mods.Common.Orders
|
||||
this.variants = variants.ToArray();
|
||||
}
|
||||
|
||||
public MouseButton ActionButton => gameSettings.ResolveActionButton(MouseActionType.PlaceBuilding);
|
||||
|
||||
static PlaceBuildingCellType MakeCellType(bool valid, bool lineBuild = false)
|
||||
{
|
||||
var cell = valid ? PlaceBuildingCellType.Valid : PlaceBuildingCellType.Invalid;
|
||||
@@ -126,9 +129,11 @@ namespace OpenRA.Mods.Common.Orders
|
||||
|
||||
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))
|
||||
var actionButton = gameSettings.ResolveActionButton(MouseActionType.PlaceBuilding);
|
||||
var cancelButton = gameSettings.ResolveCancelButton(MouseActionType.PlaceBuilding);
|
||||
if ((mi.Button == actionButton && mi.Event == MouseInputEvent.Down) || (mi.Button == cancelButton && mi.Event == MouseInputEvent.Up))
|
||||
{
|
||||
if (mi.Button == MouseButton.Right)
|
||||
if (mi.Button == cancelButton)
|
||||
world.CancelInputMode();
|
||||
|
||||
var ret = InnerOrder(world, cell, mi).ToArray();
|
||||
@@ -168,7 +173,7 @@ namespace OpenRA.Mods.Common.Orders
|
||||
var bi = variants[variant].BuildingInfo;
|
||||
var notification = Queue.Info.CannotPlaceAudio ?? placeBuildingInfo.CannotPlaceNotification;
|
||||
|
||||
if (mi.Button == MouseButton.Left)
|
||||
if (mi.Button == ActionButton)
|
||||
{
|
||||
var orderType = "PlaceBuilding";
|
||||
var topLeft = TopLeft;
|
||||
|
||||
@@ -19,19 +19,13 @@ namespace OpenRA.Mods.Common.Orders
|
||||
{
|
||||
public class RepairOrderGenerator : OrderGenerator
|
||||
{
|
||||
protected override MouseActionType ActionType => MouseActionType.GlobalCommand;
|
||||
|
||||
public RepairOrderGenerator(World world)
|
||||
: base(world) { }
|
||||
|
||||
protected override IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
if (mi.Button == MouseButton.Right)
|
||||
world.CancelInputMode();
|
||||
|
||||
return OrderInner(world, mi);
|
||||
}
|
||||
|
||||
static IEnumerable<Order> OrderInner(World world, MouseInput mi)
|
||||
{
|
||||
if (mi.Button != MouseButton.Left)
|
||||
yield break;
|
||||
|
||||
var underCursor = world.ScreenMap.ActorsAtMouse(mi)
|
||||
.Select(a => a.Actor)
|
||||
.FirstOrDefault(a => a.AppearsFriendlyTo(world.LocalPlayer.PlayerActor) && !world.FogObscures(a));
|
||||
@@ -86,8 +80,7 @@ namespace OpenRA.Mods.Common.Orders
|
||||
|
||||
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
mi.Button = MouseButton.Left;
|
||||
return OrderInner(world, mi).Any()
|
||||
return OrderInner(world, cell, worldPixel, mi).Any()
|
||||
? "repair" : "repair-blocked";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,16 @@ namespace OpenRA.Mods.Common.Orders
|
||||
{
|
||||
readonly string worldSelectCursor = ChromeMetrics.Get<string>("WorldSelectCursor");
|
||||
readonly string worldDefaultCursor = ChromeMetrics.Get<string>("WorldDefaultCursor");
|
||||
readonly GameSettings gameSettings;
|
||||
|
||||
protected virtual MouseActionType ActionType => MouseActionType.Contextual;
|
||||
public MouseButton ActionButton => gameSettings.ResolveActionButton(ActionType);
|
||||
public MouseButton CancelButton => gameSettings.ResolveCancelButton(ActionType);
|
||||
|
||||
public UnitOrderGenerator(World world)
|
||||
{
|
||||
gameSettings = Game.Settings.Game;
|
||||
}
|
||||
|
||||
protected static Target TargetForInput(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
@@ -72,7 +82,7 @@ namespace OpenRA.Mods.Common.Orders
|
||||
var target = TargetForInput(world, cell, worldPixel, mi);
|
||||
|
||||
bool useSelect;
|
||||
if (Game.Settings.Game.UseClassicMouseStyle && !InputOverridesSelection(world, worldPixel, mi))
|
||||
if (gameSettings.UseClassicMouseStyle && !InputOverridesSelection(world, worldPixel, mi))
|
||||
useSelect = target.Type == TargetType.Actor && target.Actor.Info.HasTraitInfo<ISelectableInfo>();
|
||||
else
|
||||
{
|
||||
@@ -137,9 +147,9 @@ namespace OpenRA.Mods.Common.Orders
|
||||
/// First priority is given to orders that interact with the given actors.
|
||||
/// Second priority is given to actors in the given cell.
|
||||
/// </summary>
|
||||
protected static UnitOrderResult OrderForUnit(Actor self, Target target, CPos xy, MouseInput mi)
|
||||
protected UnitOrderResult OrderForUnit(Actor self, Target target, CPos xy, MouseInput mi)
|
||||
{
|
||||
if (mi.Button != Game.Settings.Game.MouseButtonPreference.Action)
|
||||
if (mi.Button != ActionButton)
|
||||
return null;
|
||||
|
||||
if (self.Owner != self.World.LocalPlayer)
|
||||
|
||||
Reference in New Issue
Block a user