Ejemplo n.º 1
0
        internal static UIPanel MakeSeparateListPanel(object item, object subitem, PropertyFieldWrapper memberInfo, IList array, int index, Func <string> AbridgedTextDisplayFunction)
        {
            UIPanel uIPanel = new UIPanel();

            uIPanel.CopyStyle(Interface.modConfig.uIPanel);
            uIPanel.BackgroundColor = UICommon.MainPanelBackground;

            BackgroundColorAttribute bca = ConfigManager.GetCustomAttribute <BackgroundColorAttribute>(memberInfo, subitem, null);

            if (bca != null)
            {
                uIPanel.BackgroundColor = bca.color;
            }

            //uIElement.Append(uIPanel);

            UIList separateList = new UIList();

            separateList.CopyStyle(Interface.modConfig.mainConfigList);
            separateList.Height.Set(-40f, 1f);
            separateList.Top.Set(40f, 0f);
            uIPanel.Append(separateList);
            int i   = 0;
            int top = 0;

            UIScrollbar uIScrollbar = new UIScrollbar();

            uIScrollbar.SetView(100f, 1000f);
            uIScrollbar.Height.Set(-40f, 1f);
            uIScrollbar.Top.Set(40f, 0f);
            uIScrollbar.HAlign = 1f;
            uIPanel.Append(uIScrollbar);
            separateList.SetScrollbar(uIScrollbar);

            string name = ConfigManager.GetCustomAttribute <LabelAttribute>(memberInfo, subitem, null)?.Label ?? memberInfo.Name;

            if (index != -1)
            {
                name = name + " #" + (index + 1);
            }
            Interface.modConfig.subPageStack.Push(name);
            //UIPanel heading = new UIPanel();
            //UIText headingText = new UIText(name);

            name = string.Join(" > ", Interface.modConfig.subPageStack.Reverse());   //.Aggregate((current, next) => current + "/" + next);

            UITextPanel <string> heading = new UITextPanel <string>(name);           // TODO: ToString as well. Separate label?

            heading.HAlign = 0f;
            //heading.Width.Set(-10, 0.5f);
            //heading.Left.Set(60, 0f);
            heading.Top.Set(-6, 0);
            heading.Height.Set(40, 0);
            //var headingContainer = GetContainer(heading, i++);
            //headingContainer.Height.Pixels = 40;
            uIPanel.Append(heading);
            //headingText.Top.Set(6, 0);
            //headingText.Left.Set(0, .5f);
            //headingText.HAlign = .5f;
            //uIPanel.Append(headingText);
            //top += 40;

            UITextPanel <string> back = new UITextPanel <string>("Back");

            back.HAlign = 1f;
            back.Width.Set(50, 0f);
            back.Top.Set(-6, 0);
            //top += 40;
            //var capturedCurrent = Interface.modConfig.currentConfigList;
            back.OnClick += (a, c) => {
                Interface.modConfig.uIElement.RemoveChild(uIPanel);
                Interface.modConfig.configPanelStack.Pop();
                Interface.modConfig.uIElement.Append(Interface.modConfig.configPanelStack.Peek());
                //Interface.modConfig.configPanelStack.Peek().SetScrollbar(Interface.modConfig.uIScrollbar);
                //Interface.modConfig.currentConfigList = capturedCurrent;
            };
            back.WithFadedMouseOver();
            //var backContainer = GetContainer(back, i++);
            //backContainer.Height.Pixels = 40;
            uIPanel.Append(back);

            //var b = new UIText("Test");
            //separateList.Add(b);
            // Make rest of list


            // load all mod config options into UIList
            // TODO: Inheritance with ModConfig? DeclaredOnly?

            if (true)
            {
                int  order       = 0;
                bool hasToString = false;
                if (array != null)
                {
                    var listType = memberInfo.Type.GetGenericArguments()[0];
                    hasToString = listType.GetMethod("ToString", new Type[0]).DeclaringType != typeof(object);
                }
                else
                {
                    hasToString = memberInfo.Type.GetMethod("ToString", new Type[0]).DeclaringType != typeof(object);
                }
                if (AbridgedTextDisplayFunction != null)
                {
                    var display = new UITextPanel <FuncStringWrapper>(new FuncStringWrapper()
                    {
                        func = AbridgedTextDisplayFunction,
                    })
                    {
                        DrawPanel = true
                    };
                    display.Recalculate();
                    var container = GetContainer(display, order++);
                    container.Height.Pixels = (int)display.GetOuterDimensions().Height;
                    separateList.Add(container);
                }
                //if (hasToString)
                //	_TextDisplayFunction = () => index + 1 + ": " + (array[index]?.ToString() ?? "null");
                foreach (PropertyFieldWrapper variable in ConfigManager.GetFieldsAndProperties(subitem))
                {
                    if (Attribute.IsDefined(variable.MemberInfo, typeof(JsonIgnoreAttribute)) && !Attribute.IsDefined(variable.MemberInfo, typeof(LabelAttribute)))                     // TODO, appropriately named attribute
                    {
                        continue;
                    }
                    HeaderAttribute header = ConfigManager.GetCustomAttribute <HeaderAttribute>(variable, null, null);
                    if (header != null)
                    {
                        var wrapper = new PropertyFieldWrapper(typeof(HeaderAttribute).GetProperty(nameof(HeaderAttribute.Header)));
                        WrapIt(separateList, ref top, wrapper, header, order++);
                    }
                    WrapIt(separateList, ref top, variable, subitem, order++);
                }
            }
            else
            {
                //ignoreSeparatePage just to simplify ToString label--> had some issues.
                //WrapIt(separateList, ref top, memberInfo, item, 1, ignoreSeparatePage: true);
            }

            Interface.modConfig.subPageStack.Pop();
            return(uIPanel);
        }
Ejemplo n.º 2
0
        public override void OnInitialize()
        {
            _UIView = new UIElement();
            _UIView.SetPadding(0f);
            _UIView.Width.Set(vwidth - 3f * vpadding, 0f);
            _UIView.Height.Set(vheight + 75f, 0f);
            _UIView.Left.Set(Main.screenWidth / 2f - _UIView.Width.Pixels / 2f, 0f);
            _UIView.Top.Set(Main.screenHeight / 2f - _UIView.Height.Pixels / 2f, 0f);
            //uncomment this to see the UIView
            //var testPanel = new UIPanel();
            //testPanel.CopyStyle(_UIView);
            //testPanel.Left.Set(0f, 0f);
            //testPanel.Top.Set(0f, 0f);
            //testPanel.BackgroundColor = Color.Yellow;
            //_UIView.Append(testPanel);
            base.Append(_UIView);

            shopPanel = new UIPanel();
            shopPanel.BackgroundColor = baseUIPanelBGColor;
            shopPanel.SetPadding(vpadding);
            shopPanel.Width.Set(_UIView.Width.Pixels, 0f);
            shopPanel.Height.Set(_UIView.Height.Pixels, 0f);
            //shopPanel.Left.Set(3f * vpadding + sortPanelWidth, 0f);
            //shopPanel.Top.Set((_UIView.Height.Pixels - vheight) / 4f, 0f);
            shopPanel.OnMouseDown += ShopPanel_OnMouseDown;
            shopPanel.OnMouseUp   += ShopPanel_OnMouseUp;
            _UIView.Append(shopPanel);

            leftTitle = new UIText("SHOP/CRAFT", 0.95f, true);
            leftTitle.Top.Set(vpadding, 0f);
            shopPanel.Append(leftTitle);

            rightTitle = new UIText("COLLECTED", 0.95f, true);
            rightTitle.Top.Set(vpadding, 0f);
            rightTitle.Left.Set(vwidth / 2f - 58f + vpadding * 4f, 0f);
            shopPanel.Append(rightTitle);

            leftSortPanel = new UISortPanel();
            leftSortPanel.Left.Set(vwidth / 2f - 50f - vpadding * 3f, 0f);
            shopPanel.Append(leftSortPanel);

            leftSortButton = new UISortButton();
            leftSortButton.Initialize();
            leftSortButton._button.OnClick += (s, e) =>
            {
                SortingMode.ApplySort(ref leftPanel, (SortingMode.ShopSortingMode)SortingMode.GetNewSort(typeof(SortingMode.ShopSortingMode)));
            };
            leftSortButton.OnDrawSelf += (s, e) =>
            {
                if (s.IsMouseHovering || s._button.IsMouseHovering)
                {
                    Main.hoverItemName = $"Current sorting mode: {SortingMode.GetSortingModeTooltip(SortingMode.CurrentShopSortMode)}\n" +
                                         $"Traverse through sorting modes by pressing this button\n" +
                                         $"You can also apply sorting modes by pressing elements in the UI!";
                }
            };
            leftSortPanel.AddButton(leftSortButton);
            leftSortPanel.AppendButtons();

            rightSortPanel = new UISortPanel();
            rightSortPanel.Left.Set(vwidth - 50f - vpadding * 5f, 0f);
            shopPanel.Append(rightSortPanel);

            rightSortButton = new UISortButton();
            rightSortButton.Initialize();
            rightSortButton._button.OnClick += (s, e) =>
            {
                SortingMode.ApplySort(ref rightPanel, (SortingMode.CollectibleSortingMode)SortingMode.GetNewSort(typeof(SortingMode.CollectibleSortingMode)));
            };
            rightSortButton.OnDrawSelf += (s, e) =>
            {
                if (s.IsMouseHovering || s._button.IsMouseHovering)
                {
                    Main.hoverItemName = $"Current sorting mode: {SortingMode.GetSortingModeTooltip(SortingMode.CurrentCollectibleSortMode)}\n" +
                                         $"Traverse through sorting modes by pressing this button\n" +
                                         $"You can also apply sorting modes by pressing elements in the UI!";
                }
            };
            rightSortPanel.AddButton(rightSortButton);
            rightSortPanel.AppendButtons();

            UIPanel leftPanelBG = new UIPanel();

            leftPanelBG.OverflowHidden  = true;
            leftPanelBG.BackgroundColor = sectionUIPanelBGColor;
            leftPanelBG.SetPadding(0);
            leftPanelBG.Width.Set(vwidth / 2f - 40f + vpadding, 0f);
            leftPanelBG.Height.Set(vheight, 0f);
            leftPanelBG.Top.Set(55f, 0f);
            shopPanel.Append(leftPanelBG);

            leftPanel = new UIList();
            leftPanel.OverflowHidden = true;
            leftPanel.SetPadding(vpadding);
            leftPanel.Width.Set(vwidth / 2f, 0f);
            leftPanel.Height.Set(vheight + (_UIView.Height.Pixels - vheight) / 2f, 0f);
            leftPanelBG.Append(leftPanel);             // append leftPanel to shopPanel

            leftScrollbar = new UIScrollbar();
            leftScrollbar.Height.Set(vheight - 4f * vpadding, 0f);
            leftScrollbar.Width.Set(22f, 0f);
            leftScrollbar.Left.Set(vwidth / 2f - 80f + vpadding, 0f);
            leftScrollbar.Top.Set(vpadding, 0f);
            leftPanel.Append(leftScrollbar);
            leftPanel.SetScrollbar(leftScrollbar);

            UIPanel rightPanelBG = new UIPanel();

            rightPanelBG.CopyStyle(leftPanelBG);
            rightPanelBG.Left.Set(vwidth / 2f - 58f + vpadding * 4f, 0f);
            shopPanel.Append(rightPanelBG);

            rightPanel = new UIList();
            rightPanel.CopyStyle(leftPanel);
            //rightPanel.Width.Set(vwidth/2f + vpadding + leftScrollbar.Width.Pixels, 0f);
            //rightPanel.Left.Set(vwidth/2f - 58f + vpadding * 3f, 0f);
            rightPanelBG.Append(rightPanel);             // append rightPanel to shopPanel

            rightScrollbar = new UIScrollbar();
            rightScrollbar.CopyStyle(leftScrollbar);
            rightScrollbar.Left.Set(vwidth / 2f - 80f + vpadding, 0f);
            rightPanel.Append(rightScrollbar);
            rightPanel.SetScrollbar(rightScrollbar);

            // Temp fill of collectibles
            TEMPCollectibles = new List <Tuple <int, int> >();
            var tmpC = new Tuple <int, int>[]
            {
                new Tuple <int, int>(ItemID.Bone, 1000),
                new Tuple <int, int>(ItemID.DemoniteOre, 1500),
            };

            for (int i = 0; i < tmpC.Length; i++)
            {
                TEMPCollectibles.Add(tmpC[i]);
            }

            for (int i = ItemID.Sapphire; i < ItemID.Diamond + 1; i++)
            {
                TEMPCollectibles.Add(new Tuple <int, int>(i, 50));
            }

            for (int i = ItemID.LivingCursedFireBlock; i < ItemID.LivingUltrabrightFireBlock + 1; i++)
            {
                TEMPCollectibles.Add(new Tuple <int, int>(i, 30));
            }

            collectibleUIPanels = new List <CollectibleUIPanel>();
            for (int i = 0; i < TEMPCollectibles.Count; i++)
            {
                CollectibleUIPanel collectibleUIPanel = new CollectibleUIPanel();
                collectibleUIPanel.Initialize();
                collectibleUIPanel.SetItem(TEMPCollectibles[i].Item1, TEMPCollectibles[i].Item2);
                collectibleUIPanels.Add(collectibleUIPanel);
                rightPanel.Add(collectibleUIPanel);
            }
            SortingMode.ApplySort(ref rightPanel, SortingMode.CollectibleSortingMode.UnitDesc);

            //var tmp = new ShopSortButton();
            //rightSortPanel.AddButton(tmp);
            //rightSortPanel.AppendButtons();

            shopUIPanels = new List <ShopUIPanel>();
            // Leftpanel filler
            for (int i = 0; i < 10; i++)
            {
                ShopUIPanel shopUIPanel = new ShopUIPanel();
                shopUIPanel.Initialize();
                shopUIPanel.SetResult(ItemID.SoulofFlight + Main.rand.Next(50), Main.rand.Next(50));
                for (int j = 0; j < shopUIPanel.materialPanels.Length; j++)
                {
                    var currentPanel = shopUIPanel.materialPanels[j];
                    currentPanel.item.SetDefaults(collectibleUIPanels[Main.rand.Next(collectibleUIPanels.Count - 1)].itemPanel.item.type);
                    currentPanel.item.stack = Main.rand.Next(6);
                }
                for (int j = 0; j < shopUIPanel.currencyPanels.Length; j++)
                {
                    var currentPanel = shopUIPanel.currencyPanels[j];
                    currentPanel.item.stack = Main.rand.Next(20 * (j + 1));
                }
                shopUIPanel.Top.Set((shopUIPanel.Height.Pixels + vpadding / 2f) * i, 0f);
                shopUIPanels.Add(shopUIPanel);
                leftPanel.Add(shopUIPanels[shopUIPanels.Count - 1]);                 // Do not append, Add for the scrollbar
            }
            SortingMode.ApplySort(ref leftPanel, SortingMode.ShopSortingMode.Normal);
        }