diff --git a/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs b/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs index 41642f0..a406129 100644 --- a/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs +++ b/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs @@ -15,8 +15,6 @@ namespace UnityEngine.UI.Extensions public List AvailableOptions; - public System.Action OnSelectionChanged; // fires when selection is changed; - //private bool isInitialized = false; private bool _isPanelActive = false; private bool _hasDrawnOnce = false; @@ -24,6 +22,7 @@ namespace UnityEngine.UI.Extensions private InputField _mainInput; private RectTransform _inputRT; + private Button _arrow_Button; private RectTransform _rectTransform; @@ -73,11 +72,98 @@ namespace UnityEngine.UI.Extensions RedrawPanel(); } } - + + public bool interactible + { + get { return _mainInput.interactable || _arrow_Button.interactable; } + private set { + _mainInput.interactable = value; + _arrow_Button.interactable = value; + if (!value && _isPanelActive) { + ToggleDropdownPanel (false); + } + } + } + + [SerializeField] + //I couldn't come up with a better name + private bool _technicallyInteractible = true; + public bool TechnicallyInteractible + { + get { return _technicallyInteractible; } + set + { + _technicallyInteractible = value; + interactible = _technicallyInteractible && (AvailableOptions.Count > 0 || _remainInteractableIfEmpty); + } + } + + [SerializeField] + private bool _remainInteractableIfEmpty = true; + public bool RemainInteractableIfEmpty + { + get { return _remainInteractableIfEmpty; } + set + { + _remainInteractableIfEmpty = value; + interactible = _technicallyInteractible && (AvailableOptions.Count > 0 || _remainInteractableIfEmpty); + } + } + + public bool SelectFirstItemOnStart = false; + + [SerializeField] + private bool _ChangeInputTextColorBasedOnMatchingItems = false; + public bool ChangeInputTextColorBasedOnMatchingItems{ + get { return _remainInteractableIfEmpty; } + set + { + _ChangeInputTextColorBasedOnMatchingItems = value; + if (_ChangeInputTextColorBasedOnMatchingItems) { + SetInputTextColor (); + } + } + } + + //TODO design as foldout for Inspector + public Color ValidSelectionTextColor = Color.green; + public Color MatchingItemsRemainingTextColor = Color.black; + public Color NoItemsRemainingTextColor = Color.red; + + private bool _selectionIsValid = false; + + [System.Serializable] + public class SelectionChangedEvent : UnityEngine.Events.UnityEvent { + } + + [System.Serializable] + public class SelectinTextChangedEvent : UnityEngine.Events.UnityEvent { + } + + [System.Serializable] + public class SelectionValidityChangedEvent : UnityEngine.Events.UnityEvent { + } + + // fires when input text is changed; + public SelectinTextChangedEvent OnSelectinTextChanged; + // fires when when an Item gets selected / deselected (including when items are added/removed once this is possible) + public SelectionValidityChangedEvent OnSelectionValidityChanged; + // fires in both cases + public SelectionChangedEvent OnSelectionChanged; + + + public void Awake() { Initialize(); } + public void Start() + { + if (SelectFirstItemOnStart && AvailableOptions.Count > 0) { + ToggleDropdownPanel (false); + OnItemClicked (AvailableOptions [0]); + } + } private bool Initialize() { @@ -88,6 +174,8 @@ namespace UnityEngine.UI.Extensions _inputRT = _rectTransform.FindChild("InputField").GetComponent(); _mainInput = _inputRT.GetComponent(); + _arrow_Button = _rectTransform.FindChild ("ArrowBtn").GetComponent