public TradeChatNotificationControl(TradeChatLine line, Action close) { InitializeComponent(); Title = "Trade Chat Match"; Player = $"{line.PlayerName}:"; Time = $"[{line.Time.ToString("HH:mm")}]"; ContentWords = line.Words; CloseNotification = close; DataContext = this; GenerateRuns(); }
public void ShowTradeChatMatchNotification(TradeChatLine line) { if (Ready) { Task.Run(() => AudioService.Instance.PlayNotif2()); if (!NotificationRunning) { Task.Run(() => { App.Current.Dispatcher.Invoke(delegate { TrayIcon.ShowCustomBalloon(new TradeChatNotificationControl(line, TrayIcon.CloseBalloon), System.Windows.Controls.Primitives.PopupAnimation.Slide, DURATION); }); }); } } }
public void ParseTradeChatLine(string line, List <string> words) { TradeChatLine tradeChatLine = new TradeChatLine(); // Time int timeIndex = line.IndexOf(" "); if (timeIndex == -1) { return; } timeIndex = line.IndexOf(" ", timeIndex + 1); if (timeIndex == -1) { return; } var strTime = line.Substring(0, timeIndex); if (string.IsNullOrEmpty(strTime) || string.IsNullOrWhiteSpace(strTime)) { return; } DateTime date; if (!DateTime.TryParse(strTime.Replace("/", "-"), out date)) { return; } tradeChatLine.Time = date; // Player name int playerNameStartIndex = line.IndexOf("$"); if (playerNameStartIndex == -1) { return; } int playerNameEndIndex = line.IndexOf(":", playerNameStartIndex + 1); if (playerNameEndIndex == -1) { return; } tradeChatLine.PlayerName = line.Substring(playerNameStartIndex + 1, playerNameEndIndex - playerNameStartIndex - 1); // Highlighted whisper string whisper = line.Substring(line.IndexOf(": ") + 2); List <TradeChatWords> tradeWords = new List <TradeChatWords>(); foreach (var word in words) { int index = 0; while ((index = whisper.IndexOf(word)) != -1) { if (index != -1) { int endIndex = index + word.Length; if (endIndex <= whisper.Length) { tradeWords.Add(new TradeChatWords() { Highlighted = true, Words = whisper.Substring(index, endIndex - index), Index = index }); whisper = $"{whisper.Substring(0, index)}~{whisper.Substring(endIndex)}"; } } } } int currentIndex = 0; while (currentIndex < whisper.Length) { int nextIndex = whisper.IndexOf('~', currentIndex); if (nextIndex == -1) { tradeWords.Add(new TradeChatWords() { Words = whisper.Substring(currentIndex), Index = currentIndex }); break; } tradeWords.Add(new TradeChatWords() { Words = whisper.Substring(currentIndex, nextIndex - currentIndex), Index = currentIndex }); currentIndex = nextIndex + 1; } tradeChatLine.Words = tradeWords.OrderBy(w => w.Index).ToList(); AppService.Instance.NewTradeChatLine(tradeChatLine); }
public void NewTradeChatLine(TradeChatLine line) { OnNewTradeChatLine(line); }