Skip to content

Commit 71c39ce

Browse files
committed
enhancement: player context menu
- extracts player context menu out of EntityBox.cs - (new) feature: allows to right-click players in order to view player's context menu! - (new) player context menu item: private message!
1 parent b82ddf4 commit 71c39ce

File tree

5 files changed

+291
-158
lines changed

5 files changed

+291
-158
lines changed

Intersect.Client.Core/Entities/Player.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Intersect.Client.Entities.Projectiles;
55
using Intersect.Client.Framework.Entities;
66
using Intersect.Client.Framework.GenericClasses;
7+
using Intersect.Client.Framework.Input;
78
using Intersect.Client.Framework.Items;
89
using Intersect.Client.General;
910
using Intersect.Client.Interface.Game.Chat;
@@ -1720,6 +1721,14 @@ private void AutoTurnToTarget(Entity en)
17201721
PickLastDirection(Dir);
17211722
}
17221723

1724+
private static void ToggleTargetContextMenu(Entity en)
1725+
{
1726+
if (Globals.InputManager.MouseButtonDown(MouseButtons.Right))
1727+
{
1728+
Interface.Interface.GameUi.TargetContextMenu.ToggleHidden(en);
1729+
}
1730+
}
1731+
17231732
public bool TryBlock()
17241733
{
17251734
var shieldIndex = Options.ShieldIndex;
@@ -2622,6 +2631,7 @@ public void DrawTargets()
26222631

26232632
en.Value.DrawTarget((int)Enums.TargetType.Selected);
26242633
AutoTurnToTarget(en.Value);
2634+
ToggleTargetContextMenu(en.Value);
26252635
}
26262636

26272637
foreach (MapInstance eventMap in Maps.MapInstance.Lookup.Values.Cast<MapInstance>())
@@ -2660,6 +2670,7 @@ public void DrawTargets()
26602670

26612671
en.Value.DrawTarget((int)Enums.TargetType.Selected);
26622672
AutoTurnToTarget(en.Value);
2673+
ToggleTargetContextMenu(en.Value);
26632674
}
26642675
}
26652676

@@ -2693,6 +2704,7 @@ public void DrawTargets()
26932704
if (TargetType != 0 || TargetIndex != en.Value.Id)
26942705
{
26952706
en.Value.DrawTarget((int)Enums.TargetType.Hover);
2707+
ToggleTargetContextMenu(en.Value);
26962708
}
26972709
}
26982710
}
@@ -2717,6 +2729,7 @@ public void DrawTargets()
27172729
if (TargetType != 1 || TargetIndex != en.Value.Id)
27182730
{
27192731
en.Value.DrawTarget((int)Enums.TargetType.Hover);
2732+
ToggleTargetContextMenu(en.Value);
27202733
}
27212734
}
27222735
}

Intersect.Client.Core/Interface/Game/EntityPanel/EntityBox.cs

Lines changed: 3 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
using Intersect.Client.Framework.File_Management;
55
using Intersect.Client.Framework.Gwen;
66
using Intersect.Client.Framework.Gwen.Control;
7-
using Intersect.Client.Framework.Gwen.Control.EventArguments;
87
using Intersect.Client.General;
98
using Intersect.Client.Localization;
10-
using Intersect.Client.Networking;
119
using Intersect.Configuration;
1210
using Intersect.Enums;
1311
using Intersect.GameObjects;
@@ -96,20 +94,8 @@ public partial class EntityBox
9694

9795
public bool ShouldUpdateStatuses;
9896

99-
public bool IsHidden;
100-
10197
// Context menu
102-
private Button _contextMenuButton;
103-
104-
private Framework.Gwen.Control.Menu _contextMenu;
105-
106-
private MenuItem _tradeMenuItem;
107-
108-
private MenuItem _partyMenuItem;
109-
110-
private MenuItem _friendMenuItem;
111-
112-
private MenuItem _guildMenuItem;
98+
private readonly Button _contextMenuButton;
11399

114100
//Init
115101
public EntityBox(Canvas gameCanvas, EntityType entityType, Entity? myEntity, bool isPlayerBox = false)
@@ -180,35 +166,10 @@ public EntityBox(Canvas gameCanvas, EntityType entityType, Entity? myEntity, boo
180166
// Target context menu with basic options.
181167
if (!_isPlayerBox)
182168
{
183-
_contextMenu = new Framework.Gwen.Control.Menu(gameCanvas, "TargetContextMenu")
184-
{
185-
IsHidden = true,
186-
IconMarginDisabled = true
187-
};
188-
189-
_contextMenu.Children.Clear();
190-
191-
_tradeMenuItem = _contextMenu.AddItem(Strings.EntityBox.Trade);
192-
_tradeMenuItem.Clicked += tradeRequest_Clicked;
193-
194-
_partyMenuItem = _contextMenu.AddItem(Strings.EntityBox.Party);
195-
_partyMenuItem.Clicked += invite_Clicked;
196-
197-
_friendMenuItem = _contextMenu.AddItem(Strings.EntityBox.Friend);
198-
_friendMenuItem.Clicked += friendRequest_Clicked;
199-
200-
_guildMenuItem = _contextMenu.AddItem(Strings.Guilds.Guild);
201-
_guildMenuItem.Clicked += guildRequest_Clicked;
202-
203-
_contextMenu.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());
204-
205169
_contextMenuButton = new Button(EntityInfoPanel, "ContextMenuButton");
206-
_contextMenuButton.Clicked += (sender, e) =>
170+
_contextMenuButton.Clicked += (_, _) =>
207171
{
208-
_contextMenu.SizeToChildren();
209-
_contextMenu.Open(Pos.None);
210-
_contextMenu.SetPosition(_contextMenuButton.LocalPosToCanvas(new Point(0, 0)).X,
211-
_contextMenuButton.LocalPosToCanvas(new Point(0, 0)).Y + _contextMenuButton.Height);
172+
Interface.GameUi.TargetContextMenu.ToggleHidden(_contextMenuButton);
212173
};
213174

214175
EntityStatusWindow = new ImagePanel(EntityWindow, "EntityStatusWindow");
@@ -283,7 +244,6 @@ public void ShowAllElements()
283244

284245
if (!_isPlayerBox)
285246
{
286-
TryShowGuildButton();
287247
_contextMenuButton.Show();
288248
EventDesc.Show();
289249
}
@@ -417,15 +377,13 @@ public void Update()
417377
//Update the event/entity face.
418378
UpdateImage();
419379

420-
IsHidden = true;
421380
if (EntityType != EntityType.Event)
422381
{
423382
EntityName.SetText(MyEntity.Name);
424383
UpdateLevel();
425384
UpdateMap();
426385
UpdateHpBar(elapsedTime);
427386
UpdateMpBar(elapsedTime);
428-
IsHidden = false;
429387
}
430388
else
431389
{
@@ -449,7 +407,6 @@ public void Update()
449407
}
450408
else if (_contextMenuButton.IsHidden && !_isPlayerBox)
451409
{
452-
TryShowGuildButton();
453410
_contextMenuButton.Show();
454411
}
455412
}
@@ -938,108 +895,6 @@ public void Dispose()
938895
EntityWindow.Dispose();
939896
}
940897

941-
//Input Handlers
942-
void invite_Clicked(Base sender, ClickedEventArgs arguments)
943-
{
944-
if (Globals.Me.TargetIndex != Guid.Empty && Globals.Me.TargetIndex != Globals.Me.Id)
945-
{
946-
if (Globals.Me.CombatTimer < Timing.Global.Milliseconds)
947-
{
948-
PacketSender.SendPartyInvite(Globals.Me.TargetIndex);
949-
}
950-
else
951-
{
952-
PacketSender.SendChatMsg(Strings.Parties.InFight.ToString(), 4);
953-
}
954-
}
955-
}
956-
957-
//Input Handlers
958-
void tradeRequest_Clicked(Base sender, ClickedEventArgs arguments)
959-
{
960-
if (Globals.Me.TargetIndex != Guid.Empty && Globals.Me.TargetIndex != Globals.Me.Id)
961-
{
962-
if (Globals.Me.CombatTimer < Timing.Global.Milliseconds)
963-
{
964-
PacketSender.SendTradeRequest(Globals.Me.TargetIndex);
965-
}
966-
else
967-
{
968-
PacketSender.SendChatMsg(Strings.Trading.InFight.ToString(), 4);
969-
}
970-
}
971-
}
972-
973-
//Input Handlers
974-
void friendRequest_Clicked(Base sender, ClickedEventArgs arguments)
975-
{
976-
if (Globals.Me.TargetIndex != Guid.Empty && Globals.Me.TargetIndex != Globals.Me.Id)
977-
{
978-
if (Globals.Me.CombatTimer < Timing.Global.Milliseconds)
979-
{
980-
PacketSender.SendAddFriend(MyEntity.Name);
981-
}
982-
else
983-
{
984-
PacketSender.SendChatMsg(Strings.Friends.InFight.ToString(), 4);
985-
}
986-
}
987-
}
988-
989-
990-
void guildRequest_Clicked(Base sender, ClickedEventArgs arguments)
991-
{
992-
if (MyEntity is Player plyr && MyEntity != Globals.Me)
993-
{
994-
if (string.IsNullOrWhiteSpace(plyr.Guild))
995-
{
996-
if (Globals.Me?.GuildRank?.Permissions?.Invite ?? false)
997-
{
998-
if (Globals.Me.CombatTimer < Timing.Global.Milliseconds)
999-
{
1000-
PacketSender.SendInviteGuild(MyEntity.Name);
1001-
}
1002-
else
1003-
{
1004-
PacketSender.SendChatMsg(Strings.Friends.InFight.ToString(), 4);
1005-
}
1006-
}
1007-
}
1008-
else
1009-
{
1010-
Chat.ChatboxMsg.AddMessage(new Chat.ChatboxMsg(Strings.Guilds.InviteAlreadyInGuild, Color.Red, ChatMessageType.Guild));
1011-
}
1012-
}
1013-
}
1014-
1015-
void TryShowGuildButton()
1016-
{
1017-
var shouldShow = false;
1018-
if (MyEntity is Player plyr && MyEntity != Globals.Me && string.IsNullOrWhiteSpace(plyr.Guild))
1019-
{
1020-
if (Globals.Me?.GuildRank?.Permissions?.Invite ?? false)
1021-
{
1022-
shouldShow = true;
1023-
}
1024-
}
1025-
1026-
if (shouldShow)
1027-
{
1028-
if (!_contextMenu.Children.Contains(_guildMenuItem))
1029-
{
1030-
_contextMenu.Children.Add(_guildMenuItem);
1031-
}
1032-
}
1033-
else
1034-
{
1035-
if (_contextMenu.Children.Contains(_guildMenuItem))
1036-
{
1037-
_contextMenu.Children.Remove(_guildMenuItem);
1038-
}
1039-
}
1040-
}
1041-
1042-
1043898
public void Hide()
1044899
{
1045900
EntityWindow.Hide();

Intersect.Client.Core/Interface/Game/GameInterface.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public GameInterface(Canvas canvas) : base(canvas)
9494
GameCanvas = canvas;
9595
EscapeMenu = new EscapeMenu(GameCanvas) {IsHidden = true};
9696
SimplifiedEscapeMenu = new SimplifiedEscapeMenu(GameCanvas) {IsHidden = true};
97+
TargetContextMenu = new TargetContextMenu(GameCanvas) {IsHidden = true};
9798
AnnouncementWindow = new AnnouncementWindow(GameCanvas) { IsHidden = true };
9899

99100
InitGameGui();
@@ -102,9 +103,11 @@ public GameInterface(Canvas canvas) : base(canvas)
102103
public Canvas GameCanvas { get; }
103104

104105
public EscapeMenu EscapeMenu { get; }
105-
106+
106107
public SimplifiedEscapeMenu SimplifiedEscapeMenu { get; }
107108

109+
public TargetContextMenu TargetContextMenu { get; }
110+
108111
public AnnouncementWindow AnnouncementWindow { get; }
109112

110113
public Menu GameMenu { get; private set; }

0 commit comments

Comments
 (0)