Terraria ModLoader  0.11.1
A framework for Terraria mods
ConfigAttributes.cs
Go to the documentation of this file.
1 using Microsoft.Xna.Framework;
2 using System;
3 
4 namespace Terraria.ModLoader.Config
5 {
9  [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Class)]
11  {
12  public Color color;
13  public BackgroundColorAttribute(int r, int g, int b, int a = 255)
14  {
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)]
44  public class LabelAttribute : Attribute
45  {
46  readonly string label;
47  public LabelAttribute(string label)
48  {
49  this.label = label;
50  }
51  public string Label => label.StartsWith("$") ? Localization.Language.GetTextValue(label.Substring(1)) : label;
52  }
53 
54  // [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
55  // public class StringRepresentationAttribute : Attribute
56  // TODO
57 
62  [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
63  public class TooltipAttribute : Attribute
64  {
65  readonly string tooltip;
66  public TooltipAttribute(string tooltip)
67  {
68  this.tooltip = tooltip;
69  }
70  public string Tooltip => tooltip.StartsWith("$") ? Localization.Language.GetTextValue(tooltip.Substring(1)) : tooltip;
71  }
72 
77  [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
78  public class HeaderAttribute : Attribute
79  {
80  readonly string header;
81  public HeaderAttribute(string header) {
82  this.header = header;
83  }
84  public string Header => header.StartsWith("$") ? Localization.Language.GetTextValue(header.Substring(1)) : header;
85  }
86 
90  [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Class | AttributeTargets.Enum)]
92  {
93  public Type t;
95  {
96  this.t = t;
97  }
98  }
99 
103  [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
105  {
106  public object defaultValue;
107  public DefaultListValueAttribute(int defaultValue)
108  {
109  this.defaultValue = defaultValue;
110  }
111 
112  public DefaultListValueAttribute(float defaultValue)
113  {
114  this.defaultValue = defaultValue;
115  }
116 
117  public DefaultListValueAttribute(object defaultValue)
118  {
119  this.defaultValue = defaultValue;
120  }
121  }
122 
126  [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
128  {
129  public string[] optionLabels { get; set; }
130  public OptionStringsAttribute(string[] optionLabels)
131  {
132  this.optionLabels = optionLabels;
133  }
134  }
135 
140  [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
142  {
143  public object increment;
144  public IncrementAttribute(int increment)
145  {
146  this.increment = increment;
147  }
148  public IncrementAttribute(float increment)
149  {
150  this.increment = increment;
151  }
152  public IncrementAttribute(uint increment)
153  {
154  this.increment = increment;
155  }
156  public IncrementAttribute(byte increment)
157  {
158  this.increment = increment;
159  }
160  }
161 
165  [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
166  public class RangeAttribute : Attribute
167  {
168  public object min;
169  public object max;
170 
171  public RangeAttribute(int min, int max)
172  {
173  this.min = min;
174  this.max = max;
175  }
176 
177  public RangeAttribute(float min, float max)
178  {
179  this.min = min;
180  this.max = max;
181  }
182  public RangeAttribute(uint min, uint max)
183  {
184  this.min = min;
185  this.max = max;
186  }
187  public RangeAttribute(byte min, byte max)
188  {
189  this.min = min;
190  this.max = max;
191  }
192  }
193 
197  [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
199  {
200  }
201 
205  [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Class)]
207  {
208  }
209 
210  // Unimplemented below:
211 
212  // Hide or Disable this item while in game.
213  //[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
214  //public class HideInGameAttribute : Attribute { }
215 
216  // Hide or Disable this item while a client?
217  //[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
218  //public class HideForClientAttribute : Attribute { }
219 
220  //public class JsonDefaultValueAttribute : Attribute
221  //{
222  // public string json;
223  // public JsonDefaultValueAttribute(string json)
224  // {
225  // this.json = json;
226  // }
227  //}
228 
229  // Problem: shared reference.
230  //public class JsonDefaultValueAttribute : DefaultValueAttribute
231  //{
232  // public string json;
233  // public JsonDefaultValueAttribute(string json, Type type) : base(ConvertFromJson(json, type))
234  // {
235  // this.json = json;
236  // }
237 
238  // private static object ConvertFromJson(string json, Type type)
239  // {
240  // //var value = Activator.CreateInstance(type);
241  // //JsonConvert.PopulateObject(json, value, ConfigManager.serializerSettings);
242  // //return value;
243  // var value = JsonConvert.DeserializeObject(json, type, new JsonSerializerSettings
244  // {
245  // //MissingMemberHandling = MissingMemberHandling.Error,
246  // //NullValueHandling = NullValueHandling.Include,
247  // //DefaultValueHandling = DefaultValueHandling.Populate
248  // });
249  // return value;
250  // }
251  //}
252 
253  //[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = false, Inherited = true)]
254  //public class StringRepresentationAttribute : Attribute
255  //{
256  // public Func<string> StringRepresentation { get; set; }
257 
258  // public StringRepresentationAttribute(Type delegateType, string delegateName)
259  // {
260  // StringRepresentation = (Func<string>)Delegate.CreateDelegate(delegateType, delegateType.GetMethod(delegateName));
261  // }
262  //}
263 
264  //[StringRepresentation(typeof(TestDelegate), "GetConnection")]
265  //public class Test
266  //{
267  //}
268 
269  //[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
270  //public class StringRepresentationAttribute : Attribute
271  //{
272  // public Func<string> SomeProperty { get; set; }
273  //}
274 }
This attribute adds a label above this property or field in the ModConfig UI that acts as a header...
This attribute hints that changing the value of the annotated property or field will put the config i...
Add this attribute and the sliders will show white tick marks at each increment.
Use this attribute to specify a custom UI element to be used for the annotated property, field, or class in the ModConfig UI.
Defines the default value to be added when using the ModConfig UI to add elements to a List ...
This serves as the central class which loads mods. It contains many static fields and methods related...
Definition: ModLoader.cs:24
Specifies a range for primative data values. Without this, default min and max are as follows: float:...
This attribute sets a hover tooltip for the annotated property or field to be shown in the ModConfig ...
SliderColorAttribute(int r, int g, int b, int a=255)
This specifies that the annotated item will appear as a button that leads to a separate page in the U...
This attribute sets a label for the property, field, or class for use in the ModConfig UI...
Specifies a background color to be used for the property, field, or class in the ModConfig UI...
Specifies a slider color for ModConfig elements that use a slider. The default color is white...
By default, string fields will provide the user with a text input field. Use this attribute to restri...
Use this to set an increment for sliders. The slider will move by the amount assigned. Remember that this is just a UI suggestion and manual editing of config files can specify other values, so validate your values. Defaults are: float: 0.01f - byte/int/uint: 1
BackgroundColorAttribute(int r, int g, int b, int a=255)