예제 #1
0
        // These triggers should work in autopause and aren't related to Player actions, so we can use UpdateUI to call them.
        //public void ProcessTriggersButAlways(TriggersSet triggersSet)
        // 0.6.1.6: hm, seemed to have backfired. Investigate why 0.6.1.5 approach would miss keypresses.
        public override void ProcessTriggers(TriggersSet triggersSet)
        {
            //if (!RecipeBrowser.instance.CheatSheetLoaded)
            {
                if (RecipeBrowser.instance.ToggleRecipeBrowserHotKey.JustPressed)
                {
                    RecipeBrowserUI.instance.ShowRecipeBrowser = !RecipeBrowserUI.instance.ShowRecipeBrowser;
                    // Debug assistance, allows for reinitializing RecipeBrowserUI
                    //if (!RecipeBrowserUI.instance.ShowRecipeBrowser)
                    //{
                    //	RecipeBrowserUI.instance.RemoveAllChildren();
                    //	var isInitializedFieldInfo = typeof(Terraria.UI.UIElement).GetField("_isInitialized", BindingFlags.Instance | BindingFlags.NonPublic);
                    //	isInitializedFieldInfo.SetValue(RecipeBrowserUI.instance, false);
                    //	RecipeBrowserUI.instance.Activate();
                    //}
                }
                if (RecipeBrowser.instance.QueryHoveredItemHotKey.JustPressed)
                {
                    // Debug assistance, manually clear craftPath calculations
                    //foreach (var slot in RecipeCatalogueUI.instance.recipeSlots)
                    //{
                    //	slot.craftPathsNeeded = false;
                    //	slot.craftPathsCalculated = false;
                    //	slot.craftPaths = null;
                    //}
                    //RecipeCatalogueUI.instance.updateNeeded = true;
                    //RecipeCatalogueUI.instance.InvalidateExtendedCraft();

                    if (!Main.HoverItem.IsAir)
                    {
                        RecipeBrowserUI.instance.ShowRecipeBrowser = true;
                        if (RecipeBrowserUI.instance.CurrentPanel == RecipeBrowserUI.RecipeCatalogue)
                        {
                            RecipeCatalogueUI.instance.queryItem.ReplaceWithFake(Main.HoverItem.type);
                        }
                        else if (RecipeBrowserUI.instance.CurrentPanel == RecipeBrowserUI.Craft)
                        {
                            CraftUI.instance.SetItem(Main.HoverItem.type);
                        }
                        else if (RecipeBrowserUI.instance.CurrentPanel == RecipeBrowserUI.ItemCatalogue)
                        {
                            ItemCatalogueUI.instance.itemGrid.Goto(delegate(UIElement element)
                            {
                                UIItemCatalogueItemSlot itemSlot = element as UIItemCatalogueItemSlot;
                                if (itemSlot != null && itemSlot.itemType == Main.HoverItem.type)
                                {
                                    ItemCatalogueUI.instance.SetItem(itemSlot);
                                    return(true);
                                }
                                return(false);
                            }, true);
                        }
                        else if (RecipeBrowserUI.instance.CurrentPanel == RecipeBrowserUI.Bestiary)
                        {
                            BestiaryUI.instance.queryItem.ReplaceWithFake(Main.HoverItem.type);
                        }
                    }
                }
            }
        }
예제 #2
0
 internal void SetItem(UIItemCatalogueItemSlot slot)
 {
     foreach (var item in itemSlots)
     {
         item.selected = false;
     }
     slot.selected = true;
 }
        internal void Update()
        {
            if (!updateNeeded)
            {
                return;
            }
            updateNeeded = false;

            if (itemSlots.Count == 0)
            {
                // should only happen once
                craftResults = new bool[ItemLoader.ItemCount];
                isLoot       = new bool[ItemLoader.ItemCount];
                itemSlots.Clear();
                for (int type = 1; type < ItemLoader.ItemCount; type++)
                {
                    Item item = new Item();
                    item.SetDefaults(type, false);                     // 300 ms vs 30 ms
                    if (item.type == 0)
                    {
                        continue;
                    }
                    var slot = new UIItemCatalogueItemSlot(item);
                    itemSlots.Add(slot);
                }

                for (int i = 0; i < Recipe.numRecipes; i++)
                {
                    Recipe recipe = Main.recipe[i];
                    craftResults[recipe.createItem.type] = true;
                }

                foreach (var kvp in LootCache.instance.lootInfos)
                {
                    //if (kvp.Key.id == 0 && kvp.Key.mod == "Terraria")
                    //	Console.WriteLine();
                    int id = kvp.Key.GetID();
                    if (id > 0)
                    {
                        isLoot[id] = true;
                    }
                }
            }



            itemGrid.Clear();
            foreach (var slot in itemSlots)
            {
                if (PassItemFilters(slot))
                {
                    itemGrid._items.Add(slot);
                    itemGrid._innerList.Append(slot);
                }
            }
            itemGrid.UpdateOrder();
            itemGrid._innerList.Recalculate();
        }
예제 #4
0
        private bool PassItemFilters(UIItemCatalogueItemSlot slot)
        {
            if (RecipeBrowserUI.modIndex != RecipeBrowserUI.instance.mods.Length - 1)
            {
                if (slot.item.modItem == null)
                {
                    return(false);
                }
                if (slot.item.modItem.mod.Name != RecipeBrowserUI.instance.mods[RecipeBrowserUI.modIndex])
                {
                    return(false);
                }
            }

            if (CraftedRadioButton.Selected)
            {
                if (!craftResults[slot.item.type])
                {
                    return(false);
                }
            }

            if (LootRadioButton.Selected)
            {
                if (!isLoot[slot.item.type])
                {
                    return(false);
                }
            }

            if (UnobtainedRadioButton.Selected && RecipeBrowserUI.instance.foundItems != null)
            {
                if (RecipeBrowserUI.instance.foundItems[slot.item.type])
                {
                    return(false);
                }
            }

            if (slot.item.Name.IndexOf(itemNameFilter.currentString, StringComparison.OrdinalIgnoreCase) == -1)
            {
                return(false);
            }

            if (itemDescriptionFilter.currentString.Length > 0)
            {
                if ((slot.item.ToolTip != null && GetTooltipsAsString(slot.item.ToolTip).IndexOf(itemDescriptionFilter.currentString, StringComparison.OrdinalIgnoreCase) != -1) /*|| (recipe.createItem.toolTip2 != null && recipe.createItem.toolTip2.ToLower().IndexOf(itemDescriptionFilter.Text, StringComparison.OrdinalIgnoreCase) != -1)*/)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #5
0
        private int ItemGridSort(UIElement x, UIElement y)
        {
            UIItemCatalogueItemSlot a = x as UIItemCatalogueItemSlot;
            UIItemCatalogueItemSlot b = y as UIItemCatalogueItemSlot;

            if (SelectedSort != null)
            {
                return(SelectedSort.sort(a.item, b.item));
            }
            return(a.itemType.CompareTo(b.itemType));
        }
예제 #6
0
        private int ItemGridSort(UIElement x, UIElement y)
        {
            UIItemCatalogueItemSlot a = x as UIItemCatalogueItemSlot;
            UIItemCatalogueItemSlot b = y as UIItemCatalogueItemSlot;

            if (a == null || b == null)
            {
                return(x.Id.CompareTo(y.Id));
            }
            if (SharedUI.instance.SelectedSort.button.hoverText == "Total Defense" && x is UIArmorSetCatalogueItemSlot armorA && y is UIArmorSetCatalogueItemSlot armorB)
            {
                return(armorA.set.Item5.CompareTo(armorB.set.Item5));                // Total Hack
            }
            if (SharedUI.instance.SelectedSort != null)
            {
                return(SharedUI.instance.SelectedSort.sort(a.item, b.item));
            }
            return(a.itemType.CompareTo(b.itemType));
        }
예제 #7
0
        private bool PassItemFilters(UIItemCatalogueItemSlot slot)
        {
            if (RecipeBrowserUI.modIndex != 0)
            {
                if (slot.item.modItem == null)
                {
                    return(false);
                }
                if (slot.item.modItem.mod.Name != RecipeBrowserUI.instance.mods[RecipeBrowserUI.modIndex])
                {
                    return(false);
                }
            }

            if (CraftedRadioButton.Selected)
            {
                if (!craftResults[slot.item.type])
                {
                    return(false);
                }
            }

            if (LootRadioButton.Selected)
            {
                if (!isLoot[slot.item.type])
                {
                    return(false);
                }
            }

            if (UnobtainedRadioButton.Selected && RecipeBrowserUI.instance.foundItems != null)
            {
                if (RecipeBrowserUI.instance.foundItems[slot.item.type])
                {
                    return(false);
                }
            }

            if (SharedUI.instance.SelectedCategory != null)
            {
                if (!SharedUI.instance.SelectedCategory.belongs(slot.item) && !SharedUI.instance.SelectedCategory.subCategories.Any(x => x.belongs(slot.item)))
                {
                    return(false);
                }
            }


            foreach (var filter in SharedUI.instance.availableFilters)
            {
                if (filter.button.selected)
                {
                    if (!filter.belongs(slot.item))
                    {
                        return(false);
                    }
                    if (filter == SharedUI.instance.ObtainableFilter)
                    {
                        bool ableToCraft = false;
                        for (int i = 0; i < Recipe.numRecipes; i++)                         // Optimize with non-trimmed RecipePath.recipeDictionary
                        {
                            Recipe recipe = Main.recipe[i];
                            if (recipe.createItem.type == slot.item.type)
                            {
                                UIRecipeSlot recipeSlot = RecipeCatalogueUI.instance.recipeSlots[i];
                                recipeSlot.CraftPathNeeded();
                                //recipeSlot.CraftPathsImmediatelyNeeded();
                                if ((recipeSlot.craftPathCalculated || recipeSlot.craftPathsCalculated) && recipeSlot.craftPaths.Count > 0)
                                {
                                    ableToCraft = true;
                                    break;
                                }
                            }
                        }
                        if (!ableToCraft)
                        {
                            return(false);
                        }
                    }
                    if (filter == SharedUI.instance.CraftableFilter)
                    {
                        bool ableToCraft = false;
                        for (int n = 0; n < Main.numAvailableRecipes; n++)
                        {
                            if (Main.recipe[Main.availableRecipe[n]].createItem.type == slot.item.type)
                            {
                                ableToCraft = true;
                                break;
                            }
                        }
                        if (!ableToCraft)
                        {
                            return(false);
                        }
                    }
                }
            }

            if (slot.item.Name.IndexOf(itemNameFilter.currentString, StringComparison.OrdinalIgnoreCase) == -1)
            {
                return(false);
            }

            if (itemDescriptionFilter.currentString.Length > 0)
            {
                if (SharedUI.instance.SelectedCategory.name == ArmorSetFeatureHelper.ArmorSetsHoverTest)
                {
                    if (slot is UIArmorSetCatalogueItemSlot setCatalogueItemSlot)
                    {
                        return(setCatalogueItemSlot.set.Item4.IndexOf(itemDescriptionFilter.currentString, StringComparison.OrdinalIgnoreCase) != -1);
                    }
                }
                if ((slot.item.ToolTip != null && GetTooltipsAsString(slot.item.ToolTip).IndexOf(itemDescriptionFilter.currentString, StringComparison.OrdinalIgnoreCase) != -1) /*|| (recipe.createItem.toolTip2 != null && recipe.createItem.toolTip2.ToLower().IndexOf(itemDescriptionFilter.Text, StringComparison.OrdinalIgnoreCase) != -1)*/)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #8
0
        internal void Update()
        {
            // TODO: investigate why this Update is slower than RecipeCatalogueUI

            if (!RecipeBrowserUI.instance.ShowRecipeBrowser || RecipeBrowserUI.instance.CurrentPanel != RecipeBrowserUI.ItemCatalogue)
            {
                return;
            }

            if (slowUpdateNeeded > 0)
            {
                slowUpdateNeeded--;
                if (slowUpdateNeeded == 0)
                {
                    updateNeeded = true;
                }
            }

            if (!updateNeeded)
            {
                return;
            }
            updateNeeded     = false;
            slowUpdateNeeded = 0;

            if (itemSlots.Count == 0)
            {
                // should only happen once
                craftResults = new bool[ItemLoader.ItemCount];
                isLoot       = new bool[ItemLoader.ItemCount];
                itemSlots.Clear();
                for (int type = 1; type < ItemLoader.ItemCount; type++)
                {
                    Item item = new Item();
                    item.SetDefaults(type, false);                     // 300 ms vs 30 ms
                    if (item.type == 0)
                    {
                        continue;
                    }
                    var slot = new UIItemCatalogueItemSlot(item);
                    itemSlots.Add(slot);
                }

                for (int i = 0; i < Recipe.numRecipes; i++)
                {
                    Recipe recipe = Main.recipe[i];
                    craftResults[recipe.createItem.type] = true;
                }

                foreach (var kvp in LootCache.instance.lootInfos)
                {
                    //if (kvp.Key.id == 0 && kvp.Key.mod == "Terraria")
                    //	Console.WriteLine();
                    int id = kvp.Key.GetID();
                    if (id > 0)
                    {
                        isLoot[id] = true;
                    }
                }
            }

            itemGrid.Clear();
            List <UIItemCatalogueItemSlot> slotsToUse = itemSlots;

            if (SharedUI.instance.SelectedCategory.name == ArmorSetFeatureHelper.ArmorSetsHoverTest)
            {
                if (ArmorSetFeatureHelper.armorSetSlots == null)
                {
                    ArmorSetFeatureHelper.CalculateArmorSets();
                }
                slotsToUse = ArmorSetFeatureHelper.armorSetSlots.Cast <UIItemCatalogueItemSlot>().ToList();
                ArmorSetFeatureHelper.AppendSpecialUI(itemGrid);
            }

            foreach (var slot in slotsToUse)
            {
                if (PassItemFilters(slot))
                {
                    itemGrid._items.Add(slot);
                    itemGrid._innerList.Append(slot);
                }
            }
            itemGrid.UpdateOrder();
            itemGrid._innerList.Recalculate();
        }