コード例 #1
0
ファイル: ShopGUI.cs プロジェクト: Jofairden/MultiShop
        public override void OnInitialize()
        {
            /// Item panel
            itemPanel          = new ItemUIPanel();
            itemPanel.OnClick += (s, e) =>
            {
                var sortMode = SortingMode.CurrentCollectibleSortMode == SortingMode.CollectibleSortingMode.NamesDesc ? SortingMode.CollectibleSortingMode.NamesAsc
                                                           : SortingMode.CurrentCollectibleSortMode == SortingMode.CollectibleSortingMode.NamesAsc ?
                               SortingMode.CollectibleSortingMode.Normal : SortingMode.CollectibleSortingMode.NamesDesc;

                SortingMode.ApplySort(ref MultiShop.instance.shopGUI.rightPanel, sortMode);
            };
            itemPanel.Width.Set(ShopUIPanel.panelwidth, 0f);
            itemPanel.Height.Set(ShopUIPanel.panelheight, 0f);
            base.Append(itemPanel);

            /// Header text (Item name)
            headerText   = "??";
            headerUIText = new UIText(headerText);
            headerUIText.Top.Set(Main.fontItemStack.MeasureString(headerUIText.Text).X / 2 + ShopGUI.vpadding / 4f, 0f);
            headerUIText.Left.Set(itemPanel.Width.Pixels + ShopGUI.vpadding, 0f);
            base.Append(headerUIText);

            /// Unit panel
            unitPanel          = new UIPanel();
            unitPanel.OnClick += (s, e) =>
            {
                var sortMode = SortingMode.CurrentCollectibleSortMode == SortingMode.CollectibleSortingMode.UnitDesc ?
                               SortingMode.CollectibleSortingMode.UnitAsc
                                                           : SortingMode.CollectibleSortingMode.UnitDesc;

                SortingMode.ApplySort(ref MultiShop.instance.shopGUI.rightPanel, sortMode);
            };
            unitPanel.OnMouseOver += (s, e) =>
            {
                (e as UIPanel).PanelUIHover();
            };
            unitPanel.OnMouseOut += (s, e) =>
            {
                (e as UIPanel).PanelUIHover(false);
            };
            unitPanel.Height.Set(itemPanel.Height.Pixels, 0f);
            unitPanel.Width.Set(base.Width.Pixels / 4f + ShopGUI.vpadding * 2f, 0f);
            unitPanel.Left.Set(base.Width.Pixels - unitPanel.Width.Pixels - ShopGUI.vpadding, 0f);
            base.Append(unitPanel);

            /// Unit UI Text
            unitUIText = new UIText("");
            SetUnits(_stack);
            unitPanel.Append(unitUIText);
        }
コード例 #2
0
ファイル: ShopGUI.cs プロジェクト: Jofairden/MultiShop
        public override void OnInitialize()
        {
            // Header
            headerUIText = new UIText(headerText);
            base.Append(headerUIText);

            // Result
            resultPanel          = new ItemUIPanel();
            resultPanel.OnClick += (s, e) =>
            {
                var sortMode = SortingMode.CurrentShopSortMode == SortingMode.ShopSortingMode.ResultNameDesc ? SortingMode.ShopSortingMode.ResultNameAsc
                                                           : SortingMode.CurrentShopSortMode == SortingMode.ShopSortingMode.ResultNameAsc ?
                               SortingMode.ShopSortingMode.Normal : SortingMode.ShopSortingMode.ResultNameDesc;

                SortingMode.ApplySort(ref MultiShop.instance.shopGUI.leftPanel, sortMode);
            };
            resultPanel.Width.Set(panelwidth * 1.5f, 0f);
            resultPanel.Height.Set(panelheight * 1.5f, 0f);
            resultPanel.Top.Set(Main.fontItemStack.MeasureString(headerText).Y, 0f);
            base.Append(resultPanel);

            // Materialpanels
            materialPanels = new ItemUIPanel[8];
            for (int i = 0; i < materialPanels.Length; i++)
            {
                materialPanels[i] = new ItemUIPanel();
                var currentPanel = materialPanels[i];
                currentPanel.Width.Set(panelwidth, 0f);
                currentPanel.Height.Set(panelheight, 0f);
                currentPanel.Top.Set(i < 4
                                        ? resultPanel.Top.Pixels
                                        : resultPanel.Top.Pixels + panelheight + ShopGUI.vpadding / 2f, 0f);
                currentPanel.Left.Set(resultPanel.Width.Pixels + ShopGUI.vpadding / 2f + (panelwidth + ShopGUI.vpadding / 2f) * (i % (materialPanels.Length / 2f)), 0f);
                base.Append(currentPanel);
            }

            // Currencypanels
            currencyPanels = new ItemUIPanel[4];
            for (int i = 0; i < currencyPanels.Length; i++)
            {
                currencyPanels[i] = new ItemUIPanel(ItemID.CopperCoin + i, 0);
                var currentPanel = currencyPanels[i];
                currentPanel.OnClick += (s, e) =>
                {
                    var sortMode = SortingMode.CurrentShopSortMode == SortingMode.ShopSortingMode.GoldDesc ? SortingMode.ShopSortingMode.GoldAsc
                                                                   : SortingMode.ShopSortingMode.GoldDesc;

                    SortingMode.ApplySort(ref MultiShop.instance.shopGUI.leftPanel, sortMode);
                };
                currentPanel.Width.Set(panelwidth, 0f);
                currentPanel.Height.Set(panelheight, 0f);
                currentPanel.Top.Set(materialPanels[materialPanels.Length - 1].Top.Pixels + ShopGUI.vpadding / 2f + panelheight, 0f);
                currentPanel.Left.Set(resultPanel.Width.Pixels + ShopGUI.vpadding / 2f + (panelwidth + ShopGUI.vpadding / 2f) * i, 0f);
                base.Append(currentPanel);
            }

            // Special slot
            specialPanel = new ItemUIPanel();
            specialPanel.item.SetDefaults(ItemID.CrystalShard);
            specialPanel.item.stack = Main.rand.Next(5);
            specialPanel.OnClick   += (s, e) =>
            {
                var sortMode = SortingMode.CurrentShopSortMode == SortingMode.ShopSortingMode.ArtifactDesc ? SortingMode.ShopSortingMode.ArtifactAsc
                                                                   : SortingMode.ShopSortingMode.ArtifactDesc;

                SortingMode.ApplySort(ref MultiShop.instance.shopGUI.leftPanel, sortMode);
            };
            specialPanel.Top.Set(resultPanel.Top.Pixels + resultPanel.Height.Pixels + ShopGUI.vpadding / 2f, 0f);
            specialPanel.Width.Set(panelwidth, 0f);
            specialPanel.Height.Set(panelheight, 0f);
            specialPanel.Left.Set(specialPanel.Width.Pixels / 4f, 0f);
            base.Append(specialPanel);

            buyUIText              = new UIText("BUY");
            buyUIText.OnMouseOver += (s, e) =>
            {
                (e as UIText).TextUIHover();
            };
            buyUIText.OnMouseOut += (s, e) =>
            {
                (e as UIText).TextUIHover(false);
            };
            var stringSize = Main.fontItemStack.MeasureString(buyUIText.Text);

            buyUIText.Top.Set(specialPanel.Top.Pixels + specialPanel.Height.Pixels + ShopGUI.vpadding / 2f, 0f);
            buyUIText.Left.Set(stringSize.X / 2f + ShopGUI.vpadding / 4f, 0f);
            base.Append(buyUIText);
        }
コード例 #3
0
ファイル: ShopGUI.cs プロジェクト: Jofairden/MultiShop
        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);
        }