fix: Moves ContextMenu out of core, streamlines code, fixes bugs (#1873)
## Summary - Removes allocation of a `List<ContextMenuEntry>` every time a context menu is created. - Moves packet/context menu creation logic out of the core - Fixes tame entry ## BREAKING CHANGE > [!Important] > **Developer Note** > ```cs > public virtual void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) > ``` > and similar functions changed to > ```cs > public virtual void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list) > ```
This commit is contained in:
parent
bb24b330e1
commit
f58117a877
88 changed files with 1206 additions and 1483 deletions
|
|
@ -4296,13 +4296,8 @@ namespace Server.Multis
|
|||
|
||||
public class SetSecureLevelEntry : ContextMenuEntry
|
||||
{
|
||||
private readonly Item m_Item;
|
||||
private ISecurable m_Securable;
|
||||
|
||||
public SetSecureLevelEntry(Item item, ISecurable securable) : base(6203, 6)
|
||||
public SetSecureLevelEntry() : base(6203, 6)
|
||||
{
|
||||
m_Item = item;
|
||||
m_Securable = securable;
|
||||
}
|
||||
|
||||
public static ISecurable GetSecurable(Mobile from, Item item)
|
||||
|
|
@ -4314,8 +4309,6 @@ namespace Server.Multis
|
|||
return null;
|
||||
}
|
||||
|
||||
ISecurable sec = null;
|
||||
|
||||
if (item is ISecurable securable)
|
||||
{
|
||||
var isOwned = item is BaseDoor door && house.Doors.Contains(door);
|
||||
|
|
@ -4332,45 +4325,50 @@ namespace Server.Multis
|
|||
|
||||
if (isOwned)
|
||||
{
|
||||
sec = securable;
|
||||
return securable;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var list = house.Secures;
|
||||
|
||||
for (var i = 0; sec == null && i < list?.Count; ++i)
|
||||
for (var i = 0; i < list?.Count; ++i)
|
||||
{
|
||||
var si = list[i];
|
||||
|
||||
if (si.Item == item)
|
||||
{
|
||||
sec = si;
|
||||
return si;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sec;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void AddTo(Mobile from, Item item, List<ContextMenuEntry> list)
|
||||
public static void AddTo(Mobile from, Item item, ref PooledRefList<ContextMenuEntry> list)
|
||||
{
|
||||
var sec = GetSecurable(from, item);
|
||||
|
||||
if (sec != null)
|
||||
{
|
||||
list.Add(new SetSecureLevelEntry(item, sec));
|
||||
list.Add(new SetSecureLevelEntry());
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnClick()
|
||||
public override void OnClick(Mobile from, IEntity target)
|
||||
{
|
||||
var sec = GetSecurable(Owner.From, m_Item);
|
||||
if (target is not Item item)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var sec = GetSecurable(from, item);
|
||||
|
||||
if (sec != null)
|
||||
{
|
||||
Owner.From.CloseGump<SetSecureLevelGump>();
|
||||
Owner.From.SendGump(new SetSecureLevelGump(Owner.From, sec, BaseHouse.FindHouseAt(m_Item)));
|
||||
from.CloseGump<SetSecureLevelGump>();
|
||||
from.SendGump(new SetSecureLevelGump(from, sec, BaseHouse.FindHouseAt(item)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue