Remove global chat integration.
This commit is contained in:
committed by
Matthias Mailänder
parent
488cec64b8
commit
502c3e2bf5
@@ -1,155 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2017 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using OpenRA.Chat;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
class GlobalChatLogic : ChromeLogic
|
||||
{
|
||||
readonly ScrollPanelWidget historyPanel;
|
||||
readonly ContainerWidget chatTemplate;
|
||||
readonly ScrollPanelWidget nicknamePanel;
|
||||
readonly Widget nicknameTemplate;
|
||||
readonly TextFieldWidget inputBox;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public GlobalChatLogic(Widget widget)
|
||||
{
|
||||
historyPanel = widget.Get<ScrollPanelWidget>("HISTORY_PANEL");
|
||||
chatTemplate = historyPanel.Get<ContainerWidget>("CHAT_TEMPLATE");
|
||||
nicknamePanel = widget.Get<ScrollPanelWidget>("NICKNAME_PANEL");
|
||||
nicknameTemplate = nicknamePanel.Get("NICKNAME_TEMPLATE");
|
||||
|
||||
var textColor = ChromeMetrics.Get<Color>("GlobalChatTextColor");
|
||||
var textLabel = chatTemplate.Get<LabelWidget>("TEXT");
|
||||
textLabel.GetColor = () => textColor;
|
||||
|
||||
historyPanel.Bind(Game.GlobalChat.History, MakeHistoryWidget, HistoryWidgetEquals, true);
|
||||
nicknamePanel.Bind(Game.GlobalChat.Users, MakeUserWidget, UserWidgetEquals, false);
|
||||
|
||||
inputBox = widget.Get<TextFieldWidget>("CHAT_TEXTFIELD");
|
||||
inputBox.IsDisabled = () => Game.GlobalChat.ConnectionStatus != ChatConnectionStatus.Joined;
|
||||
inputBox.OnEnterKey = EnterPressed;
|
||||
|
||||
// IRC protocol limits messages to 510 characters + CRLF
|
||||
inputBox.MaxLength = 510;
|
||||
|
||||
var nickName = Game.GlobalChat.SanitizedName(Game.Settings.Player.Name);
|
||||
var nicknameBox = widget.Get<TextFieldWidget>("NICKNAME_TEXTFIELD");
|
||||
nicknameBox.Text = nickName;
|
||||
nicknameBox.OnTextEdited = () =>
|
||||
{
|
||||
nicknameBox.Text = Game.GlobalChat.SanitizedName(nicknameBox.Text);
|
||||
};
|
||||
|
||||
var connectPanel = widget.Get("GLOBALCHAT_CONNECT_PANEL");
|
||||
connectPanel.IsVisible = () => Game.GlobalChat.ConnectionStatus == ChatConnectionStatus.Disconnected;
|
||||
|
||||
var disconnectButton = widget.Get<ButtonWidget>("DISCONNECT_BUTTON");
|
||||
disconnectButton.OnClick = Game.GlobalChat.Disconnect;
|
||||
|
||||
var connectAutomaticallyCheckBox = connectPanel.Get<CheckboxWidget>("CONNECT_AUTOMATICALLY_CHECKBOX");
|
||||
connectAutomaticallyCheckBox.IsChecked = () => Game.Settings.Chat.ConnectAutomatically;
|
||||
connectAutomaticallyCheckBox.OnClick = () => { Game.Settings.Chat.ConnectAutomatically ^= true; Game.Settings.Save(); };
|
||||
|
||||
var connectButton = connectPanel.Get<ButtonWidget>("CONNECT_BUTTON");
|
||||
connectButton.IsDisabled = () => !Game.GlobalChat.IsValidNickname(nicknameBox.Text);
|
||||
connectButton.OnClick = () => Game.GlobalChat.Connect(nicknameBox.Text);
|
||||
|
||||
var mainPanel = widget.Get("GLOBALCHAT_MAIN_PANEL");
|
||||
mainPanel.IsVisible = () => Game.GlobalChat.ConnectionStatus != ChatConnectionStatus.Disconnected;
|
||||
|
||||
mainPanel.Get<LabelWidget>("CHANNEL_TOPIC").GetText = () => Game.GlobalChat.Topic;
|
||||
|
||||
if (Game.Settings.Chat.ConnectAutomatically)
|
||||
Game.GlobalChat.Connect(nickName);
|
||||
}
|
||||
|
||||
Widget MakeHistoryWidget(object o)
|
||||
{
|
||||
var message = (ChatMessage)o;
|
||||
var from = message.Type == ChatMessageType.Notification ? "Battlefield Control" : message.Nick;
|
||||
var color = message.Type == ChatMessageType.Notification ? ChromeMetrics.Get<Color>("GlobalChatNotificationColor")
|
||||
: ChromeMetrics.Get<Color>("GlobalChatPlayerNameColor");
|
||||
var template = (ContainerWidget)chatTemplate.Clone();
|
||||
LobbyUtils.SetupChatLine(template, color, message.Time, from, message.Message);
|
||||
|
||||
template.Id = message.UID;
|
||||
return template;
|
||||
}
|
||||
|
||||
bool HistoryWidgetEquals(Widget widget, object o)
|
||||
{
|
||||
return ((LabelWidget)widget).Id == ((ChatMessage)o).UID;
|
||||
}
|
||||
|
||||
Widget MakeUserWidget(object o)
|
||||
{
|
||||
var nick = (string)o;
|
||||
var client = Game.GlobalChat.Users[nick];
|
||||
|
||||
var item = nicknameTemplate.Clone();
|
||||
item.Id = client.Name;
|
||||
item.IsVisible = () => true;
|
||||
var name = item.Get<LabelWidget>("NICK");
|
||||
name.GetText = () => client.Name;
|
||||
name.IsVisible = () => true;
|
||||
|
||||
// TODO: Add custom image for voice
|
||||
var indicator = item.Get<ImageWidget>("INDICATOR");
|
||||
indicator.IsVisible = () => client.IsOp || client.IsVoiced;
|
||||
indicator.GetImageName = () => client.IsOp || client.IsVoiced ? "admin" : "";
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
bool UserWidgetEquals(Widget widget, object o)
|
||||
{
|
||||
var nick = (string)o;
|
||||
return widget.Id == nick;
|
||||
}
|
||||
|
||||
bool EnterPressed()
|
||||
{
|
||||
if (inputBox.Text.Length == 0)
|
||||
return true;
|
||||
|
||||
if (inputBox.Text.StartsWith("/nick "))
|
||||
{
|
||||
var nick = inputBox.Text.Replace("/nick ", string.Empty);
|
||||
Game.GlobalChat.TrySetNickname(nick);
|
||||
}
|
||||
else
|
||||
Game.GlobalChat.SendMessage(inputBox.Text);
|
||||
|
||||
inputBox.Text = "";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool disposed;
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (disposed)
|
||||
return;
|
||||
|
||||
historyPanel.Unbind();
|
||||
nicknamePanel.Unbind();
|
||||
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,6 @@ using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using OpenRA.Chat;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Traits;
|
||||
@@ -38,9 +37,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
enum PanelType { Players, Options, Music, Kick, ForceStart }
|
||||
PanelType panel = PanelType.Players;
|
||||
|
||||
enum ChatPanelType { Lobby, Global }
|
||||
ChatPanelType chatPanel = ChatPanelType.Lobby;
|
||||
|
||||
readonly Widget lobby;
|
||||
readonly Widget editablePlayerTemplate;
|
||||
readonly Widget nonEditablePlayerTemplate;
|
||||
@@ -65,9 +61,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
MapPreview map;
|
||||
bool addBotOnMapLoad;
|
||||
bool teamChat;
|
||||
int lobbyChatUnreadMessages;
|
||||
int globalChatLastReadMessages;
|
||||
int globalChatUnreadMessages;
|
||||
|
||||
// Listen for connection failures
|
||||
void ConnectionStateChanged(OrderManager om)
|
||||
@@ -353,33 +346,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (skirmishMode)
|
||||
disconnectButton.Text = "Back";
|
||||
|
||||
var globalChat = Game.LoadWidget(null, "LOBBY_GLOBALCHAT_PANEL", lobby.Get("GLOBALCHAT_ROOT"), new WidgetArgs());
|
||||
var globalChatInput = globalChat.Get<TextFieldWidget>("CHAT_TEXTFIELD");
|
||||
|
||||
globalChat.IsVisible = () => chatPanel == ChatPanelType.Global;
|
||||
|
||||
var globalChatTab = lobby.Get<ButtonWidget>("GLOBALCHAT_TAB");
|
||||
globalChatTab.IsHighlighted = () => chatPanel == ChatPanelType.Global;
|
||||
globalChatTab.OnClick = () =>
|
||||
{
|
||||
chatPanel = ChatPanelType.Global;
|
||||
globalChatInput.TakeKeyboardFocus();
|
||||
};
|
||||
|
||||
var globalChatLabel = globalChatTab.Text;
|
||||
globalChatTab.GetText = () =>
|
||||
{
|
||||
if (globalChatUnreadMessages == 0 || chatPanel == ChatPanelType.Global)
|
||||
return globalChatLabel;
|
||||
|
||||
return globalChatLabel + " ({0})".F(globalChatUnreadMessages);
|
||||
};
|
||||
|
||||
globalChatLastReadMessages = Game.GlobalChat.History.Count(m => m.Type == ChatMessageType.Message);
|
||||
|
||||
var lobbyChat = lobby.Get("LOBBYCHAT");
|
||||
lobbyChat.IsVisible = () => chatPanel == ChatPanelType.Lobby;
|
||||
|
||||
chatLabel = lobby.Get<LabelWidget>("LABEL_CHATTYPE");
|
||||
var chatTextField = lobby.Get<TextFieldWidget>("CHAT_TEXTFIELD");
|
||||
chatTextField.MaxLength = UnitOrders.ChatMessageMaxLength;
|
||||
@@ -412,23 +378,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
chatTextField.OnEscKey = () => { chatTextField.Text = ""; return true; };
|
||||
|
||||
var lobbyChatTab = lobby.Get<ButtonWidget>("LOBBYCHAT_TAB");
|
||||
lobbyChatTab.IsHighlighted = () => chatPanel == ChatPanelType.Lobby;
|
||||
lobbyChatTab.OnClick = () =>
|
||||
{
|
||||
chatPanel = ChatPanelType.Lobby;
|
||||
chatTextField.TakeKeyboardFocus();
|
||||
};
|
||||
|
||||
var lobbyChatLabel = lobbyChatTab.Text;
|
||||
lobbyChatTab.GetText = () =>
|
||||
{
|
||||
if (lobbyChatUnreadMessages == 0 || chatPanel == ChatPanelType.Lobby)
|
||||
return lobbyChatLabel;
|
||||
|
||||
return lobbyChatLabel + " ({0})".F(lobbyChatUnreadMessages);
|
||||
};
|
||||
|
||||
lobbyChatPanel = lobby.Get<ScrollPanelWidget>("CHAT_DISPLAY");
|
||||
chatTemplate = lobbyChatPanel.Get("CHAT_TEMPLATE");
|
||||
lobbyChatPanel.RemoveChildren();
|
||||
@@ -473,22 +422,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
if (panel == PanelType.Options && OptionsTabDisabled())
|
||||
panel = PanelType.Players;
|
||||
|
||||
var newMessages = Game.GlobalChat.History.Count(m => m.Type == ChatMessageType.Message);
|
||||
globalChatUnreadMessages += newMessages - globalChatLastReadMessages;
|
||||
globalChatLastReadMessages = newMessages;
|
||||
|
||||
if (chatPanel == ChatPanelType.Lobby)
|
||||
lobbyChatUnreadMessages = 0;
|
||||
|
||||
if (chatPanel == ChatPanelType.Global)
|
||||
globalChatUnreadMessages = 0;
|
||||
}
|
||||
|
||||
void AddChatLine(Color c, string from, string text)
|
||||
{
|
||||
lobbyChatUnreadMessages += 1;
|
||||
|
||||
var template = (ContainerWidget)chatTemplate.Clone();
|
||||
LobbyUtils.SetupChatLine(template, c, DateTime.Now, from, text);
|
||||
|
||||
|
||||
@@ -109,7 +109,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
createServerTab.OnClick = () => panel = PanelType.CreateServer;
|
||||
|
||||
widget.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); };
|
||||
Game.LoadWidget(null, "GLOBALCHAT_PANEL", widget.Get("GLOBALCHAT_ROOT"), new WidgetArgs());
|
||||
|
||||
lanGameLocations = new List<BeaconLocation>();
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user