Esempio n. 1
0
        protected ModSettingsBase()
        {
            fields          = GetType().GetFields(BindingFlags.Instance | BindingFlags.Public);
            confirmedValues = new Dictionary <FieldInfo, object>(fields.Length);
            refreshActions  = new List <Action>();

            menuVisibility = new Visibility();
            menuVisibility.SetVisible(false);
            menuVisibility.AddVisibilityListener((visible) => {
                // Reset public fields to last confirmed values when leaving settings menu
                if (visible)
                {
                    foreach (FieldInfo field in fields)
                    {
                        confirmedValues[field] = field.GetValue(this);
                    }
                    RefreshGUI();
                }
                else
                {
                    foreach (FieldInfo field in fields)
                    {
                        field.SetValue(this, confirmedValues[field]);
                    }
                }
            });

            visibility        = new Visibility(menuVisibility);
            fieldVisibilities = new Dictionary <FieldInfo, Visibility>(fields.Length);
            foreach (FieldInfo field in fields)
            {
                fieldVisibilities.Add(field, new Visibility(visibility));
            }

            Attributes.ValidateFields(this);
        }