private void OnEnable() { tabs.Initialize(); localChatTab = CreateTab("Local", false, LogManager.Instance.ChatLog); debugChatTab = CreateTab("Debug", false, LogManager.Instance.DebugLog); foreach (MessageLog log in LogManager.Instance.InstantMessageLogs.Values) { CreateTab(log.Name, true, log); } LogManager.Instance.OnNewInstantMessageSession += OnNewInstantMessageSession; localChatTab.toggle.isOn = true; }
protected void OnMessage(MessageLog log, LogMessage msg) { if (TabByLog.ContainsKey(log) == false) { // If the tab doesn't exist we have to create it. (This happens if a message comes in for a tab that has been closed) log.OnMessage -= OnMessage; // We are still listening, so remove the listener to avoid multiple registrations CreateTab(msg.SenderName, true, log); } UIChatTab tab = TabByLog[log]; string s = msg.ToRtfString(); if (activeTab == tab) { messageView.AppendMessage(s); } }
/// <summary> Create new chat tab </summary> public UIChatTab CreateTab(string name, bool canClose, MessageLog log) { UIChatTab tab = tabs.InstantiateTemplate(); tab.name = $"Tab ({name})"; tab.label.text = name; tab.canClose = canClose; tab.toggle.onValueChanged.AddListener(isOn => { if (isOn) { SelectTab(tab); } }); tab.MessageLog = log; TabByLog[log] = tab; log.OnMessage += OnMessage; return(tab); }
public void SelectTab(UIChatTab tab) { activeTab = tab; messageView.Load(activeTab.MessageLog.AllMessagesAsRtfStrings); }
/// <summary> Close an existing chat tab </summary> public void CloseTab(UIChatTab uIChatTab) { TabByLog.Remove(uIChatTab.MessageLog); tabs.ReturnItemToPool(uIChatTab); }
protected void OnNewInstantMessageSession(Guid dialogId, string senderName, MessageLog log) { localChatTab = CreateTab(senderName, true, log); }