示例#1
0
        private void AddSliderSetting(ModSettingsBase modSettings, FieldInfo field, NameAttribute name, DescriptionAttribute description, SliderAttribute range)
        {
            // Create menu
            GameObject    setting  = CreateSetting(name, description, sliderPrefab, "Label_FOV");
            ConsoleSlider slider   = setting.GetComponent <ConsoleSlider>();
            UILabel       uiLabel  = slider.m_SliderObject.GetComponentInChildren <UILabel>();
            UISlider      uiSlider = slider.m_SliderObject.GetComponentInChildren <UISlider>();

            // Sanitize user values, especially if the field type is int
            bool  isFloat       = IsFloatType(field.FieldType);
            float from          = isFloat ? range.From : Mathf.Round(range.From);
            float to            = isFloat ? range.To : Mathf.Round(range.To);
            int   numberOfSteps = range.NumberOfSteps;

            if (numberOfSteps < 0)
            {
                numberOfSteps = isFloat ? 1 : Mathf.RoundToInt(Mathf.Abs(from - to)) + 1;
            }
            string numberFormat = range.NumberFormat;

            if (string.IsNullOrEmpty(numberFormat))
            {
                numberFormat = isFloat ? SliderAttribute.DefaultFloatFormat : SliderAttribute.DefaultIntFormat;
            }

            // Add listeners to update setting value
            EventDelegate.Callback callback = new Action(() => UpdateSliderValue(modSettings, field, uiSlider, uiLabel, from, to, numberFormat));
            EventDelegate.Set(slider.onChange, callback);
            EventDelegate.Set(uiSlider.onChange, callback);
            modSettings.AddRefreshAction(() => UpdateSlider(modSettings, field, uiSlider, uiLabel, from, to, numberFormat));

            // Set default value and number of steps
            float defaultValue = Convert.ToSingle(field.GetValue(modSettings));

            uiSlider.value         = (defaultValue - from) / (to - from);
            uiSlider.numberOfSteps = numberOfSteps;
            UpdateSliderLabel(field, uiLabel, defaultValue, numberFormat);

            // Control visibility
            SetVisibilityListener(modSettings, field, setting, lastHeader);
        }
示例#2
0
        private void AddChoiceSetting(ModSettingsBase modSettings, FieldInfo field, NameAttribute name, DescriptionAttribute description, ChoiceAttribute choice)
        {
            // Create menu item
            GameObject      setting  = CreateSetting(name, description, comboBoxPrefab, "Label");
            ConsoleComboBox comboBox = setting.GetComponent <ConsoleComboBox>();

            // Add selectable values
            comboBox.items.Clear();
            foreach (string choiceName in choice.Names)
            {
                comboBox.items.Add(choiceName);
            }
            comboBox.m_Localize = choice.Localize;

            // Add listener and set default value
            EventDelegate.Set(comboBox.onChange, new Action(() => UpdateChoiceValue(modSettings, field, comboBox.GetCurrentIndex())));
            modSettings.AddRefreshAction(() => UpdateChoiceComboBox(modSettings, field, comboBox));

            // Control visibility
            SetVisibilityListener(modSettings, field, setting, lastHeader);
        }
        private void AddKeySetting(ModSettingsBase modSettings, FieldInfo field, NameAttribute name, DescriptionAttribute description)
        {
            // Create menu item
            GameObject setting         = CreateSetting(name, description, ObjectPrefabs.KeyEntryPrefab, "Label");
            GameObject keyButtonObject = setting.transform.FindChild("Keybinding_Button").gameObject;

            CustomKeybinding customKeybinding = setting.AddComponent <CustomKeybinding>();

            customKeybinding.keyRebindingButton    = keyButtonObject.GetComponent <KeyRebindingButton>();
            customKeybinding.currentKeycodeSetting = (KeyCode)field.GetValue(modSettings);
            customKeybinding.RefreshLabelValue();

            UIButton uiButton = keyButtonObject.GetComponent <UIButton>();

            EventDelegate.Set(uiButton.onClick, new Action(customKeybinding.OnClick));
            customKeybinding.OnChange = new Action(() => UpdateKeyValue(modSettings, field, customKeybinding));
            modSettings.AddRefreshAction(() => UpdateKeyChoice(modSettings, field, customKeybinding));

            // Control visibility
            SetVisibilityListener(modSettings, field, setting, lastHeader);
        }