Exemplo n.º 1
0
        protected override List <DefinitionOptionElement <ItemDefinition> > CreateDefinitionOptionElementList()
        {
            var options = new List <DefinitionOptionElement <ItemDefinition> >();

            for (int i = 0; i < ItemLoader.ItemCount; i++)
            {
                var optionElement = new ItemDefinitionOptionElement(new ItemDefinition(i), optionScale);
                optionElement.OnClick += (a, b) => {
                    Value             = optionElement.definition;
                    updateNeeded      = true;
                    selectionExpanded = false;
                };
                options.Add(optionElement);
            }
            return(options);
        }
Exemplo n.º 2
0
        public override int CompareTo(object obj)
        {
            ItemDefinitionOptionElement other = obj as ItemDefinitionOptionElement;

            return(itemType.CompareTo(other.itemType));
        }
Exemplo n.º 3
0
        public override void OnBind()
        {
            base.OnBind();
            Height.Set(30f, 0f);

            //itemChoice = new UIModConfigItemDefinitionChoice(_GetValue()?.GetID() ?? 0, 0.5f);
            itemChoice = new ItemDefinitionOptionElement(Value, 0.5f);
            itemChoice.Top.Set(2f, 0f);
            itemChoice.Left.Set(-30, 1f);
            itemChoice.OnClick += (a, b) =>
            {
                itemSelectionExpanded = !itemSelectionExpanded;
                updateNeeded          = true;
            };
            Append(itemChoice);

            chooserPanel = new UIPanel();
            chooserPanel.Top.Set(30, 0);
            chooserPanel.Height.Set(200, 0);
            chooserPanel.Width.Set(0, 1);
            chooserPanel.BackgroundColor = Color.CornflowerBlue;

            UIPanel textBoxBackgroundA = new UIPanel();

            textBoxBackgroundA.Width.Set(160, 0f);
            textBoxBackgroundA.Height.Set(30, 0f);
            textBoxBackgroundA.Top.Set(-6, 0);
            textBoxBackgroundA.PaddingTop    = 0;
            textBoxBackgroundA.PaddingBottom = 0;
            chooserFilter = new UIFocusInputTextField("Filter by Name");
            chooserFilter.OnTextChange += (a, b) =>
            {
                updateNeeded = true;
            };
            chooserFilter.OnRightClick += (a, b) => chooserFilter.SetText("");
            chooserFilter.Width         = StyleDimension.Fill;
            chooserFilter.Height.Set(-6, 1f);
            chooserFilter.Top.Set(6, 0f);
            textBoxBackgroundA.Append(chooserFilter);
            chooserPanel.Append(textBoxBackgroundA);

            UIPanel textBoxBackgroundB = new UIPanel();

            textBoxBackgroundB.CopyStyle(textBoxBackgroundA);
            textBoxBackgroundB.Left.Set(180, 0);
            chooserFilterMod = new UIFocusInputTextField("Filter by Mod");
            chooserFilterMod.OnTextChange += (a, b) =>
            {
                updateNeeded = true;
            };
            chooserFilterMod.OnRightClick += (a, b) => chooserFilterMod.SetText("");
            chooserFilterMod.Width         = StyleDimension.Fill;
            chooserFilterMod.Height.Set(-6, 1f);
            chooserFilterMod.Top.Set(6, 0f);
            textBoxBackgroundB.Append(chooserFilterMod);
            chooserPanel.Append(textBoxBackgroundB);

            chooserGrid = new NestedUIGrid();
            chooserGrid.Top.Set(30, 0);
            chooserGrid.Height.Set(-30, 1);
            chooserGrid.Width.Set(-12, 1);
            chooserPanel.Append(chooserGrid);

            UIScrollbar scrollbar = new UIScrollbar();

            scrollbar.SetView(100f, 1000f);
            scrollbar.Height.Set(-30f, 1f);
            scrollbar.Top.Set(30f, 0f);
            scrollbar.Left.Pixels += 8;
            scrollbar.HAlign       = 1f;
            chooserGrid.SetScrollbar(scrollbar);
            chooserPanel.Append(scrollbar);
            //Append(chooserPanel);

            UIModConfigHoverImageSplit upDownButton = new UIModConfigHoverImageSplit(upDownTexture, "Zoom in", "Zoom out");

            upDownButton.Recalculate();
            upDownButton.Top.Set(-4f, 0f);
            upDownButton.Left.Set(-18, 1f);
            upDownButton.OnClick += (a, b) =>
            {
                Rectangle r = b.GetDimensions().ToRectangle();
                if (a.MousePosition.Y < r.Y + r.Height / 2)
                {
                    itemScale = Math.Min(1f, itemScale + 0.1f);
                }
                else
                {
                    itemScale = Math.Max(0.5f, itemScale - 0.1f);
                }
                foreach (var itemchoice in items)
                {
                    itemchoice.SetScale(itemScale);
                }
            };
            chooserPanel.Append(upDownButton);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public ItemDefinitionElement(PropertyFieldWrapper memberInfo, object item, IList <ItemDefinition> array = null, int index = -1) : base(memberInfo, item, (IList)array)
        {
            Height.Set(30f, 0f);

            _GetValue = () => DefaultGetValue();
            _SetValue = (ItemDefinition value) => DefaultSetValue(value);

            if (array != null)
            {
                _GetValue            = () => array[index];
                _SetValue            = (ItemDefinition value) => { array[index] = value; Interface.modConfig.SetPendingChanges(); };
                _TextDisplayFunction = () => index + 1 + ": ";
            }

            //itemChoice = new UIModConfigItemDefinitionChoice(_GetValue()?.GetID() ?? 0, 0.5f);
            itemChoice = new ItemDefinitionOptionElement(_GetValue(), 0.5f);
            itemChoice.Top.Set(2f, 0f);
            itemChoice.Left.Set(-30, 1f);
            itemChoice.OnClick += (a, b) =>
            {
                itemSelectionExpanded = !itemSelectionExpanded;
                updateNeeded          = true;
            };
            Append(itemChoice);

            chooserPanel = new UIPanel();
            chooserPanel.Top.Set(30, 0);
            chooserPanel.Height.Set(200, 0);
            chooserPanel.Width.Set(0, 1);
            chooserPanel.BackgroundColor = Color.CornflowerBlue;

            UIPanel textBoxBackgroundA = new UIPanel();

            textBoxBackgroundA.Width.Set(160, 0f);
            textBoxBackgroundA.Height.Set(30, 0f);
            textBoxBackgroundA.Top.Set(-6, 0);
            textBoxBackgroundA.PaddingTop    = 0;
            textBoxBackgroundA.PaddingBottom = 0;
            chooserFilter = new UIFocusInputTextField("Filter by Name");
            chooserFilter.OnTextChange += (a, b) =>
            {
                updateNeeded = true;
            };
            chooserFilter.OnRightClick += (a, b) => chooserFilter.SetText("");
            chooserFilter.Width         = StyleDimension.Fill;
            chooserFilter.Height.Set(-6, 1f);
            chooserFilter.Top.Set(6, 0f);
            textBoxBackgroundA.Append(chooserFilter);
            chooserPanel.Append(textBoxBackgroundA);

            UIPanel textBoxBackgroundB = new UIPanel();

            textBoxBackgroundB.CopyStyle(textBoxBackgroundA);
            textBoxBackgroundB.Left.Set(180, 0);
            chooserFilterMod = new UIFocusInputTextField("Filter by Mod");
            chooserFilterMod.OnTextChange += (a, b) =>
            {
                updateNeeded = true;
            };
            chooserFilterMod.OnRightClick += (a, b) => chooserFilterMod.SetText("");
            chooserFilterMod.Width         = StyleDimension.Fill;
            chooserFilterMod.Height.Set(-6, 1f);
            chooserFilterMod.Top.Set(6, 0f);
            textBoxBackgroundB.Append(chooserFilterMod);
            chooserPanel.Append(textBoxBackgroundB);

            chooserGrid = new NestedUIGrid();
            chooserGrid.Top.Set(30, 0);
            chooserGrid.Height.Set(-30, 1);
            chooserGrid.Width.Set(-12, 1);
            chooserPanel.Append(chooserGrid);

            UIScrollbar scrollbar = new UIScrollbar();

            scrollbar.SetView(100f, 1000f);
            scrollbar.Height.Set(-30f, 1f);
            scrollbar.Top.Set(30f, 0f);
            scrollbar.Left.Pixels += 8;
            scrollbar.HAlign       = 1f;
            chooserGrid.SetScrollbar(scrollbar);
            chooserPanel.Append(scrollbar);
            //Append(chooserPanel);

            UIModConfigHoverImageSplit upDownButton = new UIModConfigHoverImageSplit(upDownTexture, "Zoom in", "Zoom out");

            upDownButton.Recalculate();
            upDownButton.Top.Set(-4f, 0f);
            upDownButton.Left.Set(-18, 1f);
            upDownButton.OnClick += (a, b) =>
            {
                Rectangle r = b.GetDimensions().ToRectangle();
                if (a.MousePosition.Y < r.Y + r.Height / 2)
                {
                    itemScale = Math.Min(1f, itemScale + 0.1f);
                }
                else
                {
                    itemScale = Math.Max(0.5f, itemScale - 0.1f);
                }
                foreach (var itemchoice in items)
                {
                    itemchoice.SetScale(itemScale);
                }
            };
            chooserPanel.Append(upDownButton);
        }