Skip to content

Commit

Permalink
Remove key handling from ContainerWidget
Browse files Browse the repository at this point in the history
It has no business handling key input. This was used only for opening the ingame chat and replacing it with a `LogicKeyListener` was trivial.
  • Loading branch information
dragunoff committed Oct 4, 2024
1 parent a69ea79 commit e2b7a87
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 0 additions & 2 deletions OpenRA.Game/Widgets/Widget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,6 @@ public ContainerWidget(ContainerWidget other)

public override string GetCursor(int2 pos) { return null; }
public override Widget Clone() { return new ContainerWidget(this); }
public Func<KeyInput, bool> OnKeyPress = _ => false;
public override bool HandleKeyPress(KeyInput e) { return OnKeyPress(e); }

public override bool HandleMouseInput(MouseInput mi)
{
Expand Down
6 changes: 4 additions & 2 deletions OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ public IngameChatLogic(Widget widget, OrderManager orderManager, World world, Mo
var chatClose = chatChrome.Get<ButtonWidget>("CHAT_CLOSE");
chatClose.OnClick += CloseChat;

chatPanel.OnKeyPress = e =>
var openChatKeyListener = chatPanel.Get<LogicKeyListenerWidget>("OPEN_CHAT_KEY_LISTENER");

openChatKeyListener.AddHandler(e =>
{
if (e.Event == KeyInputEvent.Up)
return false;
Expand All @@ -223,7 +225,7 @@ public IngameChatLogic(Widget widget, OrderManager orderManager, World world, Mo
}
return false;
};
});
}

chatScrollPanel = chatChrome.Get<ScrollPanelWidget>("CHAT_SCROLLPANEL");
Expand Down
1 change: 1 addition & 0 deletions mods/cnc/chrome/ingame-chat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions mods/common/chrome/ingame-chat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e2b7a87

Please sign in to comment.