Пример #1
0
 /// <summary>
 /// Creates a new MenuItem (either a menu or menu item)
 /// </summary>
 /// <param name="id">Unique ID representing this MenuItem.</param>
 /// <param name="label">The label to be shown on this MenuItem's corresponding button.</param>
 /// <param name="iconPath">Path to the icon to be shown on this MenuItem's corresponding button. If an empty string is provided, no icon will be shown.</param>
 /// <param name="menuItemEventListener">A MenuItemEvent delegate to handle the Click action of this MenuItem's corresponding button.</param>
 public MenuItem(string id, string label, string iconPath, MenuItemEvent menuItemEventListener) : this(id, label, iconPath)
 {
     if (menuItemEventListener != null)
     {
         _menuItemEvent += menuItemEventListener;
     }
 }
 public MenuItem(int itemIndex, string itemText, MenuItemEvent itemEvent)
 {
     Index = itemIndex;
     Text  = itemText;
     Event = itemEvent;
 }
Пример #3
0
 /// <summary>
 /// Removes an event listener from this MenuItem's MenuItemEvent.
 /// </summary>
 /// <param name="menuItemEventListener">The method to remove from this MenuItem's MenuItemEvent.</param>
 public void RemoveMenuItemEventListener(MenuItemEvent menuItemEventListener)
 {
     this._menuItemEvent -= menuItemEventListener;
 }
Пример #4
0
 /// <summary>
 /// Registers another event listener to this MenuItem's MenuItemEvent. This should only be used by the containing TopMenu object.
 /// For logic that depends on the selection made by the user, listen to the events of the NavigationMenu.
 /// </summary>
 /// <param name="menuItemEventListener">The method listening to this MenuItem's MenuItemEvent.</param>
 public void AddMenuItemEventListener(MenuItemEvent menuItemEventListener)
 {
     this._menuItemEvent += menuItemEventListener;
 }
Пример #5
0
 /// <summary>
 /// Creates a new MenuItem (either a menu or menu item)
 /// </summary>
 /// <param name="id">Unique ID representing this MenuItem.</param>
 /// <param name="label">The label to be shown on this MenuItem's corresponding button.</param>
 /// <param name="iconPath">Path to the icon to be shown on this MenuItem's corresponding button. If an empty string is provided, no icon will be shown.</param>
 /// <param name="menuItemEventListener">A MenuItemEvent delegate to handle the Click action of this MenuItem's corresponding button.</param>
 public MenuItem(string id, string label, string iconPath, MenuItemEvent menuItemEventListener) : this(id, label, iconPath)
 {
     if (menuItemEventListener != null)
     {
         this._menuItemEvent += menuItemEventListener;
     }
 }
Пример #6
0
 /// <summary>
 /// Removes an event listener from this MenuItem's MenuItemEvent.
 /// </summary>
 /// <param name="menuItemEventListener">The method to remove from this MenuItem's MenuItemEvent.</param>
 public void RemoveMenuItemEventListener(MenuItemEvent menuItemEventListener)
 {
     _menuItemEvent -= menuItemEventListener;
 }
Пример #7
0
 /// <summary>
 /// Registers another event listener to this MenuItem's MenuItemEvent. This should only be used by the containing TopMenu object.
 /// For logic that depends on the selection made by the user, listen to the events of the NavigationMenu.
 /// </summary>
 /// <param name="menuItemEventListener">The method listening to this MenuItem's MenuItemEvent.</param>
 public void AddMenuItemEventListener(MenuItemEvent menuItemEventListener)
 {
     _menuItemEvent += menuItemEventListener;
 }
Пример #8
0
        public void DataBind(IUserInterface userInterface, MenuItemInfo item)
        {
            m_userInterface = userInterface;
            m_item          = item;

            if (m_item != null)
            {
                m_icon.sprite = m_item.Icon;
                m_text.text   = m_item.Text;
                if (m_item.Data != null && m_item.Data is ColorResource)
                {
                    m_icon.color = ((ColorResource)m_item.Data).Color;
                    m_text.text  = ((ColorResource)m_item.Data).ShortDescription.ToUpper();
                }

                m_icon.gameObject.SetActive(m_item.Icon != null || (m_item.Data != null && m_item.Data is ColorResource));
            }
            else
            {
                m_icon.sprite = null;
                m_icon.gameObject.SetActive(false);
                m_text.text = string.Empty;
            }

            m_item.Validate = new MenuItemValidationEvent();

            if (m_experienceMachine == null)
            {
                m_experienceMachine = IOCCore.Resolve <IExperienceMachine>();
            }
            if (m_appTheme == null)
            {
                m_appTheme = IOCCore.Resolve <IAppTheme>();
            }

            m_item.Validate.AddListener(m_experienceMachine.CanExecuteMenuCommand);
            m_item.Validate.AddListener((args) => args.IsValid = m_item.IsValid);

            var validationResult = IsValid();

            if (validationResult.IsVisible)
            {
                if (m_item.IsValid)
                {
                    m_text.color = overrideColor ? overriddenHighlight : m_appTheme.GetSelectedTheme(m_platform).buttonNormalTextColor;
                }
                else
                {
                    m_text.color = m_appTheme.GetSelectedTheme(m_platform).buttonDisabledTextColor;
                }

                if (m_image != null)
                {
                    if (m_item.IsValid)
                    {
                        m_image.color = m_appTheme.GetSelectedTheme(m_platform).buttonNormalTextColor;
                    }
                    else
                    {
                        m_image.color = m_appTheme.GetSelectedTheme(m_platform).buttonDisabledTextColor;
                    }
                }

                if (!(m_item.Data is ColorResource))
                {
                    //m_item.Action.AddListener(m_experienceMachine.ExecuteMenuCommand);
                    ((Toggle)selectable).onValueChanged.AddListener((val) =>
                    {
                        MenuItemEvent <bool> action = new MenuItemEvent <bool>();
                        action.Invoke(new MenuClickArgs(m_item.Path, m_item.Text, m_item.Command, m_item.CommandType, m_item.Data), val);
                    });
                }
            }

            gameObject.SetActive(validationResult.IsVisible);
            selectable.interactable = validationResult.IsValid;

            m_userInfo = ((UserResource)m_item.Data).UserInfo;

            userId = m_userInfo.id;
            m_selectionToggle.isOn         = false;
            m_selectionToggle.interactable = true;
            //if (m_allowTextScroll)
            //    StartCoroutine(InitializeTextScroll());
        }