Ejemplo n.º 1
0
        public override void OnActivate()
        {
            filterTextField.SetText("");
            updateNeeded = false;
            SetMessage("", Color.White);
            string configDisplayName = ((LabelAttribute)Attribute.GetCustomAttribute(modConfig.GetType(), typeof(LabelAttribute)))?.Label ?? modConfig.Name;

            headerTextPanel.SetText(string.IsNullOrEmpty(configDisplayName) ? modConfig.mod.DisplayName : modConfig.mod.DisplayName + ": " + configDisplayName);
            pendingConfig  = ConfigManager.GeneratePopulatedClone(modConfig);
            pendingChanges = pendingRevertDefaults;
            if (pendingRevertDefaults)
            {
                pendingRevertDefaults = false;
                ConfigManager.Reset(pendingConfig);
                pendingChangesUIUpdate = true;
            }

            int index = modConfigs.IndexOf(modConfig);
            int count = modConfigs.Count;

            //pendingChanges = false;
            backButton.BackgroundColor = UICommon.DefaultUIBlueMouseOver;
            uIElement.RemoveChild(saveConfigButton);
            uIElement.RemoveChild(revertConfigButton);
            uIElement.RemoveChild(previousConfigButton);
            uIElement.RemoveChild(nextConfigButton);
            if (index + 1 < count)
            {
                uIElement.Append(nextConfigButton);
            }
            if (index - 1 >= 0)
            {
                uIElement.Append(previousConfigButton);
            }

            uIElement.RemoveChild(configPanelStack.Peek());
            uIElement.Append(uIPanel);
            mainConfigItems.Clear();
            mainConfigList.Clear();
            configPanelStack.Clear();
            configPanelStack.Push(uIPanel);
            subPageStack.Clear();
            //currentConfigList = mainConfigList;
            int top = 0;

            // load all mod config options into UIList
            // TODO: Inheritance with ModConfig? DeclaredOnly?

            uIPanel.BackgroundColor = UICommon.MainPanelBackground;
            var backgroundColorAttribute = (BackgroundColorAttribute)Attribute.GetCustomAttribute(pendingConfig.GetType(), typeof(BackgroundColorAttribute));

            if (backgroundColorAttribute != null)
            {
                uIPanel.BackgroundColor = backgroundColorAttribute.color;
            }

            int order = 0;

            foreach (PropertyFieldWrapper variable in ConfigManager.GetFieldsAndProperties(pendingConfig))
            {
                if (variable.isProperty && variable.Name == "Mode")
                {
                    continue;
                }
                if (Attribute.IsDefined(variable.MemberInfo, typeof(JsonIgnoreAttribute)) && !Attribute.IsDefined(variable.MemberInfo, typeof(LabelAttribute)))                 // TODO, appropriately named attribute
                {
                    continue;
                }
                HeaderAttribute header = ConfigManager.GetCustomAttribute <HeaderAttribute>(variable, null, null);
                if (header != null)
                {
                    var wrapper = new PropertyFieldWrapper(typeof(HeaderAttribute).GetProperty(nameof(HeaderAttribute.Header)));
                    WrapIt(mainConfigList, ref top, wrapper, header, order++);
                }
                WrapIt(mainConfigList, ref top, variable, pendingConfig, order++);
            }
        }