Esempio n. 1
0
 public void AddButton(UISortButton button)
 {
     button.Initialize();
     button.offsetY = _buttons.Count * button.Width.Pixels + 2.5f * _buttons.Count;
     button.ResetTop();
     _buttons.Add(button);
 }
Esempio 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);
        }