示例#1
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            if (!updateNeeded)
            {
                return;
            }
            updateNeeded = false;
            if (selectionExpanded && options == null)
            {
                options = CreateDefinitionOptionElementList();
            }
            if (!selectionExpanded)
            {
                chooserPanel.Remove();
            }
            else
            {
                Append(chooserPanel);
            }
            float newHeight = selectionExpanded ? 240 : 30;

            Height.Set(newHeight, 0f);
            if (Parent != null && Parent is UISortableElement)
            {
                Parent.Height.Pixels = newHeight;
            }
            if (selectionExpanded)
            {
                var passed = GetPassedOptionElements();
                chooserGrid.Clear();
                chooserGrid.AddRange(passed);
            }
            //itemChoice.SetItem(_GetValue()?.GetID() ?? 0);
            optionChoice.SetItem(Value);
        }
示例#2
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            if (!updateNeeded)
            {
                return;
            }
            updateNeeded = false;
            if (itemSelectionExpanded && items == null)
            {
                items = new List <ItemDefinitionOptionElement>();
                for (int i = 0; i < ItemLoader.ItemCount; i++)
                {
                    int capturedID = i;
                    ItemDefinitionOptionElement item = new ItemDefinitionOptionElement(capturedID, 0.5f);
                    item.OnClick += (a, b) =>
                    {
                        if (capturedID >= ItemID.Count)
                        {
                            var moditem = ItemLoader.GetItem(capturedID);
                            Value = new ItemDefinition(moditem.mod.Name, moditem.Name);
                        }
                        else
                        {
                            Value = new ItemDefinition("Terraria", ItemID.Search.GetName(capturedID));
                        }
                        updateNeeded          = true;
                        itemSelectionExpanded = false;
                    };
                    items.Add(item);
                }
            }
            if (!itemSelectionExpanded)
            {
                chooserPanel.Remove();
            }
            else
            {
                Append(chooserPanel);
            }
            float newHeight = itemSelectionExpanded ? 240 : 30;

            Height.Set(newHeight, 0f);
            if (Parent != null && Parent is UISortableElement)
            {
                Parent.Height.Pixels = newHeight;
            }
            if (itemSelectionExpanded)
            {
                var passed = new List <ItemDefinitionOptionElement>();
                foreach (var item in items)
                {
                    if (ItemID.Sets.Deprecated[item.itemType])
                    {
                        continue;
                    }
                    // Should this be the localized item name?
                    if (Lang.GetItemNameValue(item.itemType).IndexOf(chooserFilter.CurrentString, StringComparison.OrdinalIgnoreCase) == -1)
                    {
                        continue;
                    }
                    string modname = "Terraria";
                    if (item.itemType > ItemID.Count)
                    {
                        modname = ItemLoader.GetItem(item.itemType).mod.DisplayName;                         // or internal name?
                    }
                    if (modname.IndexOf(chooserFilterMod.CurrentString, StringComparison.OrdinalIgnoreCase) == -1)
                    {
                        continue;
                    }
                    passed.Add(item);
                }
                chooserGrid.Clear();
                chooserGrid.AddRange(passed);
            }
            //itemChoice.SetItem(_GetValue()?.GetID() ?? 0);
            itemChoice.SetItem(Value);
        }