private DialogSimpleOption CreateSelectionItem(int i)
        {
            DialogSimpleOption option = Instantiate(m_OptionTemplate).GetComponent <DialogSimpleOption>();

            option.rectTransform.SetParent(m_OptionTemplate.transform.parent);
            option.rectTransform.localScale       = Vector3.one;
            option.rectTransform.localEulerAngles = Vector3.zero;
            option.rectTransform.localPosition    = new Vector3(option.rectTransform.localPosition.x, option.rectTransform.localPosition.y, 0f);

            OptionData data = m_OptionDataList.options[i];

            Text    text    = option.gameObject.GetChildByName <Text>("Text");
            Graphic graphic = option.gameObject.GetChildByName <Graphic>("Icon");

            text.text = data.text;

            if (data.imageData == null)
            {
                text.rectTransform.sizeDelta        = new Vector2(-48f, 0f);
                text.rectTransform.anchoredPosition = new Vector2(0f, 0f);
                Destroy(graphic.gameObject);
            }
            else
            {
                graphic.SetImage(data.imageData);
            }

            option.index          = i;
            option.onClickAction += OnItemClick;

            return(option);
        }
Example #2
0
        /// <summary>
        /// Shows an simple list dialog with an optional title, optional icon, and a required scrollable option list (label-only).
        /// <para></para>
        /// For more customizability, use <see cref="CreateSimpleList"/>.
        /// </summary>
        /// <param name="options">The strings to use for the list item labels.</param>
        /// <param name="onItemClick">Called when an option is selected.</param>
        /// <param name="titleText">The title text. Make null for no title.</param>
        /// <param name="icon">The icon next to the title. Make null for no icon.</param>
        /// <returns>The instance of the initialized, shown dialog.</returns>
        public static DialogSimpleList ShowSimpleList(string[] options, Action <int> onItemClick, string titleText, ImageData icon)
        {
            OptionDataList optionDataList = new OptionDataList();

            for (int i = 0; i < options.Length; i++)
            {
                OptionData optionData = new OptionData(options[i], null);
                optionDataList.options.Add(optionData);
            }

            return(ShowSimpleList(optionDataList, onItemClick, titleText, icon));
        }
Example #3
0
        /// <summary>
        /// Shows an simple list dialog with an optional title, optional icon, and a required scrollable option list (label-only).
        /// <para></para>
        /// For more customizability, use <see cref="CreateSimpleList"/>.
        /// </summary>
        /// <param name="options">The strings to use for the list item labels.</param>
        /// <param name="onItemClick">Called when an option is selected.</param>
        /// <param name="titleText">The title text. Make null for no title.</param>
        /// <param name="icon">The icon next to the title. Make null for no icon.</param>
        /// <returns>The instance of the initialized, shown dialog.</returns>
        public DialogRadioList ShowSimpleList(string[] options, Action <int> onItemClick, string titleText, ImageData icon)
        {
            List <OptionData> optionsData = new List <OptionData>();

            for (int i = 0; i < options.Length; i++)
            {
                OptionData optionData = new OptionData(options[i], null);
                optionsData.Add(optionData);
            }

            return(ShowSimpleList(optionsData.ToArray(), onItemClick, titleText, icon));
        }
 public virtual void Initialize(IList <string> optionsStr, Action <int> onAffirmativeButtonClicked, string affirmativeButtonText, string titleText, ImageData icon, Action onDismissiveButtonClicked, string dismissiveButtonText, int selectedIndexStart, bool allowSwitchOff = false)
 {
     OptionData[] options = new OptionData[optionsStr != null ? optionsStr.Count : 0];
     if (optionsStr != null)
     {
         for (int i = 0; i < optionsStr.Count; i++)
         {
             options[i] = new OptionData(optionsStr[i], null);
         }
     }
     Initialize(options, onAffirmativeButtonClicked, affirmativeButtonText, titleText, icon, onDismissiveButtonClicked, dismissiveButtonText, selectedIndexStart);
 }
Example #5
0
        public void RemoveData(OptionData data)
        {
            var index = options.IndexOf(data);

            if (index >= 0 && index < options.Count)
            {
                options.RemoveAt(index);
            }

            if (selectedIndexes.Contains(index))
            {
                selectedIndexes = Array.FindAll(selectedIndexes, (int value) => { return(value != index); }).ToArray();
            }
        }
Example #6
0
        protected override void ApplyReload(ScrollDataView.ReloadEventArgs oldArgs, ScrollDataView.ReloadEventArgs newArgs)
        {
            BaseDialogList dialog = DataView != null?DataView.GetComponentInParent <BaseDialogList>() : null;

            if (dialog != null)
            {
                OptionData option = Data as OptionData;
                if (m_ItemText != null)
                {
                    m_ItemText.SetGraphicText(option != null ? option.text : "");
                }
                if (m_ItemIcon != null)
                {
                    m_ItemIcon.SetImageData(option != null ? option.imageData : null);
                    //m_ItemIcon.gameObject.SetActive(m_ItemIcon.GetImageData() != null && m_ItemIcon.GetImageData().ContainsData(true));
                }
            }
        }
Example #7
0
        public void RemoveData(OptionData data)
        {
            options.Remove(data);

            selectedIndex = Mathf.Clamp(selectedIndex, 0, options.Count - 1);
        }
Example #8
0
 public void AddData(OptionData data)
 {
     options.Add(data);
 }
Example #9
0
        /// <summary>
        /// Removes an OptionData from the dropdown data list.
        /// Will not remove the item from the scene if the dropdown is open, so it's recommended to only call this while the list is closed.
        /// </summary>
        /// <param name="data">The data to remove from the list.</param>
        public void RemoveData(OptionData data)
        {
            m_OptionDataList.options.Remove(data);

            m_CurrentlySelected = Mathf.Clamp(m_CurrentlySelected, 0, m_OptionDataList.options.Count - 1);
        }
Example #10
0
 /// <summary>
 /// Adds an OptionData to the dropdown data list.
 /// Will not add an item to the scene if the dropdown is already expanded, but will add the item upon next expansion.
 /// </summary>
 /// <param name="data">The data to add to the list.</param>
 public void AddData(OptionData data)
 {
     m_OptionDataList.options.Add(data);
 }
Example #11
0
        /// <summary>
        /// Creates a single dropdown item and adds it to the dropdown list object in the scene.
        /// </summary>
        /// <param name="data">The data of the item.</param>
        /// <param name="index">The index of the item.</param>
        /// <returns>The instantiated DropdownListItem.</returns>
        private DropdownListItem CreateItem(OptionData data, int index)
        {
            DropdownListItem item = new DropdownListItem();

            GameObject itemGameObject = Instantiate(m_ListItemTemplate.rectTransform.gameObject);

            item.rectTransform = itemGameObject.GetComponent <RectTransform>();

            item.rectTransform.SetParent(m_ListItemTemplate.rectTransform.parent);
            item.rectTransform.localScale         = Vector3.one;
            item.rectTransform.localEulerAngles   = Vector3.zero;
            item.rectTransform.anchoredPosition3D = Vector3.zero;

            item.canvasGroup = item.rectTransform.GetComponent <CanvasGroup>();
            item.text        = item.rectTransform.GetChildByName <Text>("Text");

            if (m_OptionDataList.imageType == ImageDataType.Sprite)
            {
                item.image = item.rectTransform.GetChildByName <Image>("Icon");
                Destroy(item.rectTransform.GetChildByName <VectorImage>("Icon").gameObject);
            }
            else
            {
                item.image = item.rectTransform.GetChildByName <VectorImage>("Icon");
                Destroy(item.rectTransform.GetChildByName <Image>("Icon").gameObject);
            }

            DropdownTrigger trigger = itemGameObject.GetComponent <DropdownTrigger>();

            trigger.index    = index;
            trigger.dropdown = this;

            if (!string.IsNullOrEmpty(data.text))
            {
                item.text.text = data.text;
            }
            else
            {
                Destroy(item.text.gameObject);
            }

            if (data.imageData != null && data.imageData.ContainsData(true))
            {
                item.image.SetImage(data.imageData);
            }
            else
            {
                Destroy(item.image.gameObject);
            }

            itemGameObject.GetComponent <MaterialRipple>().rippleData = m_ItemRippleData.Copy();

            if (m_HighlightCurrentlySelected && index == m_CurrentlySelected)
            {
                itemGameObject.GetComponent <Image>().color = m_ItemRippleData.Color.WithAlpha(m_ItemRippleData.EndAlpha);
            }

            item.text.color  = m_ItemTextColor;
            item.image.color = m_ItemIconColor;

            item.canvasGroup.alpha = 0f;

            return(item);
        }
 public void AddItem(OptionData data)
 {
     m_OptionDataList.options.Add(data);
     CreateSelectionItem(m_OptionDataList.options.Count - 1);
 }