/*************************************************************************** * ContextMenu.cs * ------------------- * begin : May 1, 2002 * copyright : (C) The RunUO Software Team * email : info@runuo.com * * $Id$ * ***************************************************************************/ /*************************************************************************** * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * ***************************************************************************/ using System.Collections.Generic; namespace Server.ContextMenus { /// /// Represents the state of an active context menu. This includes who opened the menu, the menu's focus object, and a list of entries that the menu is composed of. /// /// public class ContextMenu { private Mobile m_From; private object m_Target; private ContextMenuEntry[] m_Entries; /// /// Gets the who opened this ContextMenu. /// public Mobile From => m_From; /// /// Gets an object of the or for which this ContextMenu is on. /// public object Target => m_Target; /// /// Gets the list of entries contained in this ContextMenu. /// public ContextMenuEntry[] Entries => m_Entries; /// /// Instantiates a new ContextMenu instance. /// /// /// The who opened this ContextMenu. /// /// /// /// The or for which this ContextMenu is on. /// /// public ContextMenu( Mobile from, object target ) { m_From = from; m_Target = target; List list = new List(); if ( target is Mobile mobile ) { mobile.GetContextMenuEntries( from, list ); } else if ( target is Item item ) { item.GetContextMenuEntries( from, list ); } //m_Entries = (ContextMenuEntry[])list.ToArray( typeof( ContextMenuEntry ) ); m_Entries = list.ToArray(); for ( int i = 0; i < m_Entries.Length; ++i ) { m_Entries[i].Owner = this; } } /// /// Returns true if this ContextMenu requires packet version 2. /// public bool RequiresNewPacket { get { for ( int i = 0; i < m_Entries.Length; ++i ) { if ( m_Entries[i].Number < 3000000 || m_Entries[i].Number > 3032767 ) return true; } return false; } } } }