diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ControlGroupLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ControlGroupLogic.cs index ae00fb9cfa..24f5b0dee0 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ControlGroupLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ControlGroupLogic.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic public ControlGroupLogic(Widget widget, World world, WorldRenderer worldRenderer) { var keyhandler = widget.Get("CONTROLGROUP_KEYHANDLER"); - keyhandler.OnKeyPress = e => + keyhandler.AddHandler(e => { if (e.Event == KeyInputEvent.Down && e.Key >= Keycode.NUMBER_0 && e.Key <= Keycode.NUMBER_9) { @@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic } return false; - }; + }); } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs index 9aacd3ad07..343fbd2778 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs @@ -153,7 +153,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic CloseChat(); var keyListener = chatChrome.Get("KEY_LISTENER"); - keyListener.OnKeyPress = e => + keyListener.AddHandler(e => { if (e.Event == KeyInputEvent.Up || !chatText.IsDisabled()) return false; @@ -165,7 +165,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic } return false; - }; + }); } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs index 786fd8e6eb..c0a7be9e44 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs @@ -138,7 +138,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic shroudLabelAlt.GetColor = () => selected.Color; var keyhandler = shroudSelector.Get("SHROUD_KEYHANDLER"); - keyhandler.OnKeyPress = HandleKeyPress; + keyhandler.AddHandler(HandleKeyPress); selected = limitViews ? groups.First().Value.First() : world.WorldActor.Owner.Shroud.ExploreMapEnabled ? combined : disableShroud; selected.OnClick(); diff --git a/OpenRA.Mods.Common/Widgets/Logic/MusicHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MusicHotkeyLogic.cs index e3e0410b53..f1c4a80455 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MusicHotkeyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MusicHotkeyLogic.cs @@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic nextKey = new NamedHotkey(yaml.Value, ks); var keyhandler = widget.Get("GLOBAL_KEYHANDLER"); - keyhandler.OnKeyPress += e => + keyhandler.AddHandler(e => { if (e.Event == KeyInputEvent.Down) { @@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic } return false; - }; + }); } void PauseOrResumeMusic() diff --git a/OpenRA.Mods.Common/Widgets/LogicKeyListenerWidget.cs b/OpenRA.Mods.Common/Widgets/LogicKeyListenerWidget.cs index dc059cd99b..53d0375fbf 100644 --- a/OpenRA.Mods.Common/Widgets/LogicKeyListenerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/LogicKeyListenerWidget.cs @@ -10,17 +10,27 @@ #endregion using System; +using System.Collections.Generic; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets { public class LogicKeyListenerWidget : Widget { - public Func OnKeyPress = _ => false; + List> handlers = new List>(); public override bool HandleKeyPress(KeyInput e) { - return OnKeyPress(e); + foreach (var handler in handlers) + if (handler(e)) + return true; + + return false; + } + + public void AddHandler(Func func) + { + handlers.Add(func); } } }