Beispiel #1
0
 public virtual void AddLine(IChatLine line)
 {
     if (ChannelName != "zkadmin" &&
         ((line is SaidLine && Program.Conf.IgnoredUsers.Contains(((SaidLine)line).AuthorName)) ||
          (line is SaidExLine && Program.Conf.IgnoredUsers.Contains(((SaidExLine)line).AuthorName))))
     {
         return;
     }
     ChatBox.AddLine(line);
     ChannelLineAdded(this, new ChannelLineArgs()
     {
         Channel = ChannelName, Line = line
     });
     HistoryManager.LogLine(ChannelName, line);
 }
Beispiel #2
0
        public PrivateMessageControl(string name)
        {
            InitializeComponent();
            ChatBox.Font                 = Program.Conf.ChatFont;
            Name                         = name;
            UserName                     = name;
            ChatBox.MouseUp             += autoscrollRichTextBox1_MouseUp;
            ChatBox.FocusInputRequested += (s, e) => GoToSendBox();
            ChatBox.ChatBackgroundColor  = TextColor.background; //same as Program.Conf.BgColor but TextWindow.cs need this.
            ChatBox.IRCForeColor         = 14;                   //mirc grey. Unknown use

            HistoryManager.InsertLastLines(UserName, ChatBox);

            VisibleChanged += PrivateMessageControl_VisibleChanged;
            Program.TasClient.BattleUserJoined += TasClient_BattleUserJoined;
            Program.TasClient.UserAdded        += TasClient_UserAdded;
            Program.TasClient.UserRemoved      += TasClient_UserRemoved;

            var extras = new BitmapButton();

            extras.Text   = "Extras";
            extras.Click += (s, e) => { ContextMenus.GetPrivateMessageContextMenu(this).Show(extras, new Point(0, 0)); };
            ChatBox.Controls.Add(extras);

            sendBox.CompleteWord += (word) => //autocomplete of username
            {
                var      w           = word.ToLower();
                string[] nameInArray = new string[1] {
                    name
                };
                System.Collections.Generic.IEnumerable <string> firstResult = nameInArray
                                                                              .Where(x => x.ToLower().StartsWith(w))
                                                                              .Union(nameInArray.Where(x => x.ToLower().Contains(w)));;
                if (true)
                {
                    ChatControl zkChatArea = Program.MainWindow.navigationControl.ChatTab.GetChannelControl("zk");
                    if (zkChatArea != null)
                    {
                        System.Collections.Generic.IEnumerable <string> extraResult = zkChatArea.playerBox.GetUserNames()
                                                                                      .Where(x => x.ToLower().StartsWith(w))
                                                                                      .Union(zkChatArea.playerBox.GetUserNames().Where(x => x.ToLower().Contains(w)));
                        firstResult = firstResult.Concat(extraResult); //Reference: http://stackoverflow.com/questions/590991/merging-two-ienumerablets
                    }
                }
                return(firstResult);
            };
        }
Beispiel #3
0
        public ChatControl(string name)
        {
            InitializeComponent();

            var isDesignMode = Process.GetCurrentProcess().ProcessName == "devenv"; // workaround for this.DesignMode not working in constructor

            if (isDesignMode)
            {
                return;
            }

            var extras = new BitmapButton();

            extras.Text   = "Extras";
            extras.Click += (s, e) => { ContextMenus.GetChannelContextMenu(this).Show(extras, new Point(0, 0)); };
            ChatBox.Controls.Add(extras);

            playerBox.DrawMode     = DrawMode.OwnerDrawVariable;
            playerBox.MeasureItem += (s, e) => { }; // needed for ListBox.OnMeasureItem
            playerBox.BackColor    = Program.Conf.BgColor;
            playerBox.ForeColor    = Program.Conf.TextColor;

            playerSearchBox.BackColor = Program.Conf.BgColor;
            playerSearchBox.ForeColor = Program.Conf.TextColor;

            ChatBox.Font = Program.Conf.ChatFont; //make sure this is done before HistoryManager adds text, or text becomes black.

            Name        = name;
            ChannelName = name;
            if (!DesignMode)
            {
                HistoryManager.InsertLastLines(ChannelName, ChatBox);
            }

            playerBox.Sorted = true;
            var lookingGlass = new PictureBox {
                Width = 20, Height = 20, Image = ZklResources.search, SizeMode = PictureBoxSizeMode.CenterImage
            };

            searchBarContainer.Controls.Add(lookingGlass);
            Program.ToolTip.SetText(lookingGlass, "Enter name or country shortcut to find");

            Program.ToolTip.SetText(playerSearchBox, "Enter name or country shortcut to find");

            VisibleChanged += ChatControl_VisibleChanged;

            ChatBox.MouseUp             += chatBox_MouseUp;
            ChatBox.MouseDown           += chatBox_MouseDown;
            ChatBox.MouseMove           += chatBox_MouseMove;
            ChatBox.FocusInputRequested += (s, e) => GoToSendBox();
            ChatBox.ChatBackgroundColor  = TextColor.background; //same as Program.Conf.BgColor but TextWindow.cs need this.
            ChatBox.IRCForeColor         = 14;                   //mirc grey. Unknown use

            Program.TasClient.ChannelUserAdded   += client_ChannelUserAdded;
            Program.TasClient.ChannelUserRemoved += client_ChannelUserRemoved;
            Program.TasClient.UserStatusChanged  += TasClient_UserStatusChanged;
            Program.TasClient.ChannelUsersAdded  += TasClient_ChannelUsersAdded;
            Program.TasClient.Said                += client_Said;
            Program.TasClient.UserRemoved         += TasClient_UserRemoved;
            Program.TasClient.ChannelTopicChanged += TasClient_ChannelTopicChanged;
            Program.TasClient.HourChime           += client_HourChime;

            Channel channel;

            Program.TasClient.JoinedChannels.TryGetValue(ChannelName, out channel);

            //Topic Box that displays over the channel
            topicBox.IRCForeColor             = 14; //mirc grey. Unknown use
            topicBox.ChatBackgroundColor      = TextColor.topicBackground;
            topicBox.HorizontalScroll.Enabled = true;
            topicBox.BorderStyle            = BorderStyle.FixedSingle;
            topicBox.VerticalScroll.Visible = false;
            topicBox.VerticalScroll.Enabled = false;
            topicBox.AutoSize       = true;
            topicBox.AutoSizeMode   = AutoSizeMode.GrowAndShrink;
            topicBox.HideScroll     = true;
            topicBox.ShowUnreadLine = false;
            topicBox.ShowHistory    = false;

            //hide mappanel for normal chat operation. Overriden in BattleChatControl.cs
            playerListMapSplitContainer.Panel2Collapsed = true;

            sendBox.CompleteWord += (word) => //autocomplete of username
            {
                var w = word.ToLower();
                IEnumerable <string> firstResult = playerBox.GetUserNames()
                                                   .Where(x => x.ToLower().StartsWith(w))
                                                   .Union(playerBox.GetUserNames().Where(x => x.ToLower().Contains(w)));
                if (true)
                {
                    ChatControl zkChatArea = Program.MainWindow.navigationControl.ChatTab.GetChannelControl("zk");
                    if (zkChatArea != null)
                    {
                        IEnumerable <string> extraResult = zkChatArea.playerBox.GetUserNames()
                                                           .Where(x => x.ToLower().StartsWith(w))
                                                           .Union(zkChatArea.playerBox.GetUserNames().Where(x => x.ToLower().Contains(w)));
                        firstResult = firstResult.Concat(extraResult);     //Reference: http://stackoverflow.com/questions/590991/merging-two-ienumerablets
                    }
                }
                return(firstResult);
            };

            if (channel != null)
            {
                foreach (var userName in Program.TasClient.JoinedChannels[ChannelName].ChannelUsers)
                {
                    AddUser(userName);
                }
            }
        }
        // warning: a lot of duplication in GetPrivateMessageContextMenuWpf! change both at once! (temporary solution)

        // warning: a lot of duplication in GetPrivateMessageContextMenuWpf! change both at once!  (temporary solution)
        public static ContextMenu GetPrivateMessageContextMenu(PrivateMessageControl control)
        {
            var contextMenu = new ContextMenu();

            try
            {
                var headerItem = new System.Windows.Forms.MenuItem("Private Channel - " + control.UserName);

                headerItem.Enabled     = false;
                headerItem.DefaultItem = true; //This is to make it appear bold
                contextMenu.MenuItems.Add(headerItem);
                contextMenu.MenuItems.Add("-");

                var details = new System.Windows.Forms.MenuItem("Details");
                details.Click += (s, e) => NavigationControl.Instance.Path = "http://zero-k.info/Users/LobbyDetail/" + control.UserName;
                contextMenu.MenuItems.Add(details);

                if (Program.FriendManager.Friends.Contains(control.UserName))
                {
                    var pinItem = new System.Windows.Forms.MenuItem("Unfriend");
                    pinItem.Click += (s, e) => Program.FriendManager.RemoveFriend(control.UserName);
                    contextMenu.MenuItems.Add(pinItem);
                }
                else
                {
                    var pinItem = new System.Windows.Forms.MenuItem("Friend");
                    pinItem.Click += (s, e) => Program.FriendManager.AddFriend(control.UserName);
                    contextMenu.MenuItems.Add(pinItem);
                }

                var isUserOnline = Program.TasClient.ExistingUsers.ContainsKey(control.UserName);

                var joinItem = new System.Windows.Forms.MenuItem("Join Same Battle");
                joinItem.Enabled = isUserOnline && Program.TasClient.ExistingUsers[control.UserName].IsInBattleRoom;
                joinItem.Click  += (s, e) => ActionHandler.JoinPlayer(control.UserName);
                contextMenu.MenuItems.Add(joinItem);

                var reportUser = new System.Windows.Forms.MenuItem("Report User");
                reportUser.Click += (s, e) => NavigationControl.Instance.Path = "http://zero-k.info/Users/ReportToAdminFromLobby/" + control.UserName;
                contextMenu.MenuItems.Add(reportUser);

                contextMenu.MenuItems.Add("-");

                var showJoinLeaveLines = new System.Windows.Forms.MenuItem("Show Join/Leave Lines")
                {
                    Checked = control.ChatBox.ShowJoinLeave
                };
                showJoinLeaveLines.Click += (s, e) => control.ChatBox.ShowJoinLeave = !control.ChatBox.ShowJoinLeave;
                contextMenu.MenuItems.Add(showJoinLeaveLines);

                var showHistoryLines = new System.Windows.Forms.MenuItem("Show Recent History")
                {
                    Checked = control.ChatBox.ShowHistory
                };
                showHistoryLines.Click += (s, e) => control.ChatBox.ShowHistory = !control.ChatBox.ShowHistory;
                contextMenu.MenuItems.Add(showHistoryLines);

                var historyItem = new System.Windows.Forms.MenuItem("Open History");
                historyItem.Click += (s, e) => HistoryManager.OpenHistory(control.UserName);
                contextMenu.MenuItems.Add(historyItem);

                if (control.CanClose)
                {
                    var closeItem = new System.Windows.Forms.MenuItem("Close");
                    closeItem.Click += (s, e) => ActionHandler.CloseChannel(control.UserName);
                    contextMenu.MenuItems.Add(closeItem);
                }

                contextMenu.MenuItems.Add("-");
                MenuItem textColoringMenu = new System.Windows.Forms.MenuItem("Compose a colored text");
                textColoringMenu.Click += (s, e) => { ActionHandler.ShowColoringPanel(control.sendBox); };
                contextMenu.MenuItems.Add(textColoringMenu);
                MenuItem unicodeTranslator = new System.Windows.Forms.MenuItem("Get Unicode symbols");
                unicodeTranslator.Click += (s, e) => { ActionHandler.ShowUnicodeTranslator(); };
                contextMenu.MenuItems.Add(unicodeTranslator);
            }
            catch (Exception e)
            {
                Trace.WriteLine("Error generating channel context menu: " + e);
            }

            return(contextMenu);
        }
        public static ContextMenu GetChannelContextMenu(ChatControl chatControl)
        {
            var contextMenu = new ContextMenu();

            try
            {
                var headerItem = new System.Windows.Forms.MenuItem("Channel - " + chatControl.ChannelName)
                {
                    Enabled = false, DefaultItem = true
                };

                contextMenu.MenuItems.Add(headerItem);
                contextMenu.MenuItems.Add("-");

                if (!(chatControl is BattleChatControl))
                {
                    var showTopic = new System.Windows.Forms.MenuItem("Show Topic Header")
                    {
                        Checked = chatControl.IsTopicVisible
                    };
                    showTopic.Click += (s, e) =>
                    {
                        chatControl.IsTopicVisible = !chatControl.IsTopicVisible;
                        showTopic.Checked          = chatControl.IsTopicVisible;
                    };
                    contextMenu.MenuItems.Add(showTopic);
                }

                if (chatControl.ChannelName != "Battle")
                {
                    var autoJoinItem = new System.Windows.Forms.MenuItem("Automatically Join Channel")
                    {
                        Checked = Program.AutoJoinManager.Channels.Contains(chatControl.ChannelName)
                    };
                    autoJoinItem.Click += (s, e) =>
                    {
                        if (autoJoinItem.Checked)
                        {
                            Program.AutoJoinManager.Remove(chatControl.ChannelName);
                        }
                        else
                        {
                            Program.AutoJoinManager.Add(chatControl.ChannelName);
                        }
                        autoJoinItem.Checked = !autoJoinItem.Checked;
                    };
                    contextMenu.MenuItems.Add(autoJoinItem);
                }

                var showJoinLeaveLines = new System.Windows.Forms.MenuItem("Show Join/Leave Lines")
                {
                    Checked = chatControl.ChatBox.ShowJoinLeave
                };
                showJoinLeaveLines.Click += (s, e) => chatControl.ChatBox.ShowJoinLeave = !chatControl.ChatBox.ShowJoinLeave;
                contextMenu.MenuItems.Add(showJoinLeaveLines);

                var showHistoryLines = new System.Windows.Forms.MenuItem("Show Recent History")
                {
                    Checked = chatControl.ChatBox.ShowHistory
                };
                showHistoryLines.Click += (s, e) => chatControl.ChatBox.ShowHistory = !chatControl.ChatBox.ShowHistory;
                contextMenu.MenuItems.Add(showHistoryLines);

                var historyItem = new System.Windows.Forms.MenuItem("Open History");
                historyItem.Click += (s, e) => HistoryManager.OpenHistory(chatControl.ChannelName);
                contextMenu.MenuItems.Add(historyItem);

                if (chatControl.CanLeave)
                {
                    var leaveItem = new System.Windows.Forms.MenuItem("Leave Channel");
                    leaveItem.Click += (s, e) => Program.TasClient.LeaveChannel(chatControl.ChannelName);
                    contextMenu.MenuItems.Add(leaveItem);
                }
                contextMenu.MenuItems.Add("-");
                MenuItem textColoringMenu = new System.Windows.Forms.MenuItem("Compose a colored text");
                textColoringMenu.Click += (s, e) => { ActionHandler.ShowColoringPanel(chatControl.sendBox); };
                contextMenu.MenuItems.Add(textColoringMenu);
                MenuItem unicodeTranslator = new System.Windows.Forms.MenuItem("Get Unicode symbols");
                unicodeTranslator.Click += (s, e) => { ActionHandler.ShowUnicodeTranslator(); };
                contextMenu.MenuItems.Add(unicodeTranslator);

                if (chatControl is BattleChatControl)
                {
                    contextMenu.MenuItems.Add("-");
                    contextMenu.MenuItems.Add(GetShowOptions());
                    contextMenu.MenuItems.Add(GetAddBotItem());
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine("Error generating channel context menu: " + e);
            }
            return(contextMenu);
        }
Beispiel #6
0
        public ChatControl(string name)
        {
            InitializeComponent();
            Init(searchBarContainer);
            Init(playerListMapSplitContainer);

            if (this.IsInDesignMode())
            {
                return;
            }


            ChatBox.Font = Config.ChatFont; //make sure this is done before HistoryManager adds text, or text becomes black.

            Name        = name;
            ChannelName = name;
            if (!DesignMode)
            {
                HistoryManager.InsertLastLines(ChannelName, ChatBox);
            }

            playerBox.IsSorted = true;
            Program.ToolTip.SetText(playerSearchBox.TextBox, "Enter name or country shortcut to find");

            VisibleChanged += ChatControl_VisibleChanged;

            ChatBox.MouseUp             += chatBox_MouseUp;
            ChatBox.MouseDown           += chatBox_MouseDown;
            ChatBox.MouseMove           += chatBox_MouseMove;
            ChatBox.FocusInputRequested += (s, e) => GoToSendBox();
            ChatBox.ChatBackgroundColor  = TextColor.background; //same as Program.Conf.BgColor but TextWindow.cs need this.
            ChatBox.IRCForeColor         = 14;                   //mirc grey. Unknown use

            Program.TasClient.ChannelUserAdded   += client_ChannelUserAdded;
            Program.TasClient.ChannelUserRemoved += client_ChannelUserRemoved;
            Program.TasClient.UserStatusChanged  += TasClient_UserStatusChanged;
            //            Program.TasClient.ChannelUsersAdded += TasClient_ChannelUsersAdded;
            Program.TasClient.Said                += client_Said;
            Program.TasClient.UserRemoved         += TasClient_UserRemoved;
            Program.TasClient.ChannelTopicChanged += TasClient_ChannelTopicChanged;

            Program.SteamHandler.Voice.UserStartsTalking += VoiceOnUserChanged;
            Program.SteamHandler.Voice.UserStopsTalking  += VoiceOnUserChanged;
            Program.SteamHandler.Voice.UserVoiceEnabled  += VoiceOnUserChanged;

            Channel channel;

            Program.TasClient.JoinedChannels.TryGetValue(ChannelName, out channel);

            minuteTimer = new Timer(60000)
            {
                AutoReset = true
            };
            minuteTimer.Elapsed += (s, e) =>
            {
                if (DateTime.Now.Minute == 0 && IsHandleCreated && !IsDisposed)
                {
                    Invoke(new Action(() => AddLine(new ChimeLine())));
                }
            };
            minuteTimer.Start();


            //Topic Box that displays over the channel
            topicBox.IRCForeColor             = 14; //mirc grey. Unknown use
            topicBox.ChatBackgroundColor      = TextColor.topicBackground;
            topicBox.HorizontalScroll.Enabled = true;
            topicBox.BorderStyle            = BorderStyle.FixedSingle;
            topicBox.VerticalScroll.Visible = false;
            topicBox.VerticalScroll.Enabled = false;
            topicBox.AutoSize       = true;
            topicBox.AutoSizeMode   = AutoSizeMode.GrowAndShrink;
            topicBox.HideScroll     = true;
            topicBox.ShowUnreadLine = false;
            topicBox.ShowHistory    = false;

            //hide mappanel for normal chat operation. Overriden in BattleChatControl.cs
            playerListMapSplitContainer.Panel2Collapsed = true;

            sendBox.CompleteWord += (word) => //autocomplete of username
            {
                var w           = word.ToLower();
                var firstResult =
                    playerBox.GetUserNames().Where(x => x.ToLower().StartsWith(w)).Union(playerBox.GetUserNames().Where(x => x.ToLower().Contains(w)));
                if (true)
                {
                    var zkChatArea = Program.MainWindow.navigationControl.ChatTab.GetChannelControl("zk");
                    if (zkChatArea != null)
                    {
                        var extraResult =
                            zkChatArea.playerBox.GetUserNames()
                            .Where(x => x.ToLower().StartsWith(w))
                            .Union(zkChatArea.playerBox.GetUserNames().Where(x => x.ToLower().Contains(w)));
                        firstResult = firstResult.Concat(extraResult);
                        //Reference: http://stackoverflow.com/questions/590991/merging-two-ienumerablets
                    }
                }
                return(firstResult);
            };

            if (channel != null)
            {
                foreach (var userName in Program.TasClient.JoinedChannels[ChannelName].Users.Keys)
                {
                    AddUser(userName);
                }
            }
        }