Fixed left-click orders and implemented a selection deadzone.
This commit is contained in:
@@ -27,8 +27,6 @@ namespace OpenRA
|
||||
{
|
||||
public static class Game
|
||||
{
|
||||
public static MouseButtonPreference mouseButtonPreference = new MouseButtonPreference();
|
||||
|
||||
public const int NetTickScale = 3; // 120 ms net tick for 40 ms local tick
|
||||
public const int Timestep = 40;
|
||||
public const int TimestepJankThreshold = 250; // Don't catch up for delays larger than 250ms
|
||||
|
||||
@@ -52,7 +52,6 @@ namespace OpenRA
|
||||
|
||||
public class MouseButtonPreference
|
||||
{
|
||||
|
||||
public MouseButton Action
|
||||
{
|
||||
get
|
||||
@@ -61,7 +60,6 @@ namespace OpenRA
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public MouseButton Cancel
|
||||
{
|
||||
get
|
||||
|
||||
@@ -88,6 +88,20 @@ namespace OpenRA.Orders
|
||||
return cursorOrder != null ? cursorOrder.Cursor : (useSelect ? "select" : "default");
|
||||
}
|
||||
|
||||
// Used for classic mouse orders, determines whether or not action at xy is move or select
|
||||
public static bool InputOverridesSelection(World world, int2 xy, MouseInput mi)
|
||||
{
|
||||
var target = Target.FromActor(world.ScreenMap.ActorsAt(xy).WithHighestSelectionPriority());
|
||||
var underCursor = world.Selection.Actors.WithHighestSelectionPriority();
|
||||
|
||||
var o = OrderForUnit(underCursor, target, mi);
|
||||
|
||||
if (o == null || o.Trait is IMove)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static UnitOrderResult OrderForUnit(Actor self, Target target, MouseInput mi)
|
||||
{
|
||||
if (self.Owner != self.World.LocalPlayer)
|
||||
@@ -96,7 +110,7 @@ namespace OpenRA.Orders
|
||||
if (self.Destroyed || !target.IsValidFor(self))
|
||||
return null;
|
||||
|
||||
if (mi.Button == Game.mouseButtonPreference.Action)
|
||||
if (mi.Button == Game.Settings.Game.MouseButtonPreference.Action)
|
||||
{
|
||||
foreach (var o in self.TraitsImplementing<IIssueOrder>()
|
||||
.SelectMany(trait => trait.Orders
|
||||
|
||||
@@ -127,8 +127,10 @@ namespace OpenRA
|
||||
public bool ViewportEdgeScroll = true;
|
||||
public bool LockMouseWindow = false;
|
||||
public MouseScrollType MouseScroll = MouseScrollType.Standard;
|
||||
public MouseButtonPreference MouseButtonPreference = new MouseButtonPreference();
|
||||
public float ViewportEdgeScrollStep = 10f;
|
||||
public float UIScrollSpeed = 50f;
|
||||
public int SelectionDeadzone = 24;
|
||||
|
||||
public bool UseClassicMouseStyle = false;
|
||||
public bool AlwaysShowStatusBars = false;
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
if (!IsDragging)
|
||||
{
|
||||
foreach (var u in SelectActorsInBox(World, lastMousePosition, lastMousePosition, _ => true))
|
||||
foreach (var u in SelectActorsInBoxWithDeadzone(World, lastMousePosition, lastMousePosition, _ => true))
|
||||
worldRenderer.DrawRollover(u);
|
||||
|
||||
return;
|
||||
@@ -48,7 +48,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
var selbox = SelectionBox;
|
||||
Game.Renderer.WorldLineRenderer.DrawRect(selbox.Value.First.ToFloat2(), selbox.Value.Second.ToFloat2(), Color.White);
|
||||
foreach (var u in SelectActorsInBox(World, selbox.Value.First, selbox.Value.Second, _ => true))
|
||||
foreach (var u in SelectActorsInBoxWithDeadzone(World, selbox.Value.First, selbox.Value.Second, _ => true))
|
||||
worldRenderer.DrawRollover(u);
|
||||
}
|
||||
|
||||
@@ -68,8 +68,8 @@ namespace OpenRA.Widgets
|
||||
|
||||
dragStart = xy;
|
||||
|
||||
// place buildings
|
||||
if(!useClassicMouseStyle)
|
||||
// Place buildings
|
||||
if (!useClassicMouseStyle || !World.Selection.Actors.Any())
|
||||
ApplyOrders(World, xy, mi);
|
||||
}
|
||||
|
||||
@@ -77,21 +77,27 @@ namespace OpenRA.Widgets
|
||||
dragEnd = xy;
|
||||
|
||||
if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Up)
|
||||
{
|
||||
if (World.OrderGenerator is UnitOrderGenerator)
|
||||
{
|
||||
if (useClassicMouseStyle && HasMouseFocus)
|
||||
{
|
||||
// order units around
|
||||
if (!hasBox && World.Selection.Actors.Any() && !multiClick)
|
||||
{
|
||||
if (!(World.ScreenMap.ActorsAt(xy).Where(x => x.HasTrait<Selectable>() && x.Trait<Selectable>().Info.Selectable &&
|
||||
(x.Owner.IsAlliedWith(World.RenderPlayer) || !World.FogObscures(x))).Any() && !mi.Modifiers.HasModifier(Modifiers.Ctrl) &&
|
||||
!mi.Modifiers.HasModifier(Modifiers.Alt) && UnitOrderGenerator.InputOverridesSelection(World, xy, mi)))
|
||||
{
|
||||
// Order units instead of selecting
|
||||
ApplyOrders(World, xy, mi);
|
||||
dragStart = dragEnd = null;
|
||||
YieldMouseFocus(mi);
|
||||
lastMousePosition = xy;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (World.OrderGenerator is UnitOrderGenerator)
|
||||
{
|
||||
if (multiClick)
|
||||
{
|
||||
var unit = World.ScreenMap.ActorsAt(xy)
|
||||
@@ -104,23 +110,28 @@ namespace OpenRA.Widgets
|
||||
}
|
||||
else if (dragStart.HasValue)
|
||||
{
|
||||
var newSelection = SelectActorsInBox(World, dragStart.Value, xy, _ => true);
|
||||
var newSelection = SelectActorsInBoxWithDeadzone(World, dragStart.Value, xy, _ => true);
|
||||
World.Selection.Combine(World, newSelection, mi.Modifiers.HasModifier(Modifiers.Shift), dragStart == xy);
|
||||
}
|
||||
}
|
||||
else if (useClassicMouseStyle)
|
||||
ApplyOrders(World, xy, mi);
|
||||
|
||||
dragStart = dragEnd = null;
|
||||
YieldMouseFocus(mi);
|
||||
}
|
||||
|
||||
if (mi.Button == MouseButton.Right && mi.Event == MouseInputEvent.Down)
|
||||
{
|
||||
// Don't do anything while selecting
|
||||
if (!hasBox)
|
||||
{
|
||||
if (useClassicMouseStyle)
|
||||
World.Selection.Clear();
|
||||
|
||||
if (!hasBox) // don't issue orders while selecting
|
||||
ApplyOrders(World, xy, mi);
|
||||
}
|
||||
}
|
||||
|
||||
lastMousePosition = xy;
|
||||
|
||||
@@ -131,7 +142,7 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
get
|
||||
{
|
||||
return dragStart.HasValue && dragEnd.HasValue;
|
||||
return dragStart.HasValue && dragEnd.HasValue && (dragStart.Value - dragEnd.Value).Length > Game.Settings.Game.SelectionDeadzone;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +204,7 @@ namespace OpenRA.Widgets
|
||||
var mi = new MouseInput
|
||||
{
|
||||
Location = screenPos,
|
||||
Button = Game.mouseButtonPreference.Action,
|
||||
Button = Game.Settings.Game.MouseButtonPreference.Action,
|
||||
Modifiers = Game.GetModifierKeys()
|
||||
};
|
||||
|
||||
@@ -245,6 +256,14 @@ namespace OpenRA.Widgets
|
||||
return false;
|
||||
}
|
||||
|
||||
static IEnumerable<Actor> SelectActorsInBoxWithDeadzone(World world, int2 a, int2 b, Func<Actor, bool> cond)
|
||||
{
|
||||
if (a == b || (a - b).Length > Game.Settings.Game.SelectionDeadzone)
|
||||
return SelectActorsInBox(world, a, b, cond);
|
||||
else
|
||||
return SelectActorsInBox(world, b, b, cond);
|
||||
}
|
||||
|
||||
static IEnumerable<Actor> SelectActorsInBox(World world, int2 a, int2 b, Func<Actor, bool> cond)
|
||||
{
|
||||
return world.ScreenMap.ActorsInBox(a, b)
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
||||
{
|
||||
if (mi.Button == Game.mouseButtonPreference.Cancel)
|
||||
if (mi.Button == Game.Settings.Game.MouseButtonPreference.Cancel)
|
||||
{
|
||||
world.CancelInputMode();
|
||||
yield break;
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
if (actors.Any())
|
||||
world.OrderGenerator = new GenericSelectTarget(actors,
|
||||
"AttackMove", "attackmove", Game.mouseButtonPreference.Action);
|
||||
"AttackMove", "attackmove", Game.Settings.Game.MouseButtonPreference.Action);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ namespace OpenRA.Mods.RA.Traits
|
||||
|
||||
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
||||
{
|
||||
if (mi.Button == Game.mouseButtonPreference.Cancel)
|
||||
if (mi.Button == Game.Settings.Game.MouseButtonPreference.Cancel)
|
||||
{
|
||||
world.CancelInputMode();
|
||||
yield break;
|
||||
@@ -157,7 +157,7 @@ namespace OpenRA.Mods.RA.Traits
|
||||
.MaxByOrDefault(a => a.Info.Traits.Contains<SelectableInfo>()
|
||||
? a.Info.Traits.Get<SelectableInfo>().Priority : int.MinValue);
|
||||
|
||||
if (mi.Button == Game.mouseButtonPreference.Action && underCursor == null)
|
||||
if (mi.Button == Game.Settings.Game.MouseButtonPreference.Action && underCursor == null)
|
||||
{
|
||||
minelayer.World.CancelInputMode();
|
||||
yield return new Order("PlaceMinefield", minelayer, false) { TargetLocation = xy };
|
||||
|
||||
@@ -153,7 +153,7 @@ namespace OpenRA.Mods.RA.Traits
|
||||
|
||||
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
||||
{
|
||||
if (mi.Button == Game.mouseButtonPreference.Cancel)
|
||||
if (mi.Button == Game.Settings.Game.MouseButtonPreference.Cancel)
|
||||
{
|
||||
world.CancelInputMode();
|
||||
yield break;
|
||||
|
||||
Reference in New Issue
Block a user