예제 #1
0
        private static UITextField AddTextField <T>(this UIHelperBase group, string text, string propertyName, Action <string> action) where T : IModOptions
        {
            var property     = typeof(T).GetProperty(propertyName);
            var initialValue = Convert.ToString(property.GetValue(OptionsWrapper <T> .Options, null));

            return((UITextField)group.AddTextfield(text, initialValue, s => { },
                                                   s =>
            {
                object value;
                if (property.PropertyType == typeof(int))
                {
                    value = Convert.ToInt32(s);
                }
                else if (property.PropertyType == typeof(short))
                {
                    value = Convert.ToInt16(s);
                }
                else if (property.PropertyType == typeof(double))
                {
                    value = Convert.ToDouble(s);
                }
                else if (property.PropertyType == typeof(float))
                {
                    value = Convert.ToSingle(s);
                }
                else
                {
                    value = s;     //TODO: more types
                }
                property.SetValue(OptionsWrapper <T> .Options, value, null);
                OptionsWrapper <T> .SaveOptions();
                action.Invoke(s);
            }));
        }
예제 #2
0
        private static UICheckBox AddCheckbox <T>(this UIHelperBase group, string text, string propertyName, Action <bool> action) where T : IModOptions
        {
            var property = typeof(T).GetProperty(propertyName);

            return((UICheckBox)group.AddCheckbox(text, (bool)property.GetValue(OptionsWrapper <T> .Options, null),
                                                 b =>
            {
                property.SetValue(OptionsWrapper <T> .Options, b, null);
                OptionsWrapper <T> .SaveOptions();
                action.Invoke(b);
            }));
        }