private TextLabel AddKeyName(string name)
        {
            TextLabel textLabel = new TextLabel();

            textLabel.Text                = ModSettingsReader.FormattedName(name);
            textLabel.ShadowColor         = Color.clear;
            textLabel.TextScale           = textScale;
            textLabel.Position            = new Vector2(x, y);
            textLabel.HorizontalAlignment = HorizontalAlignment.None;
            currentPanel.Components.Add(textLabel);
            return(textLabel);
        }
Пример #2
0
        private void Keys_DrawHeaderCallback(Rect rect)
        {
            SerializedProperty _sectionName = _sections.GetArrayElementAtIndex(currentSection).FindPropertyRelative("name");

            if (!sectionExpanded.ContainsKey(currentSection))
            {
                sectionExpanded.Add(currentSection, false);
            }
            var style = new GUIStyle(EditorStyles.foldout);

            if (_sectionName.stringValue == ModSettingsReader.internalSection)
            {
                style.normal.textColor = Color.red;
            }
            sectionExpanded[currentSection] = EditorGUI.Foldout(LineRect(rect), sectionExpanded[currentSection],
                                                                ModSettingsReader.FormattedName(_sectionName.stringValue), style);
        }
        private void AddSectionTitle(string title)
        {
            Panel background = new Panel();

            background.Position          = new Vector2(x, y - 0.5f);
            background.Size              = new Vector2(140, 6.5f);
            background.BackgroundColor   = backgroundTitleColor;
            background.Outline.Enabled   = true;
            background.Outline.Sides     = Sides.Bottom;
            background.Outline.Color     = saveButtonColor;
            background.Outline.Thickness = 1;
            currentPanel.Components.Add(background);

            TextLabel textLabel = new TextLabel(DaggerfallUI.Instance.Font5);

            textLabel.Text                = ModSettingsReader.FormattedName(title);
            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);
        }
Пример #4
0
        private void Keys_DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused)
        {
            int line = 0;

            SerializedProperty _keys    = _sections.GetArrayElementAtIndex(currentSection).FindPropertyRelative("keys");
            SerializedProperty _key     = _keys.GetArrayElementAtIndex(index);
            SerializedProperty _keyName = _key.FindPropertyRelative("name");

            if (!sectionExpanded[currentSection])
            {
                EditorGUI.LabelField(LineRect(rect), ModSettingsReader.FormattedName(_keyName.stringValue));
                SetKeySize(currentSection, index, lineHeight);
                return;
            }

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

            using (new EditorGUI.DisabledScope(isPreset))
            {
                EditorGUI.PropertyField(LineRect(rect, line++), _keyName, GUIContent.none);
                EditorGUI.PropertyField(LineRect(rect, line++), _key.FindPropertyRelative("description"));
                EditorGUI.PropertyField(LineRect(rect, line++), _type, new GUIContent("UI Control"));
            }

            int lines = 4;

            switch ((ModSettingsKey.KeyType)_type.enumValueIndex)
            {
            case ModSettingsKey.KeyType.Toggle:
                SerializedProperty _value = _key.FindPropertyRelative("toggle").FindPropertyRelative("value");
                EditorGUI.PropertyField(LineRect(rect, line++), _value, true);
                break;

            case ModSettingsKey.KeyType.MultipleChoice:
                SerializedProperty _multipleChoice = _key.FindPropertyRelative("multipleChoice");
                SerializedProperty _selected       = _multipleChoice.FindPropertyRelative("selected");
                SerializedProperty _choices        = _multipleChoice.FindPropertyRelative("choices");
                var      multipleChoice            = Target.sections[currentSection].keys[index].multipleChoice;
                string[] choices = multipleChoice.choices;
                _selected.intValue = EditorGUI.Popup(LineRect(rect, line++), _selected.intValue, choices);
                using (new EditorGUI.DisabledScope(isPreset))
                {
                    if (DropDownButton(rect, line))
                    {
                        var menu = new GenericMenu();
                        menu.AddItem(new GUIContent("Copy choices"), false, CopyChoices, new List <string>(choices));
                        if (cachedChoices != null)
                        {
                            menu.AddItem(new GUIContent("Paste choices"), false, PasteChoices, multipleChoice);
                        }
                        menu.ShowAsContext();
                    }
                    EditorGUI.PropertyField(LineRect(rect, line++), _choices, true);
                }
                lines += _choices.isExpanded ? 2 + choices.Length : 1;
                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;
                }
                EditorGUI.IntSlider(LineRect(rect, line++),
                                    _slider.FindPropertyRelative("value"), _sliderMin.intValue, _sliderMax.intValue);
                GUILayout.BeginHorizontal();
                using (new EditorGUI.DisabledScope(isPreset))
                {
                    EditorGUI.PropertyField(HalfLineRect(rect, line), _sliderMin);
                    EditorGUI.PropertyField(HalfLineRect(rect, line++, true), _sliderMax);
                }
                GUILayout.EndHorizontal();
                lines += 1;
                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;
                }
                EditorGUI.Slider(LineRect(rect, line++), _floatSliderValue, _floatSliderMin.floatValue, _floatSliderMax.floatValue);
                GUILayout.BeginHorizontal();
                using (new EditorGUI.DisabledScope(isPreset))
                {
                    EditorGUI.PropertyField(HalfLineRect(rect, line), _floatSliderMin);
                    EditorGUI.PropertyField(HalfLineRect(rect, line++, true), _floatSliderMax);
                }
                GUILayout.EndHorizontal();
                lines += 1;
                break;

            case ModSettingsKey.KeyType.Tuple:
                SerializedProperty _tuple = _key.FindPropertyRelative("tuple");
                GUILayout.BeginHorizontal();
                EditorGUI.PropertyField(HalfLineRect(rect, line), _tuple.FindPropertyRelative("first"), GUIContent.none);
                EditorGUI.PropertyField(HalfLineRect(rect, line++, true), _tuple.FindPropertyRelative("second"), GUIContent.none);
                GUILayout.EndHorizontal();
                break;

            case ModSettingsKey.KeyType.FloatTuple:
                SerializedProperty _floatTuple = _key.FindPropertyRelative("floatTuple");
                GUILayout.BeginHorizontal();
                EditorGUI.PropertyField(HalfLineRect(rect, line), _floatTuple.FindPropertyRelative("first"), GUIContent.none);
                EditorGUI.PropertyField(HalfLineRect(rect, line++, true), _floatTuple.FindPropertyRelative("second"), GUIContent.none);
                GUILayout.EndHorizontal();
                break;

            case ModSettingsKey.KeyType.Text:
                EditorGUI.PropertyField(new Rect(rect.x, rect.y + 3 * lineHeight, rect.width, EditorGUIUtility.singleLineHeight * 3),
                                        _key.FindPropertyRelative("text").FindPropertyRelative("text"));
                lines += 2;
                break;

            case ModSettingsKey.KeyType.Color:
                EditorGUI.PropertyField(LineRect(rect, line++), _key.FindPropertyRelative("color").FindPropertyRelative("color"));
                break;
            }

            SetKeySize(currentSection, index, (lines + 1) * lineHeight);
        }