/// <summary> /// Gets a unique title for a <see cref="GrhData"/> in the given category. /// </summary> /// <param name="category">The category.</param> /// <param name="title">The string to base the new title off of.</param> /// <returns>A unique title for the given <paramref name="category"/>.</returns> public static SpriteTitle GetUniqueTitle(SpriteCategory category, string title) { if (!string.IsNullOrEmpty(title)) { title = SpriteTitle.Sanitize(title); } if (!SpriteTitle.IsValid(title)) { title = "tmp"; } // Check if the given title is already free var sTitle = new SpriteTitle(title); if (GetData(category, sTitle) == null) { return(sTitle); } // Find next free number for the title suffix var copyNum = 1; SpriteTitle sNewTitle; do { copyNum++; sNewTitle = new SpriteTitle(title + " (" + copyNum + ")"); }while (GetData(category, sNewTitle) != null); return(sNewTitle); }
/// <summary> /// Gets the <see cref="GrhData"/> by the given categorization information. /// </summary> /// <param name="category">Category of the <see cref="GrhData"/>.</param> /// <param name="title">Title of the <see cref="GrhData"/>.</param> /// <returns><see cref="GrhData"/> matching the given information if found, or null if no matches.</returns> public static GrhData GetData(SpriteCategory category, SpriteTitle title) { // Get the dictionary for the category var titleDic = GetDatas(category); // If we failed to get it, return null if (titleDic == null) { return(null); } // Try and get the GrhData for the given title, returning the GrhData // if it exists, or null if it does not exist in the dictionary GrhData ret; if (titleDic.TryGetValue(title, out ret)) { return(ret); } else { return(null); } }
/// <summary> /// Gets a unique title for a <see cref="GrhData"/> in the given category. /// </summary> /// <param name="category">The category.</param> /// <param name="title">The string to base the new title off of.</param> /// <returns>A unique title for the given <paramref name="category"/>.</returns> public static SpriteTitle GetUniqueTitle(SpriteCategory category, SpriteTitle title) { return(GetUniqueTitle(category, title.ToString())); }
/// <summary> /// Gets the <see cref="ISprite"/> for the skin with the given <see cref="SpriteTitle"/>. /// </summary> /// <param name="spriteTitle">The title of the <see cref="ISprite"/> to get.</param> /// <returns>The <see cref="ISprite"/> for the skin with the given <see cref="SpriteTitle"/>, /// or null if no <see cref="ISprite"/> could be created with the given categorization information.</returns> public ISprite GetSprite(SpriteTitle spriteTitle) { return GetSprite(null, spriteTitle); }
/// <summary> /// Gets the <see cref="ISprite"/> for the skin with the given <see cref="SpriteTitle"/>. /// </summary> /// <param name="subCategory">The sprite sub-category under the skin.</param> /// <param name="spriteTitle">The title of the <see cref="ISprite"/> to get.</param> /// <returns>The <see cref="ISprite"/> for the skin with the given <see cref="SpriteTitle"/>, /// or null if no <see cref="ISprite"/> could be created with the given categorization information.</returns> public ISprite GetSprite(SpriteCategory subCategory, SpriteTitle spriteTitle) { var key = string.Empty; if (subCategory != null && subCategory.ToString().Length > 0) key += subCategory; if (spriteTitle != null) key += "." + spriteTitle; // Check for the sprite in the cache ISprite sprite; if (_spriteCache.TryGetValue(key, out sprite)) return sprite; // Check for the sprite in the current skin var fullSC = GetSpriteCategory(CurrentSkin, subCategory); var grhData = GrhInfo.GetData(fullSC, spriteTitle); // The sprite was not found in the current category, so check the default category only if the current category // is not the default category if (grhData == null && !IsCurrentSkinDefault) { fullSC = GetSpriteCategory(DefaultSkin, subCategory); grhData = GrhInfo.GetData(fullSC, spriteTitle); } // If the grhData is not null, create the sprite, otherwise have the sprite be null if (grhData == null) sprite = null; else sprite = new Grh(grhData); // Add the sprite to the cache, even if it is null try { if (sprite != null) _spriteCache.Add(key, sprite); } catch (ArgumentException ex) { const string errmsg = "Key `{0}` already exists. Multi-threading conflict? This should never happen, but its likely not critical. Exception: {1}"; if (log.IsWarnEnabled) log.WarnFormat(errmsg, key, ex); Debug.Fail(string.Format(errmsg, key, ex)); } // Return the sprite return sprite; }
/// <summary> /// Gets the <see cref="ISprite"/> for the <see cref="Control"/> with the given <paramref name="spriteTitle"/>. /// </summary> /// <param name="controlName">The name of the <see cref="Control"/>.</param> /// <param name="spriteTitle">The <see cref="SpriteTitle"/> of the <see cref="ISprite"/> to load.</param> /// <returns>The <see cref="ISprite"/> for the <see cref="Control"/> with the given /// <paramref name="spriteTitle"/>, or null if no <see cref="ISprite"/> could be created with the /// given categorization information.</returns> public ISprite GetControlSprite(string controlName, SpriteTitle spriteTitle) { return GetSprite(GetControlSpriteSubCategory(controlName), spriteTitle); }
/// <summary> /// Gets the <see cref="ISprite"/> for the <see cref="Control"/> with the given <paramref name="spriteTitle"/>. /// </summary> /// <param name="controlName">The name of the <see cref="Control"/>.</param> /// <param name="subCategory">The sprite sub-category under the <paramref name="controlName"/>.</param> /// <param name="spriteTitle">The <see cref="SpriteTitle"/> of the <see cref="ISprite"/> to load.</param> /// <returns>The <see cref="ISprite"/> for the <see cref="Control"/> with the given /// <paramref name="spriteTitle"/>.</returns> public ISprite GetControlSprite(string controlName, SpriteCategory subCategory, SpriteTitle spriteTitle) { var completeSubCategory = GetControlSpriteSubCategory(controlName); if (subCategory != null && subCategory.ToString().Length > 0) completeSubCategory += SpriteCategorization.Delimiter + subCategory; return GetSprite(completeSubCategory, spriteTitle); }
public static void Write(this IValueWriter writer, string name, SpriteTitle value) { writer.Write(name, value.ToString()); }
/// <summary> /// Gets the <see cref="ISprite"/> for the skin with the given <see cref="SpriteTitle"/>. /// </summary> /// <param name="subCategory">The sprite sub-category under the skin.</param> /// <param name="spriteTitle">The title of the <see cref="ISprite"/> to get.</param> /// <returns>The <see cref="ISprite"/> for the skin with the given <see cref="SpriteTitle"/>, /// or null if no <see cref="ISprite"/> could be created with the given categorization information.</returns> public ISprite GetSprite(SpriteCategory subCategory, SpriteTitle spriteTitle) { var key = string.Empty; if (subCategory != null && subCategory.ToString().Length > 0) { key += subCategory; } if (spriteTitle != null) { key += "." + spriteTitle; } // Check for the sprite in the cache ISprite sprite; if (_spriteCache.TryGetValue(key, out sprite)) { return(sprite); } // Check for the sprite in the current skin var fullSC = GetSpriteCategory(CurrentSkin, subCategory); var grhData = GrhInfo.GetData(fullSC, spriteTitle); // The sprite was not found in the current category, so check the default category only if the current category // is not the default category if (grhData == null && !IsCurrentSkinDefault) { fullSC = GetSpriteCategory(DefaultSkin, subCategory); grhData = GrhInfo.GetData(fullSC, spriteTitle); } // If the grhData is not null, create the sprite, otherwise have the sprite be null if (grhData == null) { sprite = null; } else { sprite = new Grh(grhData); } // Add the sprite to the cache, even if it is null try { if (sprite != null) { _spriteCache.Add(key, sprite); } } catch (ArgumentException ex) { const string errmsg = "Key `{0}` already exists. Multi-threading conflict? This should never happen, but its likely not critical. Exception: {1}"; if (log.IsWarnEnabled) { log.WarnFormat(errmsg, key, ex); } Debug.Fail(string.Format(errmsg, key, ex)); } // Return the sprite return(sprite); }
/// <summary> /// Gets the <see cref="ISprite"/> for the skin with the given <see cref="SpriteTitle"/>. /// </summary> /// <param name="spriteTitle">The title of the <see cref="ISprite"/> to get.</param> /// <returns>The <see cref="ISprite"/> for the skin with the given <see cref="SpriteTitle"/>, /// or null if no <see cref="ISprite"/> could be created with the given categorization information.</returns> public ISprite GetSprite(SpriteTitle spriteTitle) { return(GetSprite(null, spriteTitle)); }
/// <summary> /// Gets the <see cref="ISprite"/> for the <see cref="Control"/> with the given <paramref name="spriteTitle"/>. /// </summary> /// <param name="controlName">The name of the <see cref="Control"/>.</param> /// <param name="subCategory">The sprite sub-category under the <paramref name="controlName"/>.</param> /// <param name="spriteTitle">The <see cref="SpriteTitle"/> of the <see cref="ISprite"/> to load.</param> /// <returns>The <see cref="ISprite"/> for the <see cref="Control"/> with the given /// <paramref name="spriteTitle"/>.</returns> public ISprite GetControlSprite(string controlName, SpriteCategory subCategory, SpriteTitle spriteTitle) { var completeSubCategory = GetControlSpriteSubCategory(controlName); if (subCategory != null && subCategory.ToString().Length > 0) { completeSubCategory += SpriteCategorization.Delimiter + subCategory; } return(GetSprite(completeSubCategory, spriteTitle)); }
/// <summary> /// Gets the <see cref="ISprite"/> for the <see cref="Control"/> with the given <paramref name="spriteTitle"/>. /// </summary> /// <param name="controlName">The name of the <see cref="Control"/>.</param> /// <param name="spriteTitle">The <see cref="SpriteTitle"/> of the <see cref="ISprite"/> to load.</param> /// <returns>The <see cref="ISprite"/> for the <see cref="Control"/> with the given /// <paramref name="spriteTitle"/>, or null if no <see cref="ISprite"/> could be created with the /// given categorization information.</returns> public ISprite GetControlSprite(string controlName, SpriteTitle spriteTitle) { return(GetSprite(GetControlSpriteSubCategory(controlName), spriteTitle)); }