From 211821d6733da0dca0d0f84debcd088a349f9570 Mon Sep 17 00:00:00 2001 From: Matthew Neumann Date: Fri, 7 Mar 2025 15:35:41 -0800 Subject: [PATCH] Fixed some window size issues with the Edit form. Added all items to the List of items sections. Setting up framework to load skin ids from json. --- Better NCP Editor/EditValueForm.cs | 35 +++++++++++++++++++----------- Better NCP Editor/Form1.cs | 20 +++++++++++++++-- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/Better NCP Editor/EditValueForm.cs b/Better NCP Editor/EditValueForm.cs index 9b8b371..9a7cdf5 100644 --- a/Better NCP Editor/EditValueForm.cs +++ b/Better NCP Editor/EditValueForm.cs @@ -16,27 +16,36 @@ namespace Better_NCP_Editor // Set the minimum and default size. this.MinimumSize = new Size(210, 120); //this.AutoScaleDimensions = new SizeF(96F, 96F); // or your base DPI - this.AutoScaleMode = AutoScaleMode.Dpi; + this.AutoScaleMode = AutoScaleMode.None; this.FormBorderStyle = FormBorderStyle.FixedDialog; this.MaximizeBox = false; // Measure the width of the property name. - Size keySize = TextRenderer.MeasureText(propertyName, this.Font); + int propertyNameWidth = TextRenderer.MeasureText(propertyName, this.Font).Width; - // Determine the width required for the input control. - int inputWidth = 0; - if (valueType == typeof(bool)) + // For non-bool types, measure the current value width. + int currentValueWidth = valueType == typeof(bool) + ? TextRenderer.MeasureText("false", this.Font).Width + 30 + : TextRenderer.MeasureText(currentValue, this.Font).Width + 40; + + // If combo items are provided, determine the maximum width needed for them. + int comboItemsWidth = 0; + if (comboItems != null) { - // For a boolean, we'll use the longer of "true" or "false" plus padding. - inputWidth = TextRenderer.MeasureText("false", this.Font).Width + 30; - } - else - { - inputWidth = TextRenderer.MeasureText(currentValue, this.Font).Width + 40; + foreach (var item in comboItems) + { + int itemWidth = TextRenderer.MeasureText(item, this.Font).Width; + if (itemWidth > comboItemsWidth) + comboItemsWidth = itemWidth; + } + // Add padding for the dropdown arrow and some extra margin. + comboItemsWidth += 20; } - // Determine the desired width: the maximum of the key width and input width, plus extra padding. - int desiredWidth = Math.Max(keySize.Width, inputWidth) + 40; + // Determine the desired width by taking the maximum of the measured values and adding extra margins. + int desiredWidth = Math.Max(propertyNameWidth, Math.Max(currentValueWidth, comboItemsWidth)) + 40; + + // Set the client size based on the desired width. this.ClientSize = new Size(desiredWidth, 120); this.Text = $"Edit {propertyName}"; diff --git a/Better NCP Editor/Form1.cs b/Better NCP Editor/Form1.cs index 972ebb5..38ee7a3 100644 --- a/Better NCP Editor/Form1.cs +++ b/Better NCP Editor/Form1.cs @@ -357,16 +357,32 @@ namespace Better_NCP_Editor if (e.Node.Parent.Parent != null) { grandParentNodeName = e.Node.Parent.Parent.Text; - + // Populate wear items list if (propName.Equals("ShortName", StringComparison.OrdinalIgnoreCase) && grandParentNodeName.Equals("Wear items")) { comboList = _wearItems; } + // Populate belt item list else if (propName.Equals("ShortName", StringComparison.OrdinalIgnoreCase) && grandParentNodeName.Equals("Belt items")) { comboList = _beltItems; } - + // Populate belt item list + else if (propName.Equals("ShortName", StringComparison.OrdinalIgnoreCase) && grandParentNodeName.Equals("List of items")) + { + // Populate all items + comboList = new List(_allItems.Keys); + } + // Populate skin ids for wear items + else if (propName.Equals("SkinID (0 - default)",StringComparison.OrdinalIgnoreCase) && grandParentNodeName.Equals("Wear items")) + { + // load the list here + } + // Populate skin ids for belt items + else if (propName.Equals("SkinID (0 - default)", StringComparison.OrdinalIgnoreCase) && grandParentNodeName.Equals("Belt items")) + { + // load the list here + } } if (parentNodeName.Equals("Mods"))