Exemplo n.º 1
0
 private void MainWindow_SizeChanged(object sender, SizeChangedEventArgs e)
 {
     if (ironworksSettings != null)
     {
         var window = sender as Window;
         ironworksSettings.UI.MainWindowWidth  = window.Width;
         ironworksSettings.UI.MainWindowHeight = window.Height;
     }
     TranslatedChatBox.ScrollToEnd();
 }
Exemplo n.º 2
0
        private void UpdateChatbox(object state)
        {
            if (ChatQueue.q.Any())
            {// Should q be locked?
                var chat = ChatQueue.q.Take();
                int.TryParse(chat.Code, System.Globalization.NumberStyles.HexNumber, null, out var intCode);
                ChatCode code = (ChatCode)intCode;
                if (code <= ChatCode.CWLinkShell8)
                {// For now, CWLinkShell8(0x6B) is upper bound of chat related code.
                    if (ironworksSettings.Chat.ChannelVisibility.TryGetValue(code, out bool show))
                    {
                        if (show)
                        {
                            string      line        = chat.Line;
                            ChatLogItem decodedChat = chat.Bytes.DecodeAutoTranslate();
                            Log.Debug("Chat: {@Chat}", decodedChat);

                            if (code == ChatCode.Recruitment || code == ChatCode.System || code == ChatCode.Error ||
                                code == ChatCode.Notice || code == ChatCode.Emote || code == ChatCode.MarketSold)
                            {
                                if (!ContainsNativeLanguage(decodedChat.Line))
                                {
                                    var translated = ironworksContext.TranslateChat(decodedChat.Line, ironworksSettings.Chat.ChannelLanguage[code]);

                                    Application.Current.Dispatcher.Invoke(() =>
                                    {
                                        TranslatedChatBox.Text +=
#if DEBUG
                                            $"[{decodedChat.Code}]{translated}{Environment.NewLine}";
#else
                                            $"{translated}{Environment.NewLine}";
#endif
                                    });
                                }
                            }
                            else
                            {
                                var author   = decodedChat.Line.RemoveAfter(":");
                                var sentence = decodedChat.Line.RemoveBefore(":");
                                if (!ContainsNativeLanguage(decodedChat.Line))
                                {
                                    var translated = ironworksContext.TranslateChat(sentence, ironworksSettings.Chat.ChannelLanguage[code]);

                                    Application.Current.Dispatcher.Invoke(() =>
                                    {
                                        TranslatedChatBox.Text +=
#if DEBUG
                                            $"[{decodedChat.Code}]{author}:{translated}{Environment.NewLine}";
#else
                                            $"{author}:{translated}{Environment.NewLine}";
#endif
                                    });
                                }
                            }
                        }
                    }
                    else
                    {
                        Log.Information("Unexpected {@Code} when translating {@Message}", intCode, chat.Line);
                        //Application.Current.Dispatcher.Invoke(() =>
                        //{
                        //    TranslatedChatBox.Text +=
                        //$"[모르는 채널-제보요망][{chat.Code}]{chat.Line}{Environment.NewLine}";
                        //});
                    }
                }
                else
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        TranslatedChatBox.Text +=
#if DEBUG
                            $"[???][{chat.Code}]{chat.Line}{Environment.NewLine}";
#else
                            $"[???]{chat.Line}{Environment.NewLine}";
#endif
                    });
                }
                Application.Current.Dispatcher.Invoke(() =>
                {
                    TranslatedChatBox.ScrollToEnd();
                    //TranslatedChatBox.ScrollToVerticalOffset(double.MaxValue);
                });
            }
        }