コード例 #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);
            }));
        }
コード例 #3
0
        private static UIDropDown AddDropdown <T>(this UIHelperBase group, string text, string propertyName, IList <KeyValuePair <string, int> > items, Action <int> action) where T : IModOptions
        {
            var property    = typeof(T).GetProperty(propertyName);
            var defaultCode = (int)property.GetValue(OptionsWrapper <T> .Options, null);
            int defaultSelection;

            try
            {
                defaultSelection = items.First(kvp => kvp.Value == defaultCode).Value;
            } catch {
                defaultSelection = 0;
                property.SetValue(OptionsWrapper <T> .Options, items.First().Value, null);
            }
            return((UIDropDown)group.AddDropdown(text, items.Select(kvp => kvp.Key).ToArray(), defaultSelection, sel =>
            {
                var code = items[sel].Value;
                property.SetValue(OptionsWrapper <T> .Options, code, null);
                OptionsWrapper <T> .SaveOptions();
                action.Invoke(code);
            }));
        }