Add chat tab to multiplayer/replays ingame menu

This commit is contained in:
rob-v
2017-05-30 22:43:27 +02:00
committed by Paul Chote
parent daee217431
commit c848b30e9e
12 changed files with 206 additions and 35 deletions

View File

@@ -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<ButtonWidget>(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<ContainerWidget>("CHAT_PANEL");
var chatTabButton = widget.Get<ButtonWidget>(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<TextFieldWidget>("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<LabelWidget>("TITLE");
var titleTextNoTabs = widget.GetOrNull<LabelWidget>("TITLE_NO_TABS");

View File

@@ -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<ContainerWidget>("CHAT_OVERLAY");
chatOverlayDisplay = chatOverlay.Get<ChatDisplayWidget>("CHAT_DISPLAY");
chatOverlay.Visible = false;
chatOverlay = chatPanel.GetOrNull<ContainerWidget>("CHAT_OVERLAY");
if (chatOverlay != null)
{
chatOverlayDisplay = chatOverlay.Get<ChatDisplayWidget>("CHAT_DISPLAY");
chatOverlay.Visible = false;
}
chatChrome = chatPanel.Get<ContainerWidget>("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<ButtonWidget>("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<ButtonWidget>("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<ScrollPanelWidget>("CHAT_SCROLLPANEL");
chatTemplate = chatScrollPanel.Get<ContainerWidget>("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<LogicKeyListenerWidget>("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<LogicKeyListenerWidget>("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();

View File

@@ -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 += () =>
{