private void AddColorPicker(string hexColor, ModSettingsKey key)
        {
            Button colorPicker = new Button()
            {
                Position = new Vector2(x + 95, y),
                AutoSize = AutoSizeModes.None,
                Size     = new Vector2(40, 6),
            };

            colorPicker.Outline.Enabled = true;

            Color color;

            if (ColorUtility.TryParseHtmlString("#" + hexColor, out color))
            {
                colorPicker.BackgroundColor = color;
            }
            else
            {
                colorPicker.BackgroundColor = key.color.color;
            }

            colorPicker.OnMouseClick += ColorPicker_OnMouseClick;
            modColorPickers.Add(colorPicker);
            currentPanel.Components.Add(colorPicker);
        }
        public bool Key(string sectionName, string keyName, out ModSettingsKey keyOut)
        {
            var section = this[sectionName];

            if (section != null)
            {
                var key = section[keyName];
                if (key != null)
                {
                    keyOut = key;
                    return(true);
                }
            }

            keyOut = null;
            return(false);
        }
예제 #3
0
        private void AddColorPicker(string hexColor, ModSettingsKey key = null)
        {
            Button colorPicker = new Button()
            {
                Position = new Vector2(x + 95, y),
                AutoSize = AutoSizeModes.None,
                Size     = new Vector2(40, 6),
            };

            colorPicker.Outline.Enabled = true;

            if (!ModSettingsReader.IsHexColor(hexColor))
            {
                hexColor = key != null ? key.color.HexColor : "FFFFFFFF";
            }
            colorPicker.BackgroundColor = ModSettingsReader.ColorFromString(hexColor);

            colorPicker.OnMouseClick += ColorPicker_OnMouseClick;
            modColorPickers.Add(colorPicker);
            currentPanel.Components.Add(colorPicker);
        }
예제 #4
0
        public static void ParseIniToConfig(IniData iniData, ModSettingsConfiguration config)
        {
            var configSections = new List <ModSettingsConfiguration.Section>();

            foreach (SectionData section in iniData.Sections)
            {
                var configSection = new ModSettingsConfiguration.Section();
                configSection.name = section.SectionName;

                List <ModSettingsKey> keys = new List <ModSettingsKey>();
                foreach (KeyData key in section.Keys)
                {
                    var configKey = new ModSettingsKey();
                    configKey.name = key.KeyName;

                    if (key.Value == "True" || key.Value == "False")
                    {
                        configKey.type         = ModSettingsKey.KeyType.Toggle;
                        configKey.toggle       = new ModSettingsKey.Toggle();
                        configKey.toggle.value = bool.Parse(key.Value);
                    }
                    else if (key.Value.Contains(tupleDelimiterChar))
                    {
                        configKey.type       = ModSettingsKey.KeyType.FloatTuple;
                        configKey.floatTuple = new ModSettingsKey.FloatTuple();
                        int index = key.Value.IndexOf(tupleDelimiterChar);
                        float.TryParse(key.Value.Substring(0, index), out configKey.floatTuple.first);
                        float.TryParse(key.Value.Substring(index + tupleDelimiterChar.Length), out configKey.floatTuple.second);
                    }
                    else if (IsHexColor(key.Value))
                    {
                        configKey.type           = ModSettingsKey.KeyType.Color;
                        configKey.color          = new ModSettingsKey.Tint();
                        configKey.color.HexColor = key.Value;
                    }
                    else
                    {
                        configKey.type      = ModSettingsKey.KeyType.Text;
                        configKey.text      = new ModSettingsKey.Text();
                        configKey.text.text = key.Value;
                    }

                    keys.Add(configKey);
                }

                if (section.SectionName == internalSection)
                {
                    // Header
                    config.version = section.Keys[settingsVersionKey];

                    // Add section only if there are other hidden keys
                    if (keys.Count > 1)
                    {
                        configSection.keys = keys.Where(x => x.name != settingsVersionKey).ToArray();
                        configSections.Add(configSection);
                    }
                }
                else
                {
                    // Settings
                    configSection.keys = keys.ToArray();
                    configSections.Add(configSection);
                }
            }
            config.sections = configSections.ToArray();
        }
        /// <summary>
        /// Sync version and UI controls/checks from parent to this preset.
        /// A preset can have even only a portion of keys (typically a section).
        /// </summary>
        /// <param name="parent">Main settings.</param>
        /// <param name="addNewKeys">Add missing keys or sync only found ones?</param>
        public void Sync(ModSettingsConfiguration parent, bool addNewKeys)
        {
            if (!parent)
            {
                Debug.LogError("Parent not found");
                return;
            }

            version = parent.version;

            var childSections = new List <Section>();

            foreach (var parentSection in parent.sections)
            {
                Section section = this[parentSection.name];
                if (section == null)
                {
                    if (!addNewKeys)
                    {
                        continue;
                    }

                    section      = new Section();
                    section.name = parentSection.name;
                    section.keys = new ModSettingsKey[0];
                }

                var childKeys = new List <ModSettingsKey>();
                foreach (var parentKey in parentSection.keys)
                {
                    ModSettingsKey key = section[parentKey.name];
                    if (key == null)
                    {
                        if (!addNewKeys)
                        {
                            continue;
                        }

                        key      = new ModSettingsKey();
                        key.name = parentKey.name;
                    }

                    key.description = parentKey.description;
                    key.type        = parentKey.type;
                    switch (parentKey.type)
                    {
                    case KeyType.MultipleChoice:
                        if (key.multipleChoice == null)
                        {
                            key.multipleChoice = new ModSettingsKey.MultipleChoice();
                        }
                        key.multipleChoice.choices = parentKey.multipleChoice.choices;
                        break;

                    case KeyType.Slider:
                        if (key.slider == null)
                        {
                            key.slider = new ModSettingsKey.Slider();
                        }
                        key.slider.max = parentKey.slider.max;
                        key.slider.min = parentKey.slider.min;
                        break;

                    case KeyType.FloatSlider:
                        if (key.floatSlider == null)
                        {
                            key.floatSlider = new ModSettingsKey.FloatSlider();
                        }
                        key.floatSlider.max = parentKey.floatSlider.max;
                        key.floatSlider.min = parentKey.floatSlider.min;
                        break;
                    }

                    childKeys.Add(key);
                }

                section.keys = childKeys.ToArray();

                childSections.Add(section);
            }

            sections = childSections.ToArray();

            // Add to list of presets
            string presetPath = UnityEditor.AssetDatabase.GetAssetPath(this.GetInstanceID());
            string presetName = Path.GetFileNameWithoutExtension(presetPath);

            if (!parent.presets.Contains(presetName))
            {
                var presets = new List <string>(parent.presets);
                presets.Add(presetName);
                parent.presets = presets.ToArray();
            }
        }
 public bool Key(string sectionName, string keyName, KeyType keyType, out ModSettingsKey keyOut)
 {
     return(Key(sectionName, keyName, out keyOut) && keyOut.type == keyType);
 }