public static void Show(UIItemSlot slot) { if (m_Instance == null) return; // Assign the item slot m_Instance.AssignSlot(slot); // Show the window m_Instance.Show(); }
void OnEnable() { if (this.slot == null) this.slot = this.GetComponent<UIItemSlot>(); if (PlayFabDataStore.playerInventory.Count >= assignItem && !isAssigned) { isAssigned = true; itemDatabase.items.Add(PlayFabDataStore.catalogItems[PlayFabDataStore.playerInventory[assignItem - 1]]); SetItemToSlot(); } }
public void OnWindowTransitionComplete(UIWindow window, UIWindow.VisualState state) { if (state == UIWindow.VisualState.Hidden) { if (this.m_Slot != null) this.m_Slot.Unassign(); if (this.m_NameText != null) this.m_NameText.text = ""; if (this.m_DescriptionText != null) this.m_DescriptionText.text = ""; this.m_SelectedSlot = null; } }
/// <summary> /// Assigns the slot to the box. /// </summary> /// <param name="slot">Slot.</param> private void AssignSlot(UIItemSlot slot) { if (!slot.IsAssigned() || slot.GetItemInfo() == null) return; if (this.m_Slot != null) this.m_Slot.Assign(slot.GetItemInfo()); if (this.m_NameText != null) this.m_NameText.text = slot.GetItemInfo().displayName; /*if (this.m_DescriptionText != null) this.m_DescriptionText.text = slot.GetItemInfo().Subtype + " " + slot.GetItemInfo().Type;*/ // Save a ref to the slot this.m_SelectedSlot = slot; }
void Awake() { if (this.slot == null) this.slot = this.GetComponent<UIItemSlot>(); }
public void LinkUISlot(UIItemSlot uiSlot) { uiItemSlot = uiSlot; }
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; }
// todo, items on load. internal void UpdateCheckboxes() { if (!updateNeeded) { return; } updateNeeded = false; checklistGrid.Clear(); if (buttonsHaveDummyTextures) { Texture2D foundFilterTexture = Utilities.ResizeImage(ItemChecklist.instance.GetTexture("Images/filterFound"), 32, 32); Texture2D muteButtonTexture = Utilities.ResizeImage(Main.itemTexture[ItemID.Megaphone], 32, 32); //Texture2D sortButtonTexture = Utilities.ResizeImage(Main.itemTexture[ItemID.ToxicFlask], 32, 32); Texture2D modFilterButtonTexture = Utilities.ResizeImage(ItemChecklist.instance.GetTexture("Images/filterMod"), 32, 32); Texture2D collectChestItemsButtonTexture = Utilities.ResizeImage(Main.cursorTextures[8], 32, 32); Texture2D showBadgeButtonTexture = Utilities.ResizeImage(Main.itemTexture[ItemID.Book], 32, 32); // Main.extraTexture[58] foundFilterButton.SetImage(foundFilterTexture); muteButton.SetImage(muteButtonTexture); modFilterButton.SetImage(modFilterButtonTexture); collectChestItemsButton.SetImage(collectChestItemsButtonTexture); showBadgeButton.SetImage(showBadgeButtonTexture); buttonsHaveDummyTextures = false; } var itemChecklistPlayer = Main.LocalPlayer.GetModPlayer <ItemChecklistPlayer>(ItemChecklist.instance); var temp = new List <UIItemSlot>(); for (int i = 0; i < itemChecklistPlayer.findableItems.Length; i++) { if (itemChecklistPlayer.findableItems[i]) { // filters here if ((showCompleted != 1 && itemChecklistPlayer.foundItem[i]) || (showCompleted != 2 && !itemChecklistPlayer.foundItem[i])) { if (!PassModFilter(itemSlots[i])) { continue; } if (SharedUI.instance.SelectedCategory != null) { if (!SharedUI.instance.SelectedCategory.belongs(itemSlots[i].item) && !SharedUI.instance.SelectedCategory.subCategories.Any(x => x.belongs(itemSlots[i].item))) { continue; } } bool filtered = false; foreach (var filter in SharedUI.instance.availableFilters) { if (filter.button.selected) { if (!filter.belongs(itemSlots[i].item)) { filtered = true; } } } if (filtered) { continue; } if (itemSlots[i].item.Name.IndexOf(itemNameFilter.currentString, StringComparison.OrdinalIgnoreCase) == -1) { continue; } if (itemDescriptionFilter.currentString.Length > 0) { if ((itemSlots[i].item.ToolTip != null && GetTooltipsAsString(itemSlots[i].item.ToolTip).IndexOf(itemDescriptionFilter.currentString, StringComparison.OrdinalIgnoreCase) != -1) /*|| (recipe.createItem.toolTip2 != null && recipe.createItem.toolTip2.ToLower().IndexOf(itemDescriptionFilter.Text, StringComparison.OrdinalIgnoreCase) != -1)*/) { } else { continue; } } UIItemSlot box = itemSlots[i]; box.badge = SharedUI.instance.SelectedSort?.badge(box.item) ?? ""; temp.Add(box); } } } checklistGrid.AddRange(temp); if (lastfoundID > 0) { checklistGrid.Recalculate(); if (showCompleted != 1) // Don't Goto when unfound is the display mode. { checklistGrid.Goto(delegate(UIElement element) { UIItemSlot itemSlot = element as UIItemSlot; return(itemSlot != null && itemSlot.id == lastfoundID); }, true); } lastfoundID = -1; } }