Merge pull request #3004 from pchote/sidebar-mouse-interaction
C&C widget mouse event polish
This commit is contained in:
@@ -23,7 +23,7 @@ namespace OpenRA.Widgets
|
|||||||
static readonly Action Nothing = () => {};
|
static readonly Action Nothing = () => {};
|
||||||
public int2 CursorOffset = new int2(0, 20);
|
public int2 CursorOffset = new int2(0, 20);
|
||||||
public Action BeforeRender = Nothing;
|
public Action BeforeRender = Nothing;
|
||||||
public int TooltipDelay = 2;
|
public int TooltipDelay = 5;
|
||||||
Widget tooltip;
|
Widget tooltip;
|
||||||
|
|
||||||
public TooltipContainerWidget()
|
public TooltipContainerWidget()
|
||||||
|
|||||||
@@ -104,26 +104,21 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
|
|
||||||
public override bool HandleMouseInput(MouseInput mi)
|
public override bool HandleMouseInput(MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Event == MouseInputEvent.Move)
|
var icon = Icons.Where(i => i.Key.Contains(mi.Location))
|
||||||
{
|
|
||||||
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))
|
|
||||||
.Select(i => i.Value).FirstOrDefault();
|
.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;
|
return true;
|
||||||
|
|
||||||
var actor = Rules.Info[clicked.Name];
|
var actor = Rules.Info[icon.Name];
|
||||||
var first = clicked.Queued.FirstOrDefault();
|
var first = icon.Queued.FirstOrDefault();
|
||||||
|
|
||||||
if (mi.Button == MouseButton.Left)
|
if (mi.Button == MouseButton.Left)
|
||||||
{
|
{
|
||||||
@@ -131,20 +126,20 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
if (first != null && first.Done && actor.Traits.Contains<BuildingInfo>())
|
if (first != null && first.Done && actor.Traits.Contains<BuildingInfo>())
|
||||||
{
|
{
|
||||||
Sound.Play(TabClick);
|
Sound.Play(TabClick);
|
||||||
world.OrderGenerator = new PlaceBuildingOrderGenerator(CurrentQueue.self, clicked.Name);
|
world.OrderGenerator = new PlaceBuildingOrderGenerator(CurrentQueue.self, icon.Name);
|
||||||
}
|
}
|
||||||
// Resume a paused item
|
// Resume a paused item
|
||||||
else if (first != null && first.Paused)
|
else if (first != null && first.Paused)
|
||||||
{
|
{
|
||||||
Sound.Play(TabClick);
|
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
|
// 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.Play(TabClick);
|
||||||
Sound.PlayNotification(world.LocalPlayer, "Speech", CurrentQueue.Info.QueuedAudio, world.LocalPlayer.Country.Race);
|
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));
|
Game.GetModifierKeys().HasModifier(Modifiers.Shift) ? 5 : 1));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -162,13 +157,13 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
if (first.Paused || first.Done || first.TotalCost == first.RemainingCost)
|
if (first.Paused || first.Done || first.TotalCost == first.RemainingCost)
|
||||||
{
|
{
|
||||||
Sound.PlayNotification(world.LocalPlayer, "Speech", CurrentQueue.Info.CancelledAudio, world.LocalPlayer.Country.Race);
|
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));
|
Game.GetModifierKeys().HasModifier(Modifiers.Shift) ? 5 : 1));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Sound.PlayNotification(world.LocalPlayer, "Speech", CurrentQueue.Info.OnHoldAudio, world.LocalPlayer.Country.Race);
|
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
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -227,13 +227,13 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mi.Button != MouseButton.Left)
|
if (mi.Button != MouseButton.Left)
|
||||||
return false;
|
return true;
|
||||||
|
|
||||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
||||||
return false;
|
return true;
|
||||||
|
|
||||||
if (!Focused)
|
if (!Focused)
|
||||||
return false;
|
return true;
|
||||||
|
|
||||||
if (Focused && mi.Event == MouseInputEvent.Up)
|
if (Focused && mi.Event == MouseInputEvent.Up)
|
||||||
return LoseFocus(mi);
|
return LoseFocus(mi);
|
||||||
@@ -257,10 +257,9 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
{
|
{
|
||||||
CurrentQueue = Groups[queueGroup].Tabs[offsetloc.X/(TabWidth - 1)].Queue;
|
CurrentQueue = Groups[queueGroup].Tabs[offsetloc.X/(TabWidth - 1)].Queue;
|
||||||
Sound.PlayNotification(null, "Sounds", "ClickSound", null);
|
Sound.PlayNotification(null, "Sounds", "ClickSound", null);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return leftPressed || rightPressed;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleKeyPress(KeyInput e)
|
public override bool HandleKeyPress(KeyInput e)
|
||||||
|
|||||||
Reference in New Issue
Block a user