Skip to content

Commit 686852a

Browse files
committed
Fix child control parsing order on recalculating layout to be identical to order when first INItializing window
1 parent f3ef2d9 commit 686852a

1 file changed

Lines changed: 37 additions & 20 deletions

File tree

src/TSMapEditor/UI/Controls/INItializableWindow.cs

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ public void RefreshLayout()
105105
{
106106
ReadINIForControl(control, true);
107107
}
108+
109+
if (btnClose != null)
110+
btnClose.X = Width - btnClose.Width;
108111
}
109112

110113
private bool ReadINIForControl(XNAControl control, bool isForLayout = false)
@@ -115,13 +118,25 @@ private bool ReadINIForControl(XNAControl control, bool isForLayout = false)
115118

116119
foreach (var kvp in section.Keys)
117120
{
118-
if (!isForLayout && kvp.Key.StartsWith("$CC"))
121+
if (kvp.Key.StartsWith("$CC"))
119122
{
120-
var child = CreateChildControl(control, kvp.Value);
121-
if (!ReadINIForControl(child))
122-
throw new INIConfigException("No section exists for child control " + kvp.Value);
123+
if (!isForLayout)
124+
{
125+
var child = CreateChildControl(control, kvp.Value);
126+
if (!ReadINIForControl(child))
127+
throw new INIConfigException("No section exists for child control " + kvp.Value);
128+
129+
child.Initialize();
130+
}
131+
else
132+
{
133+
string childName = GetChildControlName(control, kvp.Value);
134+
var child = Children.First(cc => cc.Name == childName);
135+
if (child == null)
136+
throw new INIConfigException($"Processing {control.Name} in {nameof(INItializableWindow)}: Unable to find child control {kvp.Value} while calculating layout");
123137

124-
child.Initialize();
138+
ReadINIForControl(child, true);
139+
}
125140
}
126141
else if (kvp.Key == "$X")
127142
{
@@ -176,12 +191,6 @@ private bool ReadINIForControl(XNAControl control, bool isForLayout = false)
176191
}
177192
}
178193

179-
if (isForLayout)
180-
{
181-
foreach (var child in control.Children)
182-
ReadINIForControl(child, true);
183-
}
184-
185194
return true;
186195
}
187196

@@ -248,22 +257,30 @@ private void ReadLateAttributesForControl(XNAControl control)
248257
private XNAControl CreateChildControl(XNAControl parent, string keyValue)
249258
{
250259
string[] parts = keyValue.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
260+
string childName = GetChildControlName(parent, keyValue);
251261

252-
if (parts.Length != 2)
253-
throw new INIConfigException("Invalid child control definition " + keyValue);
254-
255-
if (string.IsNullOrEmpty(parts[0]))
256-
throw new INIConfigException("Empty name in child control definition for " + parent.Name);
257-
258-
if (FindChild<XNAControl>(parts[0], true) != null)
262+
if (FindChild<XNAControl>(childName, true) != null)
259263
{
260-
throw new INIConfigException("A control named " + parts[0] + " has been defined more than once.");
264+
throw new INIConfigException("A control named " + childName + " has been defined more than once.");
261265
}
262266

263267
var childControl = EditorGUICreator.Instance.CreateControl(WindowManager, parts[1]);
264-
childControl.Name = parts[0];
268+
childControl.Name = childName;
265269
parent.AddChildWithoutInitialize(childControl);
266270
return childControl;
267271
}
272+
273+
private string GetChildControlName(XNAControl parent, string keyValue)
274+
{
275+
string[] parts = keyValue.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
276+
277+
if (parts.Length != 2)
278+
throw new INIConfigException("Invalid child control definition " + keyValue);
279+
280+
if (string.IsNullOrWhiteSpace(parts[0]))
281+
throw new INIConfigException("Empty name in child control definition for " + parent.Name);
282+
283+
return parts[0];
284+
}
268285
}
269286
}

0 commit comments

Comments
 (0)