Пример #1
0
        private void logReaderEvent(object sender, LogEventArgs e)
        {
            logger.Debug("logReaderEvent " + e.line);
            TextBox textBox = null;
            CheckBox checkBox = null;

            if (e.type.Equals(LogReader.logTypes.OFFICER_CHAT)) {
                textBox = txtOfficerChat;
                checkBox = chkOfficerScroll;
            } else if (e.type.Equals(LogReader.logTypes.GUILD_CHAT)) {
                textBox = txtGuildChat;
                checkBox = chkGuildScroll;
            }

            // InvokeRequired required compares the thread ID of the
            // calling thread to the thread ID of the creating thread.
            // If these threads are different, it returns true.
            if (textBox != null) {
                if (textBox.InvokeRequired) {
                    logger.Debug("Invoking for thread saftey...");
                    LogReaderEvent d = new LogReaderEvent(logReaderEvent);
                    this.Invoke(d, new object[] { sender, e });
                } else {
                    logger.Debug("Setting the text...");
                    // Save the starting positions of the current cursor and selected text
                    int start = textBox.SelectionStart;
                    int len = textBox.SelectionLength;

                    //textBox.Text = newText;
                    textBox.AppendText(Environment.NewLine + e.line);

                    if (checkBox.Checked) {
                        textBox.SelectionStart = textBox.Text.Length;

                    } else {
                        textBox.SelectionStart = start;
                        textBox.SelectionLength = len;
                    }

                    textBox.ScrollToCaret();
                }
            }
        }
Пример #2
0
        private void logReaderEvent(object sender, LogEventArgs e)
        {
            logger.Debug("logReaderEvent " + e.line);
            RichTextBox textBox  = null;
            CheckBox    checkBox = null;

            switch (e.type)
            {
            case LogReader.logTypes.OFFICER_CHAT:
                textBox  = txtOfficerChat;
                checkBox = chkOfficerScroll;
                break;

            case LogReader.logTypes.GUILD_CHAT:
                textBox  = txtGuildChat;
                checkBox = chkGuildScroll;
                break;

            case LogReader.logTypes.TELLS:
                textBox  = txtTells;
                checkBox = chkTellsScroll;
                break;
            }

            // InvokeRequired required compares the thread ID of the
            // calling thread to the thread ID of the creating thread.
            // If these threads are different, it returns true.
            if (textBox != null)
            {
                if (textBox.InvokeRequired)
                {
                    logger.Debug("Invoking for thread saftey...");
                    LogReaderEvent d = new LogReaderEvent(logReaderEvent);
                    this.Invoke(d, new object[] { sender, e });
                }
                else
                {
                    logger.Debug("Setting the text...");
                    // Save the starting positions of the current cursor and selected text
                    int start = textBox.SelectionStart;
                    int len   = textBox.SelectionLength;
                    textBox.SelectionColor = Color.Black;

                    // remove initial timestamp
                    int    firstChat = e.line.IndexOf(']') + 2;
                    string theLine   = e.line.Substring(firstChat, e.line.Length - firstChat);

                    if (textBox == txtGuildChat)
                    {
                        bool isLootChat = guildLootChat.IsMatch(e.line) || (e.line.Split(new string[] { " // " }, StringSplitOptions.None).Length > 1);

                        if (!isLootChat)
                        {
                            if (chkGuildLootOnly.Checked)
                            {
                                guildChatBuffer.Add(theLine);
                            }
                            else
                            {
                                if (textBox.Lines.Length > 0)
                                {
                                    textBox.AppendText(Environment.NewLine);
                                }

                                textBox.AppendText(theLine);
                            }
                        }
                        else
                        {
                            guildChatBuffer.Add(theLine);

                            if (textBox.Lines.Length > 0)
                            {
                                textBox.AppendText(Environment.NewLine);
                            }

                            textBox.AppendText(theLine);
                        }

                        if (checkBox.Checked)
                        {
                            textBox.SelectionStart = textBox.Text.Length;
                        }
                        else
                        {
                            textBox.SelectionStart  = start;
                            textBox.SelectionLength = len;
                        }
                    }
                    else
                    {
                        if (textBox.Lines.Length > 0)
                        {
                            textBox.AppendText(Environment.NewLine);
                        }

                        textBox.AppendText(theLine);
                    }

                    textBox.ScrollToCaret();
                }
            }
            else if (e.type == LogReader.logTypes.LOOT)
            {
                // Group 0 is everything       Group 1     Group 2     Group 3
                //[Sun May 13 20:20:29 2018] --(You) have (looted) a (Enchanted Runestone).--
                if (e.matches[0].Groups.Count == 4)
                {
                    string userName = e.matches[0].Groups[1].Value;
                    if ("You".Equals(userName))
                    {
                        userName = PropertyManager.getManager().getProperty("UserName");
                        if (userName == null)
                        {
                            userName = "******";
                        }
                    }

                    string[] row = { userName, e.matches[0].Groups[3].Value };

                    this.Invoke(new MethodInvoker(delegate()
                    {
                        lootLogView.Items.Add(new ListViewItem(row));
                    }
                                                  ));
                }
            }
        }