Example #1
0
            public void Draw()
            {
                try
                {
                    if (!Initialized)
                    {
                        Init();
                    }

                    MenuOptions o            = menu.current.options;          // should save a lot of characters below
                    PointF      itemPosition = Position;
                    menu.current.visibleItems.Select((item, index) => new { item, index }).ToList().ForEach(n =>
                    {
                        var i           = n.item;
                        bool isSelected = menu.current.SelectedIndex == (menu.current.topMostVisibleItem + n.index);
                        if (i is MenuItemStandard)
                        {
                            if (((MenuItemStandard)i).SubDetail != null)
                            {
                                new Rectangle(itemPosition, new SizeF(o.Width, o.ItemWithDetailHeight), isSelected ? o.ItemSelectedBackgroundColor : o.ItemBackgroundColor).Draw();
                                new Text(i.Title, itemPosition.Add(o.ItemPadding), o.ItemTextSize, isSelected ? o.ItemSelectedTextColor : o.ItemTextColor).Draw();
                                if (((MenuItemStandard)i).Detail != null)
                                {
                                    new Text(((MenuItemStandard)i).Detail, new PointF(itemPosition.X + o.Width - o.ItemPadding.X, itemPosition.Y + o.ItemPadding.Y), o.ItemTextSize, isSelected ? o.ItemSelectedTextColor : o.ItemTextColor, o.ItemFont, Alignment.Right).Draw();
                                }
                                new Text(((MenuItemStandard)i).SubDetail, new PointF(itemPosition.X + o.Width - o.ItemPadding.X, itemPosition.Y + o.ItemPadding.Y + 14f), o.ItemSubDetailTextSize, isSelected ? o.ItemSelectedTextColor : o.ItemTextColor, o.ItemFont, Alignment.Right).Draw();
                                itemPosition = itemPosition.Add(new PointF(0, o.ItemWithDetailHeight + o.ItemBottomMargin));
                            }
                            else
                            {
                                new Rectangle(itemPosition, new SizeF(o.Width, o.ItemHeight), isSelected ? o.ItemSelectedBackgroundColor : o.ItemBackgroundColor).Draw();
                                if (((MenuItemStandard)i).Detail != null)
                                {
                                    new Text(((MenuItemStandard)i).Detail, new PointF(itemPosition.X + o.Width - o.ItemPadding.X, itemPosition.Y + o.ItemPadding.Y), o.ItemTextSize, isSelected ? o.ItemSelectedTextColor : o.ItemTextColor, o.ItemFont, Alignment.Right).Draw();
                                }
                                new Text(i.Title, itemPosition.Add(o.ItemPadding), o.ItemTextSize, isSelected ? o.ItemSelectedTextColor : o.ItemTextColor).Draw();
                                itemPosition = itemPosition.Add(new PointF(0, o.ItemHeight + o.ItemBottomMargin));
                            }
                        }
                        else if (i is MenuItemCheckbox)
                        {
                            new Rectangle(itemPosition, new SizeF(o.Width, o.ItemHeight), isSelected ? o.ItemSelectedBackgroundColor : o.ItemBackgroundColor).Draw();
                            bool isChecked        = ((MenuItemCheckbox)i).State;
                            string checkboxSprite = isSelected ? (isChecked ? "shop_box_tickb" : "shop_box_blankb") : (isChecked ? "shop_box_tick" : "shop_box_blank");
                            UIHelpers.DrawSprite("commonmenu", checkboxSprite, new PointF(itemPosition.X + o.Width - o.ItemPadding.X, itemPosition.Y + o.ItemPadding.Y).Add(o.MenuItemCheckboxOffset), new SizeF(o.MenuItemCheckboxSize), new Size(0, 0), Color.FromArgb(80, 255, 255, 255), false);
                            new Text(i.Title, itemPosition.Add(o.ItemPadding), o.ItemTextSize, isSelected ? o.ItemSelectedTextColor : o.ItemTextColor).Draw();
                            itemPosition = itemPosition.Add(new PointF(0, o.ItemHeight + o.ItemBottomMargin));
                        }
                        else if (i is MenuItemHorSelector <int> )                       // I gave up on trying to combine these two into one with Reflection methods
                        {
                            MenuItemHorSelector <int> item      = i as MenuItemHorSelector <int>;
                            MenuItemHorizontalSelectorType type = item.Type;
                            int state      = item.state;
                            int maxState   = item.maxState;
                            int minState   = item.minState;
                            bool hasBar    = type == MenuItemHorizontalSelectorType.Bar || type == MenuItemHorizontalSelectorType.NumberAndBar;
                            bool hasNumber = type == MenuItemHorizontalSelectorType.Number || type == MenuItemHorizontalSelectorType.NumberAndBar;
                            new Rectangle(itemPosition, new SizeF(o.Width, hasBar ? o.ItemHorSelWithBarHeight : o.ItemHeight), isSelected ? o.ItemSelectedBackgroundColor : o.ItemBackgroundColor).Draw();
                            new Text(i.Title, itemPosition.Add(o.ItemPadding), o.ItemTextSize, isSelected ? o.ItemSelectedTextColor : o.ItemTextColor).Draw();

                            if (hasNumber)
                            {
                                new Text($"{(item.overrideDetailWith != null ? item.overrideDetailWith : $"{state}/{maxState}")}", new PointF(itemPosition.X + o.Width - o.ItemPadding.X, itemPosition.Y + o.ItemPadding.Y), o.ItemTextSize, isSelected ? o.ItemSelectedTextColor : o.ItemTextColor, o.ItemFont, Alignment.Right).Draw();
                            }
                            if (hasBar)
                            {
                                float progressFraction = (state - minState) / (float)((maxState - minState));
                                new Rectangle(itemPosition.Add(o.MenuItemHorSelOuterBarOffset), new SizeF(o.Width - 2 * o.MenuItemHorSelOuterBarOffset.X, o.MenuItemHorSelOuterBarHeight), isSelected ? o.ItemHorSelSelectedOuterBgColor : o.ItemHorSelOuterBgColor).Draw();
                                new Rectangle(itemPosition.Add(o.MenuItemHorSelOuterBarOffset).Add(o.MenuItemHorSelInnerBarOffset), new SizeF(progressFraction * (o.Width - 2 * (o.MenuItemHorSelOuterBarOffset.X + o.MenuItemHorSelInnerBarOffset.X)), o.MenuItemHorSelInnerBarHeight), isSelected ? o.ItemHorSelSelectedInnerBgColor : o.ItemHorSelInnerBgColor).Draw();
                            }

                            itemPosition = itemPosition.Add(new PointF(0, (hasBar ? o.ItemHorSelWithBarHeight : o.ItemHeight) + o.ItemBottomMargin));
                        }
                        else if (i is MenuItemHorSelector <float> )                       // I gave up on trying to combine these two into one with Reflection methods, dynamic types etc. Feel free
                        {
                            MenuItemHorSelector <float> item    = i as MenuItemHorSelector <float>;
                            MenuItemHorizontalSelectorType type = item.Type;
                            float state    = item.state;
                            float maxState = item.maxState;
                            float minState = item.minState;
                            bool hasBar    = type == MenuItemHorizontalSelectorType.Bar || type == MenuItemHorizontalSelectorType.NumberAndBar;
                            bool hasNumber = type == MenuItemHorizontalSelectorType.Number || type == MenuItemHorizontalSelectorType.NumberAndBar;
                            new Rectangle(itemPosition, new SizeF(o.Width, hasBar ? o.ItemHorSelWithBarHeight : o.ItemHeight), isSelected ? o.ItemSelectedBackgroundColor : o.ItemBackgroundColor).Draw();
                            new Text(i.Title, itemPosition.Add(o.ItemPadding), o.ItemTextSize, isSelected ? o.ItemSelectedTextColor : o.ItemTextColor).Draw();

                            if (hasNumber)
                            {
                                new Text($"{(item.overrideDetailWith != null ? item.overrideDetailWith : $"{state:0.00}/{maxState:0.00}")}", new PointF(itemPosition.X + o.Width - o.ItemPadding.X, itemPosition.Y + o.ItemPadding.Y), o.ItemTextSize, isSelected ? o.ItemSelectedTextColor : o.ItemTextColor, o.ItemFont, Alignment.Right).Draw();
                            }
                            if (hasBar)
                            {
                                float progressFraction = (state - minState) / (float)((maxState - minState));
                                new Rectangle(itemPosition.Add(o.MenuItemHorSelOuterBarOffset), new SizeF(o.Width - 2 * o.MenuItemHorSelOuterBarOffset.X, o.MenuItemHorSelOuterBarHeight), isSelected ? o.ItemHorSelSelectedOuterBgColor : o.ItemHorSelOuterBgColor).Draw();
                                new Rectangle(itemPosition.Add(o.MenuItemHorSelOuterBarOffset).Add(o.MenuItemHorSelInnerBarOffset), new SizeF(progressFraction * (o.Width - 2 * (o.MenuItemHorSelOuterBarOffset.X + o.MenuItemHorSelInnerBarOffset.X)), o.MenuItemHorSelInnerBarHeight), isSelected ? o.ItemHorSelSelectedInnerBgColor : o.ItemHorSelInnerBgColor).Draw();
                            }

                            itemPosition = itemPosition.Add(new PointF(0, (hasBar ? o.ItemHorSelWithBarHeight : o.ItemHeight) + o.ItemBottomMargin));
                        }
                        else if (i is MenuItemHorNamedSelector)                         // I gave up on trying to combine these into one with Reflection methods
                        {
                            MenuItemHorNamedSelector item       = i as MenuItemHorNamedSelector;
                            MenuItemHorizontalSelectorType type = item.Type;
                            int maxState     = item.optionList.Count() - 1;
                            int minState     = 0;
                            int state        = (item.state < minState) ? minState : (item.state > maxState) ? maxState : item.state;
                            string stateName = item.optionList[state];
                            bool hasBar      = type == MenuItemHorizontalSelectorType.Bar || type == MenuItemHorizontalSelectorType.NumberAndBar;
                            bool hasNumber   = type == MenuItemHorizontalSelectorType.Number || type == MenuItemHorizontalSelectorType.NumberAndBar;
                            new Rectangle(itemPosition, new SizeF(o.Width, hasBar ? o.ItemHorSelWithBarHeight : o.ItemHeight), isSelected ? o.ItemSelectedBackgroundColor : o.ItemBackgroundColor).Draw();
                            new Text(i.Title, itemPosition.Add(o.ItemPadding), o.ItemTextSize, isSelected ? o.ItemSelectedTextColor : o.ItemTextColor).Draw();

                            if (hasNumber)
                            {
                                new Text($"{(item.overrideDetailWith != null ? item.overrideDetailWith : stateName)}", new PointF(itemPosition.X + o.Width - o.ItemPadding.X, itemPosition.Y + o.ItemPadding.Y), o.ItemTextSize, isSelected ? o.ItemSelectedTextColor : o.ItemTextColor, o.ItemFont, Alignment.Right).Draw();
                            }
                            if (hasBar)
                            {
                                float progressFraction = (state - minState) / (float)((maxState - minState));
                                new Rectangle(itemPosition.Add(o.MenuItemHorSelOuterBarOffset), new SizeF(o.Width - 2 * o.MenuItemHorSelOuterBarOffset.X, o.MenuItemHorSelOuterBarHeight), isSelected ? o.ItemHorSelSelectedOuterBgColor : o.ItemHorSelOuterBgColor).Draw();
                                new Rectangle(itemPosition.Add(o.MenuItemHorSelOuterBarOffset).Add(o.MenuItemHorSelInnerBarOffset), new SizeF(progressFraction * (o.Width - 2 * (o.MenuItemHorSelOuterBarOffset.X + o.MenuItemHorSelInnerBarOffset.X)), o.MenuItemHorSelInnerBarHeight), isSelected ? o.ItemHorSelSelectedInnerBgColor : o.ItemHorSelInnerBgColor).Draw();
                            }

                            itemPosition = itemPosition.Add(new PointF(0, (hasBar ? o.ItemHorSelWithBarHeight : o.ItemHeight) + o.ItemBottomMargin));
                        }
                        else
                        {
                            new Rectangle(itemPosition, new SizeF(o.Width, o.ItemHeight), isSelected ? o.ItemSelectedBackgroundColor : o.ItemBackgroundColor).Draw();
                            new Text(i.Title, itemPosition.Add(o.ItemPadding), o.ItemTextSize, isSelected ? o.ItemSelectedTextColor : o.ItemTextColor).Draw();
                            itemPosition = itemPosition.Add(new PointF(0, o.ItemHeight + o.ItemBottomMargin));
                        }
                    });
Example #2
0
 public void Init()
 {
     o           = menu.current.options;
     Position    = o.Origin.Add(new PointF(0, o.HeaderHeight + o.HeaderBottomMargin + o.StatusBarHeight + o.StatusBarBottomMargin));
     Initialized = true;
 }