Example #1
0
        public void AddAccordion <TEnum>(
            int x,
            int y,
            int w,
            int h,
            int pad,
            int bgID,
            int btnNormal,
            int btnSelected,
            Color txtNormal,
            Color txtSelected,
            TEnum?initValue,
            Action <int, int, int, int, TEnum> onRender) where TEnum : struct, IComparable, IFormattable, IConvertible
        {
            if (w <= 0 || h <= 0 || pad * 2 >= w || pad * 2 >= h || onRender == null)
            {
                return;
            }

            var instance = default(TEnum) as Enum;

            if (instance == null)
            {
                return;
            }

            var values = instance.GetValues <Enum>(false);

            if (values.Length == 0)
            {
                return;
            }

            if (_Accordions == null)
            {
                _Accordions = new Dictionary <int, Enum>();
            }

            var hash  = onRender.GetHashCode();
            var value = _Accordions.GetValue(hash);

            var ini = initValue != null ? initValue.Value as Enum : null;

            if (value == null || !values.Contains(value))
            {
                _Accordions[hash] = value = ini;
            }

            var btnSize = GumpsExtUtility.GetImageSize(btnNormal);

            var titleO = btnSize.Width + (pad * 2);
            var titleH = btnSize.Height + (pad * 2);

            var titleC = values.Length;

            var panelH = h - (titleC * titleH);

            foreach (var val in values.Where(v => v != null))
            {
                var v = val;
                var s = Enum.Equals(value, v);
                var l = v.ToString().SpaceWords().WrapUOHtmlBig().WrapUOHtmlColor(s ? txtSelected : txtNormal, false);

                if (bgID > -1)
                {
                    AddBackground(x, y, w, s ? titleH + panelH : titleH, bgID);
                }

                AddButton(
                    x + pad,
                    y + pad,
                    s ? btnSelected : btnNormal,
                    s ? btnNormal : btnSelected,
                    b =>
                {
                    _Accordions[hash] = s ? ini : v;

                    Refresh(true);
                });

                AddHtml(x + titleO, y + ((titleH / 2) - 10), w - titleO, 40, l, false, false);

                if (s)
                {
                    y += titleH;

                    onRender(x + pad, y, w - (pad * 2), panelH - (pad * 2), (TEnum)(object)v);

                    y += panelH;
                }
                else
                {
                    y += titleH;
                }
            }
        }
Example #2
0
 public virtual Size GetImageSize(int imageID)
 {
     return(GumpsExtUtility.GetImageSize(imageID));
 }