PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/Scripts/Gumps/AProperties/ASetBodyGump.cs

https://bitbucket.org/Kel/crepuscule
C# | 310 lines | 249 code | 54 blank | 7 comment | 44 complexity | df76f5f03ce371b9fd872fd38ffba7da MD5 | raw file
  1. /* --------------------------->
  2. * Advanced properties script by Kaon
  3. * Version 1.0
  4. * Creation : 28.03.2007
  5. * Revision : N/A
  6. * --------------------------->
  7. */
  8. using System;
  9. using System.Reflection;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. using Server;
  13. using Server.Network;
  14. using Server.HuePickers;
  15. using Server.Scripts.Commands;
  16. namespace Server.Gumps
  17. {
  18. public class ASetBodyGump : Gump
  19. {
  20. private PropertyInfo m_Property;
  21. private Mobile m_Mobile;
  22. private object m_Object;
  23. private Stack m_Stack;
  24. private int m_Page;
  25. private ArrayList m_List;
  26. private int m_OurPage;
  27. private ArrayList m_OurList;
  28. private ModelBodyType m_OurType;
  29. private int m_Index;
  30. private const int LabelColor32 = 0xFFFFFF;
  31. private const int SelectedColor32 = 0x8080FF;
  32. private const int TextColor32 = 0xFFFFFF;
  33. public ASetBodyGump( PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list, int index ) : this( prop, mobile, o, stack, page, list, 0, null, ModelBodyType.Invalid, index )
  34. {
  35. }
  36. public string Center( string text )
  37. {
  38. return String.Format( "<CENTER>{0}</CENTER>", text );
  39. }
  40. public string Color( string text, int color )
  41. {
  42. return String.Format( "<BASEFONT COLOR=#{0:X6}>{1}</BASEFONT>", color, text );
  43. }
  44. public void AddTypeButton( int x, int y, int buttonID, string text, ModelBodyType type )
  45. {
  46. bool isSelection = ( m_OurType == type );
  47. AddButton( x, y - 1, isSelection ? 4006 : 4005, 4007, buttonID, GumpButtonType.Reply, 0 );
  48. AddHtml( x + 35, y, 200, 20, Color( text, isSelection ? SelectedColor32 : LabelColor32 ), false, false );
  49. }
  50. public ASetBodyGump( PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, ArrayList list, int ourPage, ArrayList ourList, ModelBodyType ourType, int _index ) : base( 20, 30 )
  51. {
  52. m_Property = prop;
  53. m_Mobile = mobile;
  54. m_Object = o;
  55. m_Stack = stack;
  56. m_Page = page;
  57. m_List = list;
  58. m_OurPage = ourPage;
  59. m_OurList = ourList;
  60. m_OurType = ourType;
  61. m_Index = _index;
  62. AddPage( 0 );
  63. AddBackground( 0, 0, 525, 328, 5054 );
  64. AddImageTiled( 10, 10, 505, 20, 0xA40 );
  65. AddAlphaRegion( 10, 10, 505, 20 );
  66. AddImageTiled( 10, 35, 505, 283, 0xA40 );
  67. AddAlphaRegion( 10, 35, 505, 283 );
  68. AddTypeButton( 10, 10, 1, "Monster", ModelBodyType.Monsters );
  69. AddTypeButton( 130, 10, 2, "Animal", ModelBodyType.Animals );
  70. AddTypeButton( 250, 10, 3, "Marine", ModelBodyType.Sea );
  71. AddTypeButton( 370, 10, 4, "Human", ModelBodyType.Human );
  72. AddImage( 480, 12, 0x25EA );
  73. AddImage( 497, 12, 0x25E6 );
  74. if ( ourList == null )
  75. {
  76. AddLabel( 15, 40, 0x480, "Choose a body type above." );
  77. }
  78. else if ( ourList.Count == 0 )
  79. {
  80. AddLabel( 15, 40, 0x480, "The server must have UO:3D installed to use this feature." );
  81. }
  82. else
  83. {
  84. for ( int i = 0, index = (ourPage * 12); i < 12 && index >= 0 && index < ourList.Count; ++i, ++index )
  85. {
  86. InternalEntry entry = (InternalEntry)ourList[index];
  87. int itemID = entry.ItemID;
  88. Rectangle2D bounds = ItemBounds.Table[itemID & 0x3FFF];
  89. int x = 15 + ((i % 4) * 125);
  90. int y = 40 + ((i / 4) * 93);
  91. AddItem( x + ((120 - bounds.Width) / 2) - bounds.X, y + ((69 - bounds.Height) / 2) - bounds.Y, itemID );
  92. AddButton( x + 6, y + 66, 0x98D, 0x98D, 7 + index, GumpButtonType.Reply, 0 );
  93. x += 6;
  94. y += 67;
  95. AddHtml( x + 0, y - 1, 108, 21, Center( entry.DisplayName ), false, false );
  96. AddHtml( x + 0, y + 1, 108, 21, Center( entry.DisplayName ), false, false );
  97. AddHtml( x - 1, y + 0, 108, 21, Center( entry.DisplayName ), false, false );
  98. AddHtml( x + 1, y + 0, 108, 21, Center( entry.DisplayName ), false, false );
  99. AddHtml( x + 0, y + 0, 108, 21, Color( Center( entry.DisplayName ), TextColor32 ), false, false );
  100. }
  101. if ( ourPage > 0 )
  102. AddButton( 480, 12, 0x15E3, 0x15E7, 5, GumpButtonType.Reply, 0 );
  103. if ( (ourPage + 1) * 12 < ourList.Count )
  104. AddButton( 497, 12, 0x15E1, 0x15E5, 6, GumpButtonType.Reply, 0 );
  105. }
  106. }
  107. public override void OnResponse( NetState sender, RelayInfo info )
  108. {
  109. int index = info.ButtonID - 1;
  110. if ( index == -1 )
  111. {
  112. m_Mobile.SendGump( new APropertiesGump( m_Mobile, m_Object, m_Stack, m_List, m_Page ) );
  113. }
  114. else if ( index >= 0 && index < 4 )
  115. {
  116. if ( m_Monster == null )
  117. LoadLists();
  118. ModelBodyType type;
  119. ArrayList list;
  120. switch ( index )
  121. {
  122. default:
  123. case 0: type = ModelBodyType.Monsters; list = m_Monster; break;
  124. case 1: type = ModelBodyType.Animals; list = m_Animal; break;
  125. case 2: type = ModelBodyType.Sea; list = m_Sea; break;
  126. case 3: type = ModelBodyType.Human; list = m_Human; break;
  127. }
  128. m_Mobile.SendGump( new ASetBodyGump( m_Property, m_Mobile, m_Object, m_Stack, m_Page, m_List, 0, list, type, m_Index ) );
  129. }
  130. else if ( m_OurList != null )
  131. {
  132. index -= 4;
  133. if ( index == 0 && m_OurPage > 0 )
  134. {
  135. m_Mobile.SendGump( new ASetBodyGump( m_Property, m_Mobile, m_Object, m_Stack, m_Page, m_List, m_OurPage - 1, m_OurList, m_OurType, m_Index ) );
  136. }
  137. else if ( index == 1 && ((m_OurPage + 1) * 12) < m_OurList.Count )
  138. {
  139. m_Mobile.SendGump( new ASetBodyGump( m_Property, m_Mobile, m_Object, m_Stack, m_Page, m_List, m_OurPage + 1, m_OurList, m_OurType, m_Index ) );
  140. }
  141. else
  142. {
  143. index -= 2;
  144. if ( index >= 0 && index < m_OurList.Count )
  145. {
  146. try
  147. {
  148. InternalEntry entry = (InternalEntry)m_OurList[index];
  149. CommandLogging.LogChangeProperty( m_Mobile, m_Object, m_Property.Name, entry.Body.ToString() );
  150. if (m_Index >= 0)
  151. {
  152. object[] indexes = new object[] { m_Index };
  153. m_Property.SetValue(m_Object, entry.Body, indexes);
  154. }
  155. else m_Property.SetValue(m_Object, entry.Body, null);
  156. APropertiesGump.OnValueChanged( m_Object, m_Property, m_Stack, m_Index );
  157. }
  158. catch
  159. {
  160. m_Mobile.SendMessage( "An exception was caught. The property may not have changed." );
  161. }
  162. m_Mobile.SendGump( new ASetBodyGump( m_Property, m_Mobile, m_Object, m_Stack, m_Page, m_List, m_OurPage, m_OurList, m_OurType, m_Index ) );
  163. }
  164. }
  165. }
  166. }
  167. private static ArrayList m_Monster, m_Animal, m_Sea, m_Human;
  168. private static void LoadLists()
  169. {
  170. m_Monster = new ArrayList();
  171. m_Animal = new ArrayList();
  172. m_Sea = new ArrayList();
  173. m_Human = new ArrayList();
  174. List<BodyEntry> entries = new List<BodyEntry>();
  175. ArrayList tmp = Docs.LoadBodies();
  176. foreach (object entry in tmp) entries.Add(entry as BodyEntry);
  177. for ( int i = 0; i < entries.Count; ++i )
  178. {
  179. BodyEntry oldEntry = (BodyEntry)entries[i];
  180. int bodyID = oldEntry.Body.BodyID;
  181. if ( ((Body)bodyID).IsEmpty )
  182. continue;
  183. ArrayList list = null;
  184. switch ( oldEntry.BodyType )
  185. {
  186. case ModelBodyType.Monsters: list = m_Monster; break;
  187. case ModelBodyType.Animals: list = m_Animal; break;
  188. case ModelBodyType.Sea: list = m_Sea; break;
  189. case ModelBodyType.Human: list = m_Human; break;
  190. }
  191. if ( list == null )
  192. continue;
  193. int itemID = ShrinkTable.Lookup( bodyID, -1 );
  194. if ( itemID != -1 )
  195. list.Add( new InternalEntry( bodyID, itemID, oldEntry.Name ) );
  196. }
  197. m_Monster.Sort();
  198. m_Animal.Sort();
  199. m_Sea.Sort();
  200. m_Human.Sort();
  201. }
  202. private class InternalEntry : IComparable
  203. {
  204. private int m_Body;
  205. private int m_ItemID;
  206. private string m_Name;
  207. private string m_DisplayName;
  208. public int Body{ get{ return m_Body; } }
  209. public int ItemID{ get{ return m_ItemID; } }
  210. public string Name{ get{ return m_Name; } }
  211. public string DisplayName{ get{ return m_DisplayName; } }
  212. private static string[] m_GroupNames = new string[]
  213. {
  214. "ogres_", "ettins_", "walking_dead_", "gargoyles_",
  215. "orcs_", "flails_", "daemons_", "arachnids_",
  216. "dragons_", "elementals_", "serpents_", "gazers_",
  217. "liche_", "spirits_", "harpies_", "headless_",
  218. "lizard_race_", "mongbat_", "rat_race_", "scorpions_",
  219. "trolls_", "slimes_", "skeletons_", "ethereals_",
  220. "terathan_", "imps_", "cyclops_", "krakens_",
  221. "frogs_", "ophidians_", "centaurs_", "mages_",
  222. "fey_race_", "genies_", "paladins_", "shadowlords_",
  223. "succubi_", "lizards_", "rodents_", "birds_",
  224. "bovines_", "bruins_", "canines_", "deer_",
  225. "equines_", "felines_", "fowl_", "gorillas_",
  226. "kirin_", "llamas_", "ostards_", "porcines_",
  227. "ruminants_", "walrus_", "dolphins_", "sea_horse_",
  228. "sea_serpents_", "character_", "h_", "titans_"
  229. };
  230. public InternalEntry( int body, int itemID, string name )
  231. {
  232. m_Body = body;
  233. m_ItemID = itemID;
  234. m_Name = name;
  235. m_DisplayName = name.ToLower();
  236. for ( int i = 0; i < m_GroupNames.Length; ++i )
  237. {
  238. if ( m_DisplayName.StartsWith( m_GroupNames[i] ) )
  239. {
  240. m_DisplayName = m_DisplayName.Substring( m_GroupNames[i].Length );
  241. break;
  242. }
  243. }
  244. m_DisplayName = m_DisplayName.Replace( '_', ' ' );
  245. }
  246. public int CompareTo( object obj )
  247. {
  248. InternalEntry comp = (InternalEntry)obj;
  249. int v = m_Name.CompareTo( comp.m_Name );
  250. if ( v == 0 )
  251. m_Body.CompareTo( comp.m_Body );
  252. return v;
  253. }
  254. }
  255. }
  256. }