Implement middle click to cancel (skips onhold) and ctrl+cancel to cancel entire queue

This commit is contained in:
Kevin Azzam
2015-10-11 03:31:44 +02:00
parent 7e1dfa96be
commit 7b22023d57
2 changed files with 27 additions and 16 deletions

View File

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

View File

@@ -182,15 +182,11 @@ namespace OpenRA.Mods.Common.Widgets
if (icon == null) if (icon == null)
return false; return false;
// Only support left and right clicks
if (mi.Button != MouseButton.Left && mi.Button != MouseButton.Right)
return false;
// Eat mouse-up events // Eat mouse-up events
if (mi.Event != MouseInputEvent.Down) if (mi.Event != MouseInputEvent.Down)
return true; 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) 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)) if (PickUpCompletedBuildingIcon(icon, item))
{ {
@@ -237,15 +233,14 @@ namespace OpenRA.Mods.Common.Widgets
// Queue a new item // Queue a new item
Game.Sound.Play(TabClick); Game.Sound.Play(TabClick);
Game.Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Speech", CurrentQueue.Info.QueuedAudio, World.LocalPlayer.Faction.InternalName); Game.Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Speech", CurrentQueue.Info.QueuedAudio, World.LocalPlayer.Faction.InternalName);
World.IssueOrder(Order.StartProduction(CurrentQueue.Actor, icon.Name, World.IssueOrder(Order.StartProduction(CurrentQueue.Actor, icon.Name, handleCount));
handleMultiple ? 5 : 1));
return true; return true;
} }
return false; return false;
} }
bool HandleRightClick(ProductionItem item, ProductionIcon icon, bool handleMultiple) bool HandleRightClick(ProductionItem item, ProductionIcon icon, int handleCount)
{ {
if (item == null) if (item == null)
return false; 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 // 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); Game.Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Speech", CurrentQueue.Info.CancelledAudio, World.LocalPlayer.Faction.InternalName);
World.IssueOrder(Order.CancelProduction(CurrentQueue.Actor, icon.Name, World.IssueOrder(Order.CancelProduction(CurrentQueue.Actor, icon.Name, handleCount));
handleMultiple ? 5 : 1));
} }
else else
{ {
@@ -269,11 +263,28 @@ namespace OpenRA.Mods.Common.Widgets
return true; 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 item = icon.Queued.FirstOrDefault();
var handled = isLeftClick ? HandleLeftClick(item, icon, handleMultiple) var handled = btn == MouseButton.Left ? HandleLeftClick(item, icon, startCount)
: HandleRightClick(item, icon, handleMultiple); : btn == MouseButton.Right ? HandleRightClick(item, icon, cancelCount)
: btn == MouseButton.Middle ? HandleMiddleClick(item, icon, cancelCount)
: false;
if (!handled) if (!handled)
Game.Sound.Play(DisabledTabClick); Game.Sound.Play(DisabledTabClick);
@@ -288,7 +299,7 @@ namespace OpenRA.Mods.Common.Widgets
var hotkey = Hotkey.FromKeyInput(e); var hotkey = Hotkey.FromKeyInput(e);
var toBuild = icons.Values.FirstOrDefault(i => i.Hotkey == hotkey); 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() public void RefreshIcons()