Exemplo n.º 1
0
	protected void AddInsertMenuItems(ref CtxMenu.Item[] items)
	{
		int inserts = 0;
		
		if (items != null)
		{
			for (int idx=0; idx < items.Length; idx++)
			{
				if (items[idx].isSelected)
				{
					items[idx].isSelected = false;
					CtxMenu.Item newItem = new CtxMenu.Item();
					newItem.id = NextHighestItemID(ref items);
					ArrayUtility.Insert<CtxMenu.Item>(ref items, idx, newItem);
					++inserts;
				}
			}
		}

		if (inserts == 0)
		{
			CtxMenu.Item newItem = new CtxMenu.Item();
			newItem.id = NextHighestItemID(ref items);
			if (items == null)
			{
				items = new CtxMenu.Item[1];
				items[0] = newItem;
			}
			else
				ArrayUtility.Add<CtxMenu.Item>(ref items, newItem);
		}
	}
Exemplo n.º 2
0
    public static void AddMenuBar()
    {
        GameObject gameObj = NGUIMenu.SelectedRoot();

        if (gameObj != null)
        {
            EditorUtility.SetDirty(gameObj);

            GameObject ctxMenuObj = new GameObject("MenuBar");
            ctxMenuObj.layer = gameObj.layer;

            Transform ct = ctxMenuObj.transform;
            ct.parent        = gameObj.transform;
            ct.localPosition = Vector3.zero;
            ct.localRotation = Quaternion.identity;
            ct.localScale    = Vector3.one;

            CtxMenu ctxMenu = ctxMenuObj.AddComponent <CtxMenu>();
            ctxMenu.menuBar = true;
            ctxMenu.style   = CtxMenu.Style.Horizontal;

            Selection.activeGameObject = ctxMenuObj;

            Undo.RegisterCreatedObjectUndo(ctxMenuObj, "Add a Menu Bar");
        }
    }
Exemplo n.º 3
0
    private void __InitializeContextMenu() {      // IMPROVE use of string
        _ctxObject = gameObject.GetSafeMonoBehaviour<CtxObject>();
        _ctxObject.offsetMenu = true;

        if (_playerFleetMenu == null) {
            _playerFleetMenu = GuiManager.Instance.gameObject.GetSafeMonoBehavioursInChildren<CtxMenu>().Single(menu => menu.gameObject.name == "PlayerFleetMenu");

            // NOTE: Cannot set CtxMenu.items from here as CtxMenu.Awake sets defaultItems = items (null) before I can set items programmatically.
            // Accordingly, the work around is to either use the editor to set the items, or have every CtxObject set their menuItems programmatically.
            // I've chosen to use the editor for now, and to verify my editor settings from here using ValidateShipMenuItems()
            var desiredfleetMenuItems = new CtxMenu.Item[_playerFleetMenuOrders.Length];
            for (int i = 0; i < _playerFleetMenuOrders.Length; i++) {
                var item = new CtxMenu.Item();
                item.text = _playerFleetMenuOrders[i].GetValueName();    // IMPROVE GetDescription would be better for the context menu display
                item.id = i;
                desiredfleetMenuItems[i] = item;
            }
            var editorPopulatedMenuItems = _playerFleetMenu.items;
            ValidateMenuItems(editorPopulatedMenuItems, desiredfleetMenuItems);

            _lowestUnusedItemId = _playerFleetMenu.items.Length;
        }

        _ctxObject.contextMenu = _playerFleetMenu;
        D.Assert(_ctxObject.contextMenu != null, "{0}.contextMenu on {1} is null.".Inject(typeof(CtxObject).Name, Presenter.FullName));

        EventDelegate.Add(_ctxObject.onShow, OnContextMenuShow);
        EventDelegate.Add(_ctxObject.onSelection, OnContextMenuSelection);
        EventDelegate.Add(_ctxObject.onHide, OnContextMenuHide);
    }
Exemplo n.º 4
0
    /// <summary>
    /// Computes a menu position that will avoid obscuring a hierarchy
    /// of NGUI UI widgets.
    /// </summary>
    /// <returns>
    /// The menu position.
    /// </returns>
    /// <param name='menu'>
    /// The Context Menu.
    /// </param>
    /// <param name='uiObject'>
    /// The game object that is the parent for one or more NGUI UI widgets.
    /// </param>
    public static Vector3 ComputeMenuPosition(CtxMenu menu, GameObject uiObject)
    {
        Bounds   bounds = NGUIMath.CalculateAbsoluteWidgetBounds(uiObject.transform);
        UICamera uiCam  = UICamera.FindCameraForLayer(uiObject.layer);
        Rect     rect   = ComputeScreenSpaceBounds(bounds, uiCam.cachedCamera);

        return(ComputeMenuPosition(menu, rect, true));
    }
Exemplo n.º 5
0
    public override void OnInspectorGUI()
    {
        menuButton = target as CtxMenuButton;

        EditorGUIUtility.labelWidth = 120f;

        CtxMenu contextMenu = (CtxMenu)EditorGUILayout.ObjectField("Context Menu", menuButton.contextMenu,
                                                                   typeof(CtxMenu), true);

        if (menuButton.contextMenu != contextMenu)
        {
            RegisterUndo();
            menuButton.contextMenu = contextMenu;
        }

        int sel = EditorGUILayout.IntField("Selected Item", menuButton.selectedItem);

        if (menuButton.selectedItem != sel)
        {
            RegisterUndo();
            menuButton.selectedItem = sel;
        }

        UILabel label = (UILabel)EditorGUILayout.ObjectField("Current Item Label", menuButton.currentItemLabel, typeof(UILabel), true);

        if (menuButton.currentItemLabel != label)
        {
            RegisterUndo();
            menuButton.currentItemLabel = label;
        }

        UISprite icon = (UISprite)EditorGUILayout.ObjectField("Current Item Icon", menuButton.currentItemIcon, typeof(UISprite), true);

        if (menuButton.currentItemIcon != icon)
        {
            RegisterUndo();
            menuButton.currentItemIcon = icon;
        }

        NGUIEditorTools.DrawEvents("On Selection", menuButton, menuButton.onSelection);
        NGUIEditorTools.DrawEvents("On Show", menuButton, menuButton.onShow);
        NGUIEditorTools.DrawEvents("On Hide", menuButton, menuButton.onHide);

        if (menuButton.contextMenu != null)
        {
            EditMenuItemList(ref menuButton.menuItems, menuButton.contextMenu.atlas, true, ref menuButton.isEditingItems);
        }
        else
        {
            EditorGUILayout.HelpBox("You need to reference a context menu for this component to work properly.", MessageType.Warning);
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
Exemplo n.º 6
0
 private void ValidateMenuItems(CtxMenu.Item[] editorPopulatedMenuItems, CtxMenu.Item[] desiredMenuItems) {
     D.Assert(editorPopulatedMenuItems.Length == desiredMenuItems.Length, "Lengths: {0}, {1}.".Inject(editorPopulatedMenuItems.Length, desiredMenuItems.Length));
     for (int i = 0; i < editorPopulatedMenuItems.Length; i++) {
         var editorItem = editorPopulatedMenuItems[i];
         var desiredItem = desiredMenuItems[i];
         D.Assert(editorItem.id == desiredItem.id, "EditorItemID = {0}, DesiredItemID = {1}, Index = {2}.".Inject(editorItem.id, desiredItem.id, i));
         D.Assert(editorItem.text.Equals(desiredItem.text), "EditorItemText = {0}, DesiredItemText = {1}, Index = {2}.".Inject(editorItem.text, desiredItem.text, i));
         //TODO icons, other?
     }
 }
Exemplo n.º 7
0
 protected void DeleteMenuItems(ref CtxMenu.Item[] items) {
     for (int i = 0, cnt = items.Length; i < cnt;) {
         if (items[i].isSelected) {
             ArrayUtility.RemoveAt(ref items, i);
             cnt--;
         }
         else {
             i++;
         }
     }
 }
Exemplo n.º 8
0
    bool IsEditing(Flags flag)
    {
        CtxMenu contextMenu = target as CtxMenu;

        if (contextMenu != null)
        {
            return((contextMenu.editorFlags & ((uint)flag)) != 0);
        }

        return(false);
    }
Exemplo n.º 9
0
 protected int NextHighestItemID(ref CtxMenu.Item[] items) {
     int nextID = -1;
     if (items != null) {
         foreach (CtxMenu.Item item in items) {
             if (item.id > nextID) {
                 nextID = item.id;
             }
         }
     }
     return nextID + 1;
 }
Exemplo n.º 10
0
 public void ShowMenu()
 {
     if (CtxMenu.Visible || CtxMenu.Items.Count <= 0)
     {
         return;
     }
     CtxMenu.Show(this,
                  RightToLeft == RightToLeft.No
                   ? new Point(_menuGlyph.Bounds.Left, _menuGlyph.Bounds.Bottom)
                   : new Point(_menuGlyph.Bounds.Right, _menuGlyph.Bounds.Bottom));
     _menuOpen = true;
 }
Exemplo n.º 11
0
    void SetEditing(Flags flag, bool editing)
    {
        CtxMenu contextMenu = target as CtxMenu;

        if (contextMenu != null)
        {
            if (editing)
            {
                contextMenu.editorFlags |= ((uint)flag);
            }
            else
            {
                contextMenu.editorFlags &= ~((uint)flag);
            }
        }
    }
Exemplo n.º 12
0
    public override void OnInspectorGUI()
    {
        popup = target as CtxPopup;

        EditorGUIUtility.labelWidth = 120f;

        CtxMenu contextMenu = (CtxMenu)EditorGUILayout.ObjectField("Context Menu", popup.contextMenu,
                                                                   typeof(CtxMenu), true);

        if (popup.contextMenu != contextMenu)
        {
            RegisterUndo();
            popup.contextMenu = contextMenu;
        }

        int mouseButton = EditorGUILayout.IntField("Mouse Button", popup.mouseButton);

        if (popup.mouseButton != mouseButton)
        {
            RegisterUndo();
            popup.mouseButton = mouseButton;
        }

        popup.placeAtTouchPosition = EditorGUILayout.Toggle("Place at Touch Pos", popup.placeAtTouchPosition);

        NGUIEditorTools.DrawEvents("On Selection", popup, popup.onSelection);
        NGUIEditorTools.DrawEvents("On Show", popup, popup.onShow);
        NGUIEditorTools.DrawEvents("On Hide", popup, popup.onHide);

        if (popup.contextMenu != null)
        {
            EditMenuItemList(ref popup.menuItems, popup.contextMenu.atlas, true, ref popup.isEditingItems);
        }
        else
        {
            EditorGUILayout.HelpBox("You need to reference a context menu for this component to work properly.", MessageType.Warning);
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
Exemplo n.º 13
0
    public override void OnInspectorGUI()
    {
        contextObject = target as CtxObject;

        EditorGUIUtility.labelWidth = 100f;

        CtxMenu contextMenu = (CtxMenu)EditorGUILayout.ObjectField("Context Menu", contextObject.contextMenu,
                                                                   typeof(CtxMenu), true);

        if (contextObject.contextMenu != contextMenu)
        {
            RegisterUndo();
            contextObject.contextMenu = contextMenu;
        }

        bool offsetMenu = EditorGUILayout.Toggle("Offset Menu", contextObject.offsetMenu);

        if (contextObject.offsetMenu != offsetMenu)
        {
            RegisterUndo();
            contextObject.offsetMenu = offsetMenu;
        }

        NGUIEditorTools.DrawEvents("On Selection", contextObject, contextObject.onSelection);
        NGUIEditorTools.DrawEvents("On Show", contextObject, contextObject.onShow);
        NGUIEditorTools.DrawEvents("On Hide", contextObject, contextObject.onHide);

        if (contextObject.contextMenu != null)
        {
            EditMenuItemList(ref contextObject.menuItems, contextObject.contextMenu.atlas, true, ref contextObject.isEditingItems);
        }
        else
        {
            EditorGUILayout.HelpBox("You need to reference a context menu for this component to work properly.", MessageType.Warning);
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
Exemplo n.º 14
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _items.CollectionChanged -= OnCollectionChanged;
         CtxMenu.ItemClicked      -= OnMenuItemClicked;
         CtxMenu.VisibleChanged   -= OnMenuVisibleChanged;
         foreach (FaTabStripItem item in _items.Cast <FaTabStripItem>().Where(item => item != null && !item.IsDisposed))
         {
             item.Dispose();
         }
         if (CtxMenu != null && !CtxMenu.IsDisposed)
         {
             CtxMenu.Dispose();
         }
         if (_sf != null)
         {
             _sf.Dispose();
         }
     }
     base.Dispose(disposing);
 }
Exemplo n.º 15
0
    /// <summary>
    /// Computes a canonical position for the context menu given its pivot parameter
    /// and a rectangle defining the screen-space position of the context object. This
    /// attempts to position the menu such that it does not obscure the object within
    /// that region (except in the 'Center' case.)
    /// </summary>
    /// <returns>
    /// The menu position in screen space.
    /// </returns>
    /// <param name='menu'>
    /// The context menu.
    /// </param>
    /// <param name='rect'>
    /// The screen-space rectangle that we wish not to obscure.
    /// </param>
    /// <param name='parentIsHorizontal'>
    /// Changes the placement semantics depending on whether or not the parent object
    /// has a horizontal or vertical topology. Horizontal semantics favor positioning
    /// the menu above or below the parent object, while vertical semantics favor
    /// positioning the menu to the left or right of the parent object. This parameter
    /// particularly affects the corner pivots (i.e. TopLeft, BottomRight, etc.)
    /// </param>
    public static Vector3 ComputeMenuPosition(CtxMenu menu, Rect rect, bool parentIsHorizontal)
    {
        Vector3 resultPt = Vector3.zero;

        if (parentIsHorizontal)
        {
            // Horizontal semantics favor positioning the menu above or
            // below the parent object. This particularly affects the corner
            // pivots (i.e. TopLeft, BottomRight, etc.)
            switch (menu.pivot)
            {
            case UIWidget.Pivot.TopLeft:
                resultPt = new Vector3(rect.xMin, rect.yMin, 0f);
                break;

            case UIWidget.Pivot.Top:
                resultPt = new Vector3(rect.center.x, rect.yMin, 0f);
                break;

            case UIWidget.Pivot.TopRight:
                resultPt = new Vector3(rect.xMax, rect.yMin, 0f);
                break;

            case UIWidget.Pivot.Left:
                resultPt = new Vector3(rect.xMax, rect.center.y, 0f);
                break;

            case UIWidget.Pivot.Center:
                resultPt = new Vector3(rect.center.x, rect.center.y, 0f);
                break;

            case UIWidget.Pivot.Right:
                resultPt = new Vector3(rect.xMin, rect.center.y, 0f);
                break;

            case UIWidget.Pivot.BottomLeft:
                resultPt = new Vector3(rect.xMin, rect.yMax, 0f);
                break;

            case UIWidget.Pivot.Bottom:
                resultPt = new Vector3(rect.center.x, rect.yMax, 0f);
                break;

            case UIWidget.Pivot.BottomRight:
                resultPt = new Vector3(rect.xMax, rect.yMax, 0f);
                break;
            }
        }
        else
        {
            // Vertical semantics favor positioning the menu to the left or
            // right of the parent object. This particularly affects the corner
            // pivots (i.e. TopLeft, BottomRight, etc.)
            switch (menu.pivot)
            {
            case UIWidget.Pivot.TopLeft:
                resultPt = new Vector3(rect.xMax, rect.yMax, 0f);
                break;

            case UIWidget.Pivot.Top:
                resultPt = new Vector3(rect.center.x, rect.yMin, 0f);
                break;

            case UIWidget.Pivot.TopRight:
                resultPt = new Vector3(rect.xMin, rect.yMax, 0f);
                break;

            case UIWidget.Pivot.Left:
                resultPt = new Vector3(rect.xMax, rect.center.y, 0f);
                break;

            case UIWidget.Pivot.Center:
                resultPt = new Vector3(rect.center.x, rect.center.y, 0f);
                break;

            case UIWidget.Pivot.Right:
                resultPt = new Vector3(rect.xMin, rect.center.y, 0f);
                break;

            case UIWidget.Pivot.BottomLeft:
                resultPt = new Vector3(rect.xMax, rect.yMin, 0f);
                break;

            case UIWidget.Pivot.Bottom:
                resultPt = new Vector3(rect.center.x, rect.yMax, 0f);
                break;

            case UIWidget.Pivot.BottomRight:
                resultPt = new Vector3(rect.xMin, rect.yMin, 0f);
                break;
            }
        }

        return(resultPt);
    }
Exemplo n.º 16
0
	protected int SelectedItemCount(ref CtxMenu.Item[] items)
	{
		int result = 0;
		
		foreach (CtxMenu.Item item in items)
		{
			if (item.isSelected)
				++result;
		}
		
		return result;
	}
Exemplo n.º 17
0
	protected void EditMenuItemList(ref CtxMenu.Item[] menuItems, UIAtlas atlas, bool showHelp, ref bool editItems)
	{
		EditorGUILayout.BeginHorizontal();
		editItems = EditorGUILayout.Foldout(editItems, "Menu Items:");
		
		if (editItems)
		{
			if (GUILayout.Button("+", GUILayout.Width(50f)))
			{
				RegisterUndo();
				AddInsertMenuItems(ref menuItems);
				EditorUtility.SetDirty(target);
			}
			
			if (GUILayout.Button("-", GUILayout.Width(50f)))
			{
				if (SelectedItemCount(ref menuItems) > 0)
				{
					RegisterUndo();
					DeleteMenuItems(ref menuItems);
					EditorUtility.SetDirty(target);
				}
			}
		}
		
		EditorGUILayout.EndHorizontal();
		EditorGUILayout.Space();
		
		if (editItems)
		{
			if (menuItems == null || menuItems.Length == 0)
			{
				if (showHelp)
				{
					string help = "Use the + button above to add items to this list.";
					if (! (target is CtxMenu))
						help += "If you don't add items here, then the items in the context menu itself will be used.";
						
					EditorGUILayout.HelpBox(help, MessageType.Info);
				}
			}
			else
			{
				for (int i=0, cnt=menuItems.Length; i<cnt; i++)
					EditMenuItem(menuItems[i], atlas);

				if (showHelp)
				{
					EditorGUILayout.HelpBox("To delete menu items you must first select the item you wish "+
						"to delete using the checkbox next to the Style option, then use the '-' button. You "+
						"may also insert a new item before an existing item by selecting that item's checkbox "+
						"and then using the '+' button.", MessageType.Info);
				}
			}
		}
	}
Exemplo n.º 18
0
    /// <summary>
    /// Computes a canonical position for the context menu given its pivot parameter
    /// and a rectangle defining the screen-space position of the context object. This
    /// attempts to position the menu such that it does not obscure the object within
    /// that region (except in the 'Center' case.)
    /// </summary>
    /// <param name="menu">The context menu.</param>
    /// <param name="rect">The screen-space rectangle that we wish not to obscure.</param>
    /// <param name="parentIsHorizontal">Changes the placement semantics depending on whether or not the parent object
    /// has a horizontal or vertical topology. Horizontal semantics favor positioning
    /// the menu above or below the parent object, while vertical semantics favor
    /// positioning the menu to the left or right of the parent object. This parameter
    /// particularly affects the corner pivots (i.e. TopLeft, BottomRight, etc.)</param>
    /// <returns>
    /// The menu position in screen space.
    /// </returns>
    public static Vector3 ComputeMenuPosition(CtxMenu menu, Rect rect, bool parentIsHorizontal) {
        Vector3 resultPt = Vector3.zero;

        if (parentIsHorizontal) {
            // Horizontal semantics favor positioning the menu above or
            // below the parent object. This particularly affects the corner
            // pivots (i.e. TopLeft, BottomRight, etc.)
            switch (menu.pivot) {
                case UIWidget.Pivot.TopLeft:
                    resultPt = new Vector3(rect.xMin, rect.yMin, 0f);
                    break;
                case UIWidget.Pivot.Top:
                    resultPt = new Vector3(rect.center.x, rect.yMin, 0f);
                    break;
                case UIWidget.Pivot.TopRight:
                    resultPt = new Vector3(rect.xMax, rect.yMin, 0f);
                    break;
                case UIWidget.Pivot.Left:
                    resultPt = new Vector3(rect.xMax, rect.center.y, 0f);
                    break;
                case UIWidget.Pivot.Center:
                    resultPt = new Vector3(rect.center.x, rect.center.y, 0f);
                    break;
                case UIWidget.Pivot.Right:
                    resultPt = new Vector3(rect.xMin, rect.center.y, 0f);
                    break;
                case UIWidget.Pivot.BottomLeft:
                    resultPt = new Vector3(rect.xMin, rect.yMax, 0f);
                    break;
                case UIWidget.Pivot.Bottom:
                    resultPt = new Vector3(rect.center.x, rect.yMax, 0f);
                    break;
                case UIWidget.Pivot.BottomRight:
                    resultPt = new Vector3(rect.xMax, rect.yMax, 0f);
                    break;
            }
        }
        else {
            // Vertical semantics favor positioning the menu to the left or
            // right of the parent object. This particularly affects the corner
            // pivots (i.e. TopLeft, BottomRight, etc.)
            switch (menu.pivot) {
                case UIWidget.Pivot.TopLeft:
                    resultPt = new Vector3(rect.xMax, rect.yMax, 0f);
                    break;
                case UIWidget.Pivot.Top:
                    resultPt = new Vector3(rect.center.x, rect.yMin, 0f);
                    break;
                case UIWidget.Pivot.TopRight:
                    resultPt = new Vector3(rect.xMin, rect.yMax, 0f);
                    break;
                case UIWidget.Pivot.Left:
                    resultPt = new Vector3(rect.xMax, rect.center.y, 0f);
                    break;
                case UIWidget.Pivot.Center:
                    resultPt = new Vector3(rect.center.x, rect.center.y, 0f);
                    break;
                case UIWidget.Pivot.Right:
                    resultPt = new Vector3(rect.xMin, rect.center.y, 0f);
                    break;
                case UIWidget.Pivot.BottomLeft:
                    resultPt = new Vector3(rect.xMax, rect.yMin, 0f);
                    break;
                case UIWidget.Pivot.Bottom:
                    resultPt = new Vector3(rect.center.x, rect.yMax, 0f);
                    break;
                case UIWidget.Pivot.BottomRight:
                    resultPt = new Vector3(rect.xMin, rect.yMin, 0f);
                    break;
            }
        }
        return resultPt;
    }
Exemplo n.º 19
0
    /// <summary>
    /// Retrieve the menu item descriptor with the specified id. If this menu has
    /// submenus, the search will recurse into the child menus after searching all
    /// of the items in the current menu.
    /// </summary>
    /// <param name="itemsArray">The items array.</param>
    /// <param name="id">The menu item id number.</param>
    /// <returns>
    /// The menu item descriptor instance.
    /// </returns>
    public static CtxMenu.Item FindItemRecursively(CtxMenu.Item[] itemsArray, int id) {
        bool hasSubmenus = false;
        foreach (CtxMenu.Item item in itemsArray) {
            if (item.id == id) {
                return item;
            }

            if (item.submenu) {
                hasSubmenus = true;
            }
        }
        if (hasSubmenus) {
            foreach (CtxMenu.Item item in itemsArray) {
                if (item.submenu != null) {
                    CtxMenu.Item res = FindItemRecursively(item.submenu.items, id);
                    if (res != null) {
                        return res;
                    }
                }
            }
        }
        return null;
    }
Exemplo n.º 20
0
	bool IsCurrentSubmenu(CtxMenu submenu)
	{
		return (currentSubmenu == submenu);
	}
Exemplo n.º 21
0
 /// <summary>
 /// Retrieve the menu item descriptor with the specified id.
 /// </summary>
 /// <param name="items">The array of items to search.</param>
 /// <param name="id">The menu item id number.</param>
 /// <returns>
 /// The menu item descriptor instance.
 /// </returns>
 public static CtxMenu.Item FindItem(CtxMenu.Item[] items, int id) {
     foreach (CtxMenu.Item item in items) {
         if (item.id == id) {
             return item;
         }
     }
     return null;
 }
Exemplo n.º 22
0
        //safly lets you shutdown the browser

        private void btnMenu_Click(object sender, EventArgs e)
        {
            CtxMenu.Show(MousePosition);
            //opens the contextbrowser menu and opens it on your mouse position
        }
Exemplo n.º 23
0
	void OnSubmenuHide(CtxMenu submenu)
	{
		int submenuIdx = FindItemForSubmenu(submenu);
		if (submenuIdx >= 0)
		{
			itemData[submenuIdx].submenu = null;
			
			if (submenuIdx == index)
				SetHighlight(-1);
		}
		
		if (currentSubmenu == submenu)
		{
			EventDelegate.Remove(currentSubmenu.onSelection, OnSubmenuSelection);	// <-- In case the submenu was hidden with no selection being made.
			currentSubmenu = null;
		}

		if (submenu.parentMenu == this)
			UICamera.selectedObject = gameObject;
	}
Exemplo n.º 24
0
	/// <summary>
	/// Hide this context menu. For menu bars, this does not actually hide the menu bar
	/// itself, it merely closes all submenus and clears the highlight state. If you actually
	/// want to hide a menu bar, call HideMenuBar() instead.
	/// </summary>
	public void Hide()
	{
		if (isHiding)
			return;

		//Debug.Log("Menu "+this+" is hiding");
		
		isHiding = true;
		isShowing = false;
		
		if (parentMenu != null)
		{
			parentMenu.OnSubmenuHide(this);
			parentMenu = null;
		}
		
		HideSubmenu();
		menuBarActive = false;
		
		// Special case handling for menu bars: we don't actually want to delete
		// the menu widgets, but simply clear the current highlight state, as 
		// menu bars are supposed to persist.
		if (menuBar)
		{
			SetHighlight(-1);
			isHiding = false;
		}
		else
		{
			if (menuRoot != null)
			{
				if (isAnimated)
				{
					TweenScale ts = TweenScale.Begin(menuRoot.gameObject, animationDuration, CollapsedScale);
					ts.method = UITweener.Method.EaseOut;
					ts.onFinished.Add(new EventDelegate(OnHideAnimationFinished));
					
					if (hideSound)
						NGUITools.PlaySound(hideSound);
				}
				else
					DestroyMenu();
			}
		}
		
		EventDelegate.Execute(onHide);
	}
Exemplo n.º 25
0
	// Look for the menu item that corresponds to the specified submenu.
	int FindItemForSubmenu(CtxMenu submenu)
	{
		for (int i=0, cnt=items.Length; i < cnt; i++)
		{
			if (itemData[i].submenu == submenu)
				return i;
		}
		
		return -1;
	}
Exemplo n.º 26
0
	CtxMenu.Item FindItemRecursively(GameObject obj, out CtxMenu menu)
	{
		menu = null;
		
		for (int i=0, cnt=items.Length; i < cnt; i++)
		{
			if (itemData[i].background != null)
			{
				if (itemData[i].background.gameObject == obj)
				{
					menu = this;
					return items[i];
				}
			}
			else if (itemData[i].highlight != null)
			{
				if (itemData[i].highlight.gameObject == obj)
				{
					menu = this;
					return items[i];
				}
			}
			
			if (items[i].submenu)
			{
				CtxMenu.Item res = items[i].submenu.FindItemRecursively(obj, out menu);
				if (res != null)
					return res;
			}
		}
		
		return null;
	}
Exemplo n.º 27
0
	// Send the necessary events in response to an item being selected.
	void SendEvent(int id)
	{
		CtxMenu previous = current;
		
		if (onSelection != null)
		{
			current = this;
			selectedItem = id;
			EventDelegate.Execute(onSelection);
		}
		
		current = previous;
	}
Exemplo n.º 28
0
    private void InitializeContextMenu() {    // IMPROVE use of strings
        UnityUtility.ValidateComponentPresence<Collider>(gameObject);
        _ctxObject = gameObject.GetSafeMonoBehaviour<CtxObject>();
        _ctxObject.offsetMenu = true;

        if (_shipMenu == null) {
            _shipMenu = GuiManager.Instance.gameObject.GetSafeMonoBehavioursInChildren<CtxMenu>()
                .Single(menu => menu.gameObject.name.Equals("ShipMenu"));

            // NOTE: Cannot set CtxMenu.items from here as CtxMenu.Awake sets defaultItems = items (null) before I can set items programmatically.
            // Accordingly, the work around is to either use the editor to set the items, or have every CtxObject set their menuItems programmatically.
            // I've chosen to use the editor for now, and to verify my editor settings from here using ValidateShipMenuItems()
            var desiredShipMenuItems = new CtxMenu.Item[_shipMenuOrders.Length];
            for (int i = 0; i < _shipMenuOrders.Length; i++) {
                var item = new CtxMenu.Item();
                item.text = _shipMenuOrders[i].GetValueName();    // IMPROVE GetDescription would be better for the context menu display
                item.id = i;
                desiredShipMenuItems[i] = item;
            }
            var editorPopulatedShipMenuItems = _shipMenu.items;
            ValidateShipMenuItems(editorPopulatedShipMenuItems, desiredShipMenuItems);

            _lowestUnusedItemId = _shipMenu.items.Length;
        }
        if (_subMenuLookup == null) {
            _subMenuLookup = new Dictionary<ShipDirective, CtxMenu>(_shipMenuOrders.Length);
            var availableSubMenus = GuiManager.Instance.gameObject.GetSafeMonoBehavioursInChildren<CtxMenu>()
                .Where(menu => menu.gameObject.name.Equals("SubMenu")).ToArray();
            D.Assert(_shipMenuOrders.Length <= availableSubMenus.Length);
            for (int i = 0; i < _shipMenuOrders.Length; i++) {
                _subMenuLookup.Add(_shipMenuOrders[i], availableSubMenus[i]);
            }
        }
        if (_subMenuOrderLookup == null) {
            _subMenuOrderLookup = new Dictionary<ValueRange<int>, ShipDirective>();
        }
        if (_joinableFleetLookup == null) {
            _joinableFleetLookup = new Dictionary<int, FleetCmdModel>();
        }
        if (_disbandRefitBaseLookup == null) {
            _disbandRefitBaseLookup = new Dictionary<int, AUnitBaseCmdModel>();
        }

        _ctxObject.contextMenu = _shipMenu;

        EventDelegate.Add(_ctxObject.onShow, OnContextMenuShow);
        EventDelegate.Add(_ctxObject.onSelection, OnContextMenuSelection);
        EventDelegate.Add(_ctxObject.onHide, OnContextMenuHide);
    }
Exemplo n.º 29
0
 /// <summary>
 /// Retrieve the name of the icon sprite displayed by this menu item.
 /// </summary>
 /// <param name="items">The array of items to search.</param>
 /// <param name="id">The menu item id number.</param>
 /// <returns>
 /// The icon sprite name.
 /// </returns>
 public static string GetIcon(CtxMenu.Item[] items, int id) {
     CtxMenu.Item item = FindItemRecursively(items, id);
     if (item != null) {
         return item.icon;
     }
     return null;
 }
Exemplo n.º 30
0
	void HideSubmenu()
	{
		if (currentSubmenu != null)
		{
			int submenuIdx = FindItemForSubmenu(currentSubmenu);
			if (submenuIdx >= 0)
				itemData[submenuIdx].submenu = null;
			
			currentSubmenu.Hide();
			currentSubmenu = null;
		}
	}
Exemplo n.º 31
0
    /// <summary>
    /// Uncheck all but the specified item in a mutex group. This is a recursive
    /// process due to the fact that the item and/or mutex group may not be in the
    /// root menu.
    /// </summary>
    /// <param name="itemsArray">The items array.</param>
    /// <param name="id">The identifier.</param>
    /// <param name="mutexGroup">The mutex group.</param>
    /// <returns></returns>
    public static bool MutexItems(CtxMenu.Item[] itemsArray, int id, int mutexGroup) {
        bool hasSubmenus = false;
        foreach (CtxMenu.Item item in itemsArray) {
            if (item.id == id) {
                UncheckMutexItems(itemsArray, id, mutexGroup);
                return true;
            }

            if (item.submenu) {
                hasSubmenus = true;
            }
        }
        if (hasSubmenus) {
            foreach (CtxMenu.Item item in itemsArray) {
                if (item.submenu != null) {
                    if (MutexItems(item.submenu.items, id, mutexGroup)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
Exemplo n.º 32
0
 /// <summary>
 /// Computes a menu position that will avoid obscuring a hierarchy
 /// of NGUI UI widgets.
 /// </summary>
 /// <param name="menu">The Context Menu.</param>
 /// <param name="uiObject">The game object that is the parent for one or more NGUI UI widgets.</param>
 /// <returns>
 /// The menu position.
 /// </returns>
 public static Vector3 ComputeMenuPosition(CtxMenu menu, GameObject uiObject) {
     Bounds bounds = NGUIMath.CalculateAbsoluteWidgetBounds(uiObject.transform);
     UICamera uiCam = UICamera.FindCameraForLayer(uiObject.layer);
     Rect rect = ComputeScreenSpaceBounds(bounds, uiCam.cachedCamera);
     return ComputeMenuPosition(menu, rect, true);
 }
Exemplo n.º 33
0
 /// <summary>
 /// Unchecks the items in the same mutex group.
 /// </summary>
 /// <param name="itemsArray">Items array.</param>
 /// <param name="id">Identifier.</param>
 /// <param name="mutexGroup">Mutex group.</param>
 public static void UncheckMutexItems(CtxMenu.Item[] itemsArray, int id, int mutexGroup) {
     foreach (CtxMenu.Item item in itemsArray) {
         if (item.id != id && item.mutexGroup == mutexGroup) {
             item.isChecked = false;
         }
     }
 }
Exemplo n.º 34
0
 /// <summary>
 /// Sets the checkmark state for the specified menu item. Note that this flag
 /// will be ignored if the item didn't originally have its 'checkable' flag set.
 /// If this item is part of a mutex group, then the other items in the group
 /// will be unchecked when this item is checked.
 /// </summary>
 /// <param name="items">The array of items to search.</param>
 /// <param name="id">The menu item id number.</param>
 /// <param name="isChecked">The desired checkmark state.</param>
 public static void SetChecked(CtxMenu.Item[] items, int id, bool isChecked) {
     CtxMenu.Item item = FindItemRecursively(items, id);
     if (item != null && item.isCheckable) {
         item.isChecked = isChecked;
         if (item.mutexGroup >= 0) {
             MutexItems(items, id, item.mutexGroup);
         }
     }
 }
Exemplo n.º 35
0
	protected void EditMenuItem(CtxMenu.Item item, UIAtlas atlas)
	{
		if (item == null)
			return;
		
		GUILayoutOption[] itemSpriteOpt = { GUILayout.Height(16f), GUILayout.Width(140f) };
		GUILayoutOption[] itemSpriteDelOpt = { GUILayout.Height(16f), GUILayout.Width(60f) };
		
		Color normalColor, disabledColor;
		
		Rect box = EditorGUILayout.BeginVertical();
		GUILayout.Space(4f);
		GUI.Box(box, "");
		
		EditorGUILayout.BeginHorizontal();
		item.isSelected = EditorGUILayout.Toggle(item.isSelected, GUILayout.Width(12f));
		
		EditorGUIUtility.labelWidth = 64f;
		CtxMenu.ItemStyle itemStyle = (CtxMenu.ItemStyle)EditorGUILayout.EnumMaskField("Style", item.style,
			GUILayout.Width(188f));
		
		if (item.style != itemStyle)
		{
			RegisterUndo();
			
			bool wasSubmenu = item.isSubmenu;
			
			item.style = itemStyle;
			
			if (item.isSubmenu && ! wasSubmenu)
				item.id = -1;
		}
		
		if (item.isCheckable)
		{
			EditorGUIUtility.labelWidth = 44f;
			int mutexGroup = EditorGUILayout.IntField("Mutex", item.mutexGroup, GUILayout.Width(88f));
			if (mutexGroup != item.mutexGroup)
			{
				RegisterUndo();
				item.mutexGroup = mutexGroup;
			}
		}
		 
		EditorGUIUtility.labelWidth = 80f;
		EditorGUILayout.EndHorizontal();

		if ((item.style & CtxMenu.ItemStyle.Separator) != (CtxMenu.ItemStyle)0)
			item.id = -1;
		else
		{
			EditorGUILayout.BeginHorizontal();
			string text = EditorGUILayout.TextField("    Text", item.text, GUILayout.Width(204f));
			if (item.text != text)
			{
				RegisterUndo();
				item.text = text;
			}
		
			EditorGUIUtility.labelWidth = 32f;
			GUILayout.Space(12f);
			int itemId = EditorGUILayout.IntField("ID", item.id, GUILayout.Width(76f));
			if (item.id != itemId)
			{
				RegisterUndo();
				item.id = itemId;
			}
			EditorGUIUtility.labelWidth = 80f;
			
			EditorGUILayout.EndHorizontal();

			EditorGUILayout.BeginHorizontal();
			GUILayout.Label("    Icon", GUILayout.Width(76f));
	
			string iconTitle = item.icon;
			if (string.IsNullOrEmpty(iconTitle))
				iconTitle = "...";
			
			if (GUILayout.Button(iconTitle, itemSpriteOpt))
			{
				currentItem = item;
				NGUISettings.atlas = atlas;
				SpriteSelector.Show(OnItemIcon);
			}

			GUILayout.Space(12f);
			if (GUILayout.Button("None", itemSpriteDelOpt))
			{
				if (! string.IsNullOrEmpty(item.icon))
					RegisterUndo();
				
				item.icon = "";
			}
			
			EditorGUILayout.EndHorizontal();
			
			if (! string.IsNullOrEmpty(item.icon))
			{
				EditorGUILayout.BeginHorizontal();
				normalColor = EditorGUILayout.ColorField("    Normal", item.spriteColor, GUILayout.Width(140f));
				if (normalColor != item.spriteColor)
				{
					RegisterUndo();
					item.spriteColor = normalColor;
				}
				GUILayout.Space(32f);
				disabledColor = EditorGUILayout.ColorField("Disabled", item.spriteColorDisabled, GUILayout.Width(140f));
				if (item.spriteColorDisabled != disabledColor)
				{
					RegisterUndo();
					item.spriteColorDisabled = disabledColor;
				}
				EditorGUILayout.EndHorizontal();
			}
			
			if (item.isSubmenu)
			{
				CtxMenu submenu = (CtxMenu)EditorGUILayout.ObjectField("    Submenu", item.submenu, typeof(CtxMenu), true, GUILayout.Width(317f));
				if (item.submenu != submenu)
				{
					RegisterUndo();
					item.submenu = submenu;
				}
				
				if (submenu != null)
					EditMenuItemList(ref item.submenuItems, submenu.atlas, false, ref item.isEditingItems);
			}
		}
		
		GUILayout.Space(4f);
		EditorGUILayout.EndVertical();
		GUILayout.Space(4f);
	}
Exemplo n.º 36
0
 /// <summary>
 /// Determines whether the specified menu item is disabled.
 /// </summary>
 /// <param name="items">The array of items to search.</param>
 /// <param name="id">The menu item id number.</param>
 /// <returns>
 ///   <c>true</c> if the specified menu item is disabled; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsDisabled(CtxMenu.Item[] items, int id) {
     CtxMenu.Item item = FindItemRecursively(items, id);
     if (item != null) {
         return item.isDisabled;
     }
     return false;
 }
Exemplo n.º 37
0
    public override void OnInspectorGUI()
    {
        contextMenu = target as CtxMenu;

        EditorGUIUtility.labelWidth = 80f;

        ComponentSelector.Draw <UIAtlas>(contextMenu.atlas, OnSelectAtlas, false, GUILayout.Width(140f));

        //if (NGUIEditorTools.DrawPrefixButton("Atlas"))
        //	ComponentSelector.Show<UIAtlas>(OnSelectAtlas);

        EditorGUILayout.BeginHorizontal();

        CtxMenu.Style style = (CtxMenu.Style)EditorGUILayout.EnumPopup("Style", contextMenu.style, GUILayout.Width(180f));
        if (contextMenu.style != style)
        {
            RegisterUndo();
            contextMenu.style = style;

            if (style == CtxMenu.Style.Pie)
            {
                if (contextMenu.menuBar)
                {
                    contextMenu.menuBar = false;
                    CtxHelper.DestroyAllChildren(contextMenu.transform);

                    UIPanel panel = NGUITools.FindInParents <UIPanel>(contextMenu.gameObject);
                    if (panel != null)
                    {
                        panel.Refresh();
                    }

                    refresh = false;
                }
            }
        }

        if (contextMenu.style != CtxMenu.Style.Pie)
        {
            GUILayout.Space(32f);

            bool menuBar = EditorGUILayout.Toggle("Menu Bar", contextMenu.menuBar);
            if (contextMenu.menuBar != menuBar)
            {
                RegisterUndo();
                contextMenu.menuBar = menuBar;
            }
        }

        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();

        if (contextMenu.style != CtxMenu.Style.Pie)
        {
            UIWidget.Pivot pivot = (UIWidget.Pivot)EditorGUILayout.EnumPopup("Pivot", contextMenu.pivot, GUILayout.Width(180f));
            if (contextMenu.pivot != pivot)
            {
                RegisterUndo();
                contextMenu.pivot = pivot;
            }

            GUILayout.Space(32f);
        }

        bool isLocalized = EditorGUILayout.Toggle("Localized", contextMenu.isLocalized);

        if (contextMenu.isLocalized != isLocalized)
        {
            RegisterUndo();
            contextMenu.isLocalized = isLocalized;
        }

        EditorGUILayout.EndHorizontal();

        Vector2 padding = CompactVector2Field("Padding", contextMenu.padding);          //EditorGUILayout.Vector2Field("Padding", contextMenu.padding);

        if (contextMenu.padding != padding)
        {
            RegisterUndo();
            contextMenu.padding = padding;
        }

        EditorGUIUtility.labelWidth = 100f;

        NGUIEditorTools.DrawEvents("On Selection", contextMenu, contextMenu.onSelection);
        NGUIEditorTools.DrawEvents("On Show", contextMenu, contextMenu.onShow);
        NGUIEditorTools.DrawEvents("On Hide", contextMenu, contextMenu.onHide);

        EditorGUILayout.Space();

        EditorGUIUtility.labelWidth = 80f;

        Rect box = EditorGUILayout.BeginVertical();

        GUI.Box(box, "");

        if (EditorFoldout(Flags.EditBackground, "Background Options:"))
        {
            contextMenu.backgroundSprite = EditSprite(contextMenu.atlas, "Sprite", contextMenu.backgroundSprite, OnBackground);
            Color backgroundColor = EditorGUILayout.ColorField("Normal", contextMenu.backgroundColor);
            if (contextMenu.backgroundColor != backgroundColor)
            {
                RegisterUndo();
                contextMenu.backgroundColor = backgroundColor;
            }

            Color highlightedColor, disabledColor;

            if (contextMenu.style == CtxMenu.Style.Pie)
            {
                highlightedColor = EditorGUILayout.ColorField("Highlighted", contextMenu.backgroundColorSelected);
                if (contextMenu.backgroundColorSelected != highlightedColor)
                {
                    RegisterUndo();
                    contextMenu.backgroundColorSelected = highlightedColor;
                }

                disabledColor = EditorGUILayout.ColorField("Disabled", contextMenu.backgroundColorDisabled);
                if (contextMenu.backgroundColorDisabled != disabledColor)
                {
                    RegisterUndo();
                    contextMenu.backgroundColorDisabled = disabledColor;
                }
            }

            GUILayout.Space(4f);
        }

        EditorGUILayout.EndVertical();
        EditorGUILayout.Space();

        if (contextMenu.style == CtxMenu.Style.Pie)
        {
            EditorGUIUtility.labelWidth = 100f;

            box = EditorGUILayout.BeginVertical();
            GUI.Box(box, "");
            if (EditorFoldout(Flags.EditPie, "Pie Menu Options:"))
            {
                GUILayout.Space(4f);

                float pieRadius = EditorGUILayout.FloatField("Radius", contextMenu.pieRadius);
                if (contextMenu.pieRadius != pieRadius)
                {
                    RegisterUndo();
                    contextMenu.pieRadius = pieRadius;
                }

                float pieStartingAngle = EditorGUILayout.FloatField("Starting Angle", contextMenu.pieStartingAngle);
                if (contextMenu.pieStartingAngle != pieStartingAngle)
                {
                    RegisterUndo();
                    contextMenu.pieStartingAngle = pieStartingAngle;
                }

                float pieArc = EditorGUILayout.FloatField("Placement Arc", contextMenu.pieArc);
                if (contextMenu.pieArc != pieArc)
                {
                    RegisterUndo();
                    contextMenu.pieArc = pieArc;
                }

                bool pieCenterItem = EditorGUILayout.Toggle("Center Items", contextMenu.pieCenterItem);
                if (contextMenu.pieCenterItem != pieCenterItem)
                {
                    RegisterUndo();
                    contextMenu.pieCenterItem = pieCenterItem;
                }

                GUILayout.Space(4f);
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.Space();

            EditorGUIUtility.labelWidth = 80f;
        }
        else
        {
            box = EditorGUILayout.BeginVertical();
            GUI.Box(box, "");
            if (EditorFoldout(Flags.EditHighlight, "Highlight Options:"))
            {
                GUILayout.Space(4f);
                contextMenu.highlightSprite = EditSprite(contextMenu.atlas, "Sprite", contextMenu.highlightSprite, OnHighlight);
                Color highlightColor = EditorGUILayout.ColorField("Color", contextMenu.highlightColor);
                if (contextMenu.highlightColor != highlightColor)
                {
                    RegisterUndo();
                    contextMenu.highlightColor = highlightColor;
                }

                GUILayout.Space(4f);
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.Space();
        }

        box = EditorGUILayout.BeginVertical();
        GUI.Box(box, "");
        if (EditorFoldout(Flags.EditText, "Text Options:"))
        {
            GUILayout.Space(4f);

            ComponentSelector.Draw <UIFont>(contextMenu.font, OnSelectFont, false, GUILayout.Width(140f));

            if (contextMenu.font == null)
            {
                EditorGUILayout.HelpBox("Warning: please select a valid font if you want this menu to behave correctly.", MessageType.Warning);
            }

            float labelScale = EditorGUILayout.FloatField("Scale", contextMenu.labelScale);
            if (contextMenu.labelScale != labelScale)
            {
                RegisterUndo();
                contextMenu.labelScale = labelScale;
            }

            Color normalColor = EditorGUILayout.ColorField("Normal", contextMenu.labelColorNormal);
            if (contextMenu.labelColorNormal != normalColor)
            {
                RegisterUndo();
                contextMenu.labelColorNormal = normalColor;
            }

            Color highlightedColor = EditorGUILayout.ColorField("Highlighted", contextMenu.labelColorSelected);
            if (contextMenu.labelColorSelected != highlightedColor)
            {
                RegisterUndo();
                contextMenu.labelColorSelected = highlightedColor;
            }

            Color disabledColor = EditorGUILayout.ColorField("Disabled", contextMenu.labelColorDisabled);
            if (contextMenu.labelColorDisabled != disabledColor)
            {
                RegisterUndo();
                contextMenu.labelColorDisabled = disabledColor;
            }

            GUILayout.Space(4f);
        }
        EditorGUILayout.EndVertical();
        EditorGUILayout.Space();

        box = EditorGUILayout.BeginVertical();
        GUI.Box(box, "");
        if (EditorFoldout(Flags.EditCheckmark, "Checkmark Options:"))
        {
            GUILayout.Space(4f);
            contextMenu.checkmarkSprite = EditSprite(contextMenu.atlas, "Sprite", contextMenu.checkmarkSprite, OnCheckmark);
            Color checkmarkColor = EditorGUILayout.ColorField("Color", contextMenu.checkmarkColor);
            if (contextMenu.checkmarkColor != checkmarkColor)
            {
                RegisterUndo();
                contextMenu.checkmarkColor = checkmarkColor;
            }

            GUILayout.Space(4f);
        }
        EditorGUILayout.EndVertical();
        EditorGUILayout.Space();

        box = EditorGUILayout.BeginVertical();
        GUI.Box(box, "");
        if (EditorFoldout(Flags.EditSubmenu, "Submenu Options:"))
        {
            GUILayout.Space(4f);

            contextMenu.submenuIndicatorSprite =
                EditSprite(contextMenu.atlas, "Indicator", contextMenu.submenuIndicatorSprite, OnSubmenuIndicator);

            Color submenuIndColor = EditorGUILayout.ColorField("Color", contextMenu.submenuIndicatorColor);
            if (contextMenu.submenuIndicatorColor != submenuIndColor)
            {
                RegisterUndo();
                contextMenu.submenuIndicatorColor = submenuIndColor;
            }

            GUILayout.Space(4f);
        }
        EditorGUILayout.EndVertical();
        EditorGUILayout.Space();

        if (contextMenu.style != CtxMenu.Style.Pie)
        {
            box = EditorGUILayout.BeginVertical();
            GUI.Box(box, "");
            if (EditorFoldout(Flags.EditSeparator, "Separator Options:"))
            {
                GUILayout.Space(4f);
                contextMenu.separatorSprite = EditSprite(contextMenu.atlas, "Sprite", contextMenu.separatorSprite, OnSeparator);
                Color separatorColor = EditorGUILayout.ColorField("Color", contextMenu.separatorColor);
                if (contextMenu.separatorColor != separatorColor)
                {
                    RegisterUndo();
                    contextMenu.separatorColor = separatorColor;
                }

                GUILayout.Space(4f);
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.Space();
        }

        if (!contextMenu.menuBar)
        {
            box = EditorGUILayout.BeginVertical();
            GUI.Box(box, "");

            if (EditorFoldout(Flags.EditAnimation, "Animation Options:"))
            {
                bool isAnimated = EditorGUILayout.Toggle("Animated", contextMenu.isAnimated);
                if (contextMenu.isAnimated != isAnimated)
                {
                    RegisterUndo();
                    contextMenu.isAnimated = isAnimated;
                }

                float animationDuration = EditorGUILayout.FloatField("Duration", contextMenu.animationDuration);
                if (contextMenu.animationDuration != animationDuration)
                {
                    RegisterUndo();
                    contextMenu.animationDuration = animationDuration;
                }

                EditorGUIUtility.labelWidth = 100f;

                CtxMenu.GrowDirection growDirection = (CtxMenu.GrowDirection)EditorGUILayout.EnumPopup("Grow Direction",
                                                                                                       contextMenu.growDirection, GUILayout.Width(192f));

                if (contextMenu.growDirection != growDirection)
                {
                    RegisterUndo();
                    contextMenu.growDirection = growDirection;
                }

                GUILayout.Space(4f);
            }

            EditorGUILayout.EndVertical();
            EditorGUILayout.Space();
        }

        box = EditorGUILayout.BeginVertical();
        GUI.Box(box, "");

        if (EditorFoldout(Flags.EditShadow, "Shadow Options:"))
        {
            contextMenu.shadowSprite = EditSprite(contextMenu.atlas, "Sprite", contextMenu.shadowSprite, OnShadow);
            Color shadowColor = EditorGUILayout.ColorField("Color", contextMenu.shadowColor);
            if (contextMenu.shadowColor != shadowColor)
            {
                RegisterUndo();
                contextMenu.shadowColor = shadowColor;
            }

            Vector2 shadowOffset = CompactVector2Field("Offset", contextMenu.shadowOffset);
            if (shadowOffset != contextMenu.shadowOffset)
            {
                RegisterUndo();
                contextMenu.shadowOffset = shadowOffset;
            }

            Vector2 shadowSizeDelta = CompactVector2Field("Size +/-", contextMenu.shadowSizeDelta);
            if (shadowSizeDelta != contextMenu.shadowSizeDelta)
            {
                RegisterUndo();
                contextMenu.shadowSizeDelta = shadowSizeDelta;
            }

            GUILayout.Space(4f);
        }

        EditorGUILayout.EndVertical();
        EditorGUILayout.Space();

        box = EditorGUILayout.BeginVertical();
        GUI.Box(box, "");
        if (EditorFoldout(Flags.EditAudio, "Audio Options:"))
        {
            GUILayout.Space(4f);

            EditorGUIUtility.labelWidth = 70f;
            EditorGUILayout.BeginHorizontal();

            AudioClip showSound = EditorGUILayout.ObjectField("Show", contextMenu.showSound, typeof(AudioClip), false) as AudioClip;
            if (contextMenu.showSound != showSound)
            {
                RegisterUndo();
                contextMenu.showSound = showSound;
            }
            GUILayout.Space(20f);
            AudioClip hideSound = EditorGUILayout.ObjectField("Hide", contextMenu.hideSound, typeof(AudioClip), false) as AudioClip;
            if (contextMenu.hideSound != hideSound)
            {
                RegisterUndo();
                contextMenu.hideSound = hideSound;
            }

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();

            AudioClip highlightSound = EditorGUILayout.ObjectField("Highlight", contextMenu.highlightSound, typeof(AudioClip), false) as AudioClip;
            if (contextMenu.highlightSound != highlightSound)
            {
                RegisterUndo();
                contextMenu.highlightSound = highlightSound;
            }
            GUILayout.Space(20f);
            AudioClip selectSound = EditorGUILayout.ObjectField("Select", contextMenu.selectSound, typeof(AudioClip), false) as AudioClip;
            if (contextMenu.selectSound != selectSound)
            {
                RegisterUndo();
                contextMenu.selectSound = selectSound;
            }

            EditorGUILayout.EndHorizontal();
            EditorGUIUtility.labelWidth = 100f;

            GUILayout.Space(4f);
        }

        EditorGUILayout.EndVertical();
        EditorGUILayout.Space();

        bool isEditingItems = IsEditing(Flags.EditItems);

        EditMenuItemList(ref contextMenu.items, contextMenu.atlas, true, ref isEditingItems);
        SetEditing(Flags.EditItems, isEditingItems);

        if (refresh)
        {
            if (contextMenu.menuBar)
            {
                contextMenu.Refresh();
            }

            refresh = false;
        }

        // How to tell if undo or redo have been hit:
        else if (contextMenu.menuBar && Event.current.type == EventType.ValidateCommand && (Event.current.commandName == "UndoRedoPerformed"))
        {
            contextMenu.Refresh();
        }
    }
Exemplo n.º 38
0
 /// <summary>
 /// Sets the disabled state for the specified menu item.
 /// </summary>
 /// <param name="items">The array of items to search.</param>
 /// <param name="id">The menu item id number.</param>
 /// <param name="isDisabled">The desired disable state.</param>
 public static void SetDisabled(CtxMenu.Item[] items, int id, bool isDisabled) {
     CtxMenu.Item item = FindItemRecursively(items, id);
     if (item != null) {
         item.isDisabled = isDisabled;
     }
 }
Exemplo n.º 39
0
    protected void EditMenuItem(CtxMenu.Item item, UIAtlas atlas)
    {
        if (item == null)
        {
            return;
        }

        GUILayoutOption[] itemSpriteOpt    = { GUILayout.Height(16f), GUILayout.Width(140f) };
        GUILayoutOption[] itemSpriteDelOpt = { GUILayout.Height(16f), GUILayout.Width(60f) };

        Color normalColor, disabledColor;

        Rect box = EditorGUILayout.BeginVertical();

        GUILayout.Space(4f);
        GUI.Box(box, "");

        EditorGUILayout.BeginHorizontal();
        item.isSelected = EditorGUILayout.Toggle(item.isSelected, GUILayout.Width(12f));

        EditorGUIUtility.labelWidth = 64f;
        CtxMenu.ItemStyle itemStyle = (CtxMenu.ItemStyle)EditorGUILayout.EnumFlagsField("Style", item.style,
                                                                                        GUILayout.Width(188f));

        if (item.style != itemStyle)
        {
            RegisterUndo();

            bool wasSubmenu = item.isSubmenu;

            item.style = itemStyle;

            if (item.isSubmenu && !wasSubmenu)
            {
                item.id = -1;
            }
        }

        if (item.isCheckable)
        {
            EditorGUIUtility.labelWidth = 44f;
            int mutexGroup = EditorGUILayout.IntField("Mutex", item.mutexGroup, GUILayout.Width(88f));
            if (mutexGroup != item.mutexGroup)
            {
                RegisterUndo();
                item.mutexGroup = mutexGroup;
            }
        }

        EditorGUIUtility.labelWidth = 80f;
        EditorGUILayout.EndHorizontal();

        if ((item.style & CtxMenu.ItemStyle.Separator) != (CtxMenu.ItemStyle) 0)
        {
            item.id = -1;
        }
        else
        {
            EditorGUILayout.BeginHorizontal();
            string text = EditorGUILayout.TextField("    Text", item.text, GUILayout.Width(204f));
            if (item.text != text)
            {
                RegisterUndo();
                item.text = text;
            }

            EditorGUIUtility.labelWidth = 32f;
            GUILayout.Space(12f);
            int itemId = EditorGUILayout.IntField("ID", item.id, GUILayout.Width(76f));
            if (item.id != itemId)
            {
                RegisterUndo();
                item.id = itemId;
            }
            EditorGUIUtility.labelWidth = 80f;

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("    Icon", GUILayout.Width(76f));

            string iconTitle = item.icon;
            if (string.IsNullOrEmpty(iconTitle))
            {
                iconTitle = "...";
            }

            if (GUILayout.Button(iconTitle, itemSpriteOpt))
            {
                currentItem        = item;
                NGUISettings.atlas = atlas;
                SpriteSelector.Show(OnItemIcon);
            }

            GUILayout.Space(12f);
            if (GUILayout.Button("None", itemSpriteDelOpt))
            {
                if (!string.IsNullOrEmpty(item.icon))
                {
                    RegisterUndo();
                }

                item.icon = "";
            }

            EditorGUILayout.EndHorizontal();

            if (!string.IsNullOrEmpty(item.icon))
            {
                EditorGUILayout.BeginHorizontal();
                normalColor = EditorGUILayout.ColorField("    Normal", item.spriteColor, GUILayout.Width(140f));
                if (normalColor != item.spriteColor)
                {
                    RegisterUndo();
                    item.spriteColor = normalColor;
                }
                GUILayout.Space(32f);
                disabledColor = EditorGUILayout.ColorField("Disabled", item.spriteColorDisabled, GUILayout.Width(140f));
                if (item.spriteColorDisabled != disabledColor)
                {
                    RegisterUndo();
                    item.spriteColorDisabled = disabledColor;
                }
                EditorGUILayout.EndHorizontal();
            }

            if (item.isSubmenu)
            {
                CtxMenu submenu = (CtxMenu)EditorGUILayout.ObjectField("    Submenu", item.submenu, typeof(CtxMenu), true, GUILayout.Width(317f));
                if (item.submenu != submenu)
                {
                    RegisterUndo();
                    item.submenu = submenu;

#if CTX_NO_SERIALIZATION_FIX
                    if (submenu.items == null || submenu.items.Length == 0)
                    {
                        Debug.Log("Wizzy Submenu Item Transfer Test!!!!");

                        if (item.submenuItems != null && item.submenuItems.Length > 0)
                        {
                            Debug.Log("Wizzy Submenu Item Transfer!!!!");
                            submenu.items     = item.submenuItems;
                            item.submenuItems = null;

                            EditorUtility.SetDirty(submenu);
                            EditorUtility.SetDirty(target);
                        }
                    }
#endif
                }

                if (submenu != null)
#if CTX_NO_SERIALIZATION_FIX
                { EditMenuItemList(ref item.submenuItems, submenu.atlas, false, ref item.isEditingItems); }
#else
                { EditMenuItemList(ref submenu.items, submenu.atlas, false, ref item.isEditingItems); }
#endif
            }
        }

        GUILayout.Space(4f);
        EditorGUILayout.EndVertical();
        GUILayout.Space(4f);
    }
Exemplo n.º 40
0
 /// <summary>
 /// Assigns a new text string to the specified menu item. If this is a localized
 /// menu, you should only assign key strings and allow the localization
 /// logic to update the visible text.
 /// </summary>
 /// <param name="items">The array of items to search.</param>
 /// <param name="id">The menu item id number.</param>
 /// <param name="text">The text that will be displayed for this menu item.</param>
 public static void SetText(CtxMenu.Item[] items, int id, string text) {
     CtxMenu.Item item = FindItemRecursively(items, id);
     if (item != null) {
         item.text = text;
     }
 }
Exemplo n.º 41
0
	public override void OnInspectorGUI()
	{
		contextMenu = target as CtxMenu;
		
		EditorGUIUtility.labelWidth = 80f;
		
		ComponentSelector.Draw<UIAtlas>(contextMenu.atlas, OnSelectAtlas, false, GUILayout.Width(140f));
		
		//if (NGUIEditorTools.DrawPrefixButton("Atlas"))
		//	ComponentSelector.Show<UIAtlas>(OnSelectAtlas);

		EditorGUILayout.BeginHorizontal();
		
		CtxMenu.Style style = (CtxMenu.Style)EditorGUILayout.EnumPopup("Style", contextMenu.style,GUILayout.Width(180f));
		if (contextMenu.style != style)
		{
			RegisterUndo();
			contextMenu.style = style;
			
			if (style == CtxMenu.Style.Pie)
			{
				if (contextMenu.menuBar)
				{
					contextMenu.menuBar = false;
					CtxHelper.DestroyAllChildren(contextMenu.transform);
					
					UIPanel panel = NGUITools.FindInParents<UIPanel>(contextMenu.gameObject);
					if (panel != null)
						panel.Refresh();
					
					refresh = false;
				}
			}
		}
		
		if (contextMenu.style != CtxMenu.Style.Pie)
		{
			GUILayout.Space(32f);
			
			bool menuBar = EditorGUILayout.Toggle("Menu Bar", contextMenu.menuBar);
			if (contextMenu.menuBar != menuBar)
			{
				RegisterUndo();
				contextMenu.menuBar = menuBar;
			}
		}
		
		EditorGUILayout.EndHorizontal();

		EditorGUILayout.BeginHorizontal();
		
		if (contextMenu.style != CtxMenu.Style.Pie)
		{
			UIWidget.Pivot pivot = (UIWidget.Pivot)EditorGUILayout.EnumPopup("Pivot", contextMenu.pivot,GUILayout.Width(180f));
			if (contextMenu.pivot != pivot)
			{
				RegisterUndo();
				contextMenu.pivot = pivot;
			}

			GUILayout.Space(32f);
		}
		
		bool isLocalized = EditorGUILayout.Toggle("Localized", contextMenu.isLocalized);
		if (contextMenu.isLocalized != isLocalized)
		{
			RegisterUndo();
			contextMenu.isLocalized = isLocalized;
		}

		EditorGUILayout.EndHorizontal();

		Vector2 padding = CompactVector2Field("Padding", contextMenu.padding);	//EditorGUILayout.Vector2Field("Padding", contextMenu.padding);
		if (contextMenu.padding != padding)
		{
			RegisterUndo();
			contextMenu.padding = padding;
		}
		
		EditorGUIUtility.labelWidth = 100f;

		NGUIEditorTools.DrawEvents("On Selection", contextMenu, contextMenu.onSelection);
		NGUIEditorTools.DrawEvents("On Show", contextMenu, contextMenu.onShow);
		NGUIEditorTools.DrawEvents("On Hide", contextMenu, contextMenu.onHide);
		
		EditorGUILayout.Space();

		EditorGUIUtility.labelWidth = 80f;
		
		Rect box = EditorGUILayout.BeginVertical();
		GUI.Box(box, "");

		if (EditorFoldout(Flags.EditBackground, "Background Options:"))
		{
			contextMenu.backgroundSprite = EditSprite(contextMenu.atlas, "Sprite", contextMenu.backgroundSprite, OnBackground);
			Color backgroundColor = EditorGUILayout.ColorField("Normal", contextMenu.backgroundColor);
			if (contextMenu.backgroundColor != backgroundColor)
			{
				RegisterUndo();
				contextMenu.backgroundColor = backgroundColor;
			}
			
			Color highlightedColor, disabledColor;
			
			if (contextMenu.style == CtxMenu.Style.Pie)
			{
				highlightedColor = EditorGUILayout.ColorField("Highlighted", contextMenu.backgroundColorSelected);
				if (contextMenu.backgroundColorSelected != highlightedColor)
				{
					RegisterUndo();
					contextMenu.backgroundColorSelected = highlightedColor;
				}
				
				disabledColor = EditorGUILayout.ColorField("Disabled", contextMenu.backgroundColorDisabled);
				if (contextMenu.backgroundColorDisabled != disabledColor)
				{
					RegisterUndo();
					contextMenu.backgroundColorDisabled = disabledColor;
				}
			}
			
			GUILayout.Space(4f);
		}
		
		EditorGUILayout.EndVertical();
		EditorGUILayout.Space();
		
		if (contextMenu.style == CtxMenu.Style.Pie)
		{
			EditorGUIUtility.labelWidth = 100f;
			
			box = EditorGUILayout.BeginVertical();
			GUI.Box(box, "");
			if (EditorFoldout(Flags.EditPie, "Pie Menu Options:"))
			{
				GUILayout.Space(4f);
				
				float pieRadius = EditorGUILayout.FloatField("Radius", contextMenu.pieRadius);
				if (contextMenu.pieRadius != pieRadius)
				{
					RegisterUndo();
					contextMenu.pieRadius = pieRadius;
				}
				
				float pieStartingAngle = EditorGUILayout.FloatField("Starting Angle", contextMenu.pieStartingAngle);
				if (contextMenu.pieStartingAngle != pieStartingAngle)
				{
					RegisterUndo();
					contextMenu.pieStartingAngle = pieStartingAngle;
				}
				
				float pieArc = EditorGUILayout.FloatField("Placement Arc", contextMenu.pieArc);
				if (contextMenu.pieArc != pieArc)
				{
					RegisterUndo();
					contextMenu.pieArc = pieArc;
				}
				
				bool pieCenterItem = EditorGUILayout.Toggle("Center Items", contextMenu.pieCenterItem);
				if (contextMenu.pieCenterItem != pieCenterItem)
				{
					RegisterUndo();
					contextMenu.pieCenterItem = pieCenterItem;
				}
			
				GUILayout.Space(4f);
			}
			EditorGUILayout.EndVertical();
			EditorGUILayout.Space();
			
			EditorGUIUtility.labelWidth = 80f;
		}
		else
		{
			box = EditorGUILayout.BeginVertical();
			GUI.Box(box, "");
			if (EditorFoldout(Flags.EditHighlight, "Highlight Options:"))
			{
				GUILayout.Space(4f);
				contextMenu.highlightSprite = EditSprite(contextMenu.atlas, "Sprite", contextMenu.highlightSprite, OnHighlight);
				Color highlightColor = EditorGUILayout.ColorField("Color", contextMenu.highlightColor);
				if (contextMenu.highlightColor != highlightColor)
				{
					RegisterUndo();
					contextMenu.highlightColor = highlightColor;
				}
			
				GUILayout.Space(4f);
			}
			EditorGUILayout.EndVertical();
			EditorGUILayout.Space();
		}
		
		box = EditorGUILayout.BeginVertical();
		GUI.Box(box, "");
		if (EditorFoldout(Flags.EditText, "Text Options:"))
		{
			GUILayout.Space(4f);

			ComponentSelector.Draw<UIFont>(contextMenu.font, OnSelectFont, false, GUILayout.Width(140f));
			
			if (contextMenu.font == null)
				EditorGUILayout.HelpBox("Warning: please select a valid font if you want this menu to behave correctly.", MessageType.Warning);
			
			float labelScale = EditorGUILayout.FloatField("Scale", contextMenu.labelScale);
			if (contextMenu.labelScale != labelScale)
			{
				RegisterUndo();
				contextMenu.labelScale = labelScale;
			}
			
			Color normalColor = EditorGUILayout.ColorField("Normal", contextMenu.labelColorNormal);
			if (contextMenu.labelColorNormal != normalColor)
			{
				RegisterUndo();
				contextMenu.labelColorNormal = normalColor;
			}
			
			Color highlightedColor = EditorGUILayout.ColorField("Highlighted", contextMenu.labelColorSelected);
			if (contextMenu.labelColorSelected != highlightedColor)
			{
				RegisterUndo();
				contextMenu.labelColorSelected = highlightedColor;
			}
			
			Color disabledColor = EditorGUILayout.ColorField("Disabled", contextMenu.labelColorDisabled);
			if (contextMenu.labelColorDisabled != disabledColor)
			{
				RegisterUndo();
				contextMenu.labelColorDisabled = disabledColor;
			}
			
			GUILayout.Space(4f);
		}
		EditorGUILayout.EndVertical();
		EditorGUILayout.Space();
		
		box = EditorGUILayout.BeginVertical();
		GUI.Box(box, "");
		if (EditorFoldout(Flags.EditCheckmark, "Checkmark Options:"))
		{
			GUILayout.Space(4f);
			contextMenu.checkmarkSprite = EditSprite(contextMenu.atlas, "Sprite", contextMenu.checkmarkSprite, OnCheckmark);
			Color checkmarkColor = EditorGUILayout.ColorField("Color", contextMenu.checkmarkColor);
			if (contextMenu.checkmarkColor != checkmarkColor)
			{
				RegisterUndo();
				contextMenu.checkmarkColor = checkmarkColor;
			}
			
			GUILayout.Space(4f);
		}
		EditorGUILayout.EndVertical();
		EditorGUILayout.Space();
				
		box = EditorGUILayout.BeginVertical();
		GUI.Box(box, "");
		if (EditorFoldout(Flags.EditSubmenu, "Submenu Options:"))
		{
			GUILayout.Space(4f);
	
			contextMenu.submenuIndicatorSprite =
				EditSprite(contextMenu.atlas, "Indicator", contextMenu.submenuIndicatorSprite, OnSubmenuIndicator);
			
			Color submenuIndColor = EditorGUILayout.ColorField("Color", contextMenu.submenuIndicatorColor);
			if (contextMenu.submenuIndicatorColor != submenuIndColor)
			{
				RegisterUndo();
				contextMenu.submenuIndicatorColor = submenuIndColor;
			}
			
			float submenuTimeDelay = EditorGUILayout.FloatField("Show Delay", contextMenu.submenuTimeDelay);
			if (contextMenu.submenuTimeDelay != submenuTimeDelay)
			{
				RegisterUndo();
				contextMenu.submenuTimeDelay = submenuTimeDelay;
			}
			
			GUILayout.Space(4f);
		}
		EditorGUILayout.EndVertical();
		EditorGUILayout.Space();

		if (contextMenu.style != CtxMenu.Style.Pie)
		{
			box = EditorGUILayout.BeginVertical();
			GUI.Box(box, "");
			if (EditorFoldout(Flags.EditSeparator, "Separator Options:"))
			{
				GUILayout.Space(4f);
				contextMenu.separatorSprite = EditSprite(contextMenu.atlas, "Sprite", contextMenu.separatorSprite, OnSeparator);
				Color separatorColor = EditorGUILayout.ColorField("Color", contextMenu.separatorColor);
				if (contextMenu.separatorColor != separatorColor)
				{
					RegisterUndo();
					contextMenu.separatorColor = separatorColor;
				}
			
				GUILayout.Space(4f);
			}
			EditorGUILayout.EndVertical();
			EditorGUILayout.Space();
		}
		
		if (! contextMenu.menuBar)
		{
			box = EditorGUILayout.BeginVertical();
			GUI.Box(box, "");
			
			if (EditorFoldout(Flags.EditAnimation, "Animation Options:"))
			{
				bool isAnimated = EditorGUILayout.Toggle("Animated", contextMenu.isAnimated);
				if (contextMenu.isAnimated != isAnimated)
				{
					RegisterUndo();
					contextMenu.isAnimated = isAnimated;
				}
				
				float animationDuration = EditorGUILayout.FloatField("Duration", contextMenu.animationDuration);
				if (contextMenu.animationDuration != animationDuration)
				{
					RegisterUndo();
					contextMenu.animationDuration = animationDuration;
				}
				
				EditorGUIUtility.labelWidth = 100f;
	
				CtxMenu.GrowDirection growDirection = (CtxMenu.GrowDirection)EditorGUILayout.EnumPopup("Grow Direction", 
					contextMenu.growDirection, GUILayout.Width(192f));
					
				if (contextMenu.growDirection != growDirection)
				{
					RegisterUndo();
					contextMenu.growDirection = growDirection;
				}
			
				GUILayout.Space(4f);
			}
			
			EditorGUILayout.EndVertical();
			EditorGUILayout.Space();
		}
		
		box = EditorGUILayout.BeginVertical();
		GUI.Box(box, "");

		if (EditorFoldout(Flags.EditShadow, "Shadow Options:"))
		{
			contextMenu.shadowSprite = EditSprite(contextMenu.atlas, "Sprite", contextMenu.shadowSprite, OnShadow);
			Color shadowColor = EditorGUILayout.ColorField("Color", contextMenu.shadowColor);
			if (contextMenu.shadowColor != shadowColor)
			{
				RegisterUndo();
				contextMenu.shadowColor = shadowColor;
			}
			
			Vector2 shadowOffset = CompactVector2Field("Offset", contextMenu.shadowOffset);
			if (shadowOffset != contextMenu.shadowOffset)
			{
				RegisterUndo();
				contextMenu.shadowOffset = shadowOffset;
			}
			
			Vector2 shadowSizeDelta = CompactVector2Field("Size +/-", contextMenu.shadowSizeDelta);
			if (shadowSizeDelta != contextMenu.shadowSizeDelta)
			{
				RegisterUndo();
				contextMenu.shadowSizeDelta = shadowSizeDelta;
			}
			
			GUILayout.Space(4f);
		}
		
		EditorGUILayout.EndVertical();
		EditorGUILayout.Space();

		box = EditorGUILayout.BeginVertical();
		GUI.Box(box, "");
		if (EditorFoldout(Flags.EditAudio, "Audio Options:"))
		{
			GUILayout.Space(4f);
			
			EditorGUIUtility.labelWidth = 70f;
			EditorGUILayout.BeginHorizontal();
			
			AudioClip showSound = EditorGUILayout.ObjectField("Show", contextMenu.showSound, typeof(AudioClip), false) as AudioClip;
			if (contextMenu.showSound != showSound)
			{
				RegisterUndo();
				contextMenu.showSound = showSound;
			}
			GUILayout.Space(20f);
			AudioClip hideSound = EditorGUILayout.ObjectField("Hide", contextMenu.hideSound, typeof(AudioClip), false) as AudioClip;
			if (contextMenu.hideSound != hideSound)
			{
				RegisterUndo();
				contextMenu.hideSound = hideSound;
			}
			
			EditorGUILayout.EndHorizontal();
			EditorGUILayout.BeginHorizontal();
			
			AudioClip highlightSound = EditorGUILayout.ObjectField("Highlight", contextMenu.highlightSound, typeof(AudioClip), false) as AudioClip;
			if (contextMenu.highlightSound != highlightSound)
			{
				RegisterUndo();
				contextMenu.highlightSound = highlightSound;
			}
			GUILayout.Space(20f);
			AudioClip selectSound = EditorGUILayout.ObjectField("Select", contextMenu.selectSound, typeof(AudioClip), false) as AudioClip;
			if (contextMenu.selectSound != selectSound)
			{
				RegisterUndo();
				contextMenu.selectSound = selectSound;
			}
			
			EditorGUILayout.EndHorizontal();
			EditorGUIUtility.labelWidth = 100f;
			
			GUILayout.Space(4f);
		}
			
		EditorGUILayout.EndVertical();
		EditorGUILayout.Space();
		
		bool isEditingItems = IsEditing(Flags.EditItems);
		EditMenuItemList(ref contextMenu.items, contextMenu.atlas, true, ref isEditingItems);
		SetEditing(Flags.EditItems, isEditingItems);
		
		if (refresh)
		{
			if (contextMenu.menuBar)
				contextMenu.Refresh();
			
			refresh = false;
		}
		
		// How to tell if undo or redo have been hit:
		else if (contextMenu.menuBar && Event.current.type == EventType.ValidateCommand && (Event.current.commandName == "UndoRedoPerformed"))
			contextMenu.Refresh();
	}
Exemplo n.º 42
0
 /// <summary>
 /// Assign a new icon sprite to this menu item.
 /// </summary>
 /// <param name="items">The array of items to search.</param>
 /// <param name="id">The menu item id number.</param>
 /// <param name="icon">The name of the sprite to assign. Note that the sprite must be in the atlas
 /// used by this context menu. Refer to the NGUI documentation for more information.</param>
 public static void SetIcon(CtxMenu.Item[] items, int id, string icon) {
     CtxMenu.Item item = FindItemRecursively(items, id);
     if (item != null) {
         item.icon = icon;
     }
 }
Exemplo n.º 43
0
    public static void AddMenuButton()
    {
        GameObject rootObj = NGUIMenu.SelectedRoot();

        if (rootObj != null)
        {
            EditorUtility.SetDirty(rootObj);

            // Create a menu object.
            GameObject ctxMenuObj = new GameObject("Button Menu");
            ctxMenuObj.layer = rootObj.layer;

            Transform ct = ctxMenuObj.transform;
            ct.parent        = rootObj.transform;
            ct.localPosition = Vector3.zero;
            ct.localRotation = Quaternion.identity;
            ct.localScale    = Vector3.one;

            CtxMenu menu = ctxMenuObj.AddComponent <CtxMenu>();
            menu.atlas = PickAtlas();
            menu.font  = PickFont();

            // Create button object.
            GameObject ctxButtonObj = new GameObject("Menu Button");
            ctxButtonObj.layer = rootObj.layer;

            ct               = ctxButtonObj.transform;
            ct.parent        = rootObj.transform;
            ct.localPosition = Vector3.zero;
            ct.localRotation = Quaternion.identity;
            ct.localScale    = Vector3.one;

            int depth = NGUITools.CalculateNextDepth(ctxButtonObj);

            // Create child objects.

            UISprite bg = NGUITools.AddSprite(ctxButtonObj, PickAtlas(), "Button");
            bg.name   = "Background";
            bg.depth  = depth;
            bg.width  = 150;
            bg.height = 40;
            bg.MakePixelPerfect();

            UILabel lbl = NGUITools.AddWidget <UILabel>(ctxButtonObj);
            lbl.bitmapFont = PickFont();
            lbl.text       = ctxButtonObj.name;
            lbl.color      = Color.black;
            lbl.MakePixelPerfect();
            Vector2 size = lbl.printedSize;                     // Force NGUI to process metrics before adding collider. Otherwise you get incorrect-sized collider.
            size.x -= 1f;                                       // Supress compiler warning for unused 'size' variable. Sheesh...

            // Attach button and menu components.
            NGUITools.AddWidgetCollider(ctxButtonObj, true);

            CtxMenuButton menuButton = ctxButtonObj.AddComponent <CtxMenuButton>();
            menuButton.contextMenu      = menu;
            menuButton.currentItemLabel = lbl;

            ctxButtonObj.AddComponent <UIButton>().tweenTarget = bg.gameObject;
            ctxButtonObj.AddComponent <UIButtonScale>();
            ctxButtonObj.AddComponent <UIButtonOffset>();
            ctxButtonObj.AddComponent <UIPlaySound>();

            Selection.activeGameObject = ctxButtonObj;

            Undo.RegisterCreatedObjectUndo(ctxButtonObj, "Add a Menu Button");
        }
    }
Exemplo n.º 44
0
	bool IsSubmenuItemSelected(CtxMenu submenu)
	{
		int selItem = FindItem(UICamera.selectedObject);
		if (selItem >= 0)
		{
			if (itemData[selItem].submenu == submenu)
				return true;
		}
		
		return false;
	}