Merge pull request #3004 from pchote/sidebar-mouse-interaction

C&C widget mouse event polish
This commit is contained in:
Matthias Mailänder
2013-04-08 02:40:35 -07:00
3 changed files with 30 additions and 28 deletions

View File

@@ -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()

View File

@@ -104,26 +104,21 @@ namespace OpenRA.Mods.Cnc.Widgets
public override bool HandleMouseInput(MouseInput mi)
{
var icon = Icons.Where(i => i.Key.Contains(mi.Location))
.Select(i => i.Value).FirstOrDefault();
if (mi.Event == MouseInputEvent.Move)
{
var hover = Icons.Where(i => i.Key.Contains(mi.Location))
.Select(i => i.Value).FirstOrDefault();
TooltipActor = icon != null ? icon.Name : null;
TooltipActor = hover != null ? hover.Name : null;
if (icon == null)
return false;
}
// Eat mouse-up events
if (mi.Event != MouseInputEvent.Down)
return false;
var clicked = Icons.Where(i => i.Key.Contains(mi.Location))
.Select(i => i.Value).FirstOrDefault();
if (clicked == null)
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<BuildingInfo>())
{
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;
}
}
}

View File

@@ -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)