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