/// <summary> /// Import settings data from a mod. /// </summary> public static ModSettingsData Make(Mod mod) { ModSettingsData instance = new ModSettingsData(mod); if (mod.AssetBundle.Contains("modsettings.json")) { TryDeserialize(mod, "modsettings.json", ref instance); } else if (mod.AssetBundle.Contains(mod.Title + ".ini.txt")) { Debug.LogWarningFormat("{0} is using an obsolete modsettings format!", mod.Title); LoadLegacySettingsFromMod(mod, mod.Title + ".ini.txt", ref instance); } else if (mod.AssetBundle.Contains("modsettings.ini.txt")) { Debug.LogWarningFormat("{0} is using an obsolete modsettings format!", mod.Title); LoadLegacySettingsFromMod(mod, "modsettings.ini.txt", ref instance); } if (instance != null) { return(instance); } throw new ArgumentException("Mod has no associated settings."); }
private static void LoadLegacySettingsFromMod(Mod mod, string assetName, ref ModSettingsData instance) { var textAsset = mod.GetAsset <TextAsset>(assetName); using (var stream = new MemoryStream(textAsset.bytes)) using (var reader = new StreamReader(stream)) instance.ImportLegacyIni((new FileIniDataParser()).ReadData(reader)); }
/// <summary> /// Constructor for the mod settings window. /// </summary> /// <param name="mod">Mod whose values are to be exposed on screen.</param> public ModSettingsWindow(IUserInterfaceManager uiManager, Mod mod) : base(uiManager) { this.mod = mod; settings = ModSettingsData.Make(mod); settings.SaveDefaults(); settings.LoadLocalValues(); }
/// <summary> /// Constructor for the mod settings window. /// </summary> /// <param name="mod">Mod whose values are to be exposed on screen.</param> /// <param name="liveChange">True if the game is already running.</param> public ModSettingsWindow(IUserInterfaceManager uiManager, Mod mod, bool liveChange = false) : base(uiManager) { this.mod = mod; this.liveChange = liveChange; settings = ModSettingsData.Make(mod); settings.SaveDefaults(); settings.LoadLocalValues(); }
/// <summary> /// Import settings for a mod. /// </summary> /// <param name="mod">Mod to load settings for.</param> internal ModSettings(Mod mod) { if (!mod.HasSettings) { throw new ArgumentException(string.Format("{0} has no settings.", mod.Title), "mod"); } this.mod = mod; data = ModSettingsData.Make(mod); data.LoadLocalValues(); }
/// <summary> /// Import settings data from mod resources folder. /// </summary> public static ModSettingsData Make(string path) { ModSettingsData instance = new ModSettingsData(); if (TryDeserialize(path, ref instance)) { return(instance); } return(new ModSettingsData()); }
/// <summary> /// Import settings data from a mod. /// </summary> public static ModSettingsData Make(Mod mod) { ModSettingsData instance = new ModSettingsData(mod); if (HasSettings(mod) && TryDeserialize(mod, settingsFileName, ref instance)) { return(instance); } throw new ArgumentException(string.Format("Failed to load settings for mod {0}.", mod.Title)); }
private TextLabel GetKeyLabel(Section section, Key key, int height) { TextLabel textLabel = new TextLabel(); textLabel.Text = ModSettingsData.FormattedName(mod.TryLocalize("Settings", section.Name, key.Name, "Name") ?? key.Name); textLabel.ShadowColor = Color.clear; textLabel.TextScale = textScale; textLabel.HorizontalAlignment = HorizontalAlignment.None; textLabel.Position = new Vector2(x, y + (float)(height - textLabel.TextHeight) / 2); textLabel.ToolTip = defaultToolTip; textLabel.ToolTipText = mod.TryLocalize("Settings", section.Name, key.Name, "Description") ?? key.Description; return textLabel; }
private TextLabel GetKeyLabel(Key key, int height) { TextLabel textLabel = new TextLabel(); textLabel.Text = ModSettingsData.FormattedName(key.Name); textLabel.ShadowColor = Color.clear; textLabel.TextScale = textScale; textLabel.HorizontalAlignment = HorizontalAlignment.None; textLabel.Position = new Vector2(x, y + (float)(height - textLabel.TextHeight) / 2); textLabel.ToolTip = defaultToolTip; textLabel.ToolTipText = key.Description; return(textLabel); }
/// <summary> /// Constructor for the mod settings window. /// </summary> /// <param name="mod">Mod whose values are to be exposed on screen.</param> /// <param name="liveChange">True if the game is already running.</param> public ModSettingsWindow(IUserInterfaceManager uiManager, Mod mod, bool liveChange = false) : base(uiManager) { this.mod = mod; this.liveChange = liveChange; // Make room for warning label about applying settings during runtime columnHeight = liveChange ? 155 : 165; settings = ModSettingsData.Make(mod); settings.SaveDefaults(); settings.LoadLocalValues(); }
private void AddSectionTitleLabel(Section section) { Panel background = new Panel(); background.Position = new Vector2(x, y - 0.5f); background.Size = new Vector2(columnWidth, 6.5f); AddAtNextPosition((int)background.Size.y, background); TextLabel textLabel = new TextLabel(DaggerfallUI.Instance.Font4); textLabel.Text = ModSettingsData.FormattedName(mod.TryLocalize("Settings", section.Name, "Name") ?? section.Name); textLabel.TextColor = section.IsAdvanced ? sectionTitleAdvColor : sectionTitleColor; textLabel.ShadowColor = section.IsAdvanced ? sectionTitleAdvShadow : sectionTitleShadow; textLabel.TextScale = 0.9f; textLabel.Position = new Vector2(0, 0.5f); textLabel.HorizontalAlignment = HorizontalAlignment.Center; background.Components.Add(textLabel); }
private void Keys_DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused) { int line = 0; Section section = data.Sections[currentSection]; Key key = section[index]; if (!sectionExpanded[currentSection]) { EditorGUI.LabelField(LineRect(rect), ModSettingsData.FormattedName(key.Name)); SetKeySize(currentSection, index, lineHeight); return; } if (IsPreset) { using (new EditorGUI.DisabledScope(!CurrentPreset[section.Name])) { CurrentPreset[section.Name, key.Name] = EditorGUI.ToggleLeft(LineRect(rect, line++), key.Name, CurrentPreset[section.Name, key.Name]); EditorGUI.LabelField(LineRect(rect, line++), key.Description); } } else { key.Name = EditorGUI.TextField(LineRect(rect, line++), "Name", key.Name); key.Description = EditorGUI.TextField(LineRect(rect, line++), "Description", key.Description); } using (new EditorGUI.DisabledScope(IsPreset)) data.SetType(currentSection, index, ref key, (KeyType)EditorGUI.EnumPopup(LineRect(rect, line++), "UI Control", key.KeyType)); using (new EditorGUI.DisabledScope(IsPreset && !CurrentPreset[section.Name])) { rect.y += lineHeight * 3; int lines = key.OnEditorWindow( rect, (subrect, label, rects) => GUILayoutHelper.Horizontal(subrect, label, rects), (subrect, linesPerItem, rects) => GUILayoutHelper.Vertical(subrect, linesPerItem, rects), cache); SetKeySize(currentSection, index, (lines + 4) * lineHeight); } }
private void AddSectionTitleLabel(Section section) { Panel background = new Panel(); background.Position = new Vector2(x, y - 0.5f); background.Size = new Vector2(columnWidth, 6.5f); background.BackgroundColor = section.IsAdvanced ? backgroundTitleAdvColor : backgroundTitleColor; background.Outline.Enabled = true; background.Outline.Sides = Sides.Bottom; background.Outline.Color = section.IsAdvanced ? resetButtonColor : saveButtonColor; background.Outline.Thickness = 1; AddAtNextPosition((int)background.Size.y, background); TextLabel textLabel = new TextLabel(DaggerfallUI.Instance.Font5); textLabel.Text = ModSettingsData.FormattedName(mod.TryLocalize("Settings", section.Name, "Name") ?? section.Name); textLabel.TextColor = sectionTitleColor; textLabel.ShadowColor = sectionTitleShadow; textLabel.TextScale = 0.9f; textLabel.Position = new Vector2(0, 0.5f); textLabel.HorizontalAlignment = HorizontalAlignment.Center; background.Components.Add(textLabel); }
private void Load() { data = ModSettingsData.Make(SettingsPath); data.SaveDefaults(); data.LoadPresets(PresetPath); sections = new ReorderableList(data.Sections, typeof(SectionCollection), true, true, true, true); sections.drawHeaderCallback = Sections_DrawHeaderCallback; sections.drawElementCallback = Sections_DrawElementCallback; sections.elementHeightCallback = Sections_ElementHeightCallback; sections.onAddCallback = Sections_OnAddCallback; sections.onRemoveCallback = Sections_OnRemoveCallback; sections.onReorderCallback = Sections_OnReorderCallback; keys.Clear(); foreach (var section in data.Sections) { ReorderableList key = new ReorderableList(section.Keys, typeof(KeyCollection), true, true, true, true); key.drawHeaderCallback = Keys_DrawHeaderCallback; key.drawElementCallback = Keys_DrawElementCallback; key.elementHeightCallback = Keys_ElementHeightCallback; key.onAddCallback = Keys_OnAddCallback; key.onRemoveCallback = Keys_OnRemoveCallback; keys.Add(key); } presets = new ReorderableList(data.Presets, typeof(Preset), true, true, true, true); presets.drawHeaderCallback = r => presetsExpanded = EditorGUI.Foldout(r, presetsExpanded, "Presets"); presets.drawElementCallback = Presets_DrawElementCallback; presets.elementHeightCallback = x => presetsExpanded ? lineHeight : 0; currentPreset = -1; LoadPreset(-1); data.SyncPresets(); modName = Path.GetFileName(targetPath); localPath = GetLocalPath(targetPath); }
private void Keys_DrawHeaderCallback(Rect rect) { Section section = data.Sections[currentSection]; var style = new GUIStyle(EditorStyles.foldout); if (section.IsAdvanced) { style.normal.textColor = Color.red; } if (IsPreset) { var toggleRect = new Rect(rect.x, rect.y, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight); CurrentPreset[section.Name] = EditorGUI.Toggle(toggleRect, CurrentPreset[section.Name]); rect.x += toggleRect.width; } if (!sectionExpanded.ContainsKey(currentSection)) { sectionExpanded.Add(currentSection, false); } sectionExpanded[currentSection] = EditorGUI.Foldout(LineRect(rect), sectionExpanded[currentSection], ModSettingsData.FormattedName(section.Name), style); }
public PresetPicker(IUserInterfaceManager uiManager, DaggerfallBaseWindow previousWindow, ModSettingsData settings) : base(uiManager, previousWindow) { this.settings = settings; }
/// <summary> /// Makes an instance of mod settings from existing settings data. /// </summary> /// <param name="mod">Target mod.</param> /// <param name="data">Settings data for target mod.</param> internal ModSettings(Mod mod, ModSettingsData data) { this.mod = mod; this.data = data; }
public PresetPicker(IUserInterfaceManager uiManager, Mod mod, ModSettingsData settings) : base(uiManager) { this.mod = mod; this.settings = settings; }