Beispiel #1
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            if (_isPreset.boolValue)
            {
                EditorGUILayout.HelpBox("Create a preset for a mod. Remember to add it to the list of presets", MessageType.Info);
            }
            else
            {
                EditorGUILayout.HelpBox("Create settings for a mod. Remember to name the file 'modsettings.asset'", MessageType.Info);
            }

            // Header
            EditorGUILayout.LabelField("Header", EditorStyles.boldLabel);
            using (new EditorGUI.DisabledScope(_isPreset.boolValue))
                EditorGUILayout.PropertyField(_version);
            EditorGUILayout.PropertyField(_isPreset);

            // Presets tools
            if (_isPreset.boolValue)
            {
                presetSyncExpanded = EditorGUILayout.Foldout(presetSyncExpanded, "Sync", true);
                if (presetSyncExpanded)
                {
                    EditorGUILayout.HelpBox("Sync preset with main settings (doesn't reset compatible values)", MessageType.None);
                    parent = (ModSettingsConfiguration)EditorGUILayout.ObjectField("Parent", parent, typeof(ModSettingsConfiguration), true);
                    if (parent)
                    {
                        addNewKeys = EditorGUILayout.Toggle(new GUIContent("Add New Keys", "Add missing keys or only sync existing ones?"), addNewKeys);
                        if (GUILayout.Button("Sync"))
                        {
                            Target.Sync(parent, addNewKeys);
                        }
                    }
                }
                EditorGUILayout.PropertyField(_presetSettings, true);
            }
            else
            {
                EditorGUILayout.PropertyField(_presets, true);
            }

            // Settings
            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Settings", EditorStyles.boldLabel);

            sectionsExpanded = EditorGUILayout.Foldout(sectionsExpanded, "Sections", true);
            if (sectionsExpanded)
            {
                EditorGUI.indentLevel++;

                editMode = EditorGUILayout.Toggle("Edit Mode", editMode);

                using (new EditorGUI.DisabledScope(true))
                {
                    sectionsCount = EditorGUILayout.IntField("Size", sectionsCount);
                }

                var sectionNames = new List <string>();

                for (int i = 0; i < _sections.arraySize; i++)
                {
                    SerializedProperty _section     = _sections.GetArrayElementAtIndex(i);
                    SerializedProperty _sectionName = _section.FindPropertyRelative("name");
                    if (string.IsNullOrEmpty(_sectionName.stringValue))
                    {
                        _sectionName.stringValue = "Section";
                    }
                    sectionNames.Add(_sectionName.stringValue);

                    if (IsSectionFoldoutExpanded(i, _sectionName.stringValue))
                    {
                        EditorGUI.indentLevel++;

                        using (new EditorGUI.DisabledScope(_isPreset.boolValue))
                            EditorGUILayout.PropertyField(_sectionName);

                        SerializedProperty _keys = _section.FindPropertyRelative("keys");

                        var keyNames = new List <string>();

                        using (new EditorGUI.DisabledScope(true))
                        {
                            int thisKeysCount = KeysCount(i);
                        }

                        for (int j = 0; j < _keys.arraySize; j++)
                        {
                            SerializedProperty _key     = _keys.GetArrayElementAtIndex(j);
                            SerializedProperty _keyName = _key.FindPropertyRelative("name");
                            if (string.IsNullOrEmpty(_keyName.stringValue))
                            {
                                _keyName.stringValue = "Key";
                            }
                            keyNames.Add(_keyName.stringValue);

                            if (IsKeyFoldoutExpanded(i, j, _keyName.stringValue))
                            {
                                SerializedProperty _type = _key.FindPropertyRelative("type");

                                using (new EditorGUI.DisabledScope(_isPreset.boolValue))
                                {
                                    EditorGUILayout.PropertyField(_keyName);
                                    EditorGUILayout.PropertyField(_key.FindPropertyRelative("description"));
                                    EditorGUILayout.PropertyField(_type);
                                }

                                var keyType = (ModSettingsKey.KeyType)_type.enumValueIndex;
                                switch (keyType)
                                {
                                case ModSettingsKey.KeyType.Toggle:
                                    EditorGUILayout.PropertyField(_key.FindPropertyRelative("toggle").FindPropertyRelative("value"));
                                    break;

                                case ModSettingsKey.KeyType.MultipleChoice:
                                    SerializedProperty _multipleChoice = _key.FindPropertyRelative("multipleChoice");
                                    SerializedProperty _selected       = _multipleChoice.FindPropertyRelative("selected");
                                    _selected.intValue = EditorGUILayout.Popup(_selected.intValue, Target.sections[i].keys[j].multipleChoice.choices);
                                    using (new EditorGUI.DisabledScope(_isPreset.boolValue))
                                        EditorGUILayout.PropertyField(_multipleChoice.FindPropertyRelative("choices"), true);
                                    break;

                                case ModSettingsKey.KeyType.Slider:
                                    SerializedProperty _slider    = _key.FindPropertyRelative("slider");
                                    SerializedProperty _sliderMin = _slider.FindPropertyRelative("min");
                                    SerializedProperty _sliderMax = _slider.FindPropertyRelative("max");
                                    if (_sliderMin.intValue == 0 && _sliderMax.intValue == 0)
                                    {
                                        _sliderMax.intValue = 100;
                                    }
                                    EditorGUILayout.IntSlider(_slider.FindPropertyRelative("value"), _sliderMin.intValue, _sliderMax.intValue);
                                    GUILayout.BeginHorizontal();
                                    using (new EditorGUI.DisabledScope(_isPreset.boolValue))
                                    {
                                        EditorGUILayout.PropertyField(_sliderMin);
                                        EditorGUILayout.PropertyField(_sliderMax);
                                    }
                                    GUILayout.EndHorizontal();
                                    break;

                                case ModSettingsKey.KeyType.FloatSlider:
                                    SerializedProperty _floatSlider      = _key.FindPropertyRelative("floatSlider");
                                    SerializedProperty _floatSliderValue = _floatSlider.FindPropertyRelative("value");
                                    SerializedProperty _floatSliderMin   = _floatSlider.FindPropertyRelative("min");
                                    SerializedProperty _floatSliderMax   = _floatSlider.FindPropertyRelative("max");
                                    if (_floatSliderMin.floatValue == 0 && _floatSliderMax.floatValue == 0)
                                    {
                                        _floatSliderMax.floatValue = 1;
                                    }
                                    EditorGUILayout.Slider(_floatSliderValue, _floatSliderMin.floatValue, _floatSliderMax.floatValue);
                                    GUILayout.BeginHorizontal();
                                    using (new EditorGUI.DisabledScope(_isPreset.boolValue))
                                    {
                                        EditorGUILayout.PropertyField(_floatSliderMin);
                                        EditorGUILayout.PropertyField(_floatSliderMax);
                                    }
                                    GUILayout.EndHorizontal();
                                    break;

                                case ModSettingsKey.KeyType.Tuple:
                                    SerializedProperty _tuple = _key.FindPropertyRelative("tuple");
                                    GUILayout.BeginHorizontal();
                                    EditorGUILayout.PropertyField(_tuple.FindPropertyRelative("first"));
                                    EditorGUILayout.PropertyField(_tuple.FindPropertyRelative("second"));
                                    GUILayout.EndHorizontal();
                                    break;

                                case ModSettingsKey.KeyType.FloatTuple:
                                    SerializedProperty _floatTuple = _key.FindPropertyRelative("floatTuple");
                                    GUILayout.BeginHorizontal();
                                    EditorGUILayout.PropertyField(_floatTuple.FindPropertyRelative("first"));
                                    EditorGUILayout.PropertyField(_floatTuple.FindPropertyRelative("second"));
                                    GUILayout.EndHorizontal();
                                    break;

                                case ModSettingsKey.KeyType.Text:
                                    EditorGUILayout.PropertyField(_key.FindPropertyRelative("text").FindPropertyRelative("text"));
                                    break;

                                case ModSettingsKey.KeyType.Color:
                                    EditorGUILayout.PropertyField(_key.FindPropertyRelative("color").FindPropertyRelative("color"));
                                    break;
                                }

                                if (editMode)
                                {
                                    keysCount[i] += InsertOrRemove(_keys, j, i);
                                }
                            }
                        }

                        EditorGUI.indentLevel--;

                        if (editMode)
                        {
                            sectionsCount += InsertOrRemove(_sections, i);
                        }

                        if (DuplicatesDetected(keyNames))
                        {
                            EditorGUILayout.HelpBox("Multiple keys with the same name in a section detected!", MessageType.Error);
                        }
                    }
                }

                EditorGUI.indentLevel--;

                if (DuplicatesDetected(sectionNames))
                {
                    EditorGUILayout.HelpBox("Multiple sections with the same name detected!", MessageType.Error);
                }
            }

            // Import/Export
            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Import/Export", EditorStyles.boldLabel);
            EditorGUILayout.HelpBox("Import from/export to Untracked/modsettings.json, export to Untracked/modsettings.ini", MessageType.None);

            if (GUILayout.Button("Import"))
            {
                Target.Import();
            }

            if (GUILayout.Button("Export"))
            {
                Target.Export();
            }

            if (GUILayout.Button("Export (Ini)"))
            {
                Target.ExportToIni();
            }

            serializedObject.ApplyModifiedProperties();
        }
Beispiel #2
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUILayout.HelpBox("Create settings for a mod. Remember to name the file 'modsettings.asset'", MessageType.Info);

            // Header
            EditorGUILayout.LabelField("Header", EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(_version);
            EditorGUILayout.PropertyField(_isPreset);

            if (_isPreset.boolValue)
            {
                EditorGUILayout.PropertyField(_presetSettings, true);
            }
            else
            {
                EditorGUILayout.PropertyField(_presets, true);
            }

            // Settings
            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Settings", EditorStyles.boldLabel);

            sectionsExpanded = EditorGUILayout.Foldout(sectionsExpanded, "Sections", true);
            if (sectionsExpanded)
            {
                EditorGUI.indentLevel++;
                sectionsCount = EditorGUILayout.IntField("Size", sectionsCount);
                if (_sections.arraySize != sectionsCount)
                {
                    ResizeArray(ref _sections, sectionsCount);
                }

                var sectionNames = new List <string>();

                for (int i = 0; i < _sections.arraySize; i++)
                {
                    SerializedProperty _section     = _sections.GetArrayElementAtIndex(i);
                    SerializedProperty _sectionName = _section.FindPropertyRelative("name");
                    if (string.IsNullOrEmpty(_sectionName.stringValue))
                    {
                        _sectionName.stringValue = "Section";
                    }
                    sectionNames.Add(_sectionName.stringValue);

                    if (IsSectionFoldoutExpanded(i, _sectionName.stringValue))
                    {
                        EditorGUI.indentLevel++;
                        EditorGUILayout.PropertyField(_sectionName);

                        SerializedProperty _keys = _section.FindPropertyRelative("keys");

                        var keyNames = new List <string>();

                        int thisKeysCount = KeysCount(i);
                        if (_keys.arraySize != thisKeysCount)
                        {
                            ResizeArray(ref _keys, thisKeysCount);
                        }

                        for (int j = 0; j < _keys.arraySize; j++)
                        {
                            SerializedProperty _key     = _keys.GetArrayElementAtIndex(j);
                            SerializedProperty _keyName = _key.FindPropertyRelative("name");
                            if (string.IsNullOrEmpty(_keyName.stringValue))
                            {
                                _keyName.stringValue = "Key";
                            }
                            keyNames.Add(_keyName.stringValue);

                            if (IsKeyFoldoutExpanded(i, j, _keyName.stringValue))
                            {
                                EditorGUILayout.PropertyField(_keyName);
                                EditorGUILayout.PropertyField(_key.FindPropertyRelative("description"));

                                SerializedProperty _type = _key.FindPropertyRelative("type");
                                EditorGUILayout.PropertyField(_type);

                                var keyType = (ModSettingsKey.KeyType)_type.enumValueIndex;
                                switch (keyType)
                                {
                                case ModSettingsKey.KeyType.Toggle:
                                    EditorGUILayout.PropertyField(_key.FindPropertyRelative("toggle").FindPropertyRelative("value"));
                                    break;

                                case ModSettingsKey.KeyType.MultipleChoice:
                                    EditorGUILayout.PropertyField(_key.FindPropertyRelative("multipleChoice").FindPropertyRelative("choices"), true);
                                    break;

                                case ModSettingsKey.KeyType.Slider:
                                    SerializedProperty _slider    = _key.FindPropertyRelative("slider");
                                    SerializedProperty _sliderMin = _slider.FindPropertyRelative("min");
                                    SerializedProperty _sliderMax = _slider.FindPropertyRelative("max");
                                    if (_sliderMin.intValue == 0 && _sliderMax.intValue == 0)
                                    {
                                        _sliderMax.intValue = 100;
                                    }
                                    EditorGUILayout.IntSlider(_slider.FindPropertyRelative("value"), _sliderMin.intValue, _sliderMax.intValue);
                                    GUILayout.BeginHorizontal();
                                    EditorGUILayout.PropertyField(_sliderMin);
                                    EditorGUILayout.PropertyField(_sliderMax);
                                    GUILayout.EndHorizontal();
                                    break;

                                case ModSettingsKey.KeyType.FloatSlider:
                                    SerializedProperty _floatSlider      = _key.FindPropertyRelative("floatSlider");
                                    SerializedProperty _floatSliderValue = _floatSlider.FindPropertyRelative("value");
                                    SerializedProperty _floatSliderMin   = _floatSlider.FindPropertyRelative("min");
                                    SerializedProperty _floatSliderMax   = _floatSlider.FindPropertyRelative("max");
                                    if (_floatSliderMin.floatValue == 0 && _floatSliderMax.floatValue == 0)
                                    {
                                        _floatSliderMax.floatValue = 1;
                                    }
                                    EditorGUILayout.Slider(_floatSliderValue, _floatSliderMin.floatValue, _floatSliderMax.floatValue);
                                    GUILayout.BeginHorizontal();
                                    EditorGUILayout.PropertyField(_floatSliderMin);
                                    EditorGUILayout.PropertyField(_floatSliderMax);
                                    GUILayout.EndHorizontal();
                                    break;

                                case ModSettingsKey.KeyType.Tuple:
                                    SerializedProperty _tuple = _key.FindPropertyRelative("tuple");
                                    GUILayout.BeginHorizontal();
                                    EditorGUILayout.PropertyField(_tuple.FindPropertyRelative("first"));
                                    EditorGUILayout.PropertyField(_tuple.FindPropertyRelative("second"));
                                    GUILayout.EndHorizontal();
                                    break;

                                case ModSettingsKey.KeyType.FloatTuple:
                                    SerializedProperty _floatTuple = _key.FindPropertyRelative("floatTuple");
                                    GUILayout.BeginHorizontal();
                                    EditorGUILayout.PropertyField(_floatTuple.FindPropertyRelative("first"));
                                    EditorGUILayout.PropertyField(_floatTuple.FindPropertyRelative("second"));
                                    GUILayout.EndHorizontal();
                                    break;

                                case ModSettingsKey.KeyType.Text:
                                    EditorGUILayout.PropertyField(_key.FindPropertyRelative("text").FindPropertyRelative("text"));
                                    break;

                                case ModSettingsKey.KeyType.Color:
                                    EditorGUILayout.PropertyField(_key.FindPropertyRelative("color").FindPropertyRelative("color"));
                                    break;
                                }
                            }
                        }

                        EditorGUI.indentLevel--;

                        if (DuplicatesDetected(keyNames))
                        {
                            EditorGUILayout.HelpBox("Multiple keys with the same name in a section detected!", MessageType.Error);
                        }
                    }
                }

                EditorGUI.indentLevel--;

                if (DuplicatesDetected(sectionNames))
                {
                    EditorGUILayout.HelpBox("Multiple sections with the same name detected!", MessageType.Error);
                }
            }

            // Import/Export
            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Import/Export", EditorStyles.boldLabel);
            EditorGUILayout.HelpBox("Import from/export to Untracked/modsettings.json", MessageType.None);

            if (GUILayout.Button("Import"))
            {
                Target.Import();
            }

            if (GUILayout.Button("Export"))
            {
                Target.Export();
            }

            serializedObject.ApplyModifiedProperties();
        }
Beispiel #3
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            lineHeight = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;

            if (isPreset = _isPreset.boolValue)
            {
                EditorGUILayout.HelpBox("Create a preset for a mod. This is a group of a portion or all settings values. " +
                                        "Remember to sync it with the main settings asset.", MessageType.Info);
            }
            else
            {
                EditorGUILayout.HelpBox("Create settings for a mod. Remember to name the file 'modsettings.asset'. " +
                                        "You can acces them in game through DaggerfallWorkshop.Game.Utility.ModSupport.ModSettings.", MessageType.Info);
            }

            // Header
            EditorGUILayout.LabelField("Header", EditorStyles.boldLabel);
            EditorGUILayout.Separator();
            using (new EditorGUI.DisabledScope(isPreset))
                EditorGUILayout.PropertyField(_version);
            EditorGUILayout.PropertyField(_isPreset);

            // Presets tools
            if (isPreset)
            {
                presetSyncExpanded = EditorGUILayout.Foldout(presetSyncExpanded, "Sync", true);
                if (presetSyncExpanded)
                {
                    EditorGUILayout.HelpBox("Sync preset with main settings (doesn't reset compatible values)", MessageType.None);
                    parent = (ModSettingsConfiguration)EditorGUILayout.ObjectField("Parent", parent, typeof(ModSettingsConfiguration), true);
                    if (parent)
                    {
                        addNewKeys = EditorGUILayout.Toggle(new GUIContent("Add New Keys", "Add missing keys or only sync existing ones?"), addNewKeys);
                        if (GUILayout.Button("Sync"))
                        {
                            Target.Sync(parent, addNewKeys);
                        }
                    }
                }

                EditorGUILayout.PropertyField(_presetSettings, new GUIContent("Info"), true);
            }
            else
            {
                if (presets == null)
                {
                    presets = new ReorderableList(serializedObject, _presets, true, true, true, true);
                    presets.drawHeaderCallback  = Presets_DrawHeaderCallback;
                    presets.drawElementCallback = Presets_DrawElementCallback;
                }
                EditorGUI.indentLevel++;
                presets.DoLayoutList();
                EditorGUI.indentLevel--;
            }

            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

            // Settings
            EditorGUILayout.LabelField("Settings", EditorStyles.boldLabel);
            EditorGUILayout.Separator();
            selectionGridSelected = GUILayout.SelectionGrid(selectionGridSelected, new string[] { "Sections", "Keys" }, 2);

            sections.draggable = sections.displayAdd = sections.displayRemove = !isPreset;
            foreach (var keyControl in keys)
            {
                keyControl.draggable = keyControl.displayAdd = keyControl.displayRemove = !isPreset;
            }

            if (selectionGridSelected == 0)
            {
                sections.DoLayoutList();
            }

            bool duplicateSections = false, duplicateKeys = false;

            sectionNames.Clear();
            keyNames.Clear();
            for (int i = 0; i < _sections.arraySize; i++)
            {
                SerializedProperty _section     = _sections.GetArrayElementAtIndex(i);
                SerializedProperty _sectionName = _section.FindPropertyRelative("name");
                _sectionName.stringValue = !string.IsNullOrEmpty(_sectionName.stringValue) ?
                                           _sectionName.stringValue.Replace(" ", string.Empty) : "Section";
                sectionNames.Add(_sectionName.stringValue);

                EditorGUI.indentLevel++;

                SerializedProperty _keys = _section.FindPropertyRelative("keys");
                var keyNames             = new List <string>();
                for (int j = 0; j < _keys.arraySize; j++)
                {
                    SerializedProperty _keyName = _keys.GetArrayElementAtIndex(j).FindPropertyRelative("name");
                    _keyName.stringValue = !string.IsNullOrEmpty(_keyName.stringValue) ?
                                           _keyName.stringValue.Replace(" ", string.Empty) : "Key";
                    keyNames.Add(_keyName.stringValue);
                }

                duplicateKeys |= DuplicatesDetected(keyNames);
                this.keyNames.Add(keyNames);

                if (selectionGridSelected == 1)
                {
                    keys[currentSection = i].DoLayoutList();
                }

                EditorGUI.indentLevel--;
            }

            duplicateSections |= DuplicatesDetected(sectionNames);

            if (duplicateSections)
            {
                EditorGUILayout.HelpBox("Multiple sections with the same name detected!", MessageType.Error);
            }
            if (duplicateKeys)
            {
                EditorGUILayout.HelpBox("Multiple keys with the same name in a section detected!", MessageType.Error);
            }

            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

            // Import/Export
            EditorGUILayout.LabelField("Import/Export", EditorStyles.boldLabel);
            EditorGUILayout.Separator();
            EditorGUILayout.HelpBox(string.Format("Import from/export to Untracked/modsettings.{0}", parseFormat == 0 ? "ini" : "json"), MessageType.None);
            parseFormat = GUILayout.SelectionGrid(parseFormat, new string[] { "Ini", "Json" }, 2);
            if (parseFormat == 0)
            {
                if (GUILayout.Button("Import"))
                {
                    Target.ImportFromIni();
                }
                else if (GUILayout.Button("Export"))
                {
                    Target.ExportToIni();
                }
            }
            else
            {
                if (GUILayout.Button("Import"))
                {
                    Target.Import();
                }
                else if (GUILayout.Button("Export"))
                {
                    Target.Export();
                }
            }

            serializedObject.ApplyModifiedProperties();
        }