From 771b9ddfdad4a406be3d25946647fe1020b5e32c Mon Sep 17 00:00:00 2001 From: Ivaylo Draganov Date: Mon, 30 Sep 2024 16:59:14 +0300 Subject: [PATCH] Remove key handling from `ContainerWidget` It has no business handling key input. This was used only for opening the ingame chat and replacing it with a `LogicKeyListener` was trivial. --- OpenRA.Game/Widgets/Widget.cs | 2 -- OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs | 6 ++++-- mods/cnc/chrome/ingame-chat.yaml | 1 + mods/common/chrome/ingame-chat.yaml | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 28973b8179..14eed8b2c3 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -632,8 +632,6 @@ namespace OpenRA.Widgets public override string GetCursor(int2 pos) { return null; } public override Widget Clone() { return new ContainerWidget(this); } - public Func OnKeyPress = _ => false; - public override bool HandleKeyPress(KeyInput e) { return OnKeyPress(e); } public override bool HandleMouseInput(MouseInput mi) { diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs index f8d4ecce5a..be902e4d9f 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs @@ -209,7 +209,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic var chatClose = chatChrome.Get("CHAT_CLOSE"); chatClose.OnClick += CloseChat; - chatPanel.OnKeyPress = e => + var openChatKeyListener = chatPanel.Get("OPEN_CHAT_KEY_LISTENER"); + + openChatKeyListener.AddHandler(e => { if (e.Event == KeyInputEvent.Up) return false; @@ -223,7 +225,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic } return false; - }; + }); } chatScrollPanel = chatChrome.Get("CHAT_SCROLLPANEL"); diff --git a/mods/cnc/chrome/ingame-chat.yaml b/mods/cnc/chrome/ingame-chat.yaml index f17743b06d..1a1ae8f8ce 100644 --- a/mods/cnc/chrome/ingame-chat.yaml +++ b/mods/cnc/chrome/ingame-chat.yaml @@ -11,6 +11,7 @@ Container@CHAT_PANEL: System: SYSTEM_LINE_TEMPLATE Mission: CHAT_LINE_TEMPLATE Children: + LogicKeyListener@OPEN_CHAT_KEY_LISTENER: Container@CHAT_OVERLAY: Width: PARENT_RIGHT - 24 Height: PARENT_BOTTOM - 30 diff --git a/mods/common/chrome/ingame-chat.yaml b/mods/common/chrome/ingame-chat.yaml index 53a43c5602..b0864fb7c8 100644 --- a/mods/common/chrome/ingame-chat.yaml +++ b/mods/common/chrome/ingame-chat.yaml @@ -11,6 +11,7 @@ Container@CHAT_PANEL: System: SYSTEM_LINE_TEMPLATE Mission: CHAT_LINE_TEMPLATE Children: + LogicKeyListener@OPEN_CHAT_KEY_LISTENER: Container@CHAT_OVERLAY: Width: PARENT_RIGHT - 24 Height: PARENT_BOTTOM - 30