Skip to content

Commit 63ca3c7

Browse files
committed
Added Max-, MinValue & StepSize to PropertyAttribute
1 parent 4622c7c commit 63ca3c7

File tree

9 files changed

+135
-31
lines changed

9 files changed

+135
-31
lines changed

Arma.Studio.Data/ArmA.Studio.Data.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@
178178
<Compile Include="UI\EditorInfoDrawingBrush.cs" />
179179
<Compile Include="UI\EditorInfoIcon.cs" />
180180
<Compile Include="UI\RelayDataTemplateSelector.cs" />
181+
<Compile Include="Utility.cs" />
181182
</ItemGroup>
182183
<ItemGroup>
183184
<Content Include="TypeExtensions.tt">

Arma.Studio.Data/UI/PropertyAttribute.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,32 @@ public class PropertyAttribute : Attribute
3232
/// </summary>
3333
public object Default { get; set; }
3434

35+
/// <summary>
36+
/// UI-Configuration.
37+
/// The Minimum value the property is supposed to have.
38+
/// </summary>
39+
public double MinValue { get; set; }
40+
/// <summary>
41+
/// UI-Configuration.
42+
/// The Maximum value the property is supposed to have.
43+
/// </summary>
44+
public double MaxValue { get; set; }
45+
/// <summary>
46+
/// UI-Configuration.
47+
/// Stepsize for numeric up-down.
48+
/// </summary>
49+
public double Stepsize { get; set; }
50+
3551
public PropertyAttribute(string title)
3652
{
3753
this.Title = title;
3854
this.Display = true;
3955
this.Description = string.Empty;
4056
this.Group = null;
4157
this.Default = null;
58+
this.MinValue = double.MinValue;
59+
this.MaxValue = double.MaxValue;
60+
this.Stepsize = 1;
4261
}
4362
}
4463
}

Arma.Studio.PropertiesWindow/PropertyContainers/PropertyContainerBase.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ public object Value
2626
}
2727
}
2828

29+
/// <summary>
30+
/// UI-Configuration.
31+
/// The Minimum value the property is supposed to have.
32+
/// </summary>
33+
public double MinValue { get; set; }
34+
/// <summary>
35+
/// UI-Configuration.
36+
/// The Maximum value the property is supposed to have.
37+
/// </summary>
38+
public double MaxValue { get; set; }
39+
/// <summary>
40+
/// UI-Configuration.
41+
/// Stepsize for numeric up-down.
42+
/// </summary>
43+
public double Stepsize { get; set; }
44+
2945
public string Title { get; }
3046
public string ToolTip { get; }
3147
public PropertyContainerBase(string title, string tooltip, object data, string propertyName, Func<object, object> getFunc, Action<object, object> setFunc)

Arma.Studio.PropertiesWindow/PropertyContainers/PropertyContainerColor.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ public static PropertyContainerColor Create(object data, PropertyInfo propertyIn
2727
{
2828
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
2929
}
30-
return new PropertyContainerColor(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Color)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
30+
var container = new PropertyContainerColor(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Color)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
31+
container.Stepsize = attribute.Stepsize;
32+
container.MinValue = attribute.MinValue;
33+
container.MaxValue = attribute.MaxValue;
34+
return container;
3135
}
3236
}
3337
}

Arma.Studio.PropertiesWindow/PropertyContainers/PropertyContainerEnum.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,18 @@ public static PropertyContainerEnum Create(object data, PropertyInfo propertyInf
4545
}
4646

4747
var enumValues = Enum.GetValues(propertyInfo.PropertyType);
48-
return new PropertyContainerEnum(
48+
var container = new PropertyContainerEnum(
4949
attribute.Title,
5050
attribute.Description,
5151
data,
5252
propertyInfo.Name,
5353
enumValues.Cast<object>().Select((it) => new EnumValue(it, Studio.Data.UI.Converters.EnumNameConverter.Instance.Convert(propertyInfo.PropertyType, it))),
5454
(obj) => propertyInfo.GetValue(obj, null),
5555
(obj, val) => propertyInfo.SetValue(obj, val, null));
56+
container.Stepsize = attribute.Stepsize;
57+
container.MinValue = attribute.MinValue;
58+
container.MaxValue = attribute.MaxValue;
59+
return container;
5660
}
5761
}
5862
}

Arma.Studio.PropertiesWindow/PropertyContainers/PropertyContainerPrimitive.cs

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ public static PropertyContainerByte Create(object data, PropertyInfo propertyInf
2020
{
2121
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
2222
}
23-
return new PropertyContainerByte(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Byte)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
23+
var container = new PropertyContainerByte(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Byte)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
24+
container.Stepsize = attribute.Stepsize;
25+
container.MinValue = attribute.MinValue;
26+
container.MaxValue = attribute.MaxValue;
27+
return container;
2428
}
2529
}
2630
public class PropertyContainerSByte : PropertyContainerBase
@@ -41,7 +45,11 @@ public static PropertyContainerSByte Create(object data, PropertyInfo propertyIn
4145
{
4246
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
4347
}
44-
return new PropertyContainerSByte(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (SByte)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
48+
var container = new PropertyContainerSByte(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (SByte)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
49+
container.Stepsize = attribute.Stepsize;
50+
container.MinValue = attribute.MinValue;
51+
container.MaxValue = attribute.MaxValue;
52+
return container;
4553
}
4654
}
4755
public class PropertyContainerInt32 : PropertyContainerBase
@@ -62,7 +70,11 @@ public static PropertyContainerInt32 Create(object data, PropertyInfo propertyIn
6270
{
6371
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
6472
}
65-
return new PropertyContainerInt32(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Int32)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
73+
var container = new PropertyContainerInt32(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Int32)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
74+
container.Stepsize = attribute.Stepsize;
75+
container.MinValue = attribute.MinValue;
76+
container.MaxValue = attribute.MaxValue;
77+
return container;
6678
}
6779
}
6880
public class PropertyContainerUInt32 : PropertyContainerBase
@@ -83,7 +95,11 @@ public static PropertyContainerUInt32 Create(object data, PropertyInfo propertyI
8395
{
8496
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
8597
}
86-
return new PropertyContainerUInt32(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (UInt32)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
98+
var container = new PropertyContainerUInt32(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (UInt32)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
99+
container.Stepsize = attribute.Stepsize;
100+
container.MinValue = attribute.MinValue;
101+
container.MaxValue = attribute.MaxValue;
102+
return container;
87103
}
88104
}
89105
public class PropertyContainerInt16 : PropertyContainerBase
@@ -104,7 +120,11 @@ public static PropertyContainerInt16 Create(object data, PropertyInfo propertyIn
104120
{
105121
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
106122
}
107-
return new PropertyContainerInt16(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Int16)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
123+
var container = new PropertyContainerInt16(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Int16)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
124+
container.Stepsize = attribute.Stepsize;
125+
container.MinValue = attribute.MinValue;
126+
container.MaxValue = attribute.MaxValue;
127+
return container;
108128
}
109129
}
110130
public class PropertyContainerUInt16 : PropertyContainerBase
@@ -125,7 +145,11 @@ public static PropertyContainerUInt16 Create(object data, PropertyInfo propertyI
125145
{
126146
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
127147
}
128-
return new PropertyContainerUInt16(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (UInt16)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
148+
var container = new PropertyContainerUInt16(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (UInt16)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
149+
container.Stepsize = attribute.Stepsize;
150+
container.MinValue = attribute.MinValue;
151+
container.MaxValue = attribute.MaxValue;
152+
return container;
129153
}
130154
}
131155
public class PropertyContainerInt64 : PropertyContainerBase
@@ -146,7 +170,11 @@ public static PropertyContainerInt64 Create(object data, PropertyInfo propertyIn
146170
{
147171
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
148172
}
149-
return new PropertyContainerInt64(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Int64)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
173+
var container = new PropertyContainerInt64(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Int64)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
174+
container.Stepsize = attribute.Stepsize;
175+
container.MinValue = attribute.MinValue;
176+
container.MaxValue = attribute.MaxValue;
177+
return container;
150178
}
151179
}
152180
public class PropertyContainerUInt64 : PropertyContainerBase
@@ -167,7 +195,11 @@ public static PropertyContainerUInt64 Create(object data, PropertyInfo propertyI
167195
{
168196
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
169197
}
170-
return new PropertyContainerUInt64(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (UInt64)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
198+
var container = new PropertyContainerUInt64(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (UInt64)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
199+
container.Stepsize = attribute.Stepsize;
200+
container.MinValue = attribute.MinValue;
201+
container.MaxValue = attribute.MaxValue;
202+
return container;
171203
}
172204
}
173205
public class PropertyContainerSingle : PropertyContainerBase
@@ -188,7 +220,11 @@ public static PropertyContainerSingle Create(object data, PropertyInfo propertyI
188220
{
189221
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
190222
}
191-
return new PropertyContainerSingle(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Single)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
223+
var container = new PropertyContainerSingle(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Single)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
224+
container.Stepsize = attribute.Stepsize;
225+
container.MinValue = attribute.MinValue;
226+
container.MaxValue = attribute.MaxValue;
227+
return container;
192228
}
193229
}
194230
public class PropertyContainerDouble : PropertyContainerBase
@@ -209,7 +245,11 @@ public static PropertyContainerDouble Create(object data, PropertyInfo propertyI
209245
{
210246
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
211247
}
212-
return new PropertyContainerDouble(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Double)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
248+
var container = new PropertyContainerDouble(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Double)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
249+
container.Stepsize = attribute.Stepsize;
250+
container.MinValue = attribute.MinValue;
251+
container.MaxValue = attribute.MaxValue;
252+
return container;
213253
}
214254
}
215255
public class PropertyContainerChar : PropertyContainerBase
@@ -230,7 +270,11 @@ public static PropertyContainerChar Create(object data, PropertyInfo propertyInf
230270
{
231271
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
232272
}
233-
return new PropertyContainerChar(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Char)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
273+
var container = new PropertyContainerChar(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Char)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
274+
container.Stepsize = attribute.Stepsize;
275+
container.MinValue = attribute.MinValue;
276+
container.MaxValue = attribute.MaxValue;
277+
return container;
234278
}
235279
}
236280
public class PropertyContainerBoolean : PropertyContainerBase
@@ -251,7 +295,11 @@ public static PropertyContainerBoolean Create(object data, PropertyInfo property
251295
{
252296
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
253297
}
254-
return new PropertyContainerBoolean(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Boolean)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
298+
var container = new PropertyContainerBoolean(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Boolean)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
299+
container.Stepsize = attribute.Stepsize;
300+
container.MinValue = attribute.MinValue;
301+
container.MaxValue = attribute.MaxValue;
302+
return container;
255303
}
256304
}
257305
public class PropertyContainerString : PropertyContainerBase
@@ -272,7 +320,11 @@ public static PropertyContainerString Create(object data, PropertyInfo propertyI
272320
{
273321
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
274322
}
275-
return new PropertyContainerString(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (String)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
323+
var container = new PropertyContainerString(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (String)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
324+
container.Stepsize = attribute.Stepsize;
325+
container.MinValue = attribute.MinValue;
326+
container.MaxValue = attribute.MaxValue;
327+
return container;
276328
}
277329
}
278330
public class PropertyContainerDecimal : PropertyContainerBase
@@ -293,7 +345,11 @@ public static PropertyContainerDecimal Create(object data, PropertyInfo property
293345
{
294346
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
295347
}
296-
return new PropertyContainerDecimal(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Decimal)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
348+
var container = new PropertyContainerDecimal(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (Decimal)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
349+
container.Stepsize = attribute.Stepsize;
350+
container.MinValue = attribute.MinValue;
351+
container.MaxValue = attribute.MaxValue;
352+
return container;
297353
}
298354
}
299355
}

Arma.Studio.PropertiesWindow/PropertyContainers/PropertyContainerPrimitive.tt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ namespace Arma.Studio.PropertiesWindow.PropertyContainers
4343
{
4444
throw new ArgumentException("Missing Arma.Studio.Data.UI.PropertyAttribute.", nameof(propertyInfo));
4545
}
46-
return new PropertyContainer<#= type.Name #>(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (<#= type.Name #>)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
46+
var container = new PropertyContainer<#= type.Name #>(attribute.Title, attribute.Description, data, propertyInfo.Name, (obj) => (<#= type.Name #>)propertyInfo.GetValue(obj, null), (obj, val) => propertyInfo.SetValue(obj, val, null));
47+
container.Stepsize = attribute.Stepsize;
48+
container.MinValue = attribute.MinValue;
49+
container.MaxValue = attribute.MaxValue;
50+
return container;
4751
}
4852
}
4953
<# } #>

0 commit comments

Comments
 (0)