From 5580ad4663fbe33eda2ed287716030b7a7f20a8a Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 8 Apr 2013 18:21:01 +1200 Subject: [PATCH 1/2] Fix C&C sidebar cursor/world cursor interaction. Fixes #2989. --- .../Widgets/ProductionPaletteWidget.cs | 47 ++++++++++--------- .../Widgets/ProductionTabsWidget.cs | 9 ++-- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/OpenRA.Mods.Cnc/Widgets/ProductionPaletteWidget.cs b/OpenRA.Mods.Cnc/Widgets/ProductionPaletteWidget.cs index d8f4470004..b77c41159e 100755 --- a/OpenRA.Mods.Cnc/Widgets/ProductionPaletteWidget.cs +++ b/OpenRA.Mods.Cnc/Widgets/ProductionPaletteWidget.cs @@ -104,26 +104,21 @@ namespace OpenRA.Mods.Cnc.Widgets public override bool HandleMouseInput(MouseInput mi) { - if (mi.Event == MouseInputEvent.Move) - { - var hover = Icons.Where(i => i.Key.Contains(mi.Location)) - .Select(i => i.Value).FirstOrDefault(); - - TooltipActor = hover != null ? hover.Name : null; - return false; - } - - if (mi.Event != MouseInputEvent.Down) - return false; - - var clicked = Icons.Where(i => i.Key.Contains(mi.Location)) + var icon = Icons.Where(i => i.Key.Contains(mi.Location)) .Select(i => i.Value).FirstOrDefault(); - if (clicked == null) + if (mi.Event == MouseInputEvent.Move) + TooltipActor = icon != null ? icon.Name : null; + + if (icon == null) + return false; + + // Eat mouse-up events + if (mi.Event != MouseInputEvent.Down) return true; - var actor = Rules.Info[clicked.Name]; - var first = clicked.Queued.FirstOrDefault(); + var actor = Rules.Info[icon.Name]; + var first = icon.Queued.FirstOrDefault(); if (mi.Button == MouseButton.Left) { @@ -131,20 +126,20 @@ namespace OpenRA.Mods.Cnc.Widgets if (first != null && first.Done && actor.Traits.Contains()) { Sound.Play(TabClick); - world.OrderGenerator = new PlaceBuildingOrderGenerator(CurrentQueue.self, clicked.Name); + world.OrderGenerator = new PlaceBuildingOrderGenerator(CurrentQueue.self, icon.Name); } // Resume a paused item else if (first != null && first.Paused) { Sound.Play(TabClick); - world.IssueOrder(Order.PauseProduction(CurrentQueue.self, clicked.Name, false)); + world.IssueOrder(Order.PauseProduction(CurrentQueue.self, icon.Name, false)); } // Queue a new item - else if (CurrentQueue.BuildableItems().Any(a => a.Name == clicked.Name)) + else if (CurrentQueue.BuildableItems().Any(a => a.Name == icon.Name)) { Sound.Play(TabClick); Sound.PlayNotification(world.LocalPlayer, "Speech", CurrentQueue.Info.QueuedAudio, world.LocalPlayer.Country.Race); - world.IssueOrder(Order.StartProduction(CurrentQueue.self, clicked.Name, + world.IssueOrder(Order.StartProduction(CurrentQueue.self, icon.Name, Game.GetModifierKeys().HasModifier(Modifiers.Shift) ? 5 : 1)); } else @@ -162,13 +157,13 @@ namespace OpenRA.Mods.Cnc.Widgets if (first.Paused || first.Done || first.TotalCost == first.RemainingCost) { Sound.PlayNotification(world.LocalPlayer, "Speech", CurrentQueue.Info.CancelledAudio, world.LocalPlayer.Country.Race); - world.IssueOrder(Order.CancelProduction(CurrentQueue.self, clicked.Name, + world.IssueOrder(Order.CancelProduction(CurrentQueue.self, icon.Name, Game.GetModifierKeys().HasModifier(Modifiers.Shift) ? 5 : 1)); } else { Sound.PlayNotification(world.LocalPlayer, "Speech", CurrentQueue.Info.OnHoldAudio, world.LocalPlayer.Country.Race); - world.IssueOrder(Order.PauseProduction(CurrentQueue.self, clicked.Name, true)); + world.IssueOrder(Order.PauseProduction(CurrentQueue.self, icon.Name, true)); } } else @@ -269,5 +264,13 @@ namespace OpenRA.Mods.Cnc.Widgets } } } + + public override string GetCursor(int2 pos) + { + var icon = Icons.Where(i => i.Key.Contains(pos)) + .Select(i => i.Value).FirstOrDefault(); + + return icon != null ? base.GetCursor(pos) : null; + } } } diff --git a/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs b/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs index c9459eba05..deda1ea1b8 100755 --- a/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs +++ b/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs @@ -227,13 +227,13 @@ namespace OpenRA.Mods.Cnc.Widgets } if (mi.Button != MouseButton.Left) - return false; + return true; if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi)) - return false; + return true; if (!Focused) - return false; + return true; if (Focused && mi.Event == MouseInputEvent.Up) return LoseFocus(mi); @@ -257,10 +257,9 @@ namespace OpenRA.Mods.Cnc.Widgets { CurrentQueue = Groups[queueGroup].Tabs[offsetloc.X/(TabWidth - 1)].Queue; Sound.PlayNotification(null, "Sounds", "ClickSound", null); - return true; } - return leftPressed || rightPressed; + return true; } public override bool HandleKeyPress(KeyInput e) From 87c107c8253e4e2fc86352d2819de28bc6c65f41 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 8 Apr 2013 20:25:13 +1200 Subject: [PATCH 2/2] Increase default tooltip delay to 200ms. --- OpenRA.Game/Widgets/TooltipContainerWidget.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Game/Widgets/TooltipContainerWidget.cs b/OpenRA.Game/Widgets/TooltipContainerWidget.cs index 5d0827a425..6e0b9a7bee 100755 --- a/OpenRA.Game/Widgets/TooltipContainerWidget.cs +++ b/OpenRA.Game/Widgets/TooltipContainerWidget.cs @@ -23,7 +23,7 @@ namespace OpenRA.Widgets static readonly Action Nothing = () => {}; public int2 CursorOffset = new int2(0, 20); public Action BeforeRender = Nothing; - public int TooltipDelay = 2; + public int TooltipDelay = 5; Widget tooltip; public TooltipContainerWidget()