Add frontend code for issuing assault move orders.
This commit is contained in:
@@ -9,8 +9,11 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
using OpenRA.Mods.Common.Activities;
|
using OpenRA.Mods.Common.Activities;
|
||||||
|
using OpenRA.Orders;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
@@ -111,4 +114,54 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class AttackMoveOrderGenerator : UnitOrderGenerator
|
||||||
|
{
|
||||||
|
readonly TraitPair<AttackMove>[] subjects;
|
||||||
|
readonly MouseButton expectedButton;
|
||||||
|
|
||||||
|
public AttackMoveOrderGenerator(IEnumerable<Actor> subjects, MouseButton button)
|
||||||
|
{
|
||||||
|
expectedButton = button;
|
||||||
|
|
||||||
|
this.subjects = subjects.SelectMany(a => a.TraitsImplementing<AttackMove>()
|
||||||
|
.Select(am => new TraitPair<AttackMove>(a, am)))
|
||||||
|
.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
|
{
|
||||||
|
if (mi.Button != expectedButton)
|
||||||
|
world.CancelInputMode();
|
||||||
|
|
||||||
|
return OrderInner(world, cell, mi);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual IEnumerable<Order> OrderInner(World world, CPos cell, MouseInput mi)
|
||||||
|
{
|
||||||
|
if (mi.Button == expectedButton && world.Map.Contains(cell))
|
||||||
|
{
|
||||||
|
world.CancelInputMode();
|
||||||
|
|
||||||
|
var queued = mi.Modifiers.HasModifier(Modifiers.Shift);
|
||||||
|
var orderName = mi.Modifiers.HasModifier(Modifiers.Ctrl) ? "AssaultMove" : "AttackMove";
|
||||||
|
foreach (var s in subjects)
|
||||||
|
yield return new Order(orderName, s.Actor, queued) { TargetLocation = cell };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
|
{
|
||||||
|
if (world.Map.Contains(cell))
|
||||||
|
return mi.Modifiers.HasModifier(Modifiers.Ctrl) ? "assaultmove" : "attackmove";
|
||||||
|
|
||||||
|
return "generic-blocked";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool InputOverridesSelection(World world, int2 xy, MouseInput mi)
|
||||||
|
{
|
||||||
|
// Custom order generators always override selection
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,8 +56,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
BindButtonIcon(attackMoveButton);
|
BindButtonIcon(attackMoveButton);
|
||||||
|
|
||||||
attackMoveButton.IsDisabled = () => { UpdateStateIfNecessary(); return attackMoveDisabled; };
|
attackMoveButton.IsDisabled = () => { UpdateStateIfNecessary(); return attackMoveDisabled; };
|
||||||
attackMoveButton.IsHighlighted = () => world.OrderGenerator is GenericSelectTarget
|
attackMoveButton.IsHighlighted = () => world.OrderGenerator is AttackMoveOrderGenerator;
|
||||||
&& ((GenericSelectTarget)world.OrderGenerator).OrderName == "AttackMove";
|
|
||||||
|
|
||||||
Action<bool> toggle = allowCancel =>
|
Action<bool> toggle = allowCancel =>
|
||||||
{
|
{
|
||||||
@@ -67,8 +66,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
world.OrderGenerator = new GenericSelectTarget(selectedActors,
|
world.OrderGenerator = new AttackMoveOrderGenerator(selectedActors, Game.Settings.Game.MouseButtonPreference.Action);
|
||||||
"AttackMove", "attackmove", Game.Settings.Game.MouseButtonPreference.Action);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
attackMoveButton.OnClick = () => toggle(true);
|
attackMoveButton.OnClick = () => toggle(true);
|
||||||
@@ -97,7 +95,9 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
BindButtonIcon(forceAttackButton);
|
BindButtonIcon(forceAttackButton);
|
||||||
|
|
||||||
forceAttackButton.IsDisabled = () => { UpdateStateIfNecessary(); return forceAttackDisabled; };
|
forceAttackButton.IsDisabled = () => { UpdateStateIfNecessary(); return forceAttackDisabled; };
|
||||||
forceAttackButton.IsHighlighted = () => !forceAttackButton.IsDisabled() && IsForceModifiersActive(Modifiers.Ctrl);
|
forceAttackButton.IsHighlighted = () => !forceAttackButton.IsDisabled() && IsForceModifiersActive(Modifiers.Ctrl)
|
||||||
|
&& !(world.OrderGenerator is AttackMoveOrderGenerator);
|
||||||
|
|
||||||
forceAttackButton.OnClick = () =>
|
forceAttackButton.OnClick = () =>
|
||||||
{
|
{
|
||||||
if (forceAttackButton.IsHighlighted())
|
if (forceAttackButton.IsHighlighted())
|
||||||
@@ -201,6 +201,23 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
world.OrderGenerator = new ForceModifiersOrderGenerator(Modifiers.Shift, false);
|
world.OrderGenerator = new ForceModifiersOrderGenerator(Modifiers.Shift, false);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var keyOverrides = widget.GetOrNull<LogicKeyListenerWidget>("MODIFIER_OVERRIDES");
|
||||||
|
if (keyOverrides != null)
|
||||||
|
{
|
||||||
|
keyOverrides.OnKeyPress = ki =>
|
||||||
|
{
|
||||||
|
// HACK: enable attack move to be triggered if the ctrl key is pressed
|
||||||
|
var modified = new Hotkey(ki.Key, ki.Modifiers & ~Modifiers.Ctrl);
|
||||||
|
if (attackMoveButton.Key.GetValue() == modified)
|
||||||
|
{
|
||||||
|
attackMoveButton.OnKeyPress(ki);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Tick()
|
public override void Tick()
|
||||||
|
|||||||
@@ -293,6 +293,7 @@ Container@PLAYER_WIDGETS:
|
|||||||
Width: 276
|
Width: 276
|
||||||
Height: 36
|
Height: 36
|
||||||
Children:
|
Children:
|
||||||
|
LogicKeyListener@MODIFIER_OVERRIDES:
|
||||||
Button@ATTACK_MOVE:
|
Button@ATTACK_MOVE:
|
||||||
X: 1
|
X: 1
|
||||||
Y: 1
|
Y: 1
|
||||||
|
|||||||
@@ -167,6 +167,12 @@ Cursors:
|
|||||||
attackmove-minimap:
|
attackmove-minimap:
|
||||||
Start: 20
|
Start: 20
|
||||||
Length: 4
|
Length: 4
|
||||||
|
assaultmove:
|
||||||
|
Start: 12
|
||||||
|
Length: 8
|
||||||
|
assaultmove-minimap:
|
||||||
|
Start: 20
|
||||||
|
Length: 4
|
||||||
move-blocked:
|
move-blocked:
|
||||||
Start: 24
|
Start: 24
|
||||||
Length: 1
|
Length: 1
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ Container@PLAYER_WIDGETS:
|
|||||||
Width: 275
|
Width: 275
|
||||||
Height: 41
|
Height: 41
|
||||||
Children:
|
Children:
|
||||||
|
LogicKeyListener@MODIFIER_OVERRIDES:
|
||||||
Button@ATTACK_MOVE:
|
Button@ATTACK_MOVE:
|
||||||
Width: 34
|
Width: 34
|
||||||
Height: 41
|
Height: 41
|
||||||
|
|||||||
@@ -138,6 +138,16 @@ Cursors:
|
|||||||
Length: 8
|
Length: 8
|
||||||
X: 24
|
X: 24
|
||||||
Y: 24
|
Y: 24
|
||||||
|
assaultmove:
|
||||||
|
Start: 16
|
||||||
|
Length: 8
|
||||||
|
X: 24
|
||||||
|
Y: 24
|
||||||
|
assaultmove-minimap:
|
||||||
|
Start: 16
|
||||||
|
Length: 8
|
||||||
|
X: 24
|
||||||
|
Y: 24
|
||||||
harvest:
|
harvest:
|
||||||
Start: 16
|
Start: 16
|
||||||
Length: 8
|
Length: 8
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ Container@PLAYER_WIDGETS:
|
|||||||
Width: 275
|
Width: 275
|
||||||
Height: 26
|
Height: 26
|
||||||
Children:
|
Children:
|
||||||
|
LogicKeyListener@MODIFIER_OVERRIDES:
|
||||||
Button@ATTACK_MOVE:
|
Button@ATTACK_MOVE:
|
||||||
Logic: AddFactionSuffixLogic
|
Logic: AddFactionSuffixLogic
|
||||||
Width: 34
|
Width: 34
|
||||||
|
|||||||
@@ -217,3 +217,9 @@ Cursors:
|
|||||||
attackmove-minimap:
|
attackmove-minimap:
|
||||||
Start: 4
|
Start: 4
|
||||||
Length: 4
|
Length: 4
|
||||||
|
assaultmove:
|
||||||
|
Start: 0
|
||||||
|
Length: 4
|
||||||
|
assaultmove-minimap:
|
||||||
|
Start: 4
|
||||||
|
Length: 4
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ Container@PLAYER_WIDGETS:
|
|||||||
Width: 275
|
Width: 275
|
||||||
Height: 26
|
Height: 26
|
||||||
Children:
|
Children:
|
||||||
|
LogicKeyListener@MODIFIER_OVERRIDES:
|
||||||
Button@ATTACK_MOVE:
|
Button@ATTACK_MOVE:
|
||||||
Width: 35
|
Width: 35
|
||||||
Height: 32
|
Height: 32
|
||||||
|
|||||||
@@ -108,6 +108,12 @@ Cursors:
|
|||||||
attackmove-minimap:
|
attackmove-minimap:
|
||||||
Start: 68
|
Start: 68
|
||||||
Length: 5
|
Length: 5
|
||||||
|
assaultmove:
|
||||||
|
Start: 58
|
||||||
|
Length: 5
|
||||||
|
assaultmove-minimap:
|
||||||
|
Start: 68
|
||||||
|
Length: 5
|
||||||
harvest:
|
harvest:
|
||||||
Start: 53
|
Start: 53
|
||||||
Length: 5
|
Length: 5
|
||||||
|
|||||||
Reference in New Issue
Block a user