Merge pull request #7501 from Bynnar18/leftclick

Reimplementing Left Click Orders with Fixes
This commit is contained in:
Oliver Brakmann
2015-03-02 18:01:26 +01:00
24 changed files with 226 additions and 100 deletions

View File

@@ -49,4 +49,23 @@ namespace OpenRA
Sync.CheckSyncUnchanged(world, () => Ui.HandleInput(input));
}
}
public class MouseButtonPreference
{
public MouseButton Action
{
get
{
return Game.Settings.Game.UseClassicMouseStyle ? MouseButton.Left : MouseButton.Right;
}
}
public MouseButton Cancel
{
get
{
return Game.Settings.Game.UseClassicMouseStyle ? MouseButton.Right : MouseButton.Left;
}
}
}
}

View File

@@ -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.Order.OverrideSelection)
return false;
return true;
}
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 == MouseButton.Right)
if (mi.Button == Game.Settings.Game.MouseButtonPreference.Action)
{
foreach (var o in self.TraitsImplementing<IIssueOrder>()
.SelectMany(trait => trait.Orders

View File

@@ -127,9 +127,12 @@ 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;
public bool TeamHealthColors = false;

View File

@@ -79,6 +79,7 @@ namespace OpenRA.Traits
int OrderPriority { get; }
bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, TargetModifiers modifiers, ref string cursor);
bool IsQueued { get; }
bool OverrideSelection { get; }
}
public interface IResolveOrder { void ResolveOrder(Actor self, Order order); }

View File

@@ -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,13 +48,16 @@ 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);
}
public override bool HandleMouseInput(MouseInput mi)
{
var xy = worldRenderer.Viewport.ViewToWorldPx(mi.Location);
var useClassicMouseStyle = Game.Settings.Game.UseClassicMouseStyle;
var hasBox = SelectionBox != null;
var multiClick = mi.MultiTapCount >= 2;
@@ -65,8 +68,15 @@ namespace OpenRA.Widgets
dragStart = xy;
// place buildings
ApplyOrders(World, xy, mi);
// Place buildings, use support powers, and other non-unit things
if (!(World.OrderGenerator is UnitOrderGenerator))
{
ApplyOrders(World, xy, mi);
dragStart = dragEnd = null;
YieldMouseFocus(mi);
lastMousePosition = xy;
return true;
}
}
if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Move && dragStart.HasValue)
@@ -76,6 +86,24 @@ namespace OpenRA.Widgets
{
if (World.OrderGenerator is UnitOrderGenerator)
{
if (useClassicMouseStyle && HasMouseFocus)
{
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 (multiClick)
{
var unit = World.ScreenMap.ActorsAt(xy)
@@ -88,7 +116,7 @@ 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);
}
}
@@ -97,9 +125,17 @@ namespace OpenRA.Widgets
YieldMouseFocus(mi);
}
// don't issue orders while selecting
if (mi.Button == MouseButton.Right && mi.Event == MouseInputEvent.Down && !hasBox)
ApplyOrders(World, xy, mi);
if (mi.Button == MouseButton.Right && mi.Event == MouseInputEvent.Down)
{
// Don't do anything while selecting
if (!hasBox)
{
if (useClassicMouseStyle)
World.Selection.Clear();
ApplyOrders(World, xy, mi);
}
}
lastMousePosition = xy;
@@ -110,7 +146,7 @@ namespace OpenRA.Widgets
{
get
{
return dragStart.HasValue && dragEnd.HasValue;
return dragStart.HasValue && dragEnd.HasValue && (dragStart.Value - dragEnd.Value).Length > Game.Settings.Game.SelectionDeadzone;
}
}
@@ -172,7 +208,7 @@ namespace OpenRA.Widgets
var mi = new MouseInput
{
Location = screenPos,
Button = MouseButton.Right,
Button = Game.Settings.Game.MouseButtonPreference.Action,
Modifiers = Game.GetModifierKeys()
};
@@ -224,6 +260,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)

View File

@@ -45,6 +45,10 @@ namespace OpenRA.Mods.Cnc.Traits
public override IOrderGenerator OrderGenerator(string order, SupportPowerManager manager)
{
// Clear selection if using Left-Click Orders
if (Game.Settings.Game.UseClassicMouseStyle)
manager.Self.World.Selection.Clear();
Sound.PlayToPlayer(manager.Self.Owner, Info.SelectTargetSound);
var info = Info as IonCannonPowerInfo;
return new SelectGenericPowerTarget(order, manager, info.Cursor, MouseButton.Left);

View File

@@ -32,6 +32,7 @@ namespace OpenRA.Mods.Common.Orders
public string OrderID { get; private set; }
public int OrderPriority { get; private set; }
public bool OverrideSelection { get { return true; } }
public bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, TargetModifiers modifiers, ref string cursor)
{

View File

@@ -34,6 +34,10 @@ namespace OpenRA.Mods.Common.Orders
producer = queue.Actor;
building = name;
// Clear selection if using Left-Click Orders
if (Game.Settings.Game.UseClassicMouseStyle)
producer.World.Selection.Clear();
var map = producer.World.Map;
var tileset = producer.World.TileSet.Id.ToLowerInvariant();
buildingInfo = map.Rules.Actors[building].Traits.Get<BuildingInfo>();

View File

@@ -31,6 +31,7 @@ namespace OpenRA.Mods.Common.Orders
public string OrderID { get; private set; }
public int OrderPriority { get; private set; }
public bool? ForceAttack = null;
public bool OverrideSelection { get { return true; } }
public abstract bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor);
public abstract bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor);

View File

@@ -302,6 +302,7 @@ namespace OpenRA.Mods.Common.Traits
{
public string OrderID { get { return "Move"; } }
public int OrderPriority { get { return 4; } }
public bool OverrideSelection { get { return false; } }
readonly AircraftInfo info;

View File

@@ -194,6 +194,7 @@ namespace OpenRA.Mods.Common.Traits
public string OrderID { get; private set; }
public int OrderPriority { get; private set; }
public bool OverrideSelection { get { return true; } }
bool CanTargetActor(Actor self, Target target, TargetModifiers modifiers, ref string cursor)
{

View File

@@ -56,6 +56,7 @@ namespace OpenRA.Mods.Common.Traits
{
public string OrderID { get { return "SetRallyPoint"; } }
public int OrderPriority { get { return 0; } }
public bool OverrideSelection { get { return true; } }
public bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, TargetModifiers modifiers, ref string cursor)
{

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
{
if (mi.Button == MouseButton.Left)
if (mi.Button == Game.Settings.Game.MouseButtonPreference.Cancel)
{
world.CancelInputMode();
yield break;

View File

@@ -445,6 +445,7 @@ namespace OpenRA.Mods.Common.Traits
public string OrderID { get { return "Harvest"; } }
public int OrderPriority { get { return 10; } }
public bool IsQueued { get; protected set; }
public bool OverrideSelection { get { return true; } }
public bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, TargetModifiers modifiers, ref string cursor)
{

View File

@@ -619,6 +619,7 @@ namespace OpenRA.Mods.Common.Traits
{
readonly MobileInfo unitType;
readonly bool rejectMove;
public bool OverrideSelection { get { return false; } }
public MoveOrderTargeter(Actor self, MobileInfo unitType)
{

View File

@@ -102,6 +102,10 @@ namespace OpenRA.Mods.Common.Traits
public SelectTarget(World world, string order, SupportPowerManager manager, GrantUpgradePower power)
{
// Clear selection if using Left-Click Orders
if (Game.Settings.Game.UseClassicMouseStyle)
manager.Self.World.Selection.Clear();
this.manager = manager;
this.order = order;
this.power = power;

View File

@@ -239,6 +239,10 @@ namespace OpenRA.Mods.Common.Traits
public SelectGenericPowerTarget(string order, SupportPowerManager manager, string cursor, MouseButton button)
{
// Clear selection if using Left-Click Orders
if (Game.Settings.Game.UseClassicMouseStyle)
manager.Self.World.Selection.Clear();
this.manager = manager;
this.order = order;
this.cursor = cursor;

View File

@@ -312,6 +312,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var gs = Game.Settings.Game;
var ks = Game.Settings.Keys;
BindCheckboxPref(panel, "CLASSICORDERS_CHECKBOX", gs, "UseClassicMouseStyle");
BindCheckboxPref(panel, "EDGESCROLL_CHECKBOX", gs, "ViewportEdgeScroll");
BindCheckboxPref(panel, "LOCKMOUSE_CHECKBOX", gs, "LockMouseWindow");
BindSliderPref(panel, "SCROLLSPEED_SLIDER", gs, "ViewportEdgeScrollStep");
@@ -472,6 +473,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return () =>
{
gs.UseClassicMouseStyle = dgs.UseClassicMouseStyle;
gs.MouseScroll = dgs.MouseScroll;
gs.LockMouseWindow = dgs.LockMouseWindow;
gs.ViewportEdgeScroll = dgs.ViewportEdgeScroll;

View File

@@ -98,7 +98,7 @@ namespace OpenRA.Mods.Common.Widgets
if (actors.Any())
world.OrderGenerator = new GenericSelectTarget(actors,
"AttackMove", "attackmove", MouseButton.Right);
"AttackMove", "attackmove", Game.Settings.Game.MouseButtonPreference.Action);
return true;
}

View File

@@ -146,7 +146,7 @@ namespace OpenRA.Mods.RA.Traits
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
{
if (mi.Button == MouseButton.Left)
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 == MouseButton.Right && underCursor == null)
if (mi.Button == Game.Settings.Game.MouseButtonPreference.Action && underCursor == null)
{
minelayer.World.CancelInputMode();
yield return new Order("PlaceMinefield", minelayer, false) { TargetLocation = xy };
@@ -197,6 +197,7 @@ namespace OpenRA.Mods.RA.Traits
{
public string OrderID { get { return "BeginMinefield"; } }
public int OrderPriority { get { return 5; } }
public bool OverrideSelection { get { return true; } }
public bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, TargetModifiers modifiers, ref string cursor)
{

View File

@@ -119,6 +119,7 @@ namespace OpenRA.Mods.RA.Traits
public string OrderID { get { return "PortableChronoTeleport"; } }
public int OrderPriority { get { return 5; } }
public bool IsQueued { get; protected set; }
public bool OverrideSelection { get { return true; } }
public bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, TargetModifiers modifiers, ref string cursor)
{
@@ -153,7 +154,7 @@ namespace OpenRA.Mods.RA.Traits
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
{
if (mi.Button == MouseButton.Left)
if (mi.Button == Game.Settings.Game.MouseButtonPreference.Cancel)
{
world.CancelInputMode();
yield break;

View File

@@ -101,6 +101,10 @@ namespace OpenRA.Mods.RA.Traits
public SelectTarget(World world, string order, SupportPowerManager manager, ChronoshiftPower power)
{
// Clear selection if using Left-Click Orders
if (Game.Settings.Game.UseClassicMouseStyle)
manager.Self.World.Selection.Clear();
this.manager = manager;
this.order = order;
this.power = power;

View File

@@ -320,53 +320,16 @@ Container@SETTINGS_PANEL:
Font: Bold
Text: Input
Align: Center
Checkbox@EDGESCROLL_CHECKBOX:
Checkbox@CLASSICORDERS_CHECKBOX:
X: 15
Y: 40
Width: 130
Height: 20
Font: Regular
Text: Edge Scrolling
Checkbox@LOCKMOUSE_CHECKBOX:
X: 15
Y: 70
Width: 130
Height: 20
Font: Regular
Text: Lock mouse to window
Label@SCROLL_SPEED_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 37
Width: 95
Height: 25
Text: Scroll Speed:
Align: Right
Slider@SCROLLSPEED_SLIDER:
X: PARENT_RIGHT - WIDTH - 15
Y: 43
Width: 250
Height: 20
Ticks: 5
MinimumValue: 10
MaximumValue: 50
Label@UI_SCROLL_SPEED_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 67
Width: 95
Height: 25
Text: UI Scroll Speed:
Align: Right
Slider@UI_SCROLLSPEED_SLIDER:
X: PARENT_RIGHT - WIDTH - 15
Y: 73
Width: 250
Height: 20
Ticks: 5
MinimumValue: 1
MaximumValue: 100
Font: Regular
Text: Left-Click Orders
Label@MOUSE_SCROLL_LABEL:
X: PARENT_RIGHT - WIDTH - 120
Y: 99
Y: 39
Width: 160
Height: 20
Font: Regular
@@ -374,11 +337,55 @@ Container@SETTINGS_PANEL:
Align: Right
DropDownButton@MOUSE_SCROLL:
X: PARENT_RIGHT - WIDTH - 15
Y: 98
Y: 38
Width: 100
Height: 25
Font: Regular
Text: Enabled
Checkbox@EDGESCROLL_CHECKBOX:
X: 15
Y: 70
Width: 130
Height: 20
Font: Regular
Text: Edge Scrolling
Checkbox@LOCKMOUSE_CHECKBOX:
X: 15
Y: 100
Width: 130
Height: 20
Font: Regular
Text: Lock mouse to window
Label@SCROLL_SPEED_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 67
Width: 95
Height: 25
Text: Scroll Speed:
Align: Right
Slider@SCROLLSPEED_SLIDER:
X: PARENT_RIGHT - WIDTH - 15
Y: 73
Width: 250
Height: 20
Ticks: 5
MinimumValue: 10
MaximumValue: 50
Label@UI_SCROLL_SPEED_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 97
Width: 95
Height: 25
Text: UI Scroll Speed:
Align: Right
Slider@UI_SCROLLSPEED_SLIDER:
X: PARENT_RIGHT - WIDTH - 15
Y: 103
Width: 250
Height: 20
Ticks: 5
MinimumValue: 1
MaximumValue: 100
Label@HOTKEYS_TITLE:
Y: 135
Width: PARENT_RIGHT

View File

@@ -324,53 +324,16 @@ Background@SETTINGS_PANEL:
Width: PARENT_RIGHT - 10
Height: PARENT_BOTTOM
Children:
Checkbox@EDGESCROLL_CHECKBOX:
Checkbox@CLASSICORDERS_CHECKBOX:
X: 15
Y: 40
Width: 130
Height: 20
Font: Regular
Text: Edge Scrolling
Checkbox@LOCKMOUSE_CHECKBOX:
X: 15
Y: 70
Width: 130
Height: 20
Font: Regular
Text: Lock mouse to window
Label@SCROLL_SPEED_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 37
Width: 95
Height: 25
Text: Scroll Speed:
Align: Right
Slider@SCROLLSPEED_SLIDER:
X: PARENT_RIGHT - WIDTH - 15
Y: 43
Width: 250
Height: 20
Ticks: 5
MinimumValue: 10
MaximumValue: 50
Label@UI_SCROLL_SPEED_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 67
Width: 95
Height: 25
Text: UI Scroll Speed:
Align: Right
Slider@UI_SCROLLSPEED_SLIDER:
X: PARENT_RIGHT - WIDTH - 15
Y: 73
Width: 250
Height: 20
Ticks: 5
MinimumValue: 1
MaximumValue: 100
Font: Regular
Text: Left-Click Orders
Label@MOUSE_SCROLL_LABEL:
X: PARENT_RIGHT - WIDTH - 120
Y: 99
Y: 39
Width: 160
Height: 20
Font: Regular
@@ -378,11 +341,55 @@ Background@SETTINGS_PANEL:
Align: Right
DropDownButton@MOUSE_SCROLL:
X: PARENT_RIGHT - WIDTH - 15
Y: 98
Y: 38
Width: 100
Height: 25
Font: Regular
Text: Enabled
Checkbox@EDGESCROLL_CHECKBOX:
X: 15
Y: 70
Width: 130
Height: 20
Font: Regular
Text: Edge Scrolling
Checkbox@LOCKMOUSE_CHECKBOX:
X: 15
Y: 100
Width: 130
Height: 20
Font: Regular
Text: Lock mouse to window
Label@SCROLL_SPEED_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 67
Width: 95
Height: 25
Text: Scroll Speed:
Align: Right
Slider@SCROLLSPEED_SLIDER:
X: PARENT_RIGHT - WIDTH - 15
Y: 73
Width: 250
Height: 20
Ticks: 5
MinimumValue: 10
MaximumValue: 50
Label@UI_SCROLL_SPEED_LABEL:
X: PARENT_RIGHT - WIDTH - 270
Y: 97
Width: 95
Height: 25
Text: UI Scroll Speed:
Align: Right
Slider@UI_SCROLLSPEED_SLIDER:
X: PARENT_RIGHT - WIDTH - 15
Y: 103
Width: 250
Height: 20
Ticks: 5
MinimumValue: 1
MaximumValue: 100
Label@HOTKEYS_TITLE:
Y: 135
Width: PARENT_RIGHT