#region References
using System;
using Server.Network;
#endregion
namespace Server.ContextMenus
{
///
/// Represents a single entry of a context menu.
///
///
public class ContextMenuEntry : IDisposable
{
public bool IsDisposed { get; private set; }
///
/// Gets or sets additional flags used in client communication.
///
public CMEFlags Flags { get; set; }
///
/// Gets or sets the that owns this entry.
///
public ContextMenu Owner { get; set; }
///
/// Gets or sets the localization number containing the name of this entry.
///
public int Number { get; set; }
///
/// Gets or sets the maximum range at which this entry may be used, in tiles. A value of -1 signifies no maximum range.
///
public int Range { get; set; }
///
/// Gets or sets the color for this entry. Format is A1-R5-G5-B5.
///
public int Color { get; set; }
///
/// Gets or sets whether this entry is enabled. When false, the entry will appear in a gray hue and will never be invoked.
///
public bool Enabled { get; set; }
///
/// Gets a value indicating if non local use of this entry is permitted.
///
public virtual bool NonLocalUse => false;
///
/// Instantiates a new ContextMenuEntry with a given localization number (
///
/// ). No maximum range is used.
///
///
/// The localization number containing the name of this entry.
///
///
public ContextMenuEntry(int number)
: this(number, -1)
{ }
///
/// Instantiates a new ContextMenuEntry with a given localization number (
///
/// ) and maximum range ().
///
///
/// The localization number containing the name of this entry.
///
///
///
/// The maximum range at which this entry can be used.
///
///
public ContextMenuEntry(int number, int range)
{
if (number <= 0x7FFF) // Legacy code support
{
Number = 3000000 + number;
}
else
{
Number = number;
}
Range = range;
Enabled = true;
Color = 0xFFFF;
}
~ContextMenuEntry()
{
Dispose();
}
///
/// Overridable. Virtual event invoked when the entry is clicked.
///
public virtual void OnClick()
{ }
///
/// Overridable. Virtual event invoked when the entry is clicked and the entry is disabled.
///
public virtual void OnClickDisabled()
{ }
public void Dispose()
{
if (IsDisposed)
{
return;
}
IsDisposed = true;
OnDispose();
if (Owner != null && Owner.Entries != null)
{
for (var i = 0; i < Owner.Entries.Length; i++)
{
if (Owner.Entries[i] == this)
{
Owner.Entries[i] = null;
}
}
}
Owner = null;
}
protected virtual void OnDispose()
{ }
}
}