Merge pull request #9595 from ChaoticMind/middle_click

Middle click to cancel directly (skips onhold) & ctrl+cancel to cancel entire queue
This commit is contained in:
abcdefg30
2015-12-05 16:06:09 +01:00
2 changed files with 27 additions and 16 deletions

View File

@@ -78,6 +78,7 @@ Also thanks to:
* Joppy Furr
* Kanar
* Kenny Hoxworth (hoxworth)
* Kevin Azzam (ChaoticMind)
* Krishnakanth Mallik
* Kyrre Soerensen (zypres)
* Lawrence Wang
@@ -165,4 +166,3 @@ distributed under the LGPL version 2.1 or later.
Finally, special thanks goes to the original teams
at Westwood Studios and EA for creating the classic
games which OpenRA aims to reimagine.

View File

@@ -182,15 +182,11 @@ namespace OpenRA.Mods.Common.Widgets
if (icon == null)
return false;
// Only support left and right clicks
if (mi.Button != MouseButton.Left && mi.Button != MouseButton.Right)
return false;
// Eat mouse-up events
if (mi.Event != MouseInputEvent.Down)
return true;
return HandleEvent(icon, mi.Button == MouseButton.Left, mi.Modifiers.HasModifier(Modifiers.Shift));
return HandleEvent(icon, mi.Button, mi.Modifiers);
}
protected bool PickUpCompletedBuildingIcon(ProductionIcon icon, ProductionItem item)
@@ -216,7 +212,7 @@ namespace OpenRA.Mods.Common.Widgets
}
}
bool HandleLeftClick(ProductionItem item, ProductionIcon icon, bool handleMultiple)
bool HandleLeftClick(ProductionItem item, ProductionIcon icon, int handleCount)
{
if (PickUpCompletedBuildingIcon(icon, item))
{
@@ -237,15 +233,14 @@ namespace OpenRA.Mods.Common.Widgets
// Queue a new item
Game.Sound.Play(TabClick);
Game.Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Speech", CurrentQueue.Info.QueuedAudio, World.LocalPlayer.Faction.InternalName);
World.IssueOrder(Order.StartProduction(CurrentQueue.Actor, icon.Name,
handleMultiple ? 5 : 1));
World.IssueOrder(Order.StartProduction(CurrentQueue.Actor, icon.Name, handleCount));
return true;
}
return false;
}
bool HandleRightClick(ProductionItem item, ProductionIcon icon, bool handleMultiple)
bool HandleRightClick(ProductionItem item, ProductionIcon icon, int handleCount)
{
if (item == null)
return false;
@@ -256,8 +251,7 @@ namespace OpenRA.Mods.Common.Widgets
{
// Instant cancel of things we have not started yet and things that are finished
Game.Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Speech", CurrentQueue.Info.CancelledAudio, World.LocalPlayer.Faction.InternalName);
World.IssueOrder(Order.CancelProduction(CurrentQueue.Actor, icon.Name,
handleMultiple ? 5 : 1));
World.IssueOrder(Order.CancelProduction(CurrentQueue.Actor, icon.Name, handleCount));
}
else
{
@@ -269,11 +263,28 @@ namespace OpenRA.Mods.Common.Widgets
return true;
}
bool HandleEvent(ProductionIcon icon, bool isLeftClick, bool handleMultiple)
bool HandleMiddleClick(ProductionItem item, ProductionIcon icon, int handleCount)
{
if (item == null)
return false;
// Directly cancel, skipping "on-hold"
Game.Sound.Play(TabClick);
Game.Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Speech", CurrentQueue.Info.CancelledAudio, World.LocalPlayer.Faction.InternalName);
World.IssueOrder(Order.CancelProduction(CurrentQueue.Actor, icon.Name, handleCount));
return true;
}
bool HandleEvent(ProductionIcon icon, MouseButton btn, Modifiers modifiers)
{
var startCount = modifiers.HasModifier(Modifiers.Shift) ? 5 : 1;
var cancelCount = modifiers.HasModifier(Modifiers.Ctrl) ? CurrentQueue.QueueLength : startCount;
var item = icon.Queued.FirstOrDefault();
var handled = isLeftClick ? HandleLeftClick(item, icon, handleMultiple)
: HandleRightClick(item, icon, handleMultiple);
var handled = btn == MouseButton.Left ? HandleLeftClick(item, icon, startCount)
: btn == MouseButton.Right ? HandleRightClick(item, icon, cancelCount)
: btn == MouseButton.Middle ? HandleMiddleClick(item, icon, cancelCount)
: false;
if (!handled)
Game.Sound.Play(DisabledTabClick);
@@ -288,7 +299,7 @@ namespace OpenRA.Mods.Common.Widgets
var hotkey = Hotkey.FromKeyInput(e);
var toBuild = icons.Values.FirstOrDefault(i => i.Hotkey == hotkey);
return toBuild != null ? HandleEvent(toBuild, true, false) : false;
return toBuild != null ? HandleEvent(toBuild, MouseButton.Left, Modifiers.None) : false;
}
public void RefreshIcons()