private string _NamePrefix;
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
public string NamePrefix
{
get { return _NamePrefix; }
set
{
if (_NamePrefix == value)
{
return;
}
_NamePrefix = value;
InvalidateProperties();
}
}
public virtual string GetNamePrefix()
{
return _NamePrefix;
}
private Color _NameColor;
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
public Color NameColor
{
get { return _NameColor; }
set
{
if (_NameColor == value)
{
return;
}
_NameColor = value;
InvalidateProperties();
}
}
public virtual Color GetNameColor()
{
return _NameColor;
}
/// <summary>
/// Overridable. Adds the name of this item to the given <see cref="ObjectPropertyList" />. This method should be
/// overriden if the item requires a complex naming format.
/// </summary>
public virtual void AddNameProperty(ObjectPropertyList list)
{
var color = _NameColor != Color.Empty ? _NameColor : GetNameColor();
var noColor = color.IsEmpty || color == Color.Empty;
if (!noColor)
{
var p = _Parent as Item;
while (p != null)
{
if (p.GetType().FullName == "Server.Mobiles.GenericBuyInfo+DisplayCache")
{
noColor = true;
break;
}
p = p.Parent as Item;
}
}
var colorStart = String.Empty;
var colorEnd = String.Empty;
if (!noColor)
{
colorStart = String.Format("<BASEFONT COLOR=#{0:X6}>", color.ToArgb());
colorEnd = "<BASEFONT COLOR=#FFFFFF>";
}
var prefix = !String.IsNullOrWhiteSpace(_NamePrefix) ? _NamePrefix : GetNamePrefix();
var name = Name ?? ("#" + LabelNumber);
if (Amount <= 1)
{
if (!String.IsNullOrWhiteSpace(prefix))
{
if (noColor)
{
list.Add(1050039, "{0}\t{1}", prefix, name);
}
else
{
list.Add(1050039, "{0} {1}\t{2} {3}", colorStart, prefix, name, colorEnd);
}
}
else if (noColor)
{
if (name.StartsWith("#"))
{
list.Add(LabelNumber);
}
else
{
list.Add(name);
}
}
else
{
list.Add(1050039, "{0}\t{1} {2}", colorStart, name, colorEnd);
}
}
else
{
if (!String.IsNullOrWhiteSpace(prefix))
{
if (noColor)
{
list.Add(1050039, "{0:#,0} {1}\t{2}", Amount, prefix, name);
}
else
{
list.Add(1050039, "{0} {1:#,0} {2}\t{3} {4}", colorStart, Amount, prefix, name, colorEnd);
}
}
else if (noColor)
{
list.Add(1050039, "{0:#,0}\t{1}", Amount, name);
}
else
{
list.Add(1050039, "{0} {1:#,0}\t{2} {3}", colorStart, Amount, name, colorEnd);
}
}
}
item.NameColor = Color.Blue;
public enum ItemRank
{
None = 0,
Common = 1,
Uncommon = 2,
Rare = 3,
Epic = 4,
Legendary = 5
}
public virtual Color GetNameColor()
{
if(_NameColor != Color.Empty)
{
return _NameColor;
}
switch(_Rank)
{
case ItemRank.Common: return Color.White;
case ItemRank.Uncommon: return Color.Green;
case ItemRank.Rare: return Color.Blue;
case ItemRank.Epic: return Color.Purple;
case ItemRank.Legendary: return Color.Orange;
}
return _Namecolor;
}
Hello, thanks for your reply, can you provide me a mature, single control script, I may not be able to achieve, because my skills are limited. Thank you so muchI typically make mods to Item.cs to enable dynamic name color access;
C#:private string _NamePrefix; [CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)] public string NamePrefix { get { return _NamePrefix; } set { if (_NamePrefix == value) { return; } _NamePrefix = value; InvalidateProperties(); } } public virtual string GetNamePrefix() { return _NamePrefix; } private Color _NameColor; [CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)] public Color NameColor { get { return _NameColor; } set { if (_NameColor == value) { return; } _NameColor = value; InvalidateProperties(); } } public virtual Color GetNameColor() { return _NameColor; } /// <summary> /// Overridable. Adds the name of this item to the given <see cref="ObjectPropertyList" />. This method should be /// overriden if the item requires a complex naming format. /// </summary> public virtual void AddNameProperty(ObjectPropertyList list) { var color = _NameColor != Color.Empty ? _NameColor : GetNameColor(); var noColor = color.IsEmpty || color == Color.Empty; if (!noColor) { var p = _Parent as Item; while (p != null) { if (p.GetType().FullName == "Server.Mobiles.GenericBuyInfo+DisplayCache") { noColor = true; break; } p = p.Parent as Item; } } var colorStart = String.Empty; var colorEnd = String.Empty; if (!noColor) { colorStart = String.Format("<BASEFONT COLOR=#{0:X6}>", color.ToArgb()); colorEnd = "<BASEFONT COLOR=#FFFFFF>"; } var prefix = !String.IsNullOrWhiteSpace(_NamePrefix) ? _NamePrefix : GetNamePrefix(); var name = Name ?? ("#" + LabelNumber); if (Amount <= 1) { if (!String.IsNullOrWhiteSpace(prefix)) { if (noColor) { list.Add(1050039, "{0}\t{1}", prefix, name); } else { list.Add(1050039, "{0} {1}\t{2} {3}", colorStart, prefix, name, colorEnd); } } else if (noColor) { if (name.StartsWith("#")) { list.Add(LabelNumber); } else { list.Add(name); } } else { list.Add(1050039, "{0}\t{1} {2}", colorStart, name, colorEnd); } } else { if (!String.IsNullOrWhiteSpace(prefix)) { if (noColor) { list.Add(1050039, "{0:#,0} {1}\t{2}", Amount, prefix, name); } else { list.Add(1050039, "{0} {1:#,0} {2}\t{3} {4}", colorStart, Amount, prefix, name, colorEnd); } } else if (noColor) { list.Add(1050039, "{0:#,0}\t{1}", Amount, name); } else { list.Add(1050039, "{0} {1:#,0}\t{2} {3}", colorStart, Amount, name, colorEnd); } } }
This mod allows for behaviour like;
C#:item.NameColor = Color.Blue;
Suppose you have an Item Rank system represented by an enum;
C#:public enum ItemRank { None = 0, Common = 1, Uncommon = 2, Rare = 3, Epic = 4, Legendary = 5 }
And ifyou don't want to set the NameColor of every Item individually, you could add ItemRank as a property of Item, then change the NameColor mod's GetNameColor() method to do something like this;
C#:public virtual Color GetNameColor() { if(_NameColor != Color.Empty) { return _NameColor; } switch(_Rank) { case ItemRank.Common: return Color.White; case ItemRank.Uncommon: return Color.Green; case ItemRank.Rare: return Color.Blue; case ItemRank.Epic: return Color.Purple; case ItemRank.Legendary: return Color.Orange; } return _Namecolor; }
public override void AddNameProperty(ObjectPropertyList list)
{
//Colored Item Name Mod Start
//Getting Props code
BaseWeapon wea = this as BaseWeapon;
int props = 0;
foreach (int i in Enum.GetValues(typeof(AosAttribute)))
{
if (wea != null && wea.Attributes[(AosAttribute)i] > 0) ++props;
}
if (wea != null) {foreach (int i in Enum.GetValues(typeof(AosWeaponAttribute))) if (wea.WeaponAttributes[(AosWeaponAttribute)i] > 0) ++props; }
if (wea != null) { if (wea.Slayer != SlayerName.None) ++props; if (wea.Slayer2 != SlayerName.None) ++props; }
if (this.SkillBonuses.Skill_1_Value > 0) ++props;
if (this.SkillBonuses.Skill_2_Value > 0) ++props;
if (this.SkillBonuses.Skill_3_Value > 0) ++props;
if (this.SkillBonuses.Skill_4_Value > 0) ++props;
if (this.SkillBonuses.Skill_5_Value > 0) ++props;
//AddNamePropertiey Code
string oreType = CraftResources.GetName(m_Resource);
if (oreType.ToLower() == "none" || oreType.ToLower() == "normal" || oreType != "0") oreType = "";
// Props code display
if (props >= 0 && props <= 2) // gray (Uncommon)
{
list.Add(1053099, "<BASEFONT COLOR=#FFFFFF>{0}\t{1}<BASEFONT COLOR=#FFFFFF>", oreType, GetNameString());
}
if (props >= 2 && props <= 4) //orange (Uncommon)
{
list.Add(1053099, "<BASEFONT COLOR=#DF7401>{0}\t{1}<BASEFONT COLOR=#DF7401>", oreType, GetNameString());
}
if (props >= 5 && props <= 7) // green (Rare)
{
list.Add(1053099, "<BASEFONT COLOR=#04B404>{0}\t{1}<BASEFONT COLOR=#04B404>", oreType, GetNameString());
}
if (props >= 8 && props <= 10) // red (Epic)
{
list.Add(1053099, "<BASEFONT COLOR=#FF0000>{0}\t{1}<BASEFONT COLOR=#FF0000>", oreType, GetNameString());
}
if (props >= 11 && props <= 12) // Orange (Legendary)
{
list.Add(1053099, "<BASEFONT COLOR=#8258FA>{0}\t{1}<BASEFONT COLOR=#8258FA>", oreType, GetNameString());
}
if (props >= 13) // red (Artifact)
{
list.Add(1053099, "<BASEFONT COLOR=#FF0000>{0}\t{1}<BASEFONT COLOR=#FFFFFF>", oreType, GetNameString());
}
//Colored Item Name Mod End[/B]
if (!String.IsNullOrEmpty(m_EngravedText))
{
list.Add(1062613, m_EngravedText);
}
}
We use essential cookies to make this site work, and optional cookies to enhance your experience.