A Context Menu is pretty much a drop down menu of shortcuts.


This is the basic layout of a context menu to bring up "Buy"
Code:
    public class TestContext1 : ContextMenuEntry
     {
       private Item m_item;
       private Mobile m_player;

       public TestContext1( Mobile from, Item item ) : base( 6103, 2 )//buy
       {/* base( 6103, 2 ) = base( Cliloc, Range) */
         m_item = item;
         m_player = from;
         Enabled = true;
       }

       public override void OnClick()
       {
         m_player.SendMessage("Put Some 'Buy' functions in.");
       }
     }

And this is Clear
Code:
    public class TestContext2 : ContextMenuEntry
     {
       private Mobile m_player;
       private Item m_item;

       public TestContext2( Mobile from, Item item ) : base( 0154, 2 )//3000154 - Clear, Range 1
       {
         m_item = item;
         m_player = from;
         Enabled = true;
       }
       public override void OnClick()
       {
         if (m_player.AccessLevel == AccessLevel.Player)
         {
           m_player.SendMessage("Put some 'clear' finctions in.");
         }
         else
         {
           m_player.SendMessage("Since you are Staff, Put some Staff 'clear' functions here.");
         }
       }
     }

Together they bring up...
ai.imgur.com_ljVkS3W.png

In the item, to call on the context menu's you need this...
Code:
    public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list)
     {
       if ( from.Alive )
         list.Add(new TestContext1(from, this));
         list.Add(new TestContext2(from, this));
       base.GetContextMenuEntries( from, list );
     }

All together in an item you get a working item with a drop down menu on it.
Code:
using System;
using Server;
using Server.ContextMenus;
using System.Collections.Generic;

namespace Server.Items
{
  public class TestContextItem : Item
  {
  [Constructable]
  public TestContextItem() : base(0xED4)
  {
  this.Movable = false;
       this.Name = "Context Item";
  }

  public TestContextItem(Serial serial) : base(serial)
  {
  }
     
     public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list)
     {
       if ( from.Alive )
         list.Add(new TestContext1(from, this));
         list.Add(new TestContext2(from, this));
       base.GetContextMenuEntries( from, list );
     }

     public class TestContext1 : ContextMenuEntry
     {
       private Item m_item;
       private Mobile m_player;

       public TestContext1( Mobile from, Item item ) : base( 6103, 2 )//3006103 - Buy, Range 2
       {/* base( 6103, 2 ) = base( Cliloc, Range) */
         m_item = item;
         m_player = from;
         Enabled = true;
       }

       public override void OnClick()
       {
         m_player.SendMessage("Put Some 'Buy' functions in.");
       }
     }
     
     public class TestContext2 : ContextMenuEntry
     {
       private Mobile m_player;
       private Item m_item;

       public TestContext2( Mobile from, Item item ) : base( 0154, 2 )//3000154 - Clear, Range 2
       {
         m_item = item;
         m_player = from;
       }
       public override void OnClick()
       {
         if (m_player.AccessLevel == AccessLevel.Player)
         {
           m_player.SendMessage("Put some 'clear' finctions in.");
         }
         else
         {
           m_player.SendMessage("Since you are Staff, Put some Staff 'clear' functions here.");
         }
       }
     }

  public override void Serialize(GenericWriter writer)
  {
       base.Serialize(writer);
       writer.Write((int)0);
     }
  public override void Deserialize(GenericReader reader)
  {
       base.Deserialize(reader);
       int version = reader.ReadInt();
     }
  }
}
 
Back