tModLoader v0.11.8.9
A mod to make and play Terraria mods
ConfigAttributes.cs
Go to the documentation of this file.
1using Microsoft.Xna.Framework;
2using System;
3using System.ComponentModel;
4
6{
10 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Class)]
12 {
13 public Color color;
14 public BackgroundColorAttribute(int r, int g, int b, int a = 255) {
15 this.color = new Color(r, g, b, a);
16 }
17 }
18
22 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Class)]
24 {
25 public Color color;
26 public SliderColorAttribute(int r, int g, int b, int a = 255) {
27 this.color = new Color(r, g, b, a);
28 }
29 }
30
34 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
36 {
37 }
38
43 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Class)]
45 {
46 readonly string label;
47 public LabelAttribute(string label) {
48 this.label = label;
49 }
50 public string Label => label.StartsWith("$") ? Localization.Language.GetTextValue(label.Substring(1)) : label;
51 }
52
57 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
59 {
60 readonly string tooltip;
61 public TooltipAttribute(string tooltip) {
62 this.tooltip = tooltip;
63 }
64 public string Tooltip => tooltip.StartsWith("$") ? Localization.Language.GetTextValue(tooltip.Substring(1)) : tooltip;
65 }
66
71 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
73 {
74 readonly string header;
75 public HeaderAttribute(string header) {
76 this.header = header;
77 }
78 public string Header => header.StartsWith("$") ? Localization.Language.GetTextValue(header.Substring(1)) : header;
79 }
80
84 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Class | AttributeTargets.Enum)]
86 {
87 public Type t;
89 this.t = t;
90 }
91 }
92
97 {
98 public string json;
100 this.json = json;
101 }
102 }
103
107 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
109 {
110 private object value;
111 public DefaultListValueAttribute(Type type, string value) {
112 try {
113 this.value = TypeDescriptor.GetConverter(type).ConvertFromInvariantString(value);
114 }
115 catch {
116 Logging.tML.Error("Default value attribute of type " + type.FullName + " threw converting from the string '" + value + "'.");
117 }
118 }
119
120 public DefaultListValueAttribute(char value) => this.value = value;
121 public DefaultListValueAttribute(byte value) => this.value = value;
122 public DefaultListValueAttribute(short value) => this.value = value;
123 public DefaultListValueAttribute(int value) => this.value = value;
124 public DefaultListValueAttribute(long value) => this.value = value;
125 public DefaultListValueAttribute(float value) => this.value = value;
126 public DefaultListValueAttribute(double value) => this.value = value;
127 public DefaultListValueAttribute(bool value) => this.value = value;
128 public DefaultListValueAttribute(string value) => this.value = value;
129 public DefaultListValueAttribute(object value) => this.value = value;
130
131 public virtual object Value => value;
132
133 public override bool Equals(object obj) {
134 if (obj == this) {
135 return true;
136 }
137 var other = obj as DefaultListValueAttribute;
138 if (other != null) {
139 if (Value != null) {
140 return Value.Equals(other.Value);
141 }
142 else {
143 return (other.Value == null);
144 }
145 }
146 return false;
147 }
148
149 public override int GetHashCode() => base.GetHashCode();
150
151 protected void SetValue(object value) {
152 this.value = value;
153 }
154 }
155
159 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
161 {
162 private object value;
163 public DefaultDictionaryKeyValueAttribute(Type type, string value) {
164 try {
165 this.value = TypeDescriptor.GetConverter(type).ConvertFromInvariantString(value);
166 }
167 catch {
168 Logging.tML.Error("Default value attribute of type " + type.FullName + " threw converting from the string '" + value + "'.");
169 }
170 }
171
172 public DefaultDictionaryKeyValueAttribute(char value) => this.value = value;
173 public DefaultDictionaryKeyValueAttribute(byte value) => this.value = value;
174 public DefaultDictionaryKeyValueAttribute(short value) => this.value = value;
175 public DefaultDictionaryKeyValueAttribute(int value) => this.value = value;
176 public DefaultDictionaryKeyValueAttribute(long value) => this.value = value;
177 public DefaultDictionaryKeyValueAttribute(float value) => this.value = value;
178 public DefaultDictionaryKeyValueAttribute(double value) => this.value = value;
179 public DefaultDictionaryKeyValueAttribute(bool value) => this.value = value;
180 public DefaultDictionaryKeyValueAttribute(string value) => this.value = value;
181 public DefaultDictionaryKeyValueAttribute(object value) => this.value = value;
182
183 public virtual object Value => value;
184
185 public override bool Equals(object obj) {
186 if (obj == this) {
187 return true;
188 }
189 var other = obj as DefaultDictionaryKeyValueAttribute;
190 if (other != null) {
191 if (Value != null) {
192 return Value.Equals(other.Value);
193 }
194 else {
195 return (other.Value == null);
196 }
197 }
198 return false;
199 }
200
201 public override int GetHashCode() => base.GetHashCode();
202
203 protected void SetValue(object value) {
204 this.value = value;
205 }
206 }
207
211 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
213 {
214 public string json;
216 this.json = json;
217 }
218 }
219
220 /* TODO: Implement this
221 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
222 public class CustomAddMethodAttribute : Attribute
223 {
224 public string methodName;
225 public CustomAddMethodAttribute(string methodName) {
226 this.methodName = methodName;
227 }
228 }
229 */
230
234 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
236 {
237 public string json;
239 this.json = json;
240 }
241 }
242
246 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
248 {
249 public string[] optionLabels { get; set; }
251 this.optionLabels = optionLabels;
252 }
253 }
254
259 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
261 {
262 public object increment;
264 this.increment = increment;
265 }
267 this.increment = increment;
268 }
270 this.increment = increment;
271 }
273 this.increment = increment;
274 }
275 }
276
280 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
282 {
283 public object min;
284 public object max;
285
286 public RangeAttribute(int min, int max) {
287 this.min = min;
288 this.max = max;
289 }
290
291 public RangeAttribute(float min, float max) {
292 this.min = min;
293 this.max = max;
294 }
295 public RangeAttribute(uint min, uint max) {
296 this.min = min;
297 this.max = max;
298 }
299 public RangeAttribute(byte min, byte max) {
300 this.min = min;
301 this.max = max;
302 }
303 }
304
308 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
310 {
311 }
312
316 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
318 {
319 }
320
324 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
326 {
327 }
328
332 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
334 {
337 this.showSaturationAndLightness = showSaturationAndLightness;
338 }
339 }
340
344 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Class)]
346 {
347 }
348
352 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Class)]
354 {
355 }
356
357 // Unimplemented ideas below:
358
359 // Hide or Disable this item while in game.
360 //[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
361 //public class HideInGameAttribute : Attribute { }
362
363 // Hide or Disable this item while a client?
364 //[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
365 //public class HideForClientAttribute : Attribute { }
366
367 //[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = false, Inherited = true)]
368 //public class StringRepresentationAttribute : Attribute
369 //{
370 // public Func<string> StringRepresentation { get; set; }
371
372 // public StringRepresentationAttribute(Type delegateType, string delegateName)
373 // {
374 // StringRepresentation = (Func<string>)Delegate.CreateDelegate(delegateType, delegateType.GetMethod(delegateName));
375 // }
376 //}
377
378 //[StringRepresentation(typeof(TestDelegate), "GetConnection")]
379 //public class Test
380 //{
381 //}
382
383 //[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
384 //public class StringRepresentationAttribute : Attribute
385 //{
386 // public Func<string> SomeProperty { get; set; }
387 //}
388}
Specifies a background color to be used for the property, field, or class in the ModConfig UI.
BackgroundColorAttribute(int r, int g, int b, int a=255)
Add this attribute to a Color item and the UI will present a Hue, Saturation, and Lightness sliders r...
ColorHSLSliderAttribute(bool showSaturationAndLightness=true)
Add this attribute to a Color item and Alpha will not be presented in the UI and will remain as 255 u...
Use this attribute to specify a custom UI element to be used for the annotated property,...
Defines the default key value to be added when using the ModConfig UI to add elements to a Dictionary...
Defines the default value to be added when using the ModConfig UI to add elements to a Collection (Li...
Add this attribute and the sliders will show white tick marks at each increment.
This attribute adds a label above this property or field in the ModConfig UI that acts as a header....
Use this to set an increment for sliders. The slider will move by the amount assigned....
Similar to JsonDefaultListValueAttribute, but for assigning to the Dictionary Key rather than the Val...
Similar to DefaultListValueAttribute but for reference types. It uses a json string that will be used...
Similar to DefaultValueAttribute but for reference types. It uses a json string that will be used pop...
This attribute sets a label for the property, field, or class for use in the ModConfig UI....
This attribute means the annotated item can possibly be null. This will allow the UI to make the item...
By default, string fields will provide the user with a text input field. Use this attribute to restri...
Specifies a range for primitive data values. Without this, default min and max are as follows: float:...
This attribute hints that changing the value of the annotated property or field will put the config i...
This specifies that the annotated item will appear as a button that leads to a separate page in the U...
Affects whether this data will be presented as a slider of an input field. Add this attribute to use ...
Specifies a slider color for ModConfig elements that use a slider. The default color is white.
SliderColorAttribute(int r, int g, int b, int a=255)
This attribute sets a hover tooltip for the annotated property or field to be shown in the ModConfig ...