From 9ac4eb696932015c9eea04cf25fb895c7050e8a7 Mon Sep 17 00:00:00 2001 From: "LARS-LAPTOP2\\larsme" Date: Mon, 27 Mar 2017 12:52:51 +0200 Subject: [PATCH] option to set interactible to false if there are no items to be selected (DropDownList and AutoCompleteComboBox) --- .../Controls/ComboBox/AutoCompleteComboBox.cs | 29 ++++++++++++++++++- Scripts/Controls/ComboBox/DropDownList.cs | 29 ++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs b/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs index fefe5ea..f637406 100644 --- a/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs +++ b/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs @@ -78,7 +78,7 @@ namespace UnityEngine.UI.Extensions public bool interactible { get { return _mainInput.interactable || _arrow_Button.interactable; } - set { + private set { _mainInput.interactable = value; _arrow_Button.interactable = value; if (!value && _isPanelActive) { @@ -87,6 +87,32 @@ namespace UnityEngine.UI.Extensions } } + [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 void Awake() { Initialize(); @@ -215,6 +241,7 @@ namespace UnityEngine.UI.Extensions panelObjects[_panelItems[i]] = itemObjs[i]; } } + interactible = _technicallyInteractible && (AvailableOptions.Count > 0 || _remainInteractableIfEmpty); } /// diff --git a/Scripts/Controls/ComboBox/DropDownList.cs b/Scripts/Controls/ComboBox/DropDownList.cs index 6c0f184..b4bfd33 100644 --- a/Scripts/Controls/ComboBox/DropDownList.cs +++ b/Scripts/Controls/ComboBox/DropDownList.cs @@ -74,7 +74,7 @@ namespace UnityEngine.UI.Extensions public bool interactible { get { return _mainButton.btn.interactable; } - set { + private set { _mainButton.btn.interactable = value; if (!value && _isPanelActive) { ToggleDropdownPanel (false); @@ -82,6 +82,32 @@ namespace UnityEngine.UI.Extensions } } + [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 && (Items.Count > 0 || _remainInteractableIfEmpty); + } + } + + [SerializeField] + private bool _remainInteractableIfEmpty = true; + public bool RemainInteractableIfEmpty + { + get { return _remainInteractableIfEmpty; } + set + { + _remainInteractableIfEmpty = value; + interactible = _technicallyInteractible && (Items.Count > 0 || _remainInteractableIfEmpty); + } + } + + public void Start() { Initialize(); @@ -202,6 +228,7 @@ namespace UnityEngine.UI.Extensions } _panelItems[i].gameobject.SetActive(i < Items.Count);// if we have more thanks in the panel than Items in the list hide them } + interactible = _technicallyInteractible && (Items.Count > 0 || _remainInteractableIfEmpty); } private void OnItemClicked(int indx)