Ejemplo n.º 1
0
        public void UpdateChatWindow()
        {
            if (!Globals.CanPrint || Chat_Messages.Count == 0)
            {
                Globals.l2net_home.timer_chat.Start();
                return;
            }

            //we only need to check invoke on 1 chat box... because they are all on the same form
            if (this.colorListBox_all.InvokeRequired)
            {
                UpdateChatWindow_Callback d = new UpdateChatWindow_Callback(UpdateChatWindow);
                colorListBox_all.Invoke(d);
                return;
            }

            if (Globals.ChatLock.TryEnterWriteLock(Globals.THREAD_WAIT_GUI))
            {
                try
                {
                    bool updating_local  = false;
                    bool updating_trade  = false;
                    bool updating_party  = false;
                    bool updating_clan   = false;
                    bool updating_ally   = false;
                    bool updating_system = false;
                    bool updating_bot    = false;
                    bool updating_hero   = false;

                    colorListBox_all.Enabled = false;
                    colorListBox_all.BeginUpdate();

                    //no need to check if we have chat to print... we wouldn't get here if we didn't have any

                    Chat_Line pop;
                    int       cnt = 0;

                    while (Chat_Messages.Count > 0)
                    {
                        while (Chat_Messages.Count > Globals.MAX_LINES_BYPASS)
                        {
                            pop = (Chat_Line)Chat_Messages.Dequeue();

                            if (Globals.text_out != null)
                            {
                                if (Globals.LogWriting)
                                {
                                    Globals.text_out.Write(pop.text);//it has a newline in it... so no need to use writeline
                                }
                            }
                        }

                        cnt++;
                        pop = (Chat_Line)Chat_Messages.Dequeue();

                        if (Globals.text_out != null)
                        {
                            if (Globals.LogWriting)
                            {
                                Globals.text_out.Write(pop.text);//it has a newline in it... so no need to use writeline
                            }
                        }

                        colorListBox_all.AddItemStart(pop.text, pop.color);

                        switch (pop.type)
                        {
                        case TextType.ALL:
                            if (!updating_local)
                            {
                                updating_local             = true;
                                colorListBox_local.Enabled = false;
                                colorListBox_local.BeginUpdate();
                            }
                            if (!updating_trade)
                            {
                                updating_trade             = true;
                                colorListBox_trade.Enabled = false;
                                colorListBox_trade.BeginUpdate();
                            }
                            if (!updating_party)
                            {
                                updating_party             = true;
                                colorListBox_party.Enabled = false;
                                colorListBox_party.BeginUpdate();
                            }
                            if (!updating_clan)
                            {
                                updating_clan             = true;
                                colorListBox_clan.Enabled = false;
                                colorListBox_clan.BeginUpdate();
                            }
                            if (!updating_ally)
                            {
                                updating_ally             = true;
                                colorListBox_ally.Enabled = false;
                                colorListBox_ally.BeginUpdate();
                            }
                            if (!updating_system)
                            {
                                updating_system             = true;
                                colorListBox_system.Enabled = false;
                                colorListBox_system.BeginUpdate();
                            }
                            if (!updating_bot)
                            {
                                updating_bot             = true;
                                colorListBox_bot.Enabled = false;
                                colorListBox_bot.BeginUpdate();
                            }
                            if (!updating_hero)
                            {
                                updating_hero             = true;
                                colorListBox_hero.Enabled = false;
                                colorListBox_hero.BeginUpdate();
                            }

                            colorListBox_local.AddItemStart(pop.text, pop.color);
                            colorListBox_trade.AddItemStart(pop.text, pop.color);
                            colorListBox_party.AddItemStart(pop.text, pop.color);
                            colorListBox_clan.AddItemStart(pop.text, pop.color);
                            colorListBox_ally.AddItemStart(pop.text, pop.color);
                            colorListBox_system.AddItemStart(pop.text, pop.color);
                            colorListBox_bot.AddItemStart(pop.text, pop.color);
                            break;

                        case TextType.LOCAL:
                            if (!updating_local)
                            {
                                updating_local = true;
                                colorListBox_local.BeginUpdate();
                            }
                            colorListBox_local.AddItemStart(pop.text, pop.color);
                            break;

                        case TextType.TRADE:
                            if (!updating_trade)
                            {
                                updating_trade = true;
                                colorListBox_trade.BeginUpdate();
                            }
                            colorListBox_trade.AddItemStart(pop.text, pop.color);
                            break;

                        case TextType.PARTY:
                            if (!updating_party)
                            {
                                updating_party = true;
                                colorListBox_party.BeginUpdate();
                            }
                            colorListBox_party.AddItemStart(pop.text, pop.color);
                            break;

                        case TextType.CLAN:
                            if (!updating_clan)
                            {
                                updating_clan = true;
                                colorListBox_clan.BeginUpdate();
                            }
                            colorListBox_clan.AddItemStart(pop.text, pop.color);
                            break;

                        case TextType.ALLY:
                            if (!updating_ally)
                            {
                                updating_ally = true;
                                colorListBox_ally.BeginUpdate();
                            }
                            colorListBox_ally.AddItemStart(pop.text, pop.color);
                            break;

                        case TextType.SYSTEM:
                            if (!updating_system)
                            {
                                updating_system = true;
                                colorListBox_system.BeginUpdate();
                            }
                            colorListBox_system.AddItemStart(pop.text, pop.color);
                            break;

                        case TextType.BOT:
                            if (!updating_bot)
                            {
                                updating_bot = true;
                                colorListBox_bot.BeginUpdate();
                            }
                            colorListBox_bot.AddItemStart(pop.text, pop.color);
                            break;

                        case TextType.HERO:
                            if (!updating_hero)
                            {
                                updating_hero = true;
                                colorListBox_hero.BeginUpdate();
                            }
                            colorListBox_hero.AddItemStart(pop.text, pop.color);
                            break;
                        }

                        if (cnt >= Globals.MAX_LINES_PASS)
                        {
                            Globals.l2net_home.timer_chat.Start();
                            break;
                        }
                    }

                    colorListBox_all.EndUpdate();
                    colorListBox_all.Enabled = true;
                    if (updating_local)
                    {
                        colorListBox_local.EndUpdate();
                        colorListBox_local.Enabled = true;
                    }
                    if (updating_trade)
                    {
                        colorListBox_trade.EndUpdate();
                        colorListBox_trade.Enabled = true;
                    }
                    if (updating_party)
                    {
                        colorListBox_party.EndUpdate();
                        colorListBox_party.Enabled = true;
                    }
                    if (updating_clan)
                    {
                        colorListBox_clan.EndUpdate();
                        colorListBox_clan.Enabled = true;
                    }
                    if (updating_ally)
                    {
                        colorListBox_ally.EndUpdate();
                        colorListBox_ally.Enabled = true;
                    }
                    if (updating_system)
                    {
                        colorListBox_system.EndUpdate();
                        colorListBox_system.Enabled = true;
                    }
                    if (updating_bot)
                    {
                        colorListBox_bot.EndUpdate();
                        colorListBox_bot.Enabled = true;
                    }
                    if (updating_hero)
                    {
                        colorListBox_hero.EndUpdate();
                        colorListBox_hero.Enabled = true;
                    }
                }
                catch
                {
                    //crashed...
                }
                finally
                {
                    Globals.ChatLock.ExitWriteLock();
                }
            }
            else
            {
                //we failed to lock... restart the timer
                Globals.l2net_home.timer_chat.Start();
                return;
            }
        }
Ejemplo n.º 2
0
        public void UpdateChatWindow()
        {
            if (!Globals.CanPrint || Chat_Messages.Count == 0)
            {
                Globals.l2net_home.timer_chat.Start();
                return;
            }

            //we only need to check invoke on 1 chat box... because they are all on the same form
            if (this.colorListBox_all.InvokeRequired)
            {
                UpdateChatWindow_Callback d = new UpdateChatWindow_Callback(UpdateChatWindow);
                colorListBox_all.Invoke(d);
                return;
            }

            if (Globals.ChatLock.TryEnterWriteLock(Globals.THREAD_WAIT_GUI))
            {
                try
                {
                    bool updating_local = false;
                    bool updating_trade = false;
                    bool updating_party = false;
                    bool updating_clan = false;
                    bool updating_ally = false;
                    bool updating_system = false;
                    bool updating_bot = false;
                    bool updating_hero = false;

                    colorListBox_all.Enabled = false;
                    colorListBox_all.BeginUpdate();

                    //no need to check if we have chat to print... we wouldn't get here if we didn't have any

                    Chat_Line pop;
                    int cnt = 0;

                    while (Chat_Messages.Count > 0)
                    {
                        while (Chat_Messages.Count > Globals.MAX_LINES_BYPASS)
                        {
                            pop = (Chat_Line)Chat_Messages.Dequeue();

                            if (Globals.text_out != null)
                            {
                                if (Globals.LogWriting)
                                    Globals.text_out.Write(pop.text);//it has a newline in it... so no need to use writeline
                            }
                        }

                        cnt++;
                        pop = (Chat_Line)Chat_Messages.Dequeue();

                        if (Globals.text_out != null)
                        {
                            if (Globals.LogWriting)
                            Globals.text_out.Write(pop.text);//it has a newline in it... so no need to use writeline
                        }

                        colorListBox_all.AddItemStart(pop.text, pop.color);

                        switch (pop.type)
                        {
                            case TextType.ALL:
                                if (!updating_local)
                                {
                                    updating_local = true;
                                    colorListBox_local.Enabled = false;
                                    colorListBox_local.BeginUpdate();
                                }
                                if (!updating_trade)
                                {
                                    updating_trade = true;
                                    colorListBox_trade.Enabled = false;
                                    colorListBox_trade.BeginUpdate();
                                }
                                if (!updating_party)
                                {
                                    updating_party = true;
                                    colorListBox_party.Enabled = false;
                                    colorListBox_party.BeginUpdate();
                                }
                                if (!updating_clan)
                                {
                                    updating_clan = true;
                                    colorListBox_clan.Enabled = false;
                                    colorListBox_clan.BeginUpdate();
                                }
                                if (!updating_ally)
                                {
                                    updating_ally = true;
                                    colorListBox_ally.Enabled = false;
                                    colorListBox_ally.BeginUpdate();
                                }
                                if (!updating_system)
                                {
                                    updating_system = true;
                                    colorListBox_system.Enabled = false;
                                    colorListBox_system.BeginUpdate();
                                }
                                if (!updating_bot)
                                {
                                    updating_bot = true;
                                    colorListBox_bot.Enabled = false;
                                    colorListBox_bot.BeginUpdate();
                                }
                                if (!updating_hero)
                                {
                                    updating_hero = true;
                                    colorListBox_hero.Enabled = false;
                                    colorListBox_hero.BeginUpdate();
                                }

                                colorListBox_local.AddItemStart(pop.text, pop.color);
                                colorListBox_trade.AddItemStart(pop.text, pop.color);
                                colorListBox_party.AddItemStart(pop.text, pop.color);
                                colorListBox_clan.AddItemStart(pop.text, pop.color);
                                colorListBox_ally.AddItemStart(pop.text, pop.color);
                                colorListBox_system.AddItemStart(pop.text, pop.color);
                                colorListBox_bot.AddItemStart(pop.text, pop.color);
                                break;
                            case TextType.LOCAL:
                                if (!updating_local)
                                {
                                    updating_local = true;
                                    colorListBox_local.BeginUpdate();
                                }
                                colorListBox_local.AddItemStart(pop.text, pop.color);
                                break;
                            case TextType.TRADE:
                                if (!updating_trade)
                                {
                                    updating_trade = true;
                                    colorListBox_trade.BeginUpdate();
                                }
                                colorListBox_trade.AddItemStart(pop.text, pop.color);
                                break;
                            case TextType.PARTY:
                                if (!updating_party)
                                {
                                    updating_party = true;
                                    colorListBox_party.BeginUpdate();
                                }
                                colorListBox_party.AddItemStart(pop.text, pop.color);
                                break;
                            case TextType.CLAN:
                                if (!updating_clan)
                                {
                                    updating_clan = true;
                                    colorListBox_clan.BeginUpdate();
                                }
                                colorListBox_clan.AddItemStart(pop.text, pop.color);
                                break;
                            case TextType.ALLY:
                                if (!updating_ally)
                                {
                                    updating_ally = true;
                                    colorListBox_ally.BeginUpdate();
                                }
                                colorListBox_ally.AddItemStart(pop.text, pop.color);
                                break;
                            case TextType.SYSTEM:
                                if (!updating_system)
                                {
                                    updating_system = true;
                                    colorListBox_system.BeginUpdate();
                                }
                                colorListBox_system.AddItemStart(pop.text, pop.color);
                                break;
                            case TextType.BOT:
                                if (!updating_bot)
                                {
                                    updating_bot = true;
                                    colorListBox_bot.BeginUpdate();
                                }
                                colorListBox_bot.AddItemStart(pop.text, pop.color);
                                break;
                            case TextType.HERO:
                                if (!updating_hero)
                                {
                                    updating_hero = true;
                                    colorListBox_hero.BeginUpdate();
                                }
                                colorListBox_hero.AddItemStart(pop.text, pop.color);
                                break;
                        }

                        if (cnt >= Globals.MAX_LINES_PASS)
                        {
                            Globals.l2net_home.timer_chat.Start();
                            break;
                        }
                    }

                    colorListBox_all.EndUpdate();
                    colorListBox_all.Enabled = true;
                    if (updating_local)
                    {
                        colorListBox_local.EndUpdate();
                        colorListBox_local.Enabled = true;
                    }
                    if (updating_trade)
                    {
                        colorListBox_trade.EndUpdate();
                        colorListBox_trade.Enabled = true;
                    }
                    if (updating_party)
                    {
                        colorListBox_party.EndUpdate();
                        colorListBox_party.Enabled = true;
                    }
                    if (updating_clan)
                    {
                        colorListBox_clan.EndUpdate();
                        colorListBox_clan.Enabled = true;
                    }
                    if (updating_ally)
                    {
                        colorListBox_ally.EndUpdate();
                        colorListBox_ally.Enabled = true;
                    }
                    if (updating_system)
                    {
                        colorListBox_system.EndUpdate();
                        colorListBox_system.Enabled = true;
                    }
                    if (updating_bot)
                    {
                        colorListBox_bot.EndUpdate();
                        colorListBox_bot.Enabled = true;
                    }
                    if (updating_hero)
                    {
                        colorListBox_hero.EndUpdate();
                        colorListBox_hero.Enabled = true;
                    }
                }
                catch
                {
                    //crashed...
                }
                finally
                {
                    Globals.ChatLock.ExitWriteLock();
                }
            }
            else
            {
                //we failed to lock... restart the timer
                Globals.l2net_home.timer_chat.Start();
                return;
            }
        }