View Full Version: Modification du [help

RunUO.FR Support > System > Modification du [help


Title: Modification du [help
Description: command help avec un menu


Usul - November 18, 2003 12:13 AM (GMT)
pour faciliter la lecture des diffenrentes commandes autrement que regarder dans son journal

CODE

using System;
using Server;
using System.Text;
using System.Collections;
using Server.Gumps;
using Server.Network;

namespace Server.Gumps
{
public class HelpCommandGump : Gump
{
       
        private int m_page;
        private int m_pagemax = -1;
        private ArrayList m_list;
        private string m_prefix;
        private const int const_NbAPage = 20;
       
 private void AddBlueBack( int width, int height )
 {
  AddBackground (  0,  0, width-00, height-00, 0xE10 );
  AddBackground (  8,  5, width-16, height-11, 0x053 );
  AddImageTiled ( 15, 14, width-29, height-29, 0xE14 );
  AddAlphaRegion( 15, 14, width-29, height-29 );
 }
 
 private void AddLigne(int number,ArrayList list)
 {
  StringBuilder sb = new StringBuilder();
  int col = 0;
  int lblcomw = 0;
  int lbldesw = 0;
  int lblcw = 0;
  int lbldw = 0;
  int deswmax = 0;
 
 
 
  for ( int c = number;( c < number+20 && c < list.Count); ++c )
  {
   string strc= m_prefix + ((CommandEntry)list[c]).Command;
   string strd = " ";

   object[] attrs = (((CommandEntry)list[c]).Handler.Method).GetCustomAttributes( typeof( DescriptionAttribute ), false );    
   if ( attrs.Length != 0 )
   {
    DescriptionAttribute dsc = attrs[0] as DescriptionAttribute;
   
    if ( dsc != null )
        strd = dsc.Description;
   }
   lblcw = (strc.Length*10);
   lbldw = (strd.Length*10);
   if ( lbldw >deswmax) deswmax = lbldw;
  }
  AddBlueBack( ((deswmax/5)*4)+120, 520 );
 
  AddLabelCropped( 20,15 , 150, 20 , 0x33 , "Commands List(" + Convert.ToString(m_pagemax)+") :");
  for ( int i = number;( i < number+20 && i < list.Count); ++i )
  {
   string strcommand = m_prefix + ((CommandEntry)list[i]).Command;
   string strdescrip = " ";

   object[] attrs = (((CommandEntry)list[i]).Handler.Method).GetCustomAttributes( typeof( DescriptionAttribute ), false );    
   if ( attrs.Length != 0 )
   {
    DescriptionAttribute desc = attrs[0] as DescriptionAttribute;
   
    if ( desc != null )
        strdescrip = desc.Description;
   }
   
   lblcomw = (strcommand.Length*10);
   lbldesw = (strdescrip.Length*10);
   
   ++col;
   AddButton( 20, (20*(col)+20), 0x4B9, 0x4BA,(i+3), GumpButtonType.Reply, 0 );
          AddLabelCropped( 40,((20*(col)+20)) , lblcomw , 20 , 0x21 ,strcommand);
         
          if (lblcomw<190)
    AddLabelCropped(170,((20*(col)+20)) , lbldesw , 20 , 0x481 ,": " + strdescrip);
   else
    AddLabelCropped(lblcomw+5,((20*(col)+20)) , lbldesw+20 , 20 , 0x481 ,": " + strdescrip);
   
         
 
  }
 
  //cancel
  AddButton( 20, 480, 0xFB1, 0xFB3 ,0, GumpButtonType.Reply, 0);
  AddLabelCropped(50, 485, 50 , 20 , 0x481 ,"Cancel");
 
  //back
  if (number != 0)
   AddButton( 20, 450, 0xFAE, 0xFB0 ,1, GumpButtonType.Reply, 0);
  //next
  if (number+20 <=m_pagemax)
  AddButton( 50, 450, 0xFA5, 0xFA7 ,2, GumpButtonType.Reply, 0);

 
 
 }
 private void InitializeGump(Mobile from)
 {
  m_list = new ArrayList();
 
  foreach ( CommandEntry entry in Server.Commands.Entries.Values )
  {
   if ( from.AccessLevel >= entry.AccessLevel )
    m_list.Add( entry );
  }
  m_list.Sort();
  m_pagemax = m_list.Count;
  m_prefix  = Server.Commands.CommandPrefix;
 }
 public HelpCommandGump(Mobile from ) : base ( 10, 10)
 {
  InitializeGump(from);
  m_page =0;
  AddLigne(m_page, m_list);
 }
 public HelpCommandGump(Mobile from,int page,ArrayList list) : base ( 10, 10)
 {
  m_page = page;
  if (m_pagemax == -1) InitializeGump(from);
  if (m_page<0 || m_page>m_pagemax ) m_page =0;
  AddLigne(m_page, list);
 }
 public override void OnResponse(NetState sender, RelayInfo info)
 {
  Mobile from = sender.Mobile;
  int infoid  = info.ButtonID;
  if(infoid!= 0)
  {
   switch(infoid)
   {
    case 1:
    m_page-=20;
    if (m_page<0)m_page=0;
    from.CloseGump( typeof( HelpCommandGump ) );
    from.SendGump( new HelpCommandGump( from,m_page,m_list ) );
    break;
    case 2:
    m_page+=20;
    if (m_page>=m_pagemax)m_page-=20;
    from.CloseGump( typeof( HelpCommandGump ) );
    from.SendGump( new HelpCommandGump( from,m_page,m_list ) );
    break;
    default:
           string s =((CommandEntry)m_list[infoid-3]).Command;
      from.SendAsciiMessage(0x22,s);
     
    string strdescrip="";
     object[] attrs = (((CommandEntry)m_list[infoid-3]).Handler.Method).GetCustomAttributes( typeof( DescriptionAttribute ), false );    
    if ( attrs.Length != 0 )
    {
     DescriptionAttribute desc = attrs[0] as DescriptionAttribute;
     if ( desc != null )
      strdescrip = desc.Description;
    }
    from.SendAsciiMessage(0x33,strdescrip);
    //from.Say(false ,m_prefix+s);
     break;
   }
  }
 }
}
}
//By Usul | Server : Real World | www.realworld.gr.st


(tester en version 2D et 3D)

Usul - December 12, 2003 12:29 AM (GMT)
oui c vrais il faut modifier sa dans
\Scripts\Commands\Handlers.cs
CODE

 [Usage( "Help" )]
 //[Description( "Lists all available commands." )]
 [Description( "Liste des commandes disponibles" )]
 public static void Help_OnCommand( CommandEventArgs e )
 {
  //Mobile m = e.Mobile;
  e.Mobile.SendGump( new HelpCommandGump( e.Mobile ) );
  //ArrayList list = new ArrayList();

  //foreach ( CommandEntry entry in Server.Commands.Entries.Values )
  //{
  // if ( m.AccessLevel >= entry.AccessLevel )
  //  list.Add( entry );
  //}

  //list.Sort();

  //StringBuilder sb = new StringBuilder();

  //if ( list.Count > 0 )
  // sb.Append( ((CommandEntry)list[0]).Command );

  //for ( int i = 1; i < list.Count; ++i )
  //{
  // string v = ((CommandEntry)list[i]).Command;

  // if ( (sb.Length + 1 + v.Length) >= 256 )
  // {
  //  m.SendAsciiMessage( 0x482, sb.ToString() );
  //  sb = new StringBuilder();
  //  sb.Append( v );
  // }
  // else
  // {
  //  sb.Append( ' ' );
  //  sb.Append( v );
  // }
  //}

  //if ( sb.Length > 0 )
  // m.SendAsciiMessage( 0x482, sb.ToString() );
 }




Hosted for free by InvisionFree