예제 #1
0
        /// <summary>
        /// Creates a new <see cref="ControlBorder"/> for the given skin and <see cref="Control"/>. This method should
        /// always return a new <see cref="ControlBorder"/> and not use any sort of caching.
        /// </summary>
        /// <param name="controlName">The name of the <see cref="Control"/>.</param>
        /// <param name="subCategory">The optional sub-category. Can be null.</param>
        /// <returns>A new <see cref="ControlBorder"/> for the given skin and <see cref="Control"/>.</returns>
        protected virtual ControlBorder CreateBorder(string controlName, SpriteCategory subCategory)
        {
            // Get the full sub-category
            var fullSubCategory = GetControlSpriteSubCategory(controlName);

            if (subCategory != null && subCategory.ToString().Length > 0)
            {
                fullSubCategory += SpriteCategorization.Delimiter + subCategory;
            }

            // Load all the sides
            var bg = GetSprite(fullSubCategory, "Background");
            var l  = GetSprite(fullSubCategory, "Left");
            var r  = GetSprite(fullSubCategory, "Right");
            var b  = GetSprite(fullSubCategory, "Bottom");
            var bl = GetSprite(fullSubCategory, "BottomLeft");
            var br = GetSprite(fullSubCategory, "BottomRight");
            var tl = GetSprite(fullSubCategory, "TopLeft");
            var t  = GetSprite(fullSubCategory, "Top");
            var tr = GetSprite(fullSubCategory, "TopRight");

            // Create the control
            var ret = new ControlBorder(tl, t, tr, r, br, b, bl, l, bg);

            // Try to load the user-defined border drawing styles
            var borderDrawStylesFile = GetBorderDrawStylesFilePath(fullSubCategory);

            if (!string.IsNullOrEmpty(borderDrawStylesFile))
            {
                ret.TrySetDrawStyles(borderDrawStylesFile);
            }

            return(ret);
        }
예제 #2
0
        /// <summary>
        /// Creates a new <see cref="ControlBorder"/> for the given skin and <see cref="Control"/>. This method should
        /// always return a new <see cref="ControlBorder"/> and not use any sort of caching.
        /// </summary>
        /// <param name="controlName">The name of the <see cref="Control"/>.</param>
        /// <param name="subCategory">The optional sub-category. Can be null.</param>
        /// <returns>A new <see cref="ControlBorder"/> for the given skin and <see cref="Control"/>.</returns>
        protected virtual ControlBorder CreateBorder(string controlName, SpriteCategory subCategory)
        {
            // Get the full sub-category
            var fullSubCategory = GetControlSpriteSubCategory(controlName);
            if (subCategory != null && subCategory.ToString().Length > 0)
                fullSubCategory += SpriteCategorization.Delimiter + subCategory;

            // Load all the sides
            var bg = GetSprite(fullSubCategory, "Background");
            var l = GetSprite(fullSubCategory, "Left");
            var r = GetSprite(fullSubCategory, "Right");
            var b = GetSprite(fullSubCategory, "Bottom");
            var bl = GetSprite(fullSubCategory, "BottomLeft");
            var br = GetSprite(fullSubCategory, "BottomRight");
            var tl = GetSprite(fullSubCategory, "TopLeft");
            var t = GetSprite(fullSubCategory, "Top");
            var tr = GetSprite(fullSubCategory, "TopRight");

            // Create the control
            var ret = new ControlBorder(tl, t, tr, r, br, b, bl, l, bg);

            // Try to load the user-defined border drawing styles
            var borderDrawStylesFile = GetBorderDrawStylesFilePath(fullSubCategory);
            if (!string.IsNullOrEmpty(borderDrawStylesFile))
                ret.TrySetDrawStyles(borderDrawStylesFile);

            return ret;
        }
예제 #3
0
        /// <summary>
        /// Gets the <see cref="ControlBorder"/> for the <see cref="Control"/> with the given name.
        /// </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>
        /// <returns>The <see cref="ControlBorder"/> for the <see cref="Control"/> with the given name.</returns>
        public ControlBorder GetBorder(string controlName, SpriteCategory subCategory)
        {
            var key = controlName;

            if (subCategory != null && subCategory.ToString().Length > 0)
            {
                key += subCategory;
            }

            // First, try to get the border from the cache
            ControlBorder ret;

            if (_borderCache.TryGetValue(key, out ret))
            {
                return(ret);
            }

            // Didn't exist in the cache, so create the new border and add it to the cache
            ret = CreateBorder(controlName, subCategory);

            try
            {
                _borderCache.Add(key, ret);
            }
            catch (ArgumentException ex)
            {
                Debug.Fail(
                    "Key already exists. Multi-threading conflict? This should never happen, but its likely not critical." + ex);
            }

            // Return the border
            return(ret);
        }
예제 #4
0
        /// <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));
        }
예제 #5
0
        /// <summary>
        /// Gets the absolute <see cref="SpriteCategory"/> path for the given skin and skin sub-category.
        /// </summary>
        /// <param name="skinName">The name of the skin.</param>
        /// <param name="subCategory">The sub-category under the skin directory. Can be null or empty.</param>
        /// <returns>The absolute <see cref="SpriteCategory"/> path for the given skin and skin sub-category.</returns>
        protected virtual SpriteCategory GetSpriteCategory(string skinName, SpriteCategory subCategory)
        {
            const string del = SpriteCategorization.Delimiter;

            var sb = new StringBuilder(64);

            sb.Append("GUI");
            sb.Append(del);
            sb.Append(skinName);

            if (subCategory != null && subCategory.ToString().Length > 0)
            {
                sb.Append(del);
                sb.Append(subCategory);
            }

            return(new SpriteCategory(sb.ToString()));
        }
예제 #6
0
파일: GrhInfo.cs 프로젝트: wtfcolt/game
 /// <summary>
 /// Gets a unique category based off of an existing category.
 /// </summary>
 /// <param name="category">The category to base the new category name off of.</param>
 /// <returns>A unique, unused category.</returns>
 public static SpriteCategory GetUniqueCategory(SpriteCategory category)
 {
     return(GetUniqueCategory(category.ToString()));
 }
예제 #7
0
        /// <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;
        }
예제 #8
0
        /// <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);
        }
예제 #9
0
        /// <summary>
        /// Gets the <see cref="ControlBorder"/> for the <see cref="Control"/> with the given name.
        /// </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>
        /// <returns>The <see cref="ControlBorder"/> for the <see cref="Control"/> with the given name.</returns>
        public ControlBorder GetBorder(string controlName, SpriteCategory subCategory)
        {
            var key = controlName;
            if (subCategory != null && subCategory.ToString().Length > 0)
                key += subCategory;

            // First, try to get the border from the cache
            ControlBorder ret;
            if (_borderCache.TryGetValue(key, out ret))
                return ret;

            // Didn't exist in the cache, so create the new border and add it to the cache
            ret = CreateBorder(controlName, subCategory);

            try
            {
                _borderCache.Add(key, ret);
            }
            catch (ArgumentException ex)
            {
                Debug.Fail(
                    "Key already exists. Multi-threading conflict? This should never happen, but its likely not critical." + ex);
            }

            // Return the border
            return ret;
        }
예제 #10
0
        /// <summary>
        /// Gets the absolute <see cref="SpriteCategory"/> path for the given skin and skin sub-category.
        /// </summary>
        /// <param name="skinName">The name of the skin.</param>
        /// <param name="subCategory">The sub-category under the skin directory. Can be null or empty.</param>
        /// <returns>The absolute <see cref="SpriteCategory"/> path for the given skin and skin sub-category.</returns>
        protected virtual SpriteCategory GetSpriteCategory(string skinName, SpriteCategory subCategory)
        {
            const string del = SpriteCategorization.Delimiter;

            var sb = new StringBuilder(64);
            sb.Append("GUI");
            sb.Append(del);
            sb.Append(skinName);

            if (subCategory != null && subCategory.ToString().Length > 0)
            {
                sb.Append(del);
                sb.Append(subCategory);
            }

            return new SpriteCategory(sb.ToString());
        }
예제 #11
0
 public static void Write(this IValueWriter writer, string name, SpriteCategory value)
 {
     writer.Write(name, value.ToString());
 }
예제 #12
0
        /// <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);
        }