public static LocalizedText GetItemName(int id) { id = (int)ItemID.FromNetId((short)id); if (id > 0 && id < 3930 && Lang._itemNameCache[id] != null) { return(Lang._itemNameCache[id]); } return(LocalizedText.Empty); }
/**<summary>Sets the name of an item.</summary>*/ private static void SetItemTooltip(int type, string tooltip) { // Access Lang's item tooltip cache ItemTooltip[] _itemTooltipCache = (ItemTooltip[])TerrariaReflection.Lang_itemTooltipCache.GetValue(null); // Get the cached item tooltip ItemTooltip itemTooltip = _itemTooltipCache[ItemID.FromNetId((short)type)]; // Tooltip has not been assigned. Let's assign a new one if (itemTooltip == ItemTooltip.None) { // Create a new item tooltip itemTooltip = (ItemTooltip)TerrariaReflection.ItemToolTip_ctor.Invoke(new object[] { }); // Create the tooltip's new localized text LocalizedText _text = (LocalizedText)TerrariaReflection.LocalizedText_ctor.Invoke(new object[] { "", tooltip }); // Assign the tooltip's new localized text TerrariaReflection.ItemTooltip_text.SetValue(itemTooltip, _text); // Assign the new item tooltip to the cache _itemTooltipCache[ItemID.FromNetId((short)type)] = itemTooltip; } else { // Get the tooltip's localized text LocalizedText _text = (LocalizedText)TerrariaReflection.ItemTooltip_text.GetValue(itemTooltip); // Set the text of the tooltip's localized text TerrariaReflection.LocalizedText_SetValue.Invoke(_text, new object[] { tooltip }); // Set it so that the tooltip will be revalidated the first time it's needed. TerrariaReflection.ItemTooltip_lastCulture.SetValue(itemTooltip, null); } // Create a new ItemTooltip /*ItemTooltip itemTooltip = (ItemTooltip)TerrariaReflection.ctor_ItemToolTip.Invoke(new object[] {}); * // Create a new LocalizedText * LocalizedText locText = (LocalizedText)TerrariaReflection.ctor_LocalizedText.Invoke(new object[] { "ItemTooltip" + type.ToString(), tooltip }); * * TerrariaReflection._text_ItemTooltip.SetValue(itemTooltip, locText); * * // Assign the new ItemTooltip to Lang's item tooltip cache * _itemTooltipCache[ItemID.FromNetId((short)type)] = itemTooltip;*/ // Hooray for reflection! }
//=========== HELPERS ============ #region Helpers /**<summary>Sets the name of an item.</summary>*/ private static void SetItemName(int type, string name) { // Access Lang's item name cache LocalizedText[] _itemNameCache = (LocalizedText[])TerrariaReflection.Lang_itemNameCache.GetValue(null); // Get the cached localized text item name LocalizedText locText = _itemNameCache[ItemID.FromNetId((short)type)]; // Set the localized text of the cached item name TerrariaReflection.LocalizedText_SetValue.Invoke(locText, new object[] { name }); // Create a new LocalizedText //LocalizedText locText = (LocalizedText)TerrariaReflection.ctor_LocalizedText.Invoke(new object[] { "ItemName" + type.ToString(), name }); // Assign the new LocalizedText to Lang's item name cache //_itemNameCache[ItemID.FromNetId((short)type)] = locText; // Hooray for reflection! }
public static LocalizedText GetItemName(int id) { id = (int)ItemID.FromNetId((short)id); return(id > 0 && id < 5043 && Lang._itemNameCache[id] != null ? Lang._itemNameCache[id] : LocalizedText.Empty); }
public void OnItemSetDefaults(Item item) { var section = "item" + item.type; var name = LoadString(section, "name"); var autoReuse = LoadBool(section, "autoReuse"); var damage = LoadInt(section, "damage"); var knockback = LoadFloat(section, "knockback"); var crit = LoadInt(section, "crit"); var defense = LoadInt(section, "defense"); var useTime = LoadInt(section, "useTime"); var useAnimation = LoadInt(section, "useAnimation"); var holdStyle = LoadInt(section, "holdStyle"); var useStyle = LoadInt(section, "useStyle"); var maxStack = LoadInt(section, "maxStack"); var scale = LoadFloat(section, "scale"); var toolTip = LoadString(section, "toolTip"); if (name != null) { Lang._itemNameCache[ItemID.FromNetId((short)item.type)].SetValue(name); } if (autoReuse != null) { item.autoReuse = (bool)autoReuse; } if (damage != null) { item.damage = (int)damage; } if (knockback != null) { item.knockBack = (float)knockback; } if (crit != null) { item.crit = (int)crit; } if (defense != null) { item.defense = (int)defense; } if (useTime != null) { item.useTime = (int)useTime; } if (useAnimation != null) { item.useAnimation = (int)useAnimation; } if (holdStyle != null) { item.holdStyle = (int)holdStyle; } if (useStyle != null) { item.useStyle = (int)useStyle; } if (maxStack != null) { item.maxStack = (int)maxStack; } if (scale != null) { item.scale = (float)scale; } if (toolTip != null) { item.ToolTip.SetValue(toolTip); } }