public UIState() { Width.Percent = 1f; Height.Percent = 1f; MaxWidth.Set(Main.Graphics.PreferredBackBufferWidth, 1f); MaxHeight.Set(Main.Graphics.PreferredBackBufferHeight, 1f); Recalculate(); }
public UISlider(float min = 0, float max = 1) { MinValue = min; MaxValue = max; Height.Set(20, 0); MaxHeight.Set(20, 0); Width.Set(100, 0); PaddingTop = 5f; PaddingBottom = 5f; }
public override void Recalculate() { base.Recalculate(); float defaultHeight = 30; float h = dataListElement.Parent != null?dataList.GetTotalHeight() + defaultHeight : defaultHeight; // 24 for UIElement h = Utils.Clamp(h, 30, 300 * scale); MaxHeight.Set(300 * scale, 0f); Height.Set(h, 0f); if (Parent != null && Parent is UISortableElement) { Parent.Height.Set(h, 0f); } }
public Menu(float width, float height) { MaxWidth.Set(width, 0f); MaxHeight.Set(height, 0f); SetPadding(7); buttonGrid = new UIGrid(7); buttonGrid.Width.Set(-20, 1); buttonGrid.Height.Set(0, 1); buttonGrid.ListPadding = 7f; Append(buttonGrid); AppendButtons(); }
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? }