Skip to content

Commit

Permalink
Fixed height and Y not being saved correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
X39 committed Mar 13, 2020
1 parent e3be2ea commit c201abb
Showing 1 changed file with 30 additions and 144 deletions.
174 changes: 30 additions & 144 deletions Arma.Studio.UiEditor/UI/UiEditorDataContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -567,108 +567,34 @@ public Task Save(CancellationToken cancellationToken)
{
int tabstop = 0;
string tabs() { return new string(' ', tabstop * 4); }
stream.Write("class ");
stream.Write(this.ClassName);
stream.WriteLine(" {");
tabstop++;

foreach (var propertyInfo in typeof(UiEditorDataContext).GetProperties())
void WriteOutConfig(Type t, object obj)
{
var armaNameAttributes = Attribute.GetCustomAttributes(propertyInfo, typeof(ArmaNameAttribute), true).Cast<ArmaNameAttribute>().ToArray();
if (!armaNameAttributes.Any() && !new string[] { dlg_controls, dlg_controlsBackground }.Contains(propertyInfo.Name))
{
continue;
}
var armaNameAttribute = armaNameAttributes.First();
stream.Write(tabs());
stream.Write(armaNameAttribute.Title);
var value = propertyInfo.GetValue(this, null);
if (new string[] { "x", "y", "w", "h" }.Contains(armaNameAttribute.Title))
{
switch (armaNameAttribute.Title)
{
case "x":
stream.WriteLine($" = \"safezoneX + ({value} / 1920) * safezoneW\";");
break;
case "y":
stream.WriteLine($" = \"safezoneY + ({value} / 1920) * safezoneH\";");
break;
case "w":
stream.WriteLine($" = \"({value} / 1920) * safezoneW\";");
break;
case "h":
stream.WriteLine($" = \"({value} / 1920) * safezoneH\";");
break;
}
continue;
}
if (propertyInfo.PropertyType.IsEquivalentTo(typeof(string)))
{
stream.Write(" = ");
stream.Write('"');
stream.Write(value);
stream.Write('"');
}
else if (propertyInfo.PropertyType.IsEquivalentTo(typeof(System.Windows.Media.Color)))
{
stream.Write("[] = { ");
var color = (System.Windows.Media.Color)value;
stream.Write(color.R / 255.0);
stream.Write(", ");
stream.Write(color.G / 255.0);
stream.Write(", ");
stream.Write(color.B / 255.0);
stream.Write(", ");
stream.Write(color.A / 255.0);
stream.Write(" }");
}
else if (propertyInfo.PropertyType.IsEnum)
{
stream.Write(" = ");
stream.Write(Convert.ToInt32(value, System.Globalization.CultureInfo.InvariantCulture));
}
else
{
stream.Write(" = ");
stream.Write(value);
}
stream.WriteLine(";");
}

stream.Write(tabs());
stream.WriteLine("class " + dlg_controlsBackground + " {");
tabstop++;
foreach (var control in this.BackgroundControls)
{
stream.Write(tabs());
stream.WriteLine("class " + control.ClassName + " {");
tabstop++;
foreach (var propertyInfo in control.GetType().GetProperties())
foreach (var propertyInfo in t.GetProperties())
{
var armaNameAttributes = Attribute.GetCustomAttributes(propertyInfo, typeof(ArmaNameAttribute), true).Cast<ArmaNameAttribute>().ToArray();
if (!armaNameAttributes.Any())
if (!armaNameAttributes.Any() && !new string[] { dlg_controls, dlg_controlsBackground }.Contains(propertyInfo.Name))
{
continue;
}
var armaNameAttribute = armaNameAttributes.First();
stream.Write(tabs());
stream.Write(armaNameAttribute.Title);
var value = propertyInfo.GetValue(control, null);
var value = propertyInfo.GetValue(obj, null);
if (new string[] { "x", "y", "w", "h" }.Contains(armaNameAttribute.Title))
{
switch (armaNameAttribute.Title)
{
case "x":
stream.WriteLine($" = \"safezoneX + ({value} / 1920) * safezoneW\";");
stream.WriteLine($" = \"safezoneX + ({value} / {this.CanvasManager.Width}) * safezoneW\";");
break;
case "y":
stream.WriteLine($" = \"safezoneY + ({value} / 1920) * safezoneH\";");
stream.WriteLine($" = \"safezoneY + ({value} / {this.CanvasManager.Height}) * safezoneH\";");
break;
case "w":
stream.WriteLine($" = \"({value} / 1920) * safezoneW\";");
stream.WriteLine($" = \"({value} / {this.CanvasManager.Width}) * safezoneW\";");
break;
case "h":
stream.WriteLine($" = \"({value} / 1920) * safezoneH\";");
stream.WriteLine($" = \"({value} / {this.CanvasManager.Height}) * safezoneH\";");
break;
}
continue;
Expand Down Expand Up @@ -705,6 +631,25 @@ public Task Save(CancellationToken cancellationToken)
}
stream.WriteLine(";");
}
}
stream.Write("class ");
stream.Write(this.ClassName);
stream.WriteLine(" {");
tabstop++;

WriteOutConfig(typeof(UiEditorDataContext), this);

stream.Write(tabs());
stream.WriteLine("class " + dlg_controlsBackground + " {");
tabstop++;
foreach (var control in this.BackgroundControls)
{
stream.Write(tabs());
stream.WriteLine("class " + control.ClassName + " {");
tabstop++;

WriteOutConfig(control.GetType(), control);

tabstop--;
stream.Write(tabs());
stream.WriteLine("};");
Expand All @@ -721,68 +666,9 @@ public Task Save(CancellationToken cancellationToken)
stream.Write(tabs());
stream.WriteLine("class " + control.ClassName + " {");
tabstop++;
foreach (var propertyInfo in control.GetType().GetProperties())
{
var armaNameAttributes = Attribute.GetCustomAttributes(propertyInfo, typeof(ArmaNameAttribute), true).Cast<ArmaNameAttribute>().ToArray();
if (!armaNameAttributes.Any())
{
continue;
}
var armaNameAttribute = armaNameAttributes.First();
stream.Write(tabs());
stream.Write(armaNameAttribute.Title);
var value = propertyInfo.GetValue(control, null);
if (new string[] { "x", "y", "w", "h" }.Contains(armaNameAttribute.Title))
{
switch (armaNameAttribute.Title)
{
case "x":
stream.WriteLine($" = \"safezoneX + ({value} / 1920) * safezoneW\";");
break;
case "y":
stream.WriteLine($" = \"safezoneY + ({value} / 1920) * safezoneH\";");
break;
case "w":
stream.WriteLine($" = \"({value} / 1920) * safezoneW\";");
break;
case "h":
stream.WriteLine($" = \"({value} / 1920) * safezoneH\";");
break;
}
continue;
}
if (propertyInfo.PropertyType.IsEquivalentTo(typeof(string)))
{
stream.Write(" = ");
stream.Write('"');
stream.Write(value);
stream.Write('"');
}
else if (propertyInfo.PropertyType.IsEquivalentTo(typeof(System.Windows.Media.Color)))
{
stream.Write("[] = { ");
var color = (System.Windows.Media.Color)value;
stream.Write(color.R / 255.0);
stream.Write(", ");
stream.Write(color.G / 255.0);
stream.Write(", ");
stream.Write(color.B / 255.0);
stream.Write(", ");
stream.Write(color.A / 255.0);
stream.Write(" }");
}
else if (propertyInfo.PropertyType.IsEnum)
{
stream.Write(" = ");
stream.Write(Convert.ToInt32(value, System.Globalization.CultureInfo.InvariantCulture));
}
else
{
stream.Write(" = ");
stream.Write(Convert.ToString(value, System.Globalization.CultureInfo.InvariantCulture));
}
stream.WriteLine(";");
}

WriteOutConfig(control.GetType(), control);

tabstop--;
stream.Write(tabs());
stream.WriteLine("};");
Expand Down

0 comments on commit c201abb

Please sign in to comment.