public CompositeOptionsEntry(string field, IOptionSpec spec, Type fieldType) : base(field, spec) { subOptions = new Dictionary <PropertyInfo, IOptionsEntry>(16); targetType = fieldType ?? throw new ArgumentNullException(nameof(fieldType)); value = OptionsDialog.CreateOptions(fieldType); }
protected OptionsEntry(string field, IOptionSpec attr) { if (attr == null) { throw new ArgumentNullException(nameof(attr)); } Field = field; Format = attr.Format; Title = attr.Title ?? throw new ArgumentException("attr.Title is null"); Tooltip = attr.Tooltip; Category = attr.Category; }
/// <summary> /// Creates an options entry wrapper for the specified property. /// </summary> /// <param name="info">The property to wrap.</param> /// <param name="spec">The option title and tool tip.</param> /// <returns>An options wrapper, or null if none can handle this type.</returns> private static OptionsEntry FindOptionClass(IOptionSpec spec, PropertyInfo info) { OptionsEntry entry = null; Type type = info.PropertyType; string field = info.Name; // Enumeration type if (type.IsEnum) { entry = new SelectOneOptionsEntry(field, spec, type); } else if (type == typeof(bool)) { entry = new CheckboxOptionsEntry(field, spec); } else if (type == typeof(int)) { entry = new IntOptionsEntry(field, spec, info. GetCustomAttribute <LimitAttribute>()); } else if (type == typeof(int?)) { entry = new NullableIntOptionsEntry(field, spec, info. GetCustomAttribute <LimitAttribute>()); } else if (type == typeof(float)) { entry = new FloatOptionsEntry(field, spec, info. GetCustomAttribute <LimitAttribute>()); } else if (type == typeof(float?)) { entry = new NullableFloatOptionsEntry(field, spec, info. GetCustomAttribute <LimitAttribute>()); } else if (type == typeof(string)) { entry = new StringOptionsEntry(field, spec, info. GetCustomAttribute <LimitAttribute>()); } else if (type == typeof(Action <object>)) { // Should not actually be serialized to the JSON entry = new ButtonOptionsEntry(field, spec); } else if (type == typeof(LocText)) { entry = new TextBlockOptionsEntry(field, spec); } return(entry); }
public StringOptionsEntry(string field, IOptionSpec spec, LimitAttribute limit = null) : base(field, spec) { // Use the maximum limit value for the max length, if present if (limit != null) { maxLength = Math.Max(2, (int)Math.Round(limit.Maximum)); } else { maxLength = 256; } textField = null; value = ""; }
/// <summary> /// Substitutes default strings for an options entry with an empty title. /// </summary> /// <param name="spec">The option attribute supplied (Format is still accepted!)</param> /// <param name="member">The item declaring the attribute.</param> /// <returns>A substitute attribute with default values from STRINGS.</returns> internal static IOptionSpec HandleDefaults(IOptionSpec spec, MemberInfo member) { // Replace with entries takem from the strings string prefix = "STRINGS.{0}.OPTIONS.{1}.".F(member.DeclaringType?. Namespace?.ToUpperInvariant(), member.Name?.ToUpperInvariant()); string category = ""; if (Strings.TryGet(prefix + "CATEGORY", out StringEntry entry)) { category = entry.String; } return(new OptionAttribute(prefix + "NAME", prefix + "TOOLTIP", category) { Format = spec.Format }); }
/// <summary> /// Creates an options entry wrapper for the specified property, iterating its internal /// fields to create sub-options if needed (recursively). /// </summary> /// <param name="info">The property to wrap.</param> /// <param name="spec">The option title and tool tip.</param> /// <param name="depth">The current depth of iteration to avoid infinite loops.</param> /// <returns>An options wrapper, or null if no inner properties are themselves options.</returns> internal static CompositeOptionsEntry Create(IOptionSpec spec, PropertyInfo info, int depth) { var type = info.PropertyType; var composite = new CompositeOptionsEntry(info.Name, spec, type); // Skip static properties if they exist foreach (var prop in type.GetProperties(BindingFlags.Public | BindingFlags. Instance)) { var entry = TryCreateEntry(prop, depth + 1); if (entry != null) { composite.AddField(prop, entry); } } return(composite.ChildCount > 0 ? composite : null); }
public SelectOneOptionsEntry(string field, IOptionSpec spec, Type fieldType) : base(field, spec) { var eval = Enum.GetValues(fieldType); if (eval == null) { throw new ArgumentException("No values, or invalid values, for enum"); } int n = eval.Length; if (n == 0) { throw new ArgumentException("Enum has no declared members"); } chosen = null; comboBox = null; options = new List <EnumOption>(n); for (int i = 0; i < n; i++) { options.Add(GetAttribute(eval.GetValue(i), fieldType)); } }
public NullableFloatOptionsEntry(string field, IOptionSpec spec, LimitAttribute limit = null) : base(field, spec, limit) { textField = null; value = null; }
public TextBlockOptionsEntry(string field, IOptionSpec spec) : base(field, spec) { }
public CheckboxOptionsEntry(string field, IOptionSpec spec) : base(field, spec) { check = false; checkbox = null; }
protected SlidingBaseOptionsEntry(string field, IOptionSpec spec, LimitAttribute limit = null) : base(field, spec) { limits = limit; slider = null; }
public ButtonOptionsEntry(string field, IOptionSpec spec) : base(field, spec) { }