Exemple #1
0
        public override void OnInitialize()
        {
            float slotWidth  = Main.inventoryBackTexture.Width * inventoryScale;
            float slotHeight = Main.inventoryBackTexture.Height * inventoryScale;

            float panelTop  = Main.instance.invBottom + 60;
            float panelLeft = 20f;

            UIPanel panel           = new UIPanel();
            float   innerPanelLeft  = panelLeft + panel.PaddingLeft;
            float   innerPanelWidth = columns * (slotWidth + padding) + 20f + padding;
            float   panelWidth      = panel.PaddingLeft + innerPanelWidth + panel.PaddingRight;
            float   panelHeight     = Main.screenHeight - panelTop - 40f;

            panel.Left.Set(panelLeft, 0f);
            panel.Top.Set(panelTop, 0f);
            panel.Width.Set(panelWidth, 0f);
            panel.Height.Set(panelHeight, 0f);
            panel.Recalculate();

            UIElement topBar = new UIElement();

            topBar.Width.Set(0f, 1f);
            topBar.Height.Set(32f, 0f);
            panel.Append(topBar);

            sortButtons = new UIButtonChoice(new Texture2D[]
            {
                Main.inventorySortTexture[0],
                MagicStorage.Instance.GetTexture("Assets/SortID"),
                MagicStorage.Instance.GetTexture("Assets/SortName"),
                MagicStorage.Instance.GetTexture("Assets/SortNumber")
            },
                                             new LocalizedText[]
            {
                Language.GetText("Mods.MagicStorage.Common.SortDefault"),
                Language.GetText("Mods.MagicStorage.Common.SortID"),
                Language.GetText("Mods.MagicStorage.Common.SortName"),
                Language.GetText("Mods.MagicStorage.Common.SortStack")
            });

            sortButtons.OnClick += (a, b) => {
                if ((SortMode)sortButtons.choice != sortMode)
                {
                    sortMode = (SortMode)sortButtons.choice;
                    RefreshItems();
                }
            };

            topBar.Append(sortButtons);

            UITextPanel <LocalizedText> depositButton = new UITextPanel <LocalizedText>(Language.GetText("Mods.MagicStorage.Common.DepositAll"), 1f);

            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;
            depositButton.OnClick      += ClickDeposit;
            depositButton.OnMouseOver  += (a, b) => depositButton.BackgroundColor = lightBlue;
            depositButton.OnMouseOut   += (a, b) => depositButton.BackgroundColor = blue;

            topBar.Append(depositButton);

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

            searchBar = new UISearchBar(Language.GetText("Mods.MagicStorage.Common.SearchName"));
            searchBar.Left.Set(depositButtonRight + padding, 0f);
            searchBar.Width.Set(-depositButtonRight - 2 * padding, 1f);
            searchBar.Height.Set(0f, 1f);

            topBar.Append(searchBar);

            UIElement topBar2 = new UIElement();

            topBar2.Width.Set(0f, 1f);
            topBar2.Height.Set(32f, 0f);
            topBar2.Top.Set(36f, 0f);

            panel.Append(topBar2);

            filterButtons = new UIButtonChoice(new Texture2D[]
            {
                MagicStorage.Instance.GetTexture("Assets/FilterAll"),
                MagicStorage.Instance.GetTexture("Assets/FilterMelee"),
                MagicStorage.Instance.GetTexture("Assets/FilterPickaxe"),
                MagicStorage.Instance.GetTexture("Assets/FilterArmor"),
                MagicStorage.Instance.GetTexture("Assets/FilterPotion"),
                MagicStorage.Instance.GetTexture("Assets/FilterTile"),
                MagicStorage.Instance.GetTexture("Assets/FilterMisc"),
            },
                                               new LocalizedText[]
            {
                Language.GetText("Mods.MagicStorage.Common.FilterAll"),
                Language.GetText("Mods.MagicStorage.Common.FilterWeapons"),
                Language.GetText("Mods.MagicStorage.Common.FilterTools"),
                Language.GetText("Mods.MagicStorage.Common.FilterEquips"),
                Language.GetText("Mods.MagicStorage.Common.FilterPotions"),
                Language.GetText("Mods.MagicStorage.Common.FilterTiles"),
                Language.GetText("Mods.MagicStorage.Common.FilterMisc")
            });

            filterButtons.OnClick += (a, b) => {
                if ((FilterMode)filterButtons.choice != filterMode)
                {
                    filterMode = (FilterMode)filterButtons.choice;
                    RefreshItems();
                }
            };

            topBar2.Append(filterButtons);

            searchBar2 = new UISearchBar(Language.GetText("Mods.MagicStorage.Common.SearchMod"));
            searchBar2.Left.Set(depositButtonRight + padding, 0f);
            searchBar2.Width.Set(-depositButtonRight - 2 * padding, 1f);
            searchBar2.Height.Set(0f, 1f);

            topBar2.Append(searchBar2);

            slotZone = new UISlotZone(GetItem, inventoryScale);
            slotZone.Width.Set(0f, 1f);
            slotZone.Top.Set(76f, 0f);
            slotZone.Height.Set(-116f, 1f);
            slotZone.OnMouseDown += PressSlotZone;

            panel.Append(slotZone);

            UIScrollbar scrollbar = new UIScrollbar();

            scrollbar.Left.Set(10, 0);
            slotZone.SetScrollbar(scrollbar);

            panel.Append(scrollbar);

            capacityText = new UIText(string.Empty);
            capacityText.Top.Set(-32f, 1f);
            capacityText.Left.Set(6f, 0f);
            capacityText.Height.Set(32f, 0);
            panel.Append(capacityText);

            float slotZoneHeight = capacityText.GetDimensions().Y - (filterButtons.GetDimensions().Y + filterButtons.GetDimensions().Height);

            slotZone.SetDimensions(columns, (int)(slotZoneHeight / (slotHeight + slotZone.padding)));

            Append(panel);
        }
Exemple #2
0
        public override void OnInitialize()
        {
            float slotWidth       = Main.inventoryBackTexture.Width * inventoryScale;
            float slotHeight      = Main.inventoryBackTexture.Height * inventoryScale;
            float smallSlotWidth  = Main.inventoryBackTexture.Width * smallScale;
            float smallSlotHeight = Main.inventoryBackTexture.Height * smallScale;

            float panelTop  = Main.instance.invBottom + 60;
            float panelLeft = 20f;

            UIPanel panel           = new UIPanel();
            float   innerPanelLeft  = panelLeft + panel.PaddingLeft;
            float   innerPanelWidth = columns * (slotWidth + padding) + 20f + padding;
            float   panelWidth      = panel.PaddingLeft + innerPanelWidth + panel.PaddingRight;
            float   panelHeight     = Main.screenHeight - panelTop - 40f;

            panel.Left.Set(panelLeft, 0f);
            panel.Top.Set(panelTop, 0f);
            panel.Width.Set(panelWidth, 0f);
            panel.Height.Set(panelHeight, 0f);
            panel.Recalculate();

            UIPanel recipePanel = new UIPanel();
            float   recipeLeft  = panelLeft + panelWidth;
            float   recipeWidth = columns2 * (smallSlotWidth + padding);

            recipeWidth    += recipePanel.PaddingLeft + recipePanel.PaddingRight;
            recipePanel.Top = panel.Top;
            recipePanel.Left.Set(recipeLeft, 0f);
            recipePanel.Width.Set(recipeWidth, 0f);

            UIElement topBar = new UIElement();

            topBar.Width.Set(0f, 1f);
            topBar.Height.Set(32f, 0f);
            panel.Append(topBar);

            sortButtons = new UIButtonChoice(new Texture2D[]
            {
                Main.inventorySortTexture[0],
                MagicStorage.Instance.GetTexture("Assets/SortID"),
                MagicStorage.Instance.GetTexture("Assets/SortName")
            },
                                             new LocalizedText[]
            {
                Language.GetText("Mods.MagicStorage.Common.SortDefault"),
                Language.GetText("Mods.MagicStorage.Common.SortID"),
                Language.GetText("Mods.MagicStorage.Common.SortName")
            });

            sortButtons.OnClick += ClickSortButtons;

            topBar.Append(sortButtons);

            float sortButtonsRight = sortButtons.GetDimensions().Width + padding;

            recipeButtons = new UIButtonChoice(new Texture2D[]
            {
                MagicStorage.Instance.GetTexture("Assets/RecipeAvailable"),
                MagicStorage.Instance.GetTexture("Assets/RecipeAll")
            },
                                               new LocalizedText[]
            {
                Language.GetText("Mods.MagicStorage.Common.RecipeAvailable"),
                Language.GetText("Mods.MagicStorage.Common.RecipeAll")
            });

            recipeButtons.OnClick += ClickRecipeButtons;
            float recipeButtonsLeft = sortButtonsRight + 32f + 3 * padding;

            recipeButtons.Left.Set(recipeButtonsLeft, 0f);
            topBar.Append(recipeButtons);
            float recipeButtonsRight = recipeButtonsLeft + recipeButtons.GetDimensions().Width + padding;

            searchBar = new UISearchBar(Language.GetText("Mods.MagicStorage.Common.SearchName"));
            searchBar.Left.Set(recipeButtonsRight + padding, 0f);
            searchBar.Width.Set(-recipeButtonsRight - 2 * padding, 1f);
            searchBar.Height.Set(0f, 1f);
            topBar.Append(searchBar);

            UIElement topBar2 = new UIElement();

            topBar2.Width.Set(0f, 1f);
            topBar2.Height.Set(32f, 0f);
            topBar2.Top.Set(36f, 0f);
            panel.Append(topBar2);

            filterButtons = new UIButtonChoice(new Texture2D[]
            {
                MagicStorage.Instance.GetTexture("Assets/FilterAll"),
                MagicStorage.Instance.GetTexture("Assets/FilterMelee"),
                MagicStorage.Instance.GetTexture("Assets/FilterPickaxe"),
                MagicStorage.Instance.GetTexture("Assets/FilterArmor"),
                MagicStorage.Instance.GetTexture("Assets/FilterPotion"),
                MagicStorage.Instance.GetTexture("Assets/FilterTile"),
                MagicStorage.Instance.GetTexture("Assets/FilterMisc"),
            },
                                               new LocalizedText[]
            {
                Language.GetText("Mods.MagicStorage.Common.FilterAll"),
                Language.GetText("Mods.MagicStorage.Common.FilterWeapons"),
                Language.GetText("Mods.MagicStorage.Common.FilterTools"),
                Language.GetText("Mods.MagicStorage.Common.FilterEquips"),
                Language.GetText("Mods.MagicStorage.Common.FilterPotions"),
                Language.GetText("Mods.MagicStorage.Common.FilterTiles"),
                Language.GetText("Mods.MagicStorage.Common.FilterMisc")
            });

            filterButtons.OnClick += ClickFilterButtons;

            topBar2.Append(filterButtons);

            float filterButtonsRight = filterButtons.GetDimensions().Width + padding;

            searchBar2 = new UISearchBar(Language.GetText("Mods.MagicStorage.Common.SearchMod"));
            searchBar2.Left.Set(filterButtonsRight + padding, 0f);
            searchBar2.Width.Set(-filterButtonsRight - 2 * padding, 1f);
            searchBar2.Height.Set(0f, 1f);
            topBar2.Append(searchBar2);

            UIText stationText = new UIText(Language.GetText("Mods.MagicStorage.Common.CraftingStations"));

            stationText.Top.Set(76f, 0f);
            panel.Append(stationText);

            stationZone = new UISlotZone(GetStation, inventoryScale);
            stationZone.Top.Set(100f, 0f);
            stationZone.SetDimensions(columns, 1);
            stationZone.OnMouseDown += PressStation;
            panel.Append(stationZone);

            UIText recipeText = new UIText(Language.GetText("Mods.MagicStorage.Common.Recipes"));

            recipeText.Top.Set(152f, 0f);
            panel.Append(recipeText);

            recipeZone = new UISlotZone(GetRecipe, GetRecipeColor, inventoryScale);
            recipeZone.Top.Set(176f, 0f);
            recipeZone.OnMouseDown += PressRecipe;
            panel.Append(recipeZone);

            UIScrollbar scrollbar = new UIScrollbar();

            scrollbar.Left.Set(10, 0);
            recipeZone.SetScrollbar(scrollbar);
            panel.Append(scrollbar);

            recipeZone.SetDimensions(columns, (int)((panel.Height.Pixels - panel.PaddingBottom - recipeZone.Top.Pixels) / (slotHeight + 2 * recipeZone.padding)));

            UIText recipePanelHeader = new UIText(Language.GetText("Mods.MagicStorage.Common.SelectedRecipe"));

            recipePanel.Append(recipePanelHeader);

            UIText ingredientText = new UIText(Language.GetText("Mods.MagicStorage.Common.Ingredients"));

            ingredientText.Top.Set(30f, 0f);
            recipePanel.Append(ingredientText);

            previewZone = new UISlotZone(GetSelectedItem, inventoryScale);
            previewZone.Top.Set(0f, 0f);
            previewZone.Left.Set(-slotWidth, 1f);
            recipePanel.Append(previewZone);

            ingredientZone = new UISlotZone(GetIngredient, smallScale);
            ingredientZone.Top.Set(54f, 0f);
            ingredientZone.SetDimensions(recipePanelColumns, ingredientRows);
            ingredientZone.OnMouseDown += PressIngredient;
            recipePanel.Append(ingredientZone);

            UIText reqObjText = new UIText(Language.GetText("LegacyInterface.22"));

            reqObjText.Top.Set(136f, 0f);
            recipePanel.Append(reqObjText);

            reqObjText2 = new UIText(String.Empty);
            reqObjText2.Top.Set(160f, 0f);
            recipePanel.Append(reqObjText2);

            UIText storedItemsText = new UIText(Language.GetText("Mods.MagicStorage.Common.StoredItems"));

            storedItemsText.Top.Set(190f, 0f);
            recipePanel.Append(storedItemsText);

            storageZone = new UISlotZone(GetStorage, smallScale);
            storageZone.Top.Set(214f, 0f);
            recipePanel.Append(storageZone);

            craftButton = new UITextPanel <LocalizedText>(Language.GetText("LegacyMisc.72"), 1f);
            craftButton.Top.Set(-32f, 1f);
            craftButton.Width.Set(100f, 0f);
            craftButton.Height.Set(24f, 0f);
            craftButton.PaddingTop    = 8f;
            craftButton.PaddingBottom = 8f;

            recipePanel.Append(craftButton);

            resultZone = new UISlotZone(GetResultItem, inventoryScale);
            resultZone.Left.Set(-slotWidth, 1f);
            resultZone.Top.Set(-slotHeight, 1f);
            resultZone.OnMouseDown += PressResult;
            recipePanel.Append(resultZone);

            float recipeHeight = 0;

            for (int k = storageRows; k > 0; k--)
            {
                storageZone.SetDimensions(recipePanelColumns, k);
                recipeHeight = storageZone.Height.Pixels + ingredientZone.Height.Pixels + 230f;

                if (recipeHeight < panel.Height.Pixels)
                {
                    break;
                }
            }

            recipePanel.Height.Set(recipeHeight, 0f);
            recipePanel.Recalculate();

            Append(panel);
            Append(recipePanel);
        }