Exemple #1
0
        private void MouseUpHandler(object sender, MouseEventArgs e)
        {
            if (!this.IsHitTestVisible)
            {
                return;
            }

            var menuItems     = new List <MenuItem>();
            var chatEntryFrom = this.viewModel.ChatEntry.From;

            var canMentionOrSendPrivateMessage =
                this.viewModel.VisibilityCanMentionOrSendPrivateMessage == Visibility.Visible;

            if (canMentionOrSendPrivateMessage)
            {
                menuItems.Add(
                    new MenuItem()
                {
                    Header  = CoreStrings.Chat_MessageMenu_Mention,
                    Command = this.viewModel.CommandMention
                });
            }

            menuItems.Add(
                new MenuItem()
            {
                Header  = CoreStrings.Copy,
                Command = this.viewModel.CommandCopy
            });

            if (!string.IsNullOrEmpty(this.viewModel.ChatEntry.From))
            {
                menuItems.Add(
                    new MenuItem()
                {
                    Header  = CoreStrings.Chat_MessageMenu_CopyName,
                    Command = this.viewModel.CommandCopyName
                });
            }

            if (canMentionOrSendPrivateMessage)
            {
                menuItems.Add(
                    new MenuItem()
                {
                    Header  = CoreStrings.Chat_MessageMenu_PrivateMessage,
                    Command = this.viewModel.CommandOpenPrivateChat
                });
            }

            if (PartySystem.ClientCanInvite(chatEntryFrom))
            {
                menuItems.Add(
                    new MenuItem()
                {
                    Header  = CoreStrings.Chat_MessageMenu_InviteToParty,
                    Command = this.viewModel.CommandInviteToParty
                });
            }

            if (FactionSystem.ClientCanInviteToFaction(chatEntryFrom))
            {
                menuItems.Add(
                    new MenuItem()
                {
                    Header  = CoreStrings.Faction_InviteToFaction,
                    Command = this.viewModel.CommandInviteToFaction
                });
            }

            if (this.viewModel.VisibilityCanBlock == Visibility.Visible)
            {
                menuItems.Add(
                    new MenuItem()
                {
                    Header  = CoreStrings.Chat_MessageMenu_Block,
                    Command = this.viewModel.CommandToggleBlock
                });

                menuItems.Add(
                    new MenuItem()
                {
                    Header  = CoreStrings.Chat_MessageMenu_Report,
                    Command = this.viewModel.CommandReport
                });
            }

            if (this.viewModel.VisibilityCanUnblock == Visibility.Visible)
            {
                menuItems.Add(
                    new MenuItem()
                {
                    Header  = CoreStrings.Chat_MessageMenu_Unblock,
                    Command = this.viewModel.CommandToggleBlock
                });
            }

            ClientContextMenuHelper.ShowMenuOnClick(this, menuItems);
        }
Exemple #2
0
        private void MouseUpHandler(object sender, MouseEventArgs e)
        {
            var contextMenu = this.ContextMenu;

            if (contextMenu is not null &&
                contextMenu.IsOpen)
            {
                // close current context menu
                contextMenu.IsOpen = false;
                this.ContextMenu   = null;
                return;
            }

            if (lastContextMenuCloseFrameTime + 0.2 >= Api.Client.Core.ClientRealTime)
            {
                // just closed a context menu
                return;
            }

            // create new context menu
            contextMenu = new ContextMenu();
            var contextMenuItems = contextMenu.Items;

            var viewModel     = (ViewModelPlayerEntry)this.DataContext;
            var characterName = viewModel.Name;

            contextMenuItems.Add(
                new MenuItem()
            {
                Header  = CoreStrings.Chat_MessageMenu_CopyName,
                Command = new ActionCommand(this.ExecuteCommandCopyName)
            });

            contextMenuItems.Add(
                new MenuItem()
            {
                Header  = CoreStrings.Chat_MessageMenu_PrivateMessage,
                Command = new ActionCommand(this.ExecuteCommandOpenPrivateChat)
            });

            if (PartySystem.ClientCanInvite(characterName))
            {
                contextMenuItems.Add(
                    new MenuItem()
                {
                    Header  = CoreStrings.Chat_MessageMenu_InviteToParty,
                    Command = new ActionCommand(this.ExecuteCommandInviteToParty)
                });
            }

            if (FactionSystem.ClientCanInviteToFaction(characterName))
            {
                contextMenuItems.Add(
                    new MenuItem()
                {
                    Header  = CoreStrings.Faction_InviteToFaction,
                    Command = new ActionCommand(this.ExecuteCommandInviteToFaction)
                });
            }

            contextMenuItems.Add(
                new MenuItem()
            {
                Header = viewModel.IsBlocked
                                 ? CoreStrings.Chat_MessageMenu_Unblock
                                 : CoreStrings.Chat_MessageMenu_Block,
                Command = viewModel.CommandToggleBlock
            });

            this.ContextMenu = contextMenu;

            contextMenu.Placement = PlacementMode.Relative;
            var target = sender as UIElement;

            contextMenu.PlacementTarget = target;
            var position = e.GetPosition(target);

            contextMenu.HorizontalOffset = position.X;
            contextMenu.VerticalOffset   = position.Y;
            contextMenu.IsOpen           = true;
            contextMenu.Closed          += this.ContextMenuClosedHandler;
        }