/// <summary> /// Creates a BoxProp object from a PropertyInfo /// </summary> /// <param name="info">The PropertyInfo used to extract the BoxProp object</param> /// <returns>The extracted BoxProp object</returns> public static BoxProp FromPropertyInfo(PropertyInfo info) { object[] cpa = info.GetCustomAttributes(typeof(CommandPropertyAttribute), false); if (cpa.Length > 0) { BoxProp prop = new BoxProp(); prop.Name = info.Name; prop.CanGet = info.CanRead; prop.CanSet = info.CanWrite; CommandPropertyAttribute attr = cpa[0] as CommandPropertyAttribute; prop.GetAccess = attr.ReadLevel; prop.SetAccess = attr.WriteLevel; if (prop.SetAccess.ToString() == "5") // Weird access level on Account property { prop.SetAccess = AccessLevel.Administrator; prop.CanSet = false; } prop.ValueType = GetPropType(info.PropertyType); if (prop.ValueType == BoxPropType.Enumeration) { prop.EnumName = info.PropertyType.Name; } return(prop); } return(null); }
public void CommandPropertyAttributeConstructorTest1() { AccessLevel level = new AccessLevel(); // TODO: 初始化为适当的值 CommandPropertyAttribute target = new CommandPropertyAttribute(level); Assert.Inconclusive("TODO: 实现用来验证目标的代码"); }
public void ReadLevelTest() { AccessLevel level = new AccessLevel(); // TODO: 初始化为适当的值 CommandPropertyAttribute target = new CommandPropertyAttribute( level ); // TODO: 初始化为适当的值 AccessLevel actual; actual = target.ReadLevel; Assert.Inconclusive( "验证此测试方法的正确性。" ); }
public void ReadLevelTest() { AccessLevel level = new AccessLevel(); // TODO: 初始化为适当的值 CommandPropertyAttribute target = new CommandPropertyAttribute(level); // TODO: 初始化为适当的值 AccessLevel actual; actual = target.ReadLevel; Assert.Inconclusive("验证此测试方法的正确性。"); }
public override void OnResponse(Server.Network.NetState sender, RelayInfo info) { Mobile from = sender.Mobile; if (info.ButtonID >= (int)GumpChoice.SelectPage && info.ButtonID <= (int)GumpChoice.SelectPage + (m_PropertyList.Length / m_OptionsPerPage)) { from.SendGump(new HairStylistConfigGump(m_From, m_HairStylist, m_PropertyList, info.ButtonID - (int)GumpChoice.SelectPage)); } else if (info.ButtonID >= (int)GumpChoice.EditSettings && info.ButtonID <= (int)GumpChoice.EditSettings + m_PropertyList.Length) { int index = info.ButtonID - (int)GumpChoice.EditSettings; PropertyInfo prop = m_PropertyList[index]; if (prop == null) { return; } CommandPropertyAttribute cpa = GetCPA(prop); if (!prop.CanWrite || (cpa != null && from.AccessLevel < cpa.WriteLevel)) { return; } Type type = prop.PropertyType; if (IsType(type, typeofPoint3D)) { from.SendGump(new HairStylistSetPoint3DGump(prop, from, m_HairStylist, m_PropertyList, m_Page)); } else if (IsType(type, typeofTimeSpan)) { from.SendGump(new HairStylistSetTimeSpanGump(prop, from, m_HairStylist, m_PropertyList, m_Page)); } else if (IsCustomEnum(type)) { from.SendGump(new HairStylistSetCustomEnumGump(prop, from, m_HairStylist, m_PropertyList, GetCustomEnumNames(type), m_Page)); } else if (IsType(type, typeofEnum)) { from.SendGump(new HairStylistSetListOptionGump(prop, from, m_HairStylist, m_PropertyList, Enum.GetNames(type), GetObjects(Enum.GetValues(type)), m_Page)); } else if (IsType(type, typeofBool)) { from.SendGump(new HairStylistSetListOptionGump(prop, from, m_HairStylist, m_PropertyList, PropertiesGump.m_BoolNames, PropertiesGump.m_BoolValues, m_Page)); } else if (IsType(type, typeofString) || IsType(type, typeofReal) || IsType(type, typeofNumeric)) { from.SendGump(new HairStylistSetGump(prop, from, m_HairStylist, m_PropertyList, m_Page)); } } }
private ArrayList GetGroups(Type objectType, PropertyInfo[] props) { Hashtable groups = new Hashtable(); for (int i = 0; i < props.Length; ++i) { PropertyInfo prop = props[i]; if (prop.CanRead) { CommandPropertyAttribute attr = GetCPA(prop); if (attr != null && m_Mobile.AccessLevel >= attr.ReadLevel) { Type type = prop.DeclaringType; while (true) { Type baseType = type.BaseType; if (baseType == null || baseType == typeofObject) { break; } if (baseType.GetProperty(prop.Name, prop.PropertyType) != null) { type = baseType; } else { break; } } ArrayList list = (ArrayList)groups[type]; if (list == null) { groups[type] = list = new ArrayList(); } list.Add(prop); } } } ArrayList sorted = new ArrayList(groups); sorted.Sort(new GroupComparer(objectType)); return(sorted); }
private void InitializePage(int pageNumber) { //The background AddBackground(60, 95, 515, 330, 5054); //Adds see through AddAlphaRegion(60, 95, 515, 330); int startIndex = (pageNumber * m_OptionsPerPage) > m_PropertyList.Length ? m_PropertyList.Length : (pageNumber * m_OptionsPerPage); int endIndex = (startIndex + m_OptionsPerPage) > m_PropertyList.Length ? m_PropertyList.Length : (startIndex + m_OptionsPerPage); for (int i = startIndex; i < endIndex; ++i) { PropertyInfo pI = m_PropertyList[i]; DescriptionAttribute dA = GetDescriptionAttribute(pI); CommandPropertyAttribute cpa = GetCPA(pI); //Field name AddLabelCropped(437, 120 + (((endIndex - 1) - i) * 70), 128, 20, 0x384, pI.Name); //Prop value AddImageTiled(435, 140 + (((endIndex - 1) - i) * 70), 110, 20, 0x0BBC); AddLabelCropped(437, 140 + (((endIndex - 1) - i) * 70), 108, 20, 0, PropertiesGump.ValueToString(m_HairStylist, pI)); //Edit button if (pI.CanWrite && cpa != null && m_From.AccessLevel >= cpa.WriteLevel) { AddButton(550, 142 + (((endIndex - 1) - i) * 70), 0x15E1, 0x15E5, (int)GumpChoice.EditSettings + i, GumpButtonType.Reply, 0); } //Variabel description AddHtml(70, 102 + (((endIndex - 1) - i) * 70), 360, 60, dA.Description, true, false); //Delimiter image AddImageTiled(70, 165 + (((endIndex - 1) - i) * 70), 497, 2, 96); } //Pagination for (int i = 0; i <= (m_PropertyList.Length / m_OptionsPerPage); i++) { //Highlight current page if (i == pageNumber) { AddImageTiled(67 + (i * 25), 387, 25, 25, 0xBBC); } AddButton(70 + (i * 25), 390, 0x8B1 + i, 0x8B1 + i, (int)GumpChoice.SelectPage + i, GumpButtonType.Reply, 0); } }
public override void OnResponse(NetState state, RelayInfo info) { Mobile from = state.Mobile; if (!BaseCommand.IsAccessible(from, m_Object)) { from.SendMessage("You may no longer access their properties."); return; } switch (info.ButtonID) { case 0: // Closed { if (m_Stack != null && m_Stack.Count > 0) { object obj = m_Stack.Pop(); from.SendGump(new XmlPropertiesGump(from, obj, m_Stack, null)); } break; } case 1: // Previous { if (m_Page > 0) { from.SendGump(new XmlPropertiesGump(from, m_Object, m_Stack, m_List, m_Page - 1)); } break; } case 2: // Next { if ((m_Page + 1) * EntryCount < m_List.Count) { from.SendGump(new XmlPropertiesGump(from, m_Object, m_Stack, m_List, m_Page + 1)); } break; } default: { int index = (m_Page * EntryCount) + (info.ButtonID - 3); if (index >= 0 && index < m_List.Count) { PropertyInfo prop = m_List[index] as PropertyInfo; if (prop == null) { return; } CommandPropertyAttribute attr = GetCPA(prop); if (!prop.CanWrite || attr == null || from.AccessLevel < attr.WriteLevel) { return; } Type type = prop.PropertyType; if (IsType(type, typeofMobile) || IsType(type, typeofItem)) { from.SendGump(new XmlSetObjectGump(prop, from, m_Object, m_Stack, type, m_Page, m_List)); } else if (IsType(type, typeofType)) { from.Target = new XmlSetObjectTarget(prop, from, m_Object, m_Stack, type, m_Page, m_List); } else if (IsType(type, typeofPoint3D)) { from.SendGump(new XmlSetPoint3DGump(prop, from, m_Object, m_Stack, m_Page, m_List)); } else if (IsType(type, typeofPoint2D)) { from.SendGump(new XmlSetPoint2DGump(prop, from, m_Object, m_Stack, m_Page, m_List)); } else if (IsType(type, typeofTimeSpan)) { from.SendGump(new XmlSetTimeSpanGump(prop, from, m_Object, m_Stack, m_Page, m_List)); } else if (IsCustomEnum(type)) { from.SendGump(new XmlSetCustomEnumGump(prop, from, m_Object, m_Stack, m_Page, m_List, GetCustomEnumNames(type))); } else if (IsType(type, typeofEnum)) { from.SendGump(new XmlSetListOptionGump(prop, from, m_Object, m_Stack, m_Page, m_List, Enum.GetNames(type), GetObjects(Enum.GetValues(type)))); } else if (IsType(type, typeofBool)) { from.SendGump(new XmlSetListOptionGump(prop, from, m_Object, m_Stack, m_Page, m_List, m_BoolNames, m_BoolValues)); } else if (IsType(type, typeofString) || IsType(type, typeofReal) || IsType(type, typeofNumeric)) { from.SendGump(new XmlSetGump(prop, from, m_Object, m_Stack, m_Page, m_List)); } else if (IsType(type, typeofPoison)) { from.SendGump(new XmlSetListOptionGump(prop, from, m_Object, m_Stack, m_Page, m_List, m_PoisonNames, m_PoisonValues)); } else if (IsType(type, typeofMap)) { from.SendGump(new XmlSetListOptionGump(prop, from, m_Object, m_Stack, m_Page, m_List, Map.GetMapNames(), Map.GetMapValues())); } else if (IsType(type, typeofSkills) && m_Object is Mobile) { from.SendGump(new XmlPropertiesGump(from, m_Object, m_Stack, m_List, m_Page)); from.SendGump(new SkillsGump(from, (Mobile)m_Object)); } else if (HasAttribute(type, typeofPropertyObject, true)) { from.SendGump(new XmlPropertiesGump(from, prop.GetValue(m_Object, null), m_Stack, m_Object)); } } break; } } }
private void Initialize(int page) { m_Page = page; int count = m_List.Count - (page * EntryCount); if (count < 0) { count = 0; } else if (count > EntryCount) { count = EntryCount; } int lastIndex = (page * EntryCount) + count - 1; if (lastIndex >= 0 && lastIndex < m_List.Count && m_List[lastIndex] == null) { --count; } int totalHeight = OffsetSize + ((EntryHeight + OffsetSize) * (ColumnEntryCount + 1)); AddPage(0); AddBackground(0, 0, TotalWidth * 3 + BorderSize * 2, BorderSize + totalHeight + BorderSize, BackGumpID); AddImageTiled(BorderSize, BorderSize + EntryHeight, (TotalWidth - (OldStyle ? SetWidth + OffsetSize : 0)) * 3, totalHeight - EntryHeight, OffsetGumpID); int x = BorderSize + OffsetSize; int y = BorderSize /*+ OffsetSize*/; int emptyWidth = TotalWidth - PrevWidth - NextWidth - (OffsetSize * 4) - (OldStyle ? SetWidth + OffsetSize : 0); if (m_Object is Item) { AddLabelCropped(x + TextOffsetX, y, TypeWidth - TextOffsetX, EntryHeight, TextHue, ((Item)m_Object).Name); } int propcount = 0; for (int i = 0, index = page * EntryCount; i < count && index < m_List.Count; ++i, ++index) { // do the multi column display int column = propcount / ColumnEntryCount; if (propcount % ColumnEntryCount == 0) { y = BorderSize; } x = BorderSize + OffsetSize + column * (ValueWidth + NameWidth + OffsetSize * 2 + SetOffsetX + SetWidth); y += EntryHeight + OffsetSize; object o = m_List[index]; if (o == null) { AddImageTiled(x - OffsetSize, y, TotalWidth, EntryHeight, BackGumpID + 4); propcount++; } else /*if ( o is Type ) * { * Type type = (Type)o; * * AddImageTiled( x, y, TypeWidth, EntryHeight, EntryGumpID ); * AddLabelCropped( x + TextOffsetX, y, TypeWidth - TextOffsetX, EntryHeight, TextHue, type.Name ); * x += TypeWidth + OffsetSize; * * if ( SetGumpID != 0 ) * AddImageTiled( x, y, SetWidth, EntryHeight, SetGumpID ); * } * else */ if (o is PropertyInfo) { propcount++; PropertyInfo prop = (PropertyInfo)o; // look for the default value of the equivalent property in the XmlSpawnerDefaults.DefaultEntry class int huemodifier = TextHue; FieldInfo finfo = null; Server.Mobiles.XmlSpawnerDefaults.DefaultEntry de = new Server.Mobiles.XmlSpawnerDefaults.DefaultEntry(); Type ftype = de.GetType(); if (ftype != null) { finfo = ftype.GetField(prop.Name); } // is there an equivalent default field? if (finfo != null) { // see if the value is different from the default if (ValueToString(finfo.GetValue(de)) != ValueToString(prop)) { huemodifier = 68; } } AddImageTiled(x, y, NameWidth, EntryHeight, EntryGumpID); AddLabelCropped(x + TextOffsetX, y, NameWidth - TextOffsetX, EntryHeight, huemodifier, prop.Name); x += NameWidth + OffsetSize; AddImageTiled(x, y, ValueWidth, EntryHeight, EntryGumpID); AddLabelCropped(x + TextOffsetX, y, ValueWidth - TextOffsetX, EntryHeight, huemodifier, ValueToString(prop)); x += ValueWidth + OffsetSize; if (SetGumpID != 0) { AddImageTiled(x, y, SetWidth, EntryHeight, SetGumpID); } CommandPropertyAttribute cpa = GetCPA(prop); if (prop.CanWrite && cpa != null && m_Mobile.AccessLevel >= cpa.WriteLevel) { AddButton(x + SetOffsetX, y + SetOffsetY, SetButtonID1, SetButtonID2, i + 3, GumpButtonType.Reply, 0); } } } }
public void CommandPropertyAttributeConstructorTest() { AccessLevel readLevel = new AccessLevel(); // TODO: 初始化为适当的值 AccessLevel writeLevel = new AccessLevel(); // TODO: 初始化为适当的值 CommandPropertyAttribute target = new CommandPropertyAttribute( readLevel, writeLevel ); Assert.Inconclusive( "TODO: 实现用来验证目标的代码" ); }
private void Initialize(int page) { m_Page = page; int count = m_List.Count - (page * EntryCount); if (count < 0) { count = 0; } else if (count > EntryCount) { count = EntryCount; } int lastIndex = (page * EntryCount) + count - 1; if (lastIndex >= 0 && lastIndex < m_List.Count && m_List[lastIndex] == null) { --count; } int totalHeight = OffsetSize + ((EntryHeight + OffsetSize) * (count + 1)); AddPage(0); AddBackground(0, 0, BackWidth, BorderSize + totalHeight + BorderSize, BackGumpID); AddImageTiled(BorderSize, BorderSize, TotalWidth - (OldStyle ? SetWidth + OffsetSize : 0), totalHeight, OffsetGumpID); int x = BorderSize + OffsetSize; int y = BorderSize + OffsetSize; int emptyWidth = TotalWidth - PrevWidth - NextWidth - (OffsetSize * 4) - (OldStyle ? SetWidth + OffsetSize : 0); if (OldStyle) { AddImageTiled(x, y, TotalWidth - (OffsetSize * 3) - SetWidth, EntryHeight, HeaderGumpID); } else { AddImageTiled(x, y, PrevWidth, EntryHeight, HeaderGumpID); } if (page > 0) { AddButton(x + PrevOffsetX, y + PrevOffsetY, PrevButtonID1, PrevButtonID2, 1, GumpButtonType.Reply, 0); if (PrevLabel) { AddLabel(x + PrevLabelOffsetX, y + PrevLabelOffsetY, TextHue, "Previous"); } } x += PrevWidth + OffsetSize; if (!OldStyle) { AddImageTiled(x, y, emptyWidth, EntryHeight, HeaderGumpID); } if (TypeLabel && m_Type != null) { AddHtml(x, y, emptyWidth, EntryHeight, String.Format("<BASEFONT COLOR=#FAFAFA><CENTER>{0}</CENTER></BASEFONT>", m_Type.Name), false, false); } x += emptyWidth + OffsetSize; if (!OldStyle) { AddImageTiled(x, y, NextWidth, EntryHeight, HeaderGumpID); } if ((page + 1) * EntryCount < m_List.Count) { AddButton(x + NextOffsetX, y + NextOffsetY, NextButtonID1, NextButtonID2, 2, GumpButtonType.Reply, 1); if (NextLabel) { AddLabel(x + NextLabelOffsetX, y + NextLabelOffsetY, TextHue, "Next"); } } for (int i = 0, index = page * EntryCount; i < count && index < m_List.Count; ++i, ++index) { x = BorderSize + OffsetSize; y += EntryHeight + OffsetSize; object o = m_List[index]; if (o == null) { AddImageTiled(x - OffsetSize, y, TotalWidth, EntryHeight, BackGumpID + 4); } else if (o is Type) { Type type = (Type)o; AddImageTiled(x, y, TypeWidth, EntryHeight, EntryGumpID); AddLabelCropped(x + TextOffsetX, y, TypeWidth - TextOffsetX, EntryHeight, TextHue, type.Name); x += TypeWidth + OffsetSize; if (SetGumpID != 0) { AddImageTiled(x, y, SetWidth, EntryHeight, SetGumpID); } } else if (o is PropertyInfo) { PropertyInfo prop = (PropertyInfo)o; AddImageTiled(x, y, NameWidth, EntryHeight, EntryGumpID); AddLabelCropped(x + TextOffsetX, y, NameWidth - TextOffsetX, EntryHeight, TextHue, prop.Name); x += NameWidth + OffsetSize; AddImageTiled(x, y, ValueWidth, EntryHeight, EntryGumpID); AddLabelCropped(x + TextOffsetX, y, ValueWidth - TextOffsetX, EntryHeight, TextHue, ValueToString(prop)); x += ValueWidth + OffsetSize; if (SetGumpID != 0) { AddImageTiled(x, y, SetWidth, EntryHeight, SetGumpID); } CommandPropertyAttribute cpa = GetCPA(prop); if (prop.CanWrite && cpa != null && m_Mobile.AccessLevel >= cpa.WriteLevel && !cpa.ReadOnly) { AddButton(x + SetOffsetX, y + SetOffsetY, SetButtonID1, SetButtonID2, i + 3, GumpButtonType.Reply, 0); } } } }
public static PropertyInfo[] GetPropertyInfoChain(Mobile from, Type type, string propertyString, PropertyAccess endAccess, ref string failReason) { string[] split = propertyString.Split('.'); if (split.Length == 0) { return(null); } PropertyInfo[] info = new PropertyInfo[split.Length]; for (int i = 0; i < info.Length; ++i) { string propertyName = split[i]; if (CIEqual(propertyName, "current")) { continue; } PropertyInfo[] props = type.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public); bool isFinal = (i == (info.Length - 1)); PropertyAccess access = endAccess; if (!isFinal) { access |= PropertyAccess.Read; } for (int j = 0; j < props.Length; ++j) { PropertyInfo p = props[j]; if (CIEqual(p.Name, propertyName)) { CommandPropertyAttribute attr = GetCPA(p); if (attr == null) { failReason = String.Format("Property '{0}' not found.", propertyName); return(null); } else if ((access & PropertyAccess.Read) != 0 && from.AccessLevel < attr.ReadLevel) { failReason = String.Format("You must be at least {0} to get the property '{1}'.", Mobile.GetAccessLevelName(attr.ReadLevel), propertyName); return(null); } else if ((access & PropertyAccess.Write) != 0 && from.AccessLevel < attr.WriteLevel) { failReason = String.Format("You must be at least {0} to set the property '{1}'.", Mobile.GetAccessLevelName(attr.WriteLevel), propertyName); return(null); } else if ((access & PropertyAccess.Read) != 0 && !p.CanRead) { failReason = String.Format("Property '{0}' is write only.", propertyName); return(null); } else if ((access & PropertyAccess.Write) != 0 && (!p.CanWrite || attr.ReadOnly) && isFinal) { failReason = String.Format("Property '{0}' is read only.", propertyName); return(null); } info[i] = p; type = p.PropertyType; break; } } if (info[i] == null) { failReason = String.Format("Property '{0}' not found.", propertyName); return(null); } } return(info); }