From c848b30e9eff7779eb9d0a1a7dfc9401edcb8005 Mon Sep 17 00:00:00 2001 From: rob-v Date: Tue, 30 May 2017 22:43:27 +0200 Subject: [PATCH] Add chat tab to multiplayer/replays ingame menu --- .../Widgets/Logic/Ingame/GameInfoLogic.cs | 26 +++++- .../Widgets/Logic/Ingame/IngameChatLogic.cs | 86 ++++++++++++------- .../LoadIngamePlayerOrObserverUILogic.cs | 2 +- mods/cnc/chrome/ingame-info.yaml | 9 ++ mods/cnc/chrome/ingame-infochat.yaml | 46 ++++++++++ mods/cnc/mod.yaml | 1 + mods/common/chrome/ingame-info.yaml | 11 +++ mods/common/chrome/ingame-infochat.yaml | 46 ++++++++++ mods/d2k/mod.yaml | 1 + mods/ra/mod.yaml | 1 + mods/ts/chrome/ingame-info.yaml | 11 +++ mods/ts/mod.yaml | 1 + 12 files changed, 206 insertions(+), 35 deletions(-) create mode 100644 mods/cnc/chrome/ingame-infochat.yaml create mode 100644 mods/common/chrome/ingame-infochat.yaml diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoLogic.cs index 8ca81d4ab4..94f1e1e8a8 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoLogic.cs @@ -17,7 +17,7 @@ using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic { - public enum IngameInfoPanel { AutoSelect, Map, Objectives, Debug } + public enum IngameInfoPanel { AutoSelect, Map, Objectives, Debug, Chat } class GameInfoLogic : ChromeLogic { @@ -85,7 +85,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic numTabs++; var debugTabButton = widget.Get(string.Concat("BUTTON", numTabs.ToString())); debugTabButton.Text = "Debug"; - debugTabButton.IsVisible = () => lp != null && numTabs > 1 && !hasError; + debugTabButton.IsVisible = () => numTabs > 1 && !hasError; debugTabButton.IsDisabled = () => world.IsGameOver; debugTabButton.OnClick = () => activePanel = IngameInfoPanel.Debug; debugTabButton.IsHighlighted = () => activePanel == IngameInfoPanel.Debug; @@ -99,6 +99,28 @@ namespace OpenRA.Mods.Common.Widgets.Logic activePanel = IngameInfoPanel.Debug; } + if (world.LobbyInfo.NonBotClients.Count() > 1) + { + numTabs++; + var chatPanelContainer = widget.Get("CHAT_PANEL"); + var chatTabButton = widget.Get(string.Concat("BUTTON", numTabs.ToString())); + chatTabButton.Text = "Chat"; + chatTabButton.IsVisible = () => numTabs > 1 && !hasError; + chatTabButton.IsHighlighted = () => activePanel == IngameInfoPanel.Chat; + chatTabButton.OnClick = () => + { + activePanel = IngameInfoPanel.Chat; + chatPanelContainer.Get("CHAT_TEXTFIELD").TakeKeyboardFocus(); + }; + + chatPanelContainer.IsVisible = () => activePanel == IngameInfoPanel.Chat; + + Game.LoadWidget(world, "CHAT_CONTAINER", chatPanelContainer, new WidgetArgs() { { "isMenuChat", true } }); + + if (activePanel == IngameInfoPanel.AutoSelect) + chatTabButton.OnClick(); + } + // Handle empty space when tabs aren't displayed var titleText = widget.Get("TITLE"); var titleTextNoTabs = widget.GetOrNull("TITLE_NO_TABS"); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs index 5269a44c6e..9aacd3ad07 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs @@ -9,6 +9,7 @@ */ #endregion +using System; using System.Drawing; using System.Linq; using OpenRA.Mods.Common.Commands; @@ -39,7 +40,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic bool teamChat; [ObjectCreator.UseCtor] - public IngameChatLogic(Widget widget, OrderManager orderManager, World world, ModData modData) + public IngameChatLogic(Widget widget, OrderManager orderManager, World world, ModData modData, bool isMenuChat) { this.orderManager = orderManager; this.modRules = modData.DefaultRules; @@ -54,9 +55,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic tabCompletion.Names = orderManager.LobbyInfo.Clients.Select(c => c.Name).Distinct().ToList(); var chatPanel = (ContainerWidget)widget; - chatOverlay = chatPanel.Get("CHAT_OVERLAY"); - chatOverlayDisplay = chatOverlay.Get("CHAT_DISPLAY"); - chatOverlay.Visible = false; + chatOverlay = chatPanel.GetOrNull("CHAT_OVERLAY"); + if (chatOverlay != null) + { + chatOverlayDisplay = chatOverlay.Get("CHAT_DISPLAY"); + chatOverlay.Visible = false; + } chatChrome = chatPanel.Get("CHAT_CHROME"); chatChrome.Visible = true; @@ -83,7 +87,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic } chatText.Text = ""; - CloseChat(); + if (!isMenuChat) + CloseChat(); + return true; }; @@ -99,25 +105,36 @@ namespace OpenRA.Mods.Common.Widgets.Logic return true; }; - chatText.OnEscKey = () => { CloseChat(); return true; }; - - var chatClose = chatChrome.Get("CHAT_CLOSE"); - chatClose.OnClick += CloseChat; - - chatPanel.OnKeyPress = e => + chatText.OnEscKey = () => { - if (e.Event == KeyInputEvent.Up) - return false; + if (!isMenuChat) + CloseChat(); + else + chatText.YieldKeyboardFocus(); - if (!chatChrome.IsVisible() && (e.Key == Keycode.RETURN || e.Key == Keycode.KP_ENTER)) - { - OpenChat(); - return true; - } - - return false; + return true; }; + if (!isMenuChat) + { + var chatClose = chatChrome.Get("CHAT_CLOSE"); + chatClose.OnClick += CloseChat; + + chatPanel.OnKeyPress = e => + { + if (e.Event == KeyInputEvent.Up) + return false; + + if (!chatChrome.IsVisible() && (e.Key == Keycode.RETURN || e.Key == Keycode.KP_ENTER)) + { + OpenChat(); + return true; + } + + return false; + }; + } + chatScrollPanel = chatChrome.Get("CHAT_SCROLLPANEL"); chatTemplate = chatScrollPanel.Get("CHAT_TEMPLATE"); chatScrollPanel.RemoveChildren(); @@ -129,23 +146,27 @@ namespace OpenRA.Mods.Common.Widgets.Logic orderManager.AddChatLine += AddChatLineWrapper; Game.BeforeGameStart += UnregisterEvents; - CloseChat(); chatText.IsDisabled = () => world.IsReplay && !Game.Settings.Debug.EnableDebugCommandsInReplays; - var keyListener = chatChrome.Get("KEY_LISTENER"); - keyListener.OnKeyPress = e => + if (!isMenuChat) { - if (e.Event == KeyInputEvent.Up || !chatText.IsDisabled()) - return false; + CloseChat(); - if ((e.Key == Keycode.RETURN || e.Key == Keycode.KP_ENTER || e.Key == Keycode.ESCAPE) && e.Modifiers == Modifiers.None) + var keyListener = chatChrome.Get("KEY_LISTENER"); + keyListener.OnKeyPress = e => { - CloseChat(); - return true; - } + if (e.Event == KeyInputEvent.Up || !chatText.IsDisabled()) + return false; - return false; - }; + if ((e.Key == Keycode.RETURN || e.Key == Keycode.KP_ENTER || e.Key == Keycode.ESCAPE) && e.Modifiers == Modifiers.None) + { + CloseChat(); + return true; + } + + return false; + }; + } } bool SwitchTeamChat() @@ -168,6 +189,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic chatScrollPanel.ScrollToBottom(); if (!chatText.IsDisabled()) chatText.TakeKeyboardFocus(); + chatOverlay.Visible = false; } @@ -185,7 +207,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic void AddChatLine(Color c, string from, string text, bool replayCache) { - if (!replayCache) + if (!replayCache && chatOverlayDisplay != null) chatOverlayDisplay.AddLine(c, from, text); var template = chatTemplate.Clone(); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngamePlayerOrObserverUILogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngamePlayerOrObserverUILogic.cs index 37ac4ac97d..de85094452 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngamePlayerOrObserverUILogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/LoadIngamePlayerOrObserverUILogic.cs @@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic }; } - Game.LoadWidget(world, "CHAT_PANEL", worldRoot, new WidgetArgs()); + Game.LoadWidget(world, "CHAT_PANEL", worldRoot, new WidgetArgs() { { "isMenuChat", false } }); world.GameOver += () => { diff --git a/mods/cnc/chrome/ingame-info.yaml b/mods/cnc/chrome/ingame-info.yaml index e664f3debf..4b68d15526 100644 --- a/mods/cnc/chrome/ingame-info.yaml +++ b/mods/cnc/chrome/ingame-info.yaml @@ -39,6 +39,12 @@ Container@GAME_INFO_PANEL: Width: 140 Height: 35 Visible: False + Button@BUTTON4: + X: 450 + Y: 5 + Width: 140 + Height: 35 + Visible: False Background@BACKGROUND: Y: 39 Width: PARENT_RIGHT @@ -54,3 +60,6 @@ Container@GAME_INFO_PANEL: Container@DEBUG_PANEL: Width: PARENT_RIGHT Height: PARENT_BOTTOM + Container@CHAT_PANEL: + Width: PARENT_RIGHT + Height: PARENT_BOTTOM diff --git a/mods/cnc/chrome/ingame-infochat.yaml b/mods/cnc/chrome/ingame-infochat.yaml new file mode 100644 index 0000000000..55e81f394d --- /dev/null +++ b/mods/cnc/chrome/ingame-infochat.yaml @@ -0,0 +1,46 @@ +Container@CHAT_CONTAINER: + Y: 10 + Width: PARENT_RIGHT + Height: PARENT_BOTTOM - 20 + Logic: IngameChatLogic + Children: + Container@CHAT_CHROME: + X: 15 + Width: PARENT_RIGHT - 30 + Height: PARENT_BOTTOM + Children: + Button@CHAT_MODE: + Y: PARENT_BOTTOM - HEIGHT + Width: 50 + Height: 25 + Text: Team + Font: Bold + TextField@CHAT_TEXTFIELD: + X: 55 + Y: PARENT_BOTTOM - HEIGHT + Width: PARENT_RIGHT - 55 + Height: 25 + ScrollPanel@CHAT_SCROLLPANEL: + Width: PARENT_RIGHT + Height: PARENT_BOTTOM - 30 + TopBottomSpacing: 2 + ItemSpacing: 2 + Children: + Container@CHAT_TEMPLATE: + X: 2 + Width: PARENT_RIGHT - 27 + Height: 16 + Children: + Label@NAME: + X: 3 + Width: 50 + Height: 15 + VAlign: Top + Shadow: True + Label@TEXT: + X: 12 + Width: PARENT_RIGHT - 17 + Height: 15 + WordWrap: true + VAlign: Top + Shadow: True \ No newline at end of file diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index 371e951e02..e933b45fdb 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -109,6 +109,7 @@ ChromeLayout: cnc|chrome/ingame-chat.yaml cnc|chrome/ingame-menu.yaml cnc|chrome/ingame-debug.yaml + cnc|chrome/ingame-infochat.yaml cnc|chrome/ingame-info.yaml cnc|chrome/ingame-infobriefing.yaml cnc|chrome/ingame-infoscripterror.yaml diff --git a/mods/common/chrome/ingame-info.yaml b/mods/common/chrome/ingame-info.yaml index 8a31c2a537..cdbe0cb414 100644 --- a/mods/common/chrome/ingame-info.yaml +++ b/mods/common/chrome/ingame-info.yaml @@ -50,6 +50,13 @@ Container@GAME_INFO_PANEL: Height: 25 Font: Bold Visible: False + Button@BUTTON4: + X: 360 + Y: 50 + Width: 120 + Height: 25 + Font: Bold + Visible: False Container@STATS_PANEL: Y: 65 Container@MAP_PANEL: @@ -63,3 +70,7 @@ Container@GAME_INFO_PANEL: Y: 65 Width: PARENT_RIGHT Height: PARENT_BOTTOM + Container@CHAT_PANEL: + Y: 65 + Width: PARENT_RIGHT + Height: PARENT_BOTTOM \ No newline at end of file diff --git a/mods/common/chrome/ingame-infochat.yaml b/mods/common/chrome/ingame-infochat.yaml new file mode 100644 index 0000000000..673bfdf051 --- /dev/null +++ b/mods/common/chrome/ingame-infochat.yaml @@ -0,0 +1,46 @@ +Container@CHAT_CONTAINER: + Y: 20 + Width: PARENT_RIGHT + Height: PARENT_BOTTOM - 100 + Logic: IngameChatLogic + Children: + Container@CHAT_CHROME: + X: 20 + Width: PARENT_RIGHT - 40 + Height: PARENT_BOTTOM + Children: + Button@CHAT_MODE: + Y: PARENT_BOTTOM - HEIGHT + Width: 50 + Height: 25 + Text: Team + Font: Bold + TextField@CHAT_TEXTFIELD: + X: 55 + Y: PARENT_BOTTOM - HEIGHT + Width: PARENT_RIGHT - 55 + Height: 25 + ScrollPanel@CHAT_SCROLLPANEL: + Width: PARENT_RIGHT + Height: PARENT_BOTTOM - 30 + TopBottomSpacing: 2 + ItemSpacing: 2 + Children: + Container@CHAT_TEMPLATE: + X: 2 + Width: PARENT_RIGHT - 27 + Height: 16 + Children: + Label@NAME: + X: 3 + Width: 50 + Height: 15 + VAlign: Top + Shadow: True + Label@TEXT: + X: 12 + Width: PARENT_RIGHT - 17 + Height: 15 + WordWrap: true + VAlign: Top + Shadow: True \ No newline at end of file diff --git a/mods/d2k/mod.yaml b/mods/d2k/mod.yaml index c8d6c9d57c..ed83e24102 100644 --- a/mods/d2k/mod.yaml +++ b/mods/d2k/mod.yaml @@ -78,6 +78,7 @@ ChromeLayout: d2k|chrome/ingame-player.yaml common|chrome/ingame-perf.yaml common|chrome/ingame-debug.yaml + common|chrome/ingame-infochat.yaml d2k|chrome/mainmenu.yaml common|chrome/settings.yaml common|chrome/credits.yaml diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index e99add6f82..aaa167672e 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -93,6 +93,7 @@ ChromeLayout: ra|chrome/ingame-player.yaml common|chrome/ingame-perf.yaml common|chrome/ingame-debug.yaml + common|chrome/ingame-infochat.yaml common|chrome/mainmenu.yaml common|chrome/settings.yaml common|chrome/credits.yaml diff --git a/mods/ts/chrome/ingame-info.yaml b/mods/ts/chrome/ingame-info.yaml index 8a31c2a537..2365bed0e3 100644 --- a/mods/ts/chrome/ingame-info.yaml +++ b/mods/ts/chrome/ingame-info.yaml @@ -50,6 +50,13 @@ Container@GAME_INFO_PANEL: Height: 25 Font: Bold Visible: False + Button@BUTTON4: + X: 360 + Y: 50 + Width: 120 + Height: 25 + Font: Bold + Visible: False Container@STATS_PANEL: Y: 65 Container@MAP_PANEL: @@ -63,3 +70,7 @@ Container@GAME_INFO_PANEL: Y: 65 Width: PARENT_RIGHT Height: PARENT_BOTTOM + Container@CHAT_PANEL: + Y: 65 + Width: PARENT_RIGHT + Height: PARENT_BOTTOM diff --git a/mods/ts/mod.yaml b/mods/ts/mod.yaml index 81aa4a8e99..ab4d95f854 100644 --- a/mods/ts/mod.yaml +++ b/mods/ts/mod.yaml @@ -140,6 +140,7 @@ ChromeLayout: ts|chrome/ingame-player.yaml common|chrome/ingame-perf.yaml ts|chrome/ingame-debug.yaml + common|chrome/ingame-infochat.yaml common|chrome/mainmenu.yaml ts|chrome/mainmenu-prerelease-notification.yaml common|chrome/settings.yaml