Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 30 additions & 46 deletions Intersect.Client.Core/Interface/Game/TargetContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@
using Intersect.Client.Framework.Gwen;
using Intersect.Client.Framework.Gwen.Control;
using Intersect.Client.Framework.Gwen.Control.EventArguments;
using Intersect.Client.Framework.Gwen.ControlInternal;
using Intersect.Client.Framework.Gwen.Input;
using Intersect.Client.Framework.Input;
using Intersect.Client.General;
using Intersect.Client.Localization;
using Intersect.Client.Networking;
using Intersect.Enums;
using Intersect.Framework.Core;
using Intersect.Utilities;

namespace Intersect.Client.Interface.Game;

/// <summary>
/// The GUI class for the Target Context Menu that pop up on-screen during gameplay.
/// </summary>
public sealed partial class TargetContextMenu : Framework.Gwen.Control.Menu
public sealed partial class TargetContextMenu : ContextMenu
{
private readonly MenuItem _targetNameMenuItem;
private readonly MenuDivider _nameDivider;
private readonly MenuItem _tradeMenuItem;
private readonly MenuItem _partyMenuItem;
private readonly MenuItem _friendMenuItem;
Expand All @@ -39,8 +40,13 @@ public TargetContextMenu(Canvas gameCanvas) : base(gameCanvas, nameof(TargetCont
_me = Globals.Me;

_targetNameMenuItem = AddItem(string.Empty);
_targetNameMenuItem.MouseInputEnabled = false;
AddDivider();
_nameDivider = new MenuDivider(this)
{
Dock = Pos.Top,
Margin = new Margin(IconMarginDisabled ? 0 : 24, 0, 4, 0),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does a divider have a margin?

Height = 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary when MinimumSize will already control this

MinimumSize = new Point(0, 1),
};

_tradeMenuItem = AddItem(Strings.EntityContextMenu.Trade);
_tradeMenuItem.Clicked += tradeRequest_Clicked;
Expand All @@ -58,6 +64,7 @@ public TargetContextMenu(Canvas gameCanvas) : base(gameCanvas, nameof(TargetCont
_privateMessageMenuItem.Clicked += privateMessageRequest_Clicked;

LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer?.GetResolutionString());
_buildContextMenu();
}

public void ToggleHidden(object? target)
Expand Down Expand Up @@ -119,11 +126,9 @@ public void ToggleHidden(object? target)
}
}


if (IsHidden)
{
TryShowTargetButton(shouldShowTargetNameMenuItem);
TryShowGuildButton();
_buildContextMenu(shouldShowTargetNameMenuItem);
SizeToChildren();
Open(Pos.None);
SetPosition(newX, newY);
Expand All @@ -134,27 +139,33 @@ public void ToggleHidden(object? target)
}
}

private void TryShowTargetButton(bool shouldShow)
private void _buildContextMenu(bool shouldShowTargetName = false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call it BuildContextMenu

{
_targetNameMenuItem.SetText(shouldShow ? _entity.Name : string.Empty);
ClearChildren();

if (shouldShow)
if (shouldShowTargetName)
{
var indexOf = IndexOf(_targetNameMenuItem);
AddChild(_targetNameMenuItem);
_targetNameMenuItem.SetText(_entity?.Name ?? string.Empty);
_targetNameMenuItem.MouseInputEnabled = false;
AddChild(_nameDivider);
}

if (indexOf > 0)
{
RemoveAt(indexOf);
}
AddChild(_tradeMenuItem);
AddChild(_partyMenuItem);
AddChild(_friendMenuItem);

if (indexOf != 0)
if (_entity is Player player && player != _me && string.IsNullOrWhiteSpace(player.Guild))
{
if (_me?.GuildRank?.Permissions?.Invite ?? false)
{
Insert(0, _targetNameMenuItem);
AddChild(_guildMenuItem);
}
}
else

if (_entity is Player plyr && plyr != _me)
{
Remove(_targetNameMenuItem);
AddChild(_privateMessageMenuItem);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_entity shouldn't be checked if it's a player twice

}
}

Expand Down Expand Up @@ -247,31 +258,4 @@ void privateMessageRequest_Clicked(Base sender, MouseButtonState arguments)

Interface.GameUi.SetChatboxText($"/pm {_entity.Name} ");
}

void TryShowGuildButton()
{
var shouldShow = false;
if (_entity is Player plyr && _entity != _me && string.IsNullOrWhiteSpace(plyr.Guild))
{
if (_me?.GuildRank?.Permissions?.Invite ?? false)
{
shouldShow = true;
}
}

if (shouldShow)
{
if (!Children.Contains(_guildMenuItem))
{
AddChild(_guildMenuItem);
}
}
else
{
if (Children.Contains(_guildMenuItem))
{
Remove(_guildMenuItem);
}
}
}
}
Loading