Esempio n. 1
0
        private void UpdateCounter()
        {
            int numItems = 0;
            int capacity = 0;

            foreach (TEAbstractStorageUnit abstractStorageUnit in heart.GetStorageUnits())
            {
                if (abstractStorageUnit is TEStorageUnit storageUnit)
                {
                    numItems += storageUnit.NumItems;
                    capacity += storageUnit.Capacity;
                }
            }

            int len = capacityText.Text.Length;

            capacityText.SetText(numItems + "/" + capacity + " Items");

            if (len != capacityText.Text.Length)
            {
                capacityText.Recalculate();
            }
        }
Esempio n. 2
0
        public static void Initialize()
        {
            InitLangStuff();
            float itemSlotWidth  = Main.inventoryBackTexture.Width * inventoryScale;
            float itemSlotHeight = Main.inventoryBackTexture.Height * inventoryScale;

            panelTop  = Main.instance.invBottom + 60;
            panelLeft = 20f;
            basePanel = new UIPanel();
            float innerPanelLeft  = panelLeft + basePanel.PaddingLeft;
            float innerPanelWidth = numColumns * (itemSlotWidth + padding) + 20f + padding;

            panelWidth  = basePanel.PaddingLeft + innerPanelWidth + basePanel.PaddingRight;
            panelHeight = Main.screenHeight - panelTop - 40f;
            basePanel.Left.Set(panelLeft, 0f);
            basePanel.Top.Set(panelTop, 0f);
            basePanel.Width.Set(panelWidth, 0f);
            basePanel.Height.Set(panelHeight, 0f);
            basePanel.Recalculate();

            topBar = new UIElement();
            topBar.Width.Set(0f, 1f);
            topBar.Height.Set(32f, 0f);
            basePanel.Append(topBar);

            InitSortButtons();
            topBar.Append(sortButtons);

            depositButton.Left.Set(sortButtons.GetDimensions().Width + 2 * padding, 0f);
            depositButton.Width.Set(128f, 0f);
            depositButton.Height.Set(-2 * padding, 1f);
            depositButton.PaddingTop    = 8f;
            depositButton.PaddingBottom = 8f;
            topBar.Append(depositButton);

            float depositButtonRight = sortButtons.GetDimensions().Width + 2 * padding + depositButton.GetDimensions().Width;

            searchBar.Left.Set(depositButtonRight + padding, 0f);
            searchBar.Width.Set(-depositButtonRight - 2 * padding, 1f);
            searchBar.Height.Set(0f, 1f);
            topBar.Append(searchBar);

            topBar2 = new UIElement();
            topBar2.Width.Set(0f, 1f);
            topBar2.Height.Set(32f, 0f);
            topBar2.Top.Set(36f, 0f);
            basePanel.Append(topBar2);

            InitFilterButtons();
            topBar2.Append(filterButtons);
            searchBar2.Left.Set(depositButtonRight + padding, 0f);
            searchBar2.Width.Set(-depositButtonRight - 2 * padding, 1f);
            searchBar2.Height.Set(0f, 1f);
            topBar2.Append(searchBar2);

            slotZone.Width.Set(0f, 1f);
            slotZone.Top.Set(76f, 0f);
            slotZone.Height.Set(-116f, 1f);
            basePanel.Append(slotZone);

            numRows     = (items.Count + numColumns - 1) / numColumns;
            displayRows = (int)slotZone.GetDimensions().Height / ((int)itemSlotHeight + padding);
            slotZone.SetDimensions(numColumns, displayRows);
            int noDisplayRows = numRows - displayRows;

            if (noDisplayRows < 0)
            {
                noDisplayRows = 0;
            }
            scrollBarMaxViewSize = 1 + noDisplayRows;
            scrollBar.Height.Set(displayRows * (itemSlotHeight + padding), 0f);
            scrollBar.Left.Set(-20f, 1f);
            scrollBar.SetView(scrollBarViewSize, scrollBarMaxViewSize);
            slotZone.Append(scrollBar);

            bottomBar.Width.Set(0f, 1f);
            bottomBar.Height.Set(32f, 0f);
            bottomBar.Top.Set(-32f, 1f);
            basePanel.Append(bottomBar);

            capacityText.Left.Set(6f, 0f);
            capacityText.Top.Set(6f, 0f);
            TEStorageHeart heart    = GetHeart();
            int            numItems = 0;
            int            capacity = 0;

            if (heart != null)
            {
                foreach (TEAbstractStorageUnit abstractStorageUnit in heart.GetStorageUnits())
                {
                    if (abstractStorageUnit is TEStorageUnit)
                    {
                        TEStorageUnit storageUnit = (TEStorageUnit)abstractStorageUnit;
                        numItems += storageUnit.NumItems;
                        capacity += storageUnit.Capacity;
                    }
                }
            }
            capacityText.SetText(numItems + "/" + capacity + " Items");
            bottomBar.Append(capacityText);
        }
Esempio n. 3
0
        // @Speed: We are calling this every frame. Do we need to?
        public void UpdateUI()
        {
            int padding = 2;

            if (dirty)
            {
                RebuildUI();
                dirty = false;
            }

            float slotWidth  = Main.inventoryBackTexture.Width * UI.InventoryScale;
            float slotHeight = Main.inventoryBackTexture.Height * UI.InventoryScale;

            float panelLeft       = 72;
            float panelHeight     = Main.screenHeight - Main.instance.invBottom - 40f;
            float innerPanelWidth = numColumns * (slotWidth + padding) + padding * 4;

            int rows = (int)(panelHeight / slotHeight) - 1;

            if (Crafting && rows > 4)
            {
                rows = 4;
            }

            panelHeight = rows * (slotHeight + padding) + padding * 2;
            if (Crafting)
            {
                UI.TrashSlotOffset = new Point16(4, (int)panelHeight);
            }
            else
            {
                UI.TrashSlotOffset = new Point16(4, (int)panelHeight + 7);
            }
            if (Main.recBigList)
            {
                UI.TrashSlotOffset = new Point16(3, 0);
            }

            Left.Set(panelLeft, 0f);
            Top.Set(Main.instance.invBottom, 0f);
            Width.Set(innerPanelWidth + 25, 0f);
            Height.Set(panelHeight, 0f);

            {
                slotZone.Width.Set(innerPanelWidth, 0);
                slotZone.Height.Set(0, 1);

                slotZone.SetDimensions(numColumns, rows);

                int noDisplayRows = (items.Count + numColumns - 1) / numColumns - rows; // @Magic

                var bar = slotZone.ScrollBar;
                bar.Left.Set(-22, 1f);
                bar.Top.Set(11, 0);
                bar.Height.Set(panelHeight - padding * 10, 0f);
                bar.SetView(1, noDisplayRows + 1);
            }
            {
                float sideBarLeft = innerPanelWidth + 35;

                for (int i = 0; i < sideBar.Count; i++)
                {
                    var element = sideBar[i];
                    int offset  = 0;
                    if (i > 2)
                    {
                        var sort = sideBar[2] as UIDropDown; // @Volatile :SortAndFilter
                        if (sort.Focused)
                        {
                            offset += sort.OptionsY + sort.OptionDiffY * (sort.Options.Count - 1);
                        }
                    }
                    if (i > 3)
                    {
                        var filter = sideBar[3] as UIDropDown; // @Volatile :SortAndFilter
                        if (filter.Focused)
                        {
                            offset += filter.OptionsY + filter.OptionDiffY * (filter.Options.Count - 1);
                        }
                    }
                    element.Left.Set(sideBarLeft, 0);
                    element.Top.Set(15 + 27 * i + offset, 0);
                }
            }
            {
                bottomBar.Top.Set(6, 1f);

                int numItems = 0;
                int capacity = 0;

                TEStorageHeart heart = StoragePlayer.GetStorageHeart();
                if (heart != null)
                {
                    foreach (var unit in heart.GetStorageUnits())
                    {
                        if (unit is TEStorageUnit)
                        {
                            var storageUnit = unit as TEStorageUnit;
                            numItems += storageUnit.NumItems;
                            capacity += storageUnit.Capacity;
                        }
                    }
                }
                string text = "";
                if (!Crafting)
                {
                    text = "• " + numItems + "/" + capacity + " Items";
                }

                capacityText.SetText(text);
            }
            Recalculate();
        }
Esempio n. 4
0
        public void Initialize()
        {
            InitLangStuff();
            float smallSlotWidth = Main.inventoryBackTexture.Width * CraftingGUINew.INGREDIENTS_SCALE;

            panelTop = Main.instance.invBottom + 60;

            float innerCraftingPanelWidth = MagicStorageTwo.Instance.guiM.CraftingGUI.ActualWidth;
            float ingredientWidth         = CraftingGUINew.AVAILABLE_INGREDIENT_NUM_COLS * (smallSlotWidth + UICommon.PADDING) + 20f + UICommon.PADDING;

            ingredientWidth += 12 * 2;

            panelLeft    = 20f + (OffseLeft ? MagicStorageTwo.Instance.guiM.CraftingGUI.HasRecipe ? innerCraftingPanelWidth + ingredientWidth : innerCraftingPanelWidth : 0);
            storagePanel = new UIPanel();
            panelWidth   = itemsZone.ActualWidth + storagePanel.PaddingRight + storagePanel.PaddingLeft + 20 + UICommon.PADDING;
            storagePanel.Left.Set(panelLeft, 0f);
            storagePanel.Top.Set(panelTop, 0f);
            storagePanel.Width.Set(panelWidth, 0f);
            storagePanel.Recalculate();

            upperTopBar = new UIElement();
            upperTopBar.Width.Set(0f, 1f);
            upperTopBar.Height.Set(32f, 0f);
            storagePanel.Append(upperTopBar);

            InitSortButtons();
            upperTopBar.Append(sortButtons);

            depositButton.Left.Set(sortButtons.GetDimensions().Width + 2 * UICommon.PADDING, 0f);
            depositButton.Width.Set(32 * 3 + 8 * 2 + 4, 0f);
            depositButton.Height.Set(-2 * UICommon.PADDING, 1f);
            depositButton.PaddingTop    = 8f;
            depositButton.PaddingBottom = 8f;
            upperTopBar.Append(depositButton);

            float depositButtonRight = sortButtons.GetDimensions().Width + 2 * UICommon.PADDING + depositButton.GetDimensions().Width;

            nameSearchBar.Left.Set(depositButtonRight + UICommon.PADDING, 0f);
            nameSearchBar.Width.Set(-depositButtonRight - 1 * UICommon.PADDING, 1f);
            nameSearchBar.Height.Set(0f, 1f);
            upperTopBar.Append(nameSearchBar);

            lowerTopBar = new UIElement();
            lowerTopBar.Width.Set(0f, 1f);
            lowerTopBar.Height.Set(32f, 0f);
            lowerTopBar.Top.Set(36f, 0f);
            storagePanel.Append(lowerTopBar);

            InitFilterButtons();
            lowerTopBar.Append(filterButtons);
            modSearchBar.Left.Set(depositButtonRight + UICommon.PADDING, 0f);
            modSearchBar.Width.Set(-depositButtonRight - 1 * UICommon.PADDING, 1f);
            modSearchBar.Height.Set(0f, 1f);
            lowerTopBar.Append(modSearchBar);

            itemsZone.Width.Set(0f, 1f);
            itemsZone.Top.Set(76f, 0f);
            itemsZone.Height.Set(-116f, 1f);
            storagePanel.Append(itemsZone);

            numRows     = (items.Count + NUM_COLS - 1) / NUM_COLS;
            displayRows = Math.Min(itemsZone.MaxRows, 8);
            itemsZone.SetDimensions(NUM_COLS, displayRows);
            int noDisplayRows = numRows - displayRows;

            if (noDisplayRows < 0)
            {
                noDisplayRows = 0;
            }
            scrollBarMaxViewSize = 1 + noDisplayRows;
            itemsScrollBar.Top.Set(4, 0);
            itemsScrollBar.Height.Set(itemsZone.ActualHeight, 0f);
            itemsScrollBar.Left.Set(-20f, 1f);
            itemsScrollBar.SetView(SCROLLBAR_SIZE, scrollBarMaxViewSize);

            bottomBar.Width.Set(0f, 1f);
            bottomBar.Height.Set(32f, 0f);
            bottomBar.Top.Set(itemsZone.Top.Pixels + itemsZone.ActualHeight, 0f);
            storagePanel.Append(bottomBar);

            capacityText.Left.Set(6f, 0f);
            capacityText.Top.Set(6f, 0f);
            TEStorageHeart heart    = GetHeart();
            int            numItems = 0;
            int            capacity = 0;

            if (heart != null)
            {
                foreach (TEAbstractStorageUnit abstractStorageUnit in heart.GetStorageUnits())
                {
                    if (abstractStorageUnit is TEStorageUnit)
                    {
                        TEStorageUnit storageUnit = (TEStorageUnit)abstractStorageUnit;
                        numItems += storageUnit.NumItems;
                        capacity += storageUnit.Capacity;
                    }
                }
            }
            capacityText.SetText($"{numItems}/{capacity} {Locale.GetStr(Locale.C.ITEMS)}");
            bottomBar.Append(capacityText);
            panelHeight = upperTopBar.Height.Pixels + lowerTopBar.Height.Pixels + itemsZone.ActualHeight + bottomBar.Height.Pixels + 32;
            storagePanel.Height.Set(panelHeight, 0);
            storagePanel.Recalculate();
        }