-
Notifications
You must be signed in to change notification settings - Fork 380
fix crash when open target context menu #2618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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), | ||
| Height = 1, | ||
|
||
| MinimumSize = new Point(0, 1), | ||
| }; | ||
|
|
||
| _tradeMenuItem = AddItem(Strings.EntityContextMenu.Trade); | ||
| _tradeMenuItem.Clicked += tradeRequest_Clicked; | ||
|
|
@@ -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) | ||
|
|
@@ -119,11 +126,9 @@ public void ToggleHidden(object? target) | |
| } | ||
| } | ||
|
|
||
|
|
||
| if (IsHidden) | ||
| { | ||
| TryShowTargetButton(shouldShowTargetNameMenuItem); | ||
| TryShowGuildButton(); | ||
| _buildContextMenu(shouldShowTargetNameMenuItem); | ||
| SizeToChildren(); | ||
| Open(Pos.None); | ||
| SetPosition(newX, newY); | ||
|
|
@@ -134,27 +139,33 @@ public void ToggleHidden(object? target) | |
| } | ||
| } | ||
|
|
||
| private void TryShowTargetButton(bool shouldShow) | ||
| private void _buildContextMenu(bool shouldShowTargetName = false) | ||
|
||
| { | ||
| _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); | ||
|
||
| } | ||
| } | ||
|
|
||
|
|
@@ -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); | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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?