/// <summary>
        /// Deregister the specified menu item from radio group.
        /// </summary>
        /// <param name="item">Menu item.</param>
        public void Deregister(MenuItem item)
        {
            DebugEx.VerboseFormat("MenuRadioGroup.Deregister(item = {0})", item);

            if (item.radioGroup == this)
            {
                if (mItems.Remove(item))
                {
                    item.radioGroup = null;

                    if (mSelectedItem == item)
                    {
                        if (mItems.Count == 0)
                        {
                            mSelectedItem = null;
                        }
                        else
                        {
                            mSelectedItem = mItems[0];
                        }
                    }
                }
                else
                {
                    DebugEx.ErrorFormat("Failed to deregister item \"{0}\" from radio froup", item.name);
                }
            }
            else
            {
                DebugEx.ErrorFormat("Item \"{0}\" is not registered in this radio group", item.name);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Deregisters the shortcut.
 /// </summary>
 /// <param name="shortcut">Shortcut.</param>
 public void DeregisterShortcut(MenuItem shortcut)
 {
     if (!mShortcuts.Remove(shortcut))
     {
         Debug.LogError("Failed to deregister shortcut for \"" + shortcut.name + "\"");
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="Common.UI.MenuItems.MenuRadioGroup"/> class.
        /// </summary>
        public MenuRadioGroup()
        {
            DebugEx.Verbose("Created MenuRadioGroup object");

            mItems        = new List<MenuItem>();
            mSelectedItem = null;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Deregister the specified menu item from radio group.
        /// </summary>
        /// <param name="item">Menu item.</param>
        public void Deregister(MenuItem item)
        {
            if (item.radioGroup == this)
            {
                if (mItems.Remove(item))
                {
                    item.radioGroup = null;

                    if (mSelectedItem == item)
                    {
                        if (mItems.Count == 0)
                        {
                            mSelectedItem = null;
                        }
                        else
                        {
                            mSelectedItem = mItems[0];
                        }
                    }
                }
                else
                {
                    Debug.LogError("Failed to deregister item \"" + item.name + "\" from radio froup");
                }
            }
            else
            {
                Debug.LogError("Item \"" + item.name + "\" is not registered in this radio group");
            }
        }
        /// <summary>
        /// Register the specified menu item to radio group.
        /// </summary>
        /// <param name="item">Menu item.</param>
        public void Register(MenuItem item)
        {
            DebugEx.VerboseFormat("MenuRadioGroup.Register(item = {0})", item);

            if (item.radioGroup == null)
            {
                mItems.Add(item);

                item.radioGroup = this;

                if (mItems.Count == 1)
                {
                    mSelectedItem = item;
                }
            }
            else
            {
                DebugEx.ErrorFormat("Item \"{0}\" already registered in radio group", item.name);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Registers the shortcut.
 /// </summary>
 /// <param name="shortcut">Shortcut.</param>
 public void RegisterShortcut(MenuItem shortcut)
 {
     mShortcuts.Add(shortcut);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Common.UI.MenuItems.MenuItem"/> class with given text and with
        /// assigning to specified <see cref="Common.TreeNode`1"/> instance.
        /// </summary>
        /// <param name="owner"><see cref="Common.TreeNode`1"/> instance.</param>
        /// <param name="text">Menu item text.</param>
        /// <param name="onClick">Click event handler.</param>
        /// <param name="enabled">Is this menu item enabled or not.</param>
        /// <param name="shortcutHandler">Shortcut handler.</param>
        /// <param name="shortcut">Shortcut.</param>
        /// <param name="radioGroup">Menu radio group.</param>
        public static TreeNode<CustomMenuItem> Create(
                                                        TreeNode<CustomMenuItem> owner
                                                      , string 		             text
                                                      , UnityAction              onClick         = null
                                                      , bool                     enabled         = true
                                                      , IShortcutHandler         shortcutHandler = null
                                                      , string                   shortcut        = null
                                                      , MenuRadioGroup           radioGroup      = null
                                                     )
        {
            DebugEx.VerboseFormat("MenuItem.Create(owner = {0}, text = {1}, onClick = {2}, enabled = {3}, shortcutHandler = {4}, shortcut = {5}, radioGroup = {6})"
                                  , owner
                                  , text
                                  , onClick
                                  , enabled
                                  , shortcutHandler
                                  , shortcut
                                  , radioGroup);

            MenuItem item = new MenuItem(
                                           R.sections.MenuItems.strings.Count // Token ID
                                         , null                               // Token arguments
                                         , text                               // Text
                                         , enabled                            // Enabled
                                         , onClick                            // Click event handler
                                         , shortcutHandler                    // Shortcut handler
                                         , KeyboardInput.FromString(shortcut) // Shortcut
                                         , radioGroup                         // Menu radio group
                                        );

            TreeNode<CustomMenuItem> node = owner.AddChild(item);

            item.mNode = node;

            return node;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Common.UI.MenuItems.MenuRadioGroup"/> class.
 /// </summary>
 public MenuRadioGroup()
 {
     mItems        = new List<MenuItem>();
     mSelectedItem = null;
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Register the specifiedm menu item to radio group.
        /// </summary>
        /// <param name="item">Menu item.</param>
        public void Register(MenuItem item)
        {
            if (item.radioGroup == null)
            {
                mItems.Add(item);

                item.radioGroup = this;

                if (mItems.Count == 1)
                {
                    mSelectedItem = item;
                }
            }
            else
            {
                Debug.LogError("Item \"" + item.name + "\" already registered in radio group");
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Handler for menu item selection.
 /// </summary>
 /// <param name="item">Item.</param>
 public void OnSelectItem(MenuItem item)
 {
     if (item.radioGroup != null)
     {
         item.radioGroup.selectedItem = item;
     }
     else
     {
         Debug.LogError("Unexpected OnSelectItem call");
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Handler for menu item selection.
        /// </summary>
        /// <param name="item">Item.</param>
        public void OnSelectItem(MenuItem item)
        {
            DebugEx.VerboseFormat("PopupMenu.OnSelectItem(item = {0})", item);

            if (item.radioGroup != null)
            {
                item.radioGroup.selectedItem = item;
            }
            else
            {
                DebugEx.Fatal("Unexpected behaviour in PopupMenu.OnSelectItem()");
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Common.UI.MenuItems.MenuItem"/> class with given token ID and with
        /// assigning to specified <see cref="Common.TreeNode`1"/> instance.
        /// </summary>
        /// <param name="owner"><see cref="Common.TreeNode`1"/> instance.</param>
        /// <param name="tokenId">Token ID for translation.</param>
        /// <param name="onClick">Click event handler.</param>
        /// <param name="enabled">Is this menu item enabled or not.</param>
        /// <param name="shortcutHandler">Shortcut handler.</param>
        /// <param name="shortcut">Shortcut.</param>
        /// <param name="radioGroup">Menu radio group.</param>
        public static TreeNode<CustomMenuItem> Create(
													    TreeNode<CustomMenuItem>     owner
													  , R.sections.MenuItems.strings tokenId
													  , UnityAction                  onClick         = null
													  , bool                         enabled         = true
												      , IShortcutHandler             shortcutHandler = null
													  , string                       shortcut        = null
													  , MenuRadioGroup               radioGroup      = null
													 )
        {
            MenuItem item = new MenuItem(
                                           tokenId                            // Token ID
                                         , null                               // Token arguments
                                         , null                               // Text
                                         , enabled                            // Enabled
                                         , onClick                            // Click event handler
                                         , shortcutHandler    			      // Shortcut handler
                                     	 , KeyboardInput.FromString(shortcut) // Shortcut
                                 		 , radioGroup                         // Menu radio group
                                        );

            TreeNode<CustomMenuItem> node = owner.AddChild(item);

            item.mNode = node;

            return node;
        }