55using Intersect . Client . Framework . Gwen ;
66using Intersect . Client . Framework . Gwen . Control ;
77using Intersect . Client . Framework . Gwen . Control . EventArguments ;
8+ using Intersect . Client . Framework . Gwen . ControlInternal ;
89using Intersect . Client . Framework . Gwen . Input ;
910using Intersect . Client . Framework . Input ;
1011using Intersect . Client . General ;
1112using Intersect . Client . Localization ;
1213using Intersect . Client . Networking ;
1314using Intersect . Enums ;
1415using Intersect . Framework . Core ;
15- using Intersect . Utilities ;
1616
1717namespace Intersect . Client . Interface . Game ;
1818
1919/// <summary>
2020/// The GUI class for the Target Context Menu that pop up on-screen during gameplay.
2121/// </summary>
22- public sealed partial class TargetContextMenu : Framework . Gwen . Control . Menu
22+ public sealed partial class TargetContextMenu : ContextMenu
2323{
2424 private readonly MenuItem _targetNameMenuItem ;
25+ private readonly MenuDivider _nameDivider ;
2526 private readonly MenuItem _tradeMenuItem ;
2627 private readonly MenuItem _partyMenuItem ;
2728 private readonly MenuItem _friendMenuItem ;
@@ -39,8 +40,11 @@ public TargetContextMenu(Canvas gameCanvas) : base(gameCanvas, nameof(TargetCont
3940 _me = Globals . Me ;
4041
4142 _targetNameMenuItem = AddItem ( string . Empty ) ;
42- _targetNameMenuItem . MouseInputEnabled = false ;
43- AddDivider ( ) ;
43+ _nameDivider = new MenuDivider ( this )
44+ {
45+ Dock = Pos . Top ,
46+ MinimumSize = new Point ( 0 , 1 ) ,
47+ } ;
4448
4549 _tradeMenuItem = AddItem ( Strings . EntityContextMenu . Trade ) ;
4650 _tradeMenuItem . Clicked += tradeRequest_Clicked ;
@@ -58,6 +62,7 @@ public TargetContextMenu(Canvas gameCanvas) : base(gameCanvas, nameof(TargetCont
5862 _privateMessageMenuItem . Clicked += privateMessageRequest_Clicked ;
5963
6064 LoadJsonUi ( GameContentManager . UI . InGame , Graphics . Renderer ? . GetResolutionString ( ) ) ;
65+ BuildContextMenu ( ) ;
6166 }
6267
6368 public void ToggleHidden ( object ? target )
@@ -119,11 +124,9 @@ public void ToggleHidden(object? target)
119124 }
120125 }
121126
122-
123127 if ( IsHidden )
124128 {
125- TryShowTargetButton ( shouldShowTargetNameMenuItem ) ;
126- TryShowGuildButton ( ) ;
129+ BuildContextMenu ( shouldShowTargetNameMenuItem ) ;
127130 SizeToChildren ( ) ;
128131 Open ( Pos . None ) ;
129132 SetPosition ( newX , newY ) ;
@@ -134,28 +137,34 @@ public void ToggleHidden(object? target)
134137 }
135138 }
136139
137- private void TryShowTargetButton ( bool shouldShow )
140+ private void BuildContextMenu ( bool shouldShowTargetName = false )
138141 {
139- _targetNameMenuItem . SetText ( shouldShow ? _entity . Name : string . Empty ) ;
142+ ClearChildren ( ) ;
140143
141- if ( shouldShow )
144+ if ( shouldShowTargetName )
142145 {
143- var indexOf = IndexOf ( _targetNameMenuItem ) ;
146+ AddChild ( _targetNameMenuItem ) ;
147+ _targetNameMenuItem . SetText ( _entity ? . Name ?? string . Empty ) ;
148+ _targetNameMenuItem . MouseInputEnabled = false ;
149+ AddChild ( _nameDivider ) ;
150+ }
144151
145- if ( indexOf > 0 )
152+ AddChild ( _tradeMenuItem ) ;
153+ AddChild ( _partyMenuItem ) ;
154+ AddChild ( _friendMenuItem ) ;
155+
156+ if ( _entity is Player player )
157+ {
158+ if ( player != _me && string . IsNullOrWhiteSpace ( player . Guild ) && ( _me ? . GuildRank ? . Permissions ? . Invite ?? false ) )
146159 {
147- RemoveAt ( indexOf ) ;
160+ AddChild ( _guildMenuItem ) ;
148161 }
149162
150- if ( indexOf != 0 )
163+ if ( player != _me )
151164 {
152- Insert ( 0 , _targetNameMenuItem ) ;
165+ AddChild ( _privateMessageMenuItem ) ;
153166 }
154167 }
155- else
156- {
157- Remove ( _targetNameMenuItem ) ;
158- }
159168 }
160169
161170 void invite_Clicked ( Base sender , MouseButtonState arguments )
@@ -247,31 +256,4 @@ void privateMessageRequest_Clicked(Base sender, MouseButtonState arguments)
247256
248257 Interface . GameUi . SetChatboxText ( $ "/pm { _entity . Name } ") ;
249258 }
250-
251- void TryShowGuildButton ( )
252- {
253- var shouldShow = false ;
254- if ( _entity is Player plyr && _entity != _me && string . IsNullOrWhiteSpace ( plyr . Guild ) )
255- {
256- if ( _me ? . GuildRank ? . Permissions ? . Invite ?? false )
257- {
258- shouldShow = true ;
259- }
260- }
261-
262- if ( shouldShow )
263- {
264- if ( ! Children . Contains ( _guildMenuItem ) )
265- {
266- AddChild ( _guildMenuItem ) ;
267- }
268- }
269- else
270- {
271- if ( Children . Contains ( _guildMenuItem ) )
272- {
273- Remove ( _guildMenuItem ) ;
274- }
275- }
276- }
277259}
0 commit comments