示例#1
0
        private void listBox1_MouseDown(object sender, MouseEventArgs e)
        {
            try
            {
                if (e.Button == MouseButtons.Right)
                {
                    listBox1.SelectedIndex = listBox1.IndexFromPoint(e.X, e.Y);
                }

                if (listBox1.SelectedItem != null && e.Button == MouseButtons.Right)
                {
                    int index = listBox1.IndexFromPoint(e.X, e.Y);

                    if (listBox1.SelectedIndex == index && listBox1.SelectedItem.ToString().Contains(" (online)"))
                    {
                        String itemChosen = listBox1.SelectedItem.ToString().Substring(0, listBox1.SelectedItem.ToString().IndexOf(" (online"));

                        var user = Program.TasClient.ExistingUsers.Values.SingleOrDefault(x => x.Name.ToString().ToUpper() == itemChosen.ToUpper());
                        var cm   = ContextMenus.GetPlayerContextMenu(user, false);
                        cm.Show(this, new Point(e.X + 10, e.Y + 15));
                    }
                    else if (listBox1.SelectedIndex == index && !listBox1.SelectedItem.ToString().Contains(" (online)"))
                    {
                        String itemChosen = listBox1.SelectedItem.ToString();

                        var user = LobbyClient.User.Create(itemChosen);
                        var cm   = ContextMenus.GetPlayerContextMenu(user, false);
                        cm.Show(this, new Point(e.X + 10, e.Y + 15));
                    }
                }
            }
            catch { }
        }
示例#2
0
        void ShowPlayerContextMenu(User user, Control control, Point location)
        {
            var contextMenu = ContextMenus.GetPlayerContextMenu(user, this is BattleChatControl);

            try {
                Program.ToolTip.Visible = false;
                contextMenu.Show(control, location);
            } catch (Exception ex) {
                Trace.TraceError("Error displaying tooltip:{0}", ex);
            } finally {
                Program.ToolTip.Visible = true;
            }
        }
示例#3
0
        void ShowChatContextMenu(Point location)
        {
            var contextMenu = ContextMenus.GetChannelContextMenu(this);

            try {
                Program.ToolTip.Visible = false;
                contextMenu.Show(ChatBox, location);
            } catch (Exception ex) {
                Trace.TraceError("Error displaying tooltip:{0}", ex);
            } finally {
                Program.ToolTip.Visible = true;
            }
        }
示例#4
0
        protected override void OnMouseDown([NotNull] MouseEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            base.OnMouseDown(e);
            Battle battle = GetBattle(e.X, e.Y);

            if (e.Button == MouseButtons.Left)
            {
                if (battle != null)
                {
                    if (battle.IsPassworded)
                    {
                        // hack dialog Program.FormMain
                        using (var form = new AskBattlePasswordForm(battle.Founder.Name)) if (form.ShowDialog() == DialogResult.OK)
                            {
                                ActionHandler.JoinBattle(battle.BattleID, form.Password);
                            }
                    }
                    else
                    {
                        ActionHandler.JoinBattle(battle.BattleID, null);
                    }
                }
                else if (OpenGameButtonHitTest(e.X, e.Y))
                {
                    ShowHostDialog(KnownGames.GetDefaultGame());
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                var cm = ContextMenus.GetBattleListContextMenu(battle);
                Program.ToolTip.Visible = false;
                try
                {
                    cm.Show(Parent, e.Location);
                }
                catch (Exception ex)
                {
                    Trace.TraceError("BattleListControl Error displaying tooltip: {0}", ex);
                }
                finally
                {
                    Program.ToolTip.Visible = true;
                }
            }
        }
示例#5
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);
            };
        }
示例#6
0
        private void ShowChatContextMenu(Point location, string word = null)
        {
            var contextMenu = ContextMenus.GetChannelContextMenu(this);

            contextMenu = LineDehighlighter(contextMenu, word);

            try
            {
                Program.ToolTip.Visible = false;
                contextMenu.Show(ChatBox, location);
            }
            catch (Exception ex)
            {
                Trace.TraceError("Error displaying tooltip:{0}", ex);
            }
            finally
            {
                Program.ToolTip.Visible = true;
            }
        }
示例#7
0
        void autoscrollRichTextBox1_MouseUp(object sender, MouseEventArgs me)
        {
            var word = ChatBox.HoveredWord.TrimEnd();

            if (word != null)
            {
                var user = Program.TasClient.ExistingUsers.Values.SingleOrDefault(x => x.Name.ToString().ToUpper() == word.ToUpper());
                if (user != null)
                {
                    if (me.Button == MouseButtons.Right || !Program.Conf.LeftClickSelectsPlayer)
                    {
                        ContextMenus.GetPlayerContextMenu(user, false).Show(this, me.Location);
                        return;
                    }
                }
            }

            if (me.Button == MouseButtons.Right)
            {
                ContextMenus.GetPrivateMessageContextMenu(this).Show(this, me.Location);
            }
        }
示例#8
0
        protected override void OnMouseDown([NotNull] MouseEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            base.OnMouseDown(e);
            Battle battle = GetBattle(e.X, e.Y);

            if (e.Button == MouseButtons.Left)
            {
                if (battle != null)
                {
                    if (battle.IsPassworded)
                    {
                        // hack dialog Program.FormMain
                        using (var form = new AskBattlePasswordForm(battle.Founder.Name)) if (form.ShowDialog() == DialogResult.OK)
                            {
                                ActionHandler.JoinBattle(battle.BattleID, form.Password);
                            }
                    }
                    else
                    {
                        ActionHandler.JoinBattle(battle.BattleID, null);
                    }
                }
                else if (OpenGameButtonHitTest(e.X, e.Y))
                {
                    ShowHostDialog(KnownGames.GetDefaultGame());
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                // todo - disable OnMouseMove while this is open to stop battle tooltips floating under it
                ContextMenus.GetBattleListContextMenu(battle).Show(Parent, e.Location);
                Program.ToolTip.Visible = false;
            }
        }
        void playerBox_MouseDown(object sender, MouseEventArgs mea)
        {
            if (mea.Button == MouseButtons.Left)
            {
                if (playerBox.HoverItem != null)
                {
                    if (playerBox.HoverItem.IsSpectatorsTitle)
                    {
                        ActionHandler.Spectate();
                    }
                    else if (playerBox.HoverItem.SlotButton != null)
                    {
                        ActionHandler.JoinSlot(playerBox.HoverItem.MissionSlot);
                    }
                    else if (playerBox.HoverItem.AllyTeam.HasValue)
                    {
                        ActionHandler.JoinAllyTeam(playerBox.HoverItem.AllyTeam.Value);
                    }
                }
            }

            if (mea.Button == MouseButtons.Right || !Program.Conf.LeftClickSelectsPlayer)
            {
                if (playerBox.HoverItem == null && mea.Button == MouseButtons.Right)
                {
                    var cm = ContextMenus.GetPlayerContextMenu(Program.TasClient.MyUser, true);
                    Program.ToolTip.Visible = false;
                    try {
                        cm.Show(playerBox, mea.Location);
                    } catch (Exception ex) {
                        Trace.TraceError("Error displaying tooltip: {0}", ex);
                    } finally {
                        Program.ToolTip.Visible = true;
                    }
                }
            }
            if (playerBox.HoverItem != null)
            {
                if (playerBox.HoverItem.BotBattleStatus != null)
                {
                    playerBox.SelectedItem = playerBox.HoverItem;
                    var cm = ContextMenus.GetBotContextMenu(playerBox.HoverItem.BotBattleStatus.Name);
                    Program.ToolTip.Visible = false;
                    try {
                        cm.Show(playerBox, mea.Location);
                    } catch (Exception ex) {
                        Trace.TraceError("Error displaying tooltip: {0}", ex);
                    } finally {
                        Program.ToolTip.Visible = true;
                    }
                }

                /*
                 *      if (playerBox.HoverItem.UserBattleStatus != null) {
                 *              playerBox.SelectedItem = playerBox.HoverItem;
                 *              var cm = ContextMenus.GetPlayerContextMenu(playerBox.HoverItem.User, true);
                 *              Program.ToolTip.Visible = false;
                 *              cm.Show(playerBox, mea.Location);
                 *              Program.ToolTip.Visible = true;
                 *      }*/
            }
        }
示例#10
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);
                }
            }
        }
示例#11
0
        protected override void PlayerBox_MouseClick(object sender, MouseEventArgs mea)
        {
            if (mea.Button == MouseButtons.Left)
            {
                if (this.playerBox.HoverItem != null)
                {
                    if (this.playerBox.HoverItem.IsSpectatorsTitle)
                    {
                        ActionHandler.Spectate();
                    }
                    else if (this.playerBox.HoverItem.Button != null)
                    {
                        ActionHandler.JoinAllyTeam(this.playerBox.HoverItem.AllyTeam.Value);
                    }
                }
            }

            if (mea.Button == MouseButtons.Right || !Program.Conf.LeftClickSelectsPlayer)
            {
                if (this.playerBox.HoverItem == null && mea.Button == MouseButtons.Right)
                { //right click on empty space
                    var cm = ContextMenus.GetPlayerContextMenu(Program.TasClient.MyUser, true);
                    Program.ToolTip.Visible = false;
                    try
                    {
                        cm.Show(playerBox, mea.Location);
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("Error displaying tooltip: {0}", ex);
                    }
                    finally
                    {
                        Program.ToolTip.Visible = true;
                    }
                    return;
                }
                //NOTE: code that display player's context menu on Left-mouse-click is in ChatControl.playerBox_MouseClick();
            }
            if (this.playerBox.HoverItem != null)
            {
                if (this.playerBox.HoverItem.BotBattleStatus != null)
                {
                    playerBox.SelectedItem = this.playerBox.HoverItem;
                    var cm = ContextMenus.GetBotContextMenu(this.playerBox.HoverItem.BotBattleStatus.Name);
                    Program.ToolTip.Visible = false;
                    try
                    {
                        cm.Show(playerBox, mea.Location);
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("Error displaying tooltip: {0}", ex);
                    }
                    finally
                    {
                        Program.ToolTip.Visible = true;
                    }
                    return;
                }

                /*
                 *                      if (playerBox.HoverItem.UserBattleStatus != null) {
                 *                              playerBox.SelectedItem = playerBox.HoverItem;
                 *                              var cm = ContextMenus.GetPlayerContextMenu(playerBox.HoverItem.User, true);
                 *                              Program.ToolTip.Visible = false;
                 *                              cm.Show(playerBox, mea.Location);
                 *                              Program.ToolTip.Visible = true;
                 *                      }*/
            }
            base.PlayerBox_MouseClick(sender, mea);
        }
示例#12
0
        public void AddTab(string name, string title, Control control, Image icon, string tooltip, int sortImportance)
        {
            bool isPrivateTab = control is PrivateMessageControl;

            name = isPrivateTab ? (name + "_pm") : (name + "_chan");
            var button = new ToolStripButton(name, icon)
            {
                Name        = name,
                Alignment   = ToolStripItemAlignment.Left,
                TextAlign   = ContentAlignment.MiddleLeft,
                ImageAlign  = ContentAlignment.MiddleLeft,
                AutoToolTip = false,
                ToolTipText = tooltip,
                Tag         = sortImportance,
                Text        = title,
            };

            if (control is BattleChatControl)
            {
                button.Height = button.Height * 2;
            }
            button.MouseEnter += button_MouseEnter;
            button.MouseLeave += button_MouseLeave;
            button.MouseDown  += (s, e) =>
            {
                if (e.Button == MouseButtons.Right)
                {
                    var point = new Point(button.Bounds.Location.X + e.X, button.Bounds.Location.Y + e.Y);
                    try {
                        Program.ToolTip.Visible = false;
                        if (control is ChatControl)
                        {
                            ContextMenus.GetChannelContextMenu((ChatControl)control).Show(toolStrip, point);
                        }
                        else if (control is PrivateMessageControl)
                        {
                            ContextMenus.GetPrivateMessageContextMenu((PrivateMessageControl)control).Show(toolStrip, point);
                        }
                    } catch (Exception ex) {
                        Trace.TraceError("Error displaying tooltip:{0}", ex);
                    } finally {
                        Program.ToolTip.Visible = true;
                    }
                }
                else if (e.Button == MouseButtons.Middle)
                {
                    if (control is ChatControl)
                    {
                        var chatControl = (ChatControl)control;
                        if (chatControl.CanLeave)
                        {
                            Program.TasClient.LeaveChannel(chatControl.ChannelName);
                        }
                    }
                    else if (control is PrivateMessageControl)
                    {
                        var chatControl = (PrivateMessageControl)control;
                        ActionHandler.ClosePrivateChat(chatControl.UserName);
                    }
                }
            };

            var added          = false;
            var insertItemText = sortImportance + Name;

            for (var i = 0; i < toolStrip.Items.Count; i++)
            {
                var existingItemText = (int)toolStrip.Items[i].Tag + toolStrip.Items[i].Text;
                if (String.Compare(existingItemText, insertItemText) < 0)
                {
                    toolStrip.Items.Insert(i, button);
                    added = true;
                    break;
                }
            }
            if (!added)
            {
                toolStrip.Items.Add(button);
            }

            button.Click += (s, e) =>
            {
                try
                {
                    if (control is BattleChatControl)
                    {
                        NavigationControl.Instance.Path = "chat/battle";
                    }
                    else
                    if (control is PrivateMessageControl)
                    {
                        var pmControl = (PrivateMessageControl)control;
                        var userName  = pmControl.UserName;
                        NavigationControl.Instance.Path = "chat/user/" + userName;
                    }
                    else
                    if (control is ChatControl)
                    {
                        var chatControl = (ChatControl)control;
                        var channelName = chatControl.ChannelName;
                        NavigationControl.Instance.Path = "chat/channel/" + channelName;
                    }
                } catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            };
            control.Dock    = DockStyle.Fill;
            control.Visible = false;
            controls.Add(name, control);
            panel.Controls.Add(control);
        }