Ejemplo n.º 1
0
        public override void OnInitialize()
        {
            // Is initialize called? (Yes it is called on reload) I want to reset nicely with new character or new loaded mods: visible = false;

            announce          = false;    // overwritten by modplayer
            collectChestItems = false;
            showBadge         = false;

            checklistPanel = new UIPanel();
            checklistPanel.SetPadding(10);
            checklistPanel.Left.Pixels = 0;
            checklistPanel.HAlign      = 1f;
            checklistPanel.Top.Set(85f, 0f);
            checklistPanel.Left.Set(-40f, 0f);
            checklistPanel.Width.Set(250f, 0f);
            checklistPanel.Height.Set(-125, 1f);
            checklistPanel.BackgroundColor = new Color(73, 94, 171);

            int top  = 0;
            int left = 0;

            // Because OnInitialize Happens during load and because we need it to happen for OnEnterWorld, use dummy sprite.
            buttonsHaveDummyTextures = true;

            foundFilterButton               = new UIHoverImageButton(Main.magicPixel, "Cycle Found Filter: ??");
            foundFilterButton.OnClick      += (a, b) => ToggleFoundFilterButtonClicked(a, b, true);
            foundFilterButton.OnRightClick += (a, b) => ToggleFoundFilterButtonClicked(a, b, false);
            foundFilterButton.Top.Pixels    = top;
            checklistPanel.Append(foundFilterButton);
            left += (int)spacing * 2 + 28;

            //sortButton = new UIHoverImageButton(sortButtonTexture, "Cycle Sort Method: ??");
            //sortButton.OnClick += (a, b) => ToggleSortButtonClicked(a, b, true);
            //sortButton.OnRightClick += (a, b) => ToggleSortButtonClicked(a, b, false);
            //sortButton.Left.Pixels = spacing * 4 + 28 * 2;
            //sortButton.Top.Pixels = top;
            //checklistPanel.Append(sortButton);

            modFilterButton               = new UIHoverImageButton(Main.magicPixel, "Cycle Mod Filter: ??");
            modFilterButton.OnClick      += (a, b) => ToggleModFilterButtonClicked(a, b, true);
            modFilterButton.OnRightClick += (a, b) => ToggleModFilterButtonClicked(a, b, false);
            modFilterButton.Left.Pixels   = left;
            modFilterButton.Top.Pixels    = top;
            checklistPanel.Append(modFilterButton);
            left += (int)spacing * 2 + 28;

            muteButton             = new UIToggleHoverImageButton(Main.magicPixel, ItemChecklist.instance.GetTexture("UIElements/closeButton"), "Toggle Messages", announce);
            muteButton.OnClick    += ToggleMuteButtonClicked;
            muteButton.Left.Pixels = left;
            muteButton.Top.Pixels  = top;
            checklistPanel.Append(muteButton);
            left += (int)spacing * 2 + 28;

            collectChestItemsButton             = new UIToggleHoverImageButton(Main.magicPixel, ItemChecklist.instance.GetTexture("UIElements/closeButton"), "Toggle Collect Chest Items", collectChestItems);
            collectChestItemsButton.OnClick    += ToggleFindChestItemsButtonClicked;
            collectChestItemsButton.Left.Pixels = left;
            collectChestItemsButton.Top.Pixels  = top;
            checklistPanel.Append(collectChestItemsButton);
            left += (int)spacing * 2 + 28;

            showBadgeButton             = new UIToggleHoverImageButton(Main.magicPixel, ItemChecklist.instance.GetTexture("UIElements/closeButton"), "Show Sort Value Text", showBadge);
            showBadgeButton.OnClick    += ToggleShowBadgeButtonClicked;
            showBadgeButton.Left.Pixels = left;
            showBadgeButton.Top.Pixels  = top;
            checklistPanel.Append(showBadgeButton);
            left += (int)spacing * 2 + 28;

            top += 34;

            itemNameFilter = new NewUITextBox("Filter by Name");
            itemNameFilter.OnTextChanged += () => { ValidateItemFilter(); updateNeeded = true; };
            itemNameFilter.OnTabPressed  += () => { itemDescriptionFilter.Focus(); };
            itemNameFilter.Top.Pixels     = top;
            //itemNameFilter.Left.Set(-152, 1f);
            itemNameFilter.Width.Set(0, 1f);
            itemNameFilter.Height.Set(25, 0f);
            checklistPanel.Append(itemNameFilter);

            top += 30;

            itemDescriptionFilter = new NewUITextBox("Filter by tooltip");
            itemDescriptionFilter.OnTextChanged += () => { ValidateItemDescription(); updateNeeded = true; };
            itemDescriptionFilter.OnTabPressed  += () => { itemNameFilter.Focus(); };
            itemDescriptionFilter.Top.Pixels     = top;
            //itemDescriptionFilter.Left.Set(-152, 1f);
            itemDescriptionFilter.Width.Set(0, 1f);
            itemDescriptionFilter.Height.Set(25, 0f);
            checklistPanel.Append(itemDescriptionFilter);

            top += 30;

            sharedUI = new SharedUI();
            sharedUI.Initialize();

            sharedUI.sortsAndFiltersPanel.Top.Set(top, 0f);
            sharedUI.sortsAndFiltersPanel.Width.Set(0f, 1);
            sharedUI.sortsAndFiltersPanel.Height.Set(60, 0f);
            checklistPanel.Append(sharedUI.sortsAndFiltersPanel);

            top += 68;

            checklistGrid = new UIGrid(5);
            checklistGrid.alternateSort = ItemGridSort;
            checklistGrid.Top.Pixels    = top;
            checklistGrid.Width.Set(-25f, 1f);
            checklistGrid.Height.Set(-top, 1f);
            checklistGrid.ListPadding = 2f;
            checklistPanel.Append(checklistGrid);

            FixedUIScrollbar checklistListScrollbar = new FixedUIScrollbar();

            checklistListScrollbar.SetView(100f, 1000f);
            checklistListScrollbar.Top.Pixels = top;
            checklistListScrollbar.Height.Set(-top, 1f);
            checklistListScrollbar.HAlign = 1f;
            checklistPanel.Append(checklistListScrollbar);
            checklistGrid.SetScrollbar(checklistListScrollbar);

            // Checklistlist populated when the panel is shown: UpdateCheckboxes()

            Append(checklistPanel);

            // load time impact, do this on first show?
            itemSlots = new UIItemSlot[ItemLoader.ItemCount];
            Item[] itemSlotItems = new Item[ItemLoader.ItemCount];
            for (int i = 0; i < ItemLoader.ItemCount; i++)
            {
                itemSlots[i]     = new UIItemSlot(i);
                itemSlotItems[i] = itemSlots[i].item;
            }

            FieldInfo inventoryGlowHue  = typeof(Terraria.UI.ItemSlot).GetField("inventoryGlowHue", BindingFlags.Static | BindingFlags.NonPublic);
            FieldInfo inventoryGlowTime = typeof(Terraria.UI.ItemSlot).GetField("inventoryGlowTime", BindingFlags.Static | BindingFlags.NonPublic);

            MethodInfo SortMethod = typeof(ItemSorting).GetMethod("Sort", BindingFlags.Static | BindingFlags.NonPublic);

            object[] parametersArray = new object[] { itemSlotItems, new int[0] };

            inventoryGlowHue.SetValue(null, new float[ItemLoader.ItemCount]);
            inventoryGlowTime.SetValue(null, new int[ItemLoader.ItemCount]);
            SortMethod.Invoke(null, parametersArray);
            inventoryGlowHue.SetValue(null, new float[58]);
            inventoryGlowTime.SetValue(null, new int[58]);

            int[] vanillaIDsInSortOrderTemp = itemSlotItems.Select((x) => x.type).ToArray();
            vanillaIDsInSortOrder = new int[ItemLoader.ItemCount];
            for (int i = 0; i < ItemLoader.ItemCount; i++)
            {
                vanillaIDsInSortOrder[i] = Array.FindIndex(vanillaIDsInSortOrderTemp, x => x == i);
            }

            modnames = new List <string>()
            {
                "All", "Vanilla"
            };
            modnames.AddRange(ModLoader.GetLoadedMods() /*.Where(x => x != "ModLoader")*/);

            updateNeeded = true;
        }