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); }
public override void OnBind() { base.OnBind(); data = memberInfo.GetValue(item); defaultListValueAttribute = ConfigManager.GetCustomAttribute <DefaultListValueAttribute>(memberInfo, null, null); MaxHeight.Set(300, 0f); dataListElement = new UIElement(); dataListElement.Width.Set(-10f, 1f); dataListElement.Left.Set(10f, 0f); dataListElement.Height.Set(-30, 1f); dataListElement.Top.Set(30f, 0f); //panel.SetPadding(0); //panel.BackgroundColor = Microsoft.Xna.Framework.Color.Transparent; //panel.BorderColor = Microsoft.Xna.Framework.Color.Transparent; if (data != null) { Append(dataListElement); } dataListElement.OverflowHidden = true; dataList = new NestedUIList(); dataList.Width.Set(-20, 1f); dataList.Left.Set(0, 0f); dataList.Height.Set(0, 1f); dataList.ListPadding = 5f; dataListElement.Append(dataList); UIScrollbar scrollbar = new UIScrollbar(); scrollbar.SetView(100f, 1000f); scrollbar.Height.Set(-16f, 1f); scrollbar.Top.Set(6f, 0f); scrollbar.Left.Pixels -= 3; scrollbar.HAlign = 1f; dataList.SetScrollbar(scrollbar); dataListElement.Append(scrollbar); PrepareTypes(); // allow null collections to simplify modder code for OnDeserialize and allow null and empty lists to have different meanings, etc. SetupList(); if (CanAdd) { initializeButton = new UIModConfigHoverImage(playTexture, "Initialize"); initializeButton.Top.Pixels += 4; initializeButton.Left.Pixels -= 3; initializeButton.HAlign = 1f; initializeButton.OnClick += (a, b) => { Main.PlaySound(SoundID.Tink); InitializeCollection(); SetupList(); Interface.modConfig.RecalculateChildren(); // not needed? Interface.modConfig.SetPendingChanges(); expanded = true; pendingChanges = true; }; addButton = new UIModConfigHoverImage(plusTexture, "Add"); addButton.Top.Set(4, 0f); addButton.Left.Set(-52, 1f); addButton.OnClick += (a, b) => { Main.PlaySound(SoundID.Tink); AddItem(); SetupList(); Interface.modConfig.RecalculateChildren(); Interface.modConfig.SetPendingChanges(); expanded = true; pendingChanges = true; }; deleteButton = new UIModConfigHoverImage(deleteTexture, "Clear"); deleteButton.Top.Set(4, 0f); deleteButton.Left.Set(-25, 1f); deleteButton.OnClick += (a, b) => { Main.PlaySound(SoundID.Tink); if (nullAllowed) { NullCollection(); } else { ClearCollection(); } SetupList(); Interface.modConfig.RecalculateChildren(); Interface.modConfig.SetPendingChanges(); pendingChanges = true; }; } expandButton = new UIModConfigHoverImage(collapsedTexture, "Expand"); expandButton.Top.Set(4, 0f); // 10, -25: 4, -52 expandButton.Left.Set(-79, 1f); expandButton.OnClick += (a, b) => { expanded = !expanded; pendingChanges = true; }; upDownButton = new UIModConfigHoverImageSplit(upDownTexture, "Scale Up", "Scale Down"); upDownButton.Top.Set(4, 0f); upDownButton.Left.Set(-106, 1f); upDownButton.OnClick += (a, b) => { Rectangle r = b.GetDimensions().ToRectangle(); if (a.MousePosition.Y < r.Y + r.Height / 2) { scale = Math.Min(2f, scale + 0.5f); } else { scale = Math.Max(1f, scale - 0.5f); } //dataListPanel.RecalculateChildren(); ////dataList.RecalculateChildren(); //float h = dataList.GetTotalHeight(); //MinHeight.Set(Math.Min(Math.Max(h + 84, 100), 300) * scale, 0f); //Recalculate(); //if (Parent != null && Parent is UISortableElement) { // Parent.Height.Pixels = GetOuterDimensions().Height; //} }; //Append(upButton); //var aasdf = Texture2D.FromStream(Main.instance.GraphicsDevice, Assembly.GetExecutingAssembly().GetManifestResourceStream("Terraria.ModLoader.Config.UI.ButtonDecrement.png")); //for (int i = 0; i < 100; i++) { // var vb = Texture2D.FromStream(Main.instance.GraphicsDevice, Assembly.GetExecutingAssembly().GetManifestResourceStream("Terraria.ModLoader.Config.UI.ButtonDecrement.png")); //} pendingChanges = true; Recalculate(); // Needed? }
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); }
public IntInputElement(PropertyFieldWrapper memberInfo, object item, IList <int> array, int index) : base(memberInfo, item, (IList)array) { _GetValue = () => DefaultGetValue(); _SetValue = (int value) => DefaultSetValue(value); if (array != null) { _GetValue = () => array[index]; _SetValue = (int value) => { array[index] = value; Interface.modConfig.SetPendingChanges(); }; _TextDisplayFunction = () => index + 1 + ": " + array[index]; } if (rangeAttribute != null && rangeAttribute.min is int && rangeAttribute.max is int) { min = (int)rangeAttribute.min; max = (int)rangeAttribute.max; } if (incrementAttribute != null && incrementAttribute.increment is int) { this.increment = (int)incrementAttribute.increment; } UIPanel textBoxBackground = new UIPanel(); textBoxBackground.SetPadding(0); UIFocusInputTextField uIInputTextField = new UIFocusInputTextField("Type here"); textBoxBackground.Top.Set(0f, 0f); textBoxBackground.Left.Set(-190, 1f); textBoxBackground.Width.Set(180, 0f); textBoxBackground.Height.Set(30, 0f); Append(textBoxBackground); uIInputTextField.SetText(_GetValue().ToString()); uIInputTextField.Top.Set(5, 0f); uIInputTextField.Left.Set(10, 0f); uIInputTextField.Width.Set(-42, 1f); // allow space for arrows uIInputTextField.Height.Set(20, 0); uIInputTextField.OnTextChange += (a, b) => { if (Int32.TryParse(uIInputTextField.currentString, out int val)) { _SetValue(val); } //else //{ // Interface.modConfig.SetMessage($"{uIInputTextField.currentString} isn't a valid value.", Color.Green); //} }; uIInputTextField.OnUnfocus += (a, b) => uIInputTextField.SetText(_GetValue().ToString()); textBoxBackground.Append(uIInputTextField); UIModConfigHoverImageSplit upDownButton = new UIModConfigHoverImageSplit(upDownTexture, "+" + increment, "-" + increment); upDownButton.Recalculate(); upDownButton.Top.Set(4f, 0f); upDownButton.Left.Set(-30, 1f); upDownButton.OnClick += (a, b) => { Rectangle r = b.GetDimensions().ToRectangle(); if (a.MousePosition.Y < r.Y + r.Height / 2) { _SetValue(Utils.Clamp(_GetValue() + increment, min, max)); } else { _SetValue(Utils.Clamp(_GetValue() - increment, min, max)); } uIInputTextField.SetText(_GetValue().ToString()); }; textBoxBackground.Append(upDownButton); Recalculate(); }
public override void OnBind() { base.OnBind(); this.intList = (IList <int>)list; if (intList != null) { TextDisplayFunction = () => index + 1 + ": " + intList[index]; } if (rangeAttribute != null && rangeAttribute.min is int && rangeAttribute.max is int) { min = (int)rangeAttribute.min; max = (int)rangeAttribute.max; } if (incrementAttribute != null && incrementAttribute.increment is int) { this.increment = (int)incrementAttribute.increment; } UIPanel textBoxBackground = new UIPanel(); textBoxBackground.SetPadding(0); UIFocusInputTextField uIInputTextField = new UIFocusInputTextField("Type here"); textBoxBackground.Top.Set(0f, 0f); textBoxBackground.Left.Set(-190, 1f); textBoxBackground.Width.Set(180, 0f); textBoxBackground.Height.Set(30, 0f); Append(textBoxBackground); uIInputTextField.SetText(GetValue().ToString()); uIInputTextField.Top.Set(5, 0f); uIInputTextField.Left.Set(10, 0f); uIInputTextField.Width.Set(-42, 1f); // allow space for arrows uIInputTextField.Height.Set(20, 0); uIInputTextField.OnTextChange += (a, b) => { if (Int32.TryParse(uIInputTextField.CurrentString, out int val)) { SetValue(val); } //else //{ // Interface.modConfig.SetMessage($"{uIInputTextField.currentString} isn't a valid value.", Color.Green); //} }; uIInputTextField.OnUnfocus += (a, b) => uIInputTextField.SetText(GetValue().ToString()); textBoxBackground.Append(uIInputTextField); UIModConfigHoverImageSplit upDownButton = new UIModConfigHoverImageSplit(upDownTexture, "+" + increment, "-" + increment); upDownButton.Recalculate(); upDownButton.Top.Set(4f, 0f); upDownButton.Left.Set(-30, 1f); upDownButton.OnClick += (a, b) => { Rectangle r = b.GetDimensions().ToRectangle(); if (a.MousePosition.Y < r.Y + r.Height / 2) { SetValue(Utils.Clamp(GetValue() + increment, min, max)); } else { SetValue(Utils.Clamp(GetValue() - increment, min, max)); } uIInputTextField.SetText(GetValue().ToString()); }; textBoxBackground.Append(upDownButton); Recalculate(); }