Add HotkeyReference.IsActivatedBy method.
This commit is contained in:
@@ -45,5 +45,11 @@ namespace OpenRA
|
||||
{
|
||||
return getValue();
|
||||
}
|
||||
|
||||
public bool IsActivatedBy(KeyInput e)
|
||||
{
|
||||
var currentValue = getValue();
|
||||
return currentValue.Key == e.Key && currentValue.Modifiers == e.Modifiers;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
public override bool HandleKeyPress(KeyInput e)
|
||||
{
|
||||
if (Hotkey.FromKeyInput(e) != Key.GetValue() || e.Event != KeyInputEvent.Down || (DisableKeyRepeat && e.IsRepeat))
|
||||
if (!Key.IsActivatedBy(e) || e.Event != KeyInputEvent.Down || (DisableKeyRepeat && e.IsRepeat))
|
||||
return false;
|
||||
|
||||
if (!IsDisabled())
|
||||
|
||||
@@ -72,8 +72,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
zoomDropdown.GetText = () => zoomDropdown.SelectedItem;
|
||||
zoomDropdown.OnKeyPress = e =>
|
||||
{
|
||||
var key = Hotkey.FromKeyInput(e);
|
||||
if (key != changeZoomKey.GetValue())
|
||||
if (!changeZoomKey.IsActivatedBy(e))
|
||||
return;
|
||||
|
||||
var selected = (options.IndexOf(float.Parse(selectedZoom)) + 1) % options.Length;
|
||||
|
||||
@@ -208,8 +208,8 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
keyOverrides.AddHandler(e =>
|
||||
{
|
||||
// HACK: enable attack move to be triggered if the ctrl key is pressed
|
||||
var modified = new Hotkey(e.Key, e.Modifiers & ~Modifiers.Ctrl);
|
||||
if (!attackMoveDisabled && attackMoveButton.Key.GetValue() == modified)
|
||||
e.Modifiers &= ~Modifiers.Ctrl;
|
||||
if (!attackMoveDisabled && attackMoveButton.Key.IsActivatedBy(e))
|
||||
{
|
||||
attackMoveButton.OnKeyPress(e);
|
||||
return true;
|
||||
|
||||
@@ -104,10 +104,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
if (e.Event == KeyInputEvent.Down && !e.IsRepeat)
|
||||
{
|
||||
var key = Hotkey.FromKeyInput(e);
|
||||
for (var i = 0; i < statsHotkeys.Length; i++)
|
||||
{
|
||||
if (key == statsHotkeys[i].GetValue())
|
||||
if (statsHotkeys[i].IsActivatedBy(e))
|
||||
{
|
||||
OpenMenuPanel(stats, new WidgetArgs() { { "activePanel", i } });
|
||||
return true;
|
||||
|
||||
@@ -148,8 +148,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
if (e.Event == KeyInputEvent.Down && !e.IsRepeat)
|
||||
{
|
||||
var h = Hotkey.FromKeyInput(e);
|
||||
if (h == combinedViewKey.GetValue() && !limitViews)
|
||||
if (combinedViewKey.IsActivatedBy(e) && !limitViews)
|
||||
{
|
||||
selected = combined;
|
||||
selected.OnClick();
|
||||
@@ -157,7 +156,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
return true;
|
||||
}
|
||||
|
||||
if (h == worldViewKey.GetValue() && !limitViews)
|
||||
if (worldViewKey.IsActivatedBy(e) && !limitViews)
|
||||
{
|
||||
selected = disableShroud;
|
||||
selected.OnClick();
|
||||
|
||||
@@ -124,10 +124,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
if (e.Event == KeyInputEvent.Down && !e.IsRepeat)
|
||||
{
|
||||
var key = Hotkey.FromKeyInput(e);
|
||||
for (var i = 0; i < statsHotkeys.Length; i++)
|
||||
{
|
||||
if (key == statsHotkeys[i].GetValue())
|
||||
if (statsHotkeys[i].IsActivatedBy(e))
|
||||
{
|
||||
statsDropDownOptions[i].OnClick();
|
||||
return true;
|
||||
|
||||
@@ -50,15 +50,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
if (e.Event == KeyInputEvent.Down)
|
||||
{
|
||||
var key = Hotkey.FromKeyInput(e);
|
||||
|
||||
if (key == nextKey.GetValue())
|
||||
if (nextKey.IsActivatedBy(e))
|
||||
musicPlaylist.Play(musicPlaylist.GetNextSong());
|
||||
else if (key == prevKey.GetValue())
|
||||
else if (prevKey.IsActivatedBy(e))
|
||||
musicPlaylist.Play(musicPlaylist.GetPrevSong());
|
||||
else if (key == stopKey.GetValue())
|
||||
else if (stopKey.IsActivatedBy(e))
|
||||
StopMusic();
|
||||
else if (key == pauseKey.GetValue())
|
||||
else if (pauseKey.IsActivatedBy(e))
|
||||
PauseOrResumeMusic();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,11 +30,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
keyhandler.AddHandler(e =>
|
||||
{
|
||||
if (e.Event == KeyInputEvent.Down)
|
||||
{
|
||||
var key = Hotkey.FromKeyInput(e);
|
||||
if (key == namedKey.GetValue())
|
||||
if (namedKey.IsActivatedBy(e))
|
||||
return OnHotkeyActivated(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
@@ -342,12 +342,11 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (e.Event == KeyInputEvent.Up || CurrentQueue == null)
|
||||
return false;
|
||||
|
||||
var hotkey = Hotkey.FromKeyInput(e);
|
||||
var batchModifiers = e.Modifiers.HasModifier(Modifiers.Shift) ? Modifiers.Shift : Modifiers.None;
|
||||
if (batchModifiers != Modifiers.None)
|
||||
hotkey = new Hotkey(hotkey.Key, hotkey.Modifiers ^ Modifiers.Shift);
|
||||
|
||||
var toBuild = icons.Values.FirstOrDefault(i => i.Hotkey != null && i.Hotkey.GetValue() == hotkey);
|
||||
// HACK: enable production if the shift key is pressed
|
||||
e.Modifiers &= ~Modifiers.Shift;
|
||||
var toBuild = icons.Values.FirstOrDefault(i => i.Hotkey != null && i.Hotkey.IsActivatedBy(e));
|
||||
return toBuild != null ? HandleEvent(toBuild, MouseButton.Left, batchModifiers) : false;
|
||||
}
|
||||
|
||||
|
||||
@@ -287,14 +287,13 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (e.Event != KeyInputEvent.Down)
|
||||
return false;
|
||||
|
||||
var hotkey = Hotkey.FromKeyInput(e);
|
||||
if (hotkey == PreviousProductionTabKey.GetValue())
|
||||
if (PreviousProductionTabKey.IsActivatedBy(e))
|
||||
{
|
||||
Game.Sound.PlayNotification(world.Map.Rules, null, "Sounds", "ClickSound", null);
|
||||
return SelectNextTab(true);
|
||||
}
|
||||
|
||||
if (hotkey == NextProductionTabKey.GetValue())
|
||||
if (NextProductionTabKey.IsActivatedBy(e))
|
||||
{
|
||||
Game.Sound.PlayNotification(world.Map.Rules, null, "Sounds", "ClickSound", null);
|
||||
return SelectNextTab(false);
|
||||
|
||||
@@ -161,8 +161,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
if (e.Event == KeyInputEvent.Down)
|
||||
{
|
||||
var hotkey = Hotkey.FromKeyInput(e);
|
||||
var a = icons.Values.FirstOrDefault(i => i.Hotkey != null && i.Hotkey.GetValue() == hotkey);
|
||||
var a = icons.Values.FirstOrDefault(i => i.Hotkey != null && i.Hotkey.IsActivatedBy(e));
|
||||
|
||||
if (a != null)
|
||||
{
|
||||
|
||||
@@ -447,25 +447,25 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (e.Event != KeyInputEvent.Down)
|
||||
return false;
|
||||
|
||||
if (key == JumpToTopEdgeKey.GetValue())
|
||||
if (JumpToTopEdgeKey.IsActivatedBy(e))
|
||||
{
|
||||
worldRenderer.Viewport.Center(new WPos(worldRenderer.Viewport.CenterPosition.X, 0, 0));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (key == JumpToBottomEdgeKey.GetValue())
|
||||
if (JumpToBottomEdgeKey.IsActivatedBy(e))
|
||||
{
|
||||
worldRenderer.Viewport.Center(new WPos(worldRenderer.Viewport.CenterPosition.X, worldRenderer.World.Map.ProjectedBottomRight.Y, 0));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (key == JumpToLeftEdgeKey.GetValue())
|
||||
if (JumpToLeftEdgeKey.IsActivatedBy(e))
|
||||
{
|
||||
worldRenderer.Viewport.Center(new WPos(0, worldRenderer.Viewport.CenterPosition.Y, 0));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (key == JumpToRightEdgeKey.GetValue())
|
||||
if (JumpToRightEdgeKey.IsActivatedBy(e))
|
||||
{
|
||||
worldRenderer.Viewport.Center(new WPos(worldRenderer.World.Map.ProjectedBottomRight.X, worldRenderer.Viewport.CenterPosition.Y, 0));
|
||||
return true;
|
||||
@@ -473,7 +473,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
for (var i = 0; i < saveBookmarkHotkeys.Length; i++)
|
||||
{
|
||||
if (key == saveBookmarkHotkeys[i].GetValue())
|
||||
if (saveBookmarkHotkeys[i].IsActivatedBy(e))
|
||||
{
|
||||
bookmarkPositions[i] = worldRenderer.Viewport.CenterPosition;
|
||||
return true;
|
||||
@@ -482,7 +482,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
for (var i = 0; i < restoreBookmarkHotkeys.Length; i++)
|
||||
{
|
||||
if (key == restoreBookmarkHotkeys[i].GetValue())
|
||||
if (restoreBookmarkHotkeys[i].IsActivatedBy(e))
|
||||
{
|
||||
var bookmark = bookmarkPositions[i];
|
||||
if (bookmark.HasValue)
|
||||
|
||||
@@ -244,9 +244,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
if (e.Event == KeyInputEvent.Down)
|
||||
{
|
||||
var key = Hotkey.FromKeyInput(e);
|
||||
|
||||
if (key == SelectAllKey.GetValue() && !World.IsGameOver)
|
||||
if (SelectAllKey.IsActivatedBy(e) && !World.IsGameOver)
|
||||
{
|
||||
// Select actors on the screen which belong to the current player
|
||||
var ownUnitsOnScreen = SelectActorsOnScreen(World, worldRenderer, null, player).SubsetWithHighestSelectionPriority().ToList();
|
||||
@@ -263,7 +261,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
World.Selection.Combine(World, ownUnitsOnScreen, false, false);
|
||||
}
|
||||
else if (key == SelectSameTypeKey.GetValue() && !World.IsGameOver)
|
||||
else if (SelectSameTypeKey.IsActivatedBy(e) && !World.IsGameOver)
|
||||
{
|
||||
if (!World.Selection.Actors.Any())
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user