public SettingsEntryInterface( ComponentGroup componentGroup, Vector2 position, string name, Type type, object defaultValue, object currentValue, Action <object> applySetting, bool doubleLine = false, bool autoApply = false ) { _type = type; _defaultValue = defaultValue; _applySetting = applySetting; _doubleLine = doubleLine; new TextComponent( componentGroup, position + new Vector2(50, doubleLine ? -20 : 0), new Vector2(TextWidth, doubleLine ? 40 : 30), name, FontManager.UIFontRegular, 18, alignment: TextAnchor.LowerLeft ); if (type == typeof(byte)) { _input = new InputComponent( componentGroup, position - new Vector2(0, 35 + (doubleLine ? 25 : 0)), new Vector2(InputWidth, InputHeight), currentValue.ToString(), "", TextureManager.InputFieldBackground, FontManager.UIFontRegular, 18, InputField.CharacterValidation.Integer ); // TODO: make the constructor parameter "autoApply" work with integer input new TextComponent( componentGroup, position - new Vector2(0, 60 + (doubleLine ? 25 : 0)), new Vector2(InputWidth, 20), "default value: " + defaultValue, FontManager.UIFontRegular, alignment: TextAnchor.MiddleLeft ); } else if (type == typeof(bool)) { if (currentValue is bool currentChecked) { _checkbox = new CheckboxComponent( componentGroup, position - new Vector2(90, 30 + (doubleLine ? 25 : 0)), new Vector2(20, 20), currentChecked, TextureManager.ToggleBackground, TextureManager.Checkmark ); if (autoApply) { _checkbox.SetOnToggle(_ => { ApplySetting(); }); } } new TextComponent( componentGroup, position - new Vector2(-40, 30 + (doubleLine ? 25 : 0)), new Vector2(InputWidth, 20), "default value: " + defaultValue, FontManager.UIFontRegular, alignment: TextAnchor.MiddleLeft ); } else { throw new ArgumentException("Type of object is not supported"); } }
public SettingsEntryInterface( ComponentGroup componentGroup, Vector2 position, string name, Type type, object defaultValue, object currentValue, Action <object> applySetting, bool autoApply = false ) { _type = type; _defaultValue = defaultValue; _applySetting = applySetting; float height; if (type == typeof(byte)) { height = 38f; } else if (type == typeof(bool)) { height = 32f; } else { throw new ArgumentException("Type of object is not supported"); } _text = new TextComponent( componentGroup, position, new Vector2(EntryWidth, height), name, UiManager.NormalFontSize, alignment: TextAnchor.MiddleLeft ); if (type == typeof(byte)) { _input = new InputComponent( componentGroup, position + new Vector2(EntryWidth / 2f - InputWidth / 2f, 0f), new Vector2(InputWidth, InputHeight), currentValue.ToString(), "", TextureManager.InputFieldBg, FontManager.UIFontRegular, UiManager.NormalFontSize, InputField.CharacterValidation.Integer ); if (autoApply) { _input.SetOnChange(_ => { if (_currentInputWaitApplyRoutine != null) { MonoBehaviourUtil.Instance.StopCoroutine(_currentInputWaitApplyRoutine); } _currentInputWaitApplyRoutine = MonoBehaviourUtil.Instance.StartCoroutine(InputWaitApply()); }); } // TODO: make the constructor parameter "autoApply" work with integer input } else if (type == typeof(bool)) { if (currentValue is bool currentChecked) { _checkbox = new CheckboxComponent( componentGroup, position + new Vector2(EntryWidth / 2f - CheckboxSize / 2f, 0f), new Vector2(CheckboxSize, CheckboxSize), currentChecked, TextureManager.InputFieldBg, TextureManager.CheckBoxToggle ); if (autoApply) { _checkbox.SetOnToggle(_ => { ApplySetting(); }); } } } }