public ModManager(QaeConfig config, Func <QuestomAssetsEngine> getEngine) { _config = config; _getEngine = getEngine; _modConfig = ModConfig.Load(_config); _originalModConfig = _modConfig.Clone(); }
/// <summary> /// Saves module configuration. /// </summary> private bool SaveConfig() { if (Modified) { if (ValidateConfig()) { if (config.Save(configFileName, out string errMsg)) { configCopy = config.Clone(); Modified = false; return(true); } else { ScadaUiUtils.ShowError(errMsg); return(false); } } else { return(false); } } else { return(true); } }
private void btnCancel_Click(object sender, EventArgs e) { // cancel configuration changes config = configCopy; configCopy = config.Clone(); LoadConfig(); Modified = false; }
/// <summary> /// Downloads information from the configuration file. /// </summary> private void LoadConfig() { // initialize common data configFileName = appDirs.ConfigDir + ModConfig.ConfigFileName; ctrlGeneralOptions.Visible = true; ctrlConnectionOptions.Visible = false; ctrlArcUploadOptions.Visible = false; ctrlTrigger.Visible = false; ctrlEventTrigger.Visible = false; config = new ModConfig(); if (File.Exists(configFileName) && !config.Load(configFileName, out string errMsg)) { ScadaUiUtils.ShowError(errMsg); } FillTree(); // creating a copy of the configuration configCopy = config.Clone(); }
public override void OnActivate() { SetMessage("", Color.White); string configDisplayName = ((LabelAttribute)Attribute.GetCustomAttribute(modConfig.GetType(), typeof(LabelAttribute)))?.Label ?? modConfig.Name; headerTextPanel.SetText(modConfig.mod.DisplayName + ": " + configDisplayName); pendingConfig = modConfig.Clone(); 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); mainConfigList.Clear(); configPanelStack.Clear(); configPanelStack.Push(uIPanel); subPageStack.Clear(); //currentConfigList = mainConfigList; int i = 0; 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++); } }