Skip to content

Commit

Permalink
Added a list of controls that failed to load
Browse files Browse the repository at this point in the history
  • Loading branch information
X39 committed Mar 14, 2020
1 parent a1b498d commit ee6a4b9
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 56 deletions.
18 changes: 18 additions & 0 deletions Arma.Studio.UiEditor/Properties/Language.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Arma.Studio.UiEditor/Properties/Language.resx
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,10 @@
<data name="UiEditor_HighlightAll" xml:space="preserve">
<value>Highlight all</value>
</data>
<data name="UiEditor_FailedToLoad_Body_0names" xml:space="preserve">
<value>Failed to load the following classes: {0}</value>
</data>
<data name="UiEditor_FailedToLoad_Caption" xml:space="preserve">
<value>Failed to load all classes</value>
</data>
</root>
136 changes: 80 additions & 56 deletions Arma.Studio.UiEditor/UI/UiEditorDataContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ public void Load()

var backgroundControls = dialogConfig[dlg_controlsBackground];
var foregroundControls = dialogConfig[dlg_controls];
var failedToLoadList = new List<string>();
if (backgroundControls != null)
{
var controls = getControls(backgroundControls);
Expand All @@ -466,6 +467,10 @@ public void Load()
{
this.BackgroundControls.Add(control);
}
else
{
failedToLoadList.Add(node.Name);
}
}
}
if (foregroundControls != null)
Expand All @@ -478,8 +483,20 @@ public void Load()
{
this.ForegroundControls.Add(control);
}
else
{
failedToLoadList.Add(node.Name);
}
}
}
if (failedToLoadList.Any())
{
MessageBox.Show(
String.Format(Properties.Language.UiEditor_FailedToLoad_Body_0names, String.Concat("\n- ", String.Join("\n- ", failedToLoadList))),
Properties.Language.UiEditor_FailedToLoad_Caption,
MessageBoxButton.OK,
MessageBoxImage.Information);
}
}
this.HasChanges = false;
}
Expand All @@ -497,75 +514,82 @@ private ControlBase LoadControl(SqfVm.ClrVirtualmachine vm, SqfVm.Config node)
{
return null;
}
var targetType = attributes.First().TargetType;
var instance = targetType.CreateInstance<ControlBase>();
instance.ClassName = node.Name;
foreach (var propertyInfo in targetType.GetProperties().Where((it) => it.SetMethod != null))
try
{
var armaNameAttributes = Attribute.GetCustomAttributes(propertyInfo, typeof(ArmaNameAttribute), true).Cast<ArmaNameAttribute>().ToArray();
if (!armaNameAttributes.Any())
{
continue;
}
var armaNameAttribute = armaNameAttributes.First();
var value = node[armaNameAttribute.Title]?.Value;
if (value is null)
{
continue;
}
if (propertyInfo.PropertyType.IsEquivalentTo(typeof(System.Windows.Media.Color)))
var targetType = attributes.First().TargetType;
var instance = targetType.CreateInstance<ControlBase>();
instance.ClassName = node.Name;
foreach (var propertyInfo in targetType.GetProperties().Where((it) => it.SetMethod != null))
{
var arraylist = value as System.Collections.ArrayList;
propertyInfo.SetValue(instance,
System.Windows.Media.Color.FromArgb(
(byte)(255 * Convert.ToDouble(arraylist.Count < 4 ? 0 : arraylist[3], System.Globalization.CultureInfo.InvariantCulture)),
(byte)(255 * Convert.ToDouble(arraylist.Count < 1 ? 0 : arraylist[0], System.Globalization.CultureInfo.InvariantCulture)),
(byte)(255 * Convert.ToDouble(arraylist.Count < 2 ? 0 : arraylist[1], System.Globalization.CultureInfo.InvariantCulture)),
(byte)(255 * Convert.ToDouble(arraylist.Count < 3 ? 0 : arraylist[2], System.Globalization.CultureInfo.InvariantCulture))
),
null);
}
else if (propertyInfo.PropertyType.IsEnum)
{
propertyInfo.SetValue(instance, Convert.ToInt32(value, System.Globalization.CultureInfo.InvariantCulture), null);
}
else if (value is string s)
{
if (propertyInfo.PropertyType.IsEquivalentTo(typeof(string)))
var armaNameAttributes = Attribute.GetCustomAttributes(propertyInfo, typeof(ArmaNameAttribute), true).Cast<ArmaNameAttribute>().ToArray();
if (!armaNameAttributes.Any())
{
propertyInfo.SetValue(instance, Convert.ChangeType(s.Trim('"'), propertyInfo.PropertyType, System.Globalization.CultureInfo.InvariantCulture), null);
continue;
}
else
var armaNameAttribute = armaNameAttributes.First();
var value = node[armaNameAttribute.Title]?.Value;
if (value is null)
{
var res = vm.Evaluate(s);
var resval = Convert.ChangeType(res.Data.Trim('"'), propertyInfo.PropertyType, System.Globalization.CultureInfo.InvariantCulture);
if (new string[] { "x", "y", "w", "h" }.Contains(armaNameAttribute.Title))
continue;
}
if (propertyInfo.PropertyType.IsEquivalentTo(typeof(System.Windows.Media.Color)))
{
var arraylist = value as System.Collections.ArrayList;
propertyInfo.SetValue(instance,
System.Windows.Media.Color.FromArgb(
(byte)(255 * Convert.ToDouble(arraylist.Count < 4 ? 0 : arraylist[3], System.Globalization.CultureInfo.InvariantCulture)),
(byte)(255 * Convert.ToDouble(arraylist.Count < 1 ? 0 : arraylist[0], System.Globalization.CultureInfo.InvariantCulture)),
(byte)(255 * Convert.ToDouble(arraylist.Count < 2 ? 0 : arraylist[1], System.Globalization.CultureInfo.InvariantCulture)),
(byte)(255 * Convert.ToDouble(arraylist.Count < 3 ? 0 : arraylist[2], System.Globalization.CultureInfo.InvariantCulture))
),
null);
}
else if (propertyInfo.PropertyType.IsEnum)
{
propertyInfo.SetValue(instance, Convert.ToInt32(value, System.Globalization.CultureInfo.InvariantCulture), null);
}
else if (value is string s)
{
if (propertyInfo.PropertyType.IsEquivalentTo(typeof(string)))
{
switch (armaNameAttribute.Title)
{
case "x":
case "w":
propertyInfo.SetValue(instance, this.CanvasManager.Width * (double)resval, null);
break;
case "y":
case "h":
propertyInfo.SetValue(instance, this.CanvasManager.Height * (double)resval, null);
break;
}
continue;
propertyInfo.SetValue(instance, Convert.ChangeType(s.Trim('"'), propertyInfo.PropertyType, System.Globalization.CultureInfo.InvariantCulture), null);
}
else
{
propertyInfo.SetValue(instance, resval, null);
var res = vm.Evaluate(s);
var resval = Convert.ChangeType(res.Data.Trim('"'), propertyInfo.PropertyType, System.Globalization.CultureInfo.InvariantCulture);
if (new string[] { "x", "y", "w", "h" }.Contains(armaNameAttribute.Title))
{
switch (armaNameAttribute.Title)
{
case "x":
case "w":
propertyInfo.SetValue(instance, this.CanvasManager.Width * (double)resval, null);
break;
case "y":
case "h":
propertyInfo.SetValue(instance, this.CanvasManager.Height * (double)resval, null);
break;
}
continue;
}
else
{
propertyInfo.SetValue(instance, resval, null);
}
}
}
else
{
propertyInfo.SetValue(instance, Convert.ChangeType(value, propertyInfo.PropertyType, System.Globalization.CultureInfo.InvariantCulture), null);
}
}
else
{
propertyInfo.SetValue(instance, Convert.ChangeType(value, propertyInfo.PropertyType, System.Globalization.CultureInfo.InvariantCulture), null);
}
return instance;
}
catch
{ // Any conversion exception is a load-fail, return null.
return null;
}
return instance;
}

private void ClrVirtualmachine_OnLog(object sender, SqfVm.LogEventArgs eventArgs)
Expand Down

0 comments on commit ee6a4b9

Please sign in to comment.