Beispiel #1
0
    /// <summary>
    /// Handles the OnPress event. Normally this will come through NGUI as
    /// by default this component will register itself with UICamera as the
    /// fallthrough event handler. However, if you don't want this to
    /// be the fallthrough handler then set the dontUseFallThrough flag and
    /// call this function directly from your own event handlers.
    /// </summary>
    public void OnPress(bool isPressed) {
        if (isPressed) {
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_WEBPLAYER
            // For mouse platforms we go through the additional step of filtering
            // out the events that don't match our specified mouse button.
            if (Input.GetMouseButtonDown(menuButton))
#endif
            {
                if (_lastTracked != null) {
                    //_lastTracked.HideMenu();
                    _lastTracked = null;
                }

                _tracking = Pick(Input.mousePosition);
            }
        }
        else {
            if (_tracking) {
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_WEBPLAYER
                if (Input.GetMouseButtonUp(menuButton))
#endif
                {
                    CtxObject picked = Pick(Input.mousePosition);
                    if (_tracking == picked) {
                        _tracking.ShowMenu();
                        _lastTracked = _tracking;
                    }
                }
                _tracking = null;
            }
        }
    }
    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);
    }
Beispiel #3
0
    void OnHide()
    {
        current = this;
        EventDelegate.Execute(onHide);
        EventDelegate.Remove(contextMenu.onSelection, OnMenuSelect);            // <-- In case the menu was hidden with no selection made

        gameObject.SendMessage("OnHideMenu", this, SendMessageOptions.DontRequireReceiver);
    }
Beispiel #4
0
    private void OnMenuSelect()
    {
        selectedItem = CtxMenu.current.selectedItem;

        current = this;
        EventDelegate.Execute(onSelection);

        gameObject.SendMessage("OnMenuSelection", selectedItem, SendMessageOptions.DontRequireReceiver);
    }
    void Start()
    {
        CtxObject ctxObj = GetComponent <CtxObject>();

        if (ctxObj != null)
        {
            EventDelegate.Add(ctxObj.onSelection, OnMenuSelection);
        }
    }
Beispiel #6
0
    private void __InitializeContextMenu() {    // IMPROVE use of string
        _ctxObject = gameObject.GetSafeMonoBehaviourComponent<CtxObject>();
        CtxMenu shipMenu = GuiManager.Instance.gameObject.GetSafeMonoBehaviourComponentsInChildren<CtxMenu>().Single(menu => menu.gameObject.name == "ShipMenu");
        _ctxObject.contextMenu = shipMenu;
        D.Assert(_ctxObject.contextMenu != null, "{0}.contextMenu on {1} is null.".Inject(typeof(CtxObject).Name, gameObject.name));
        UnityUtility.ValidateComponentPresence<Collider>(gameObject);

        EventDelegate.Add(_ctxObject.onShow, OnContextMenuShow);
        EventDelegate.Add(_ctxObject.onSelection, OnContextMenuSelection);
        EventDelegate.Add(_ctxObject.onHide, OnContextMenuHide);
    }
    private void __InitializeContextMenu() {      // IMPROVE use of string
        _ctxObject = gameObject.GetSafeMonoBehaviour<CtxObject>();
        _ctxObject.offsetMenu = true;

        CtxMenu generalMenu = GuiManager.Instance.gameObject.GetSafeMonoBehavioursInChildren<CtxMenu>().Single(menu => menu.gameObject.name == "GeneralMenu");
        _ctxObject.contextMenu = generalMenu;
        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);
    }
    public void OnShowMenu(CtxObject obj)
    {
        if (menuItems == null)
        {
            int cnt = (int)MenuItemID.Count;
            menuItems = new CtxMenu.Item[cnt];
            for (int i = 0; i < cnt; i++)
            {
                MenuItemID itemID = (MenuItemID)i;

                menuItems[i]      = new CtxMenu.Item();
                menuItems[i].text = ItemText(itemID);
                if (menuItems[i].text.StartsWith("Separator"))
                {
                    menuItems[i].isSeparator = true;
                }
                else
                {
                    menuItems[i].id = i;
                }
            }

            menuItems[(int)MenuItemID.Small].isCheckable  = true;
            menuItems[(int)MenuItemID.Medium].isCheckable = true;
            menuItems[(int)MenuItemID.Large].isCheckable  = true;

            menuItems[(int)MenuItemID.Small].mutexGroup  = 0;
            menuItems[(int)MenuItemID.Medium].mutexGroup = 0;
            menuItems[(int)MenuItemID.Large].mutexGroup  = 0;

            menuItems[(int)MenuItemID.Stealth].isCheckable = true;
            menuItems[(int)MenuItemID.Shield].isCheckable  = true;
        }

        if (transform.localScale.x == 1f)
        {
            CtxHelper.SetChecked(menuItems, (int)MenuItemID.Small, true);
        }
        else if (transform.localScale.x == 2f)
        {
            CtxHelper.SetChecked(menuItems, (int)MenuItemID.Medium, true);
        }
        else
        {
            CtxHelper.SetChecked(menuItems, (int)MenuItemID.Large, true);
        }

        menuItems[(int)MenuItemID.Stealth].isChecked = stealthOn;
        menuItems[(int)MenuItemID.Shield].isChecked  = shieldOn;

        obj.menuItems = menuItems;
    }
Beispiel #9
0
    // Silly trivial test to demonstrate the ability to update the menu's
    // visible state. This coroutine is fired in OnMenuShow() and toggles
    // the disabled state of the 'Stealth' menu item once per second. Note
    // that SetDisabled() implicitly calls CtxMenu.UpdateVisibleState(),
    // which is why this works.
    //
    // The coroutine exits when the menu is hidden.
    IEnumerator CheckTest(CtxObject obj)
    {
        yield return(new WaitForSeconds(1f));

        bool toggle = false;

        while (obj.contextMenu.IsVisible)
        {
            toggle = !toggle;
            obj.contextMenu.SetDisabled((int)MenuItemID.Stealth, toggle);

            yield return(new WaitForSeconds(1f));
        }
    }
Beispiel #10
0
        public static void Main(string[] args)
        {
            Program.Report("app start");
            System.AppDomain domain = System.AppDomain.CreateDomain("New domain");

            var ctxOb = new CtxObject();

            ctxOb.Report("ctxOb object");

            domain.SetData("ctxOb", ctxOb);
            domain.DoCallBack(() =>
            {
                Program.Report("inside another domain");
                var ctxOb2 = (CtxObject)System.AppDomain.CurrentDomain.GetData("ctxOb");
                ctxOb2.Report("ctxOb called from another domain");
            });

            Console.ReadLine();
        }
    public override void OnInspectorGUI() { // Note: All my context menu setup options are managed by CtxControl scripts
        _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 toPositionMenuAtCursor = EditorGUILayout.Toggle("Cursor Menu", _contextObject.toPositionMenuAtCursor);
        //if(_contextObject.toPositionMenuAtCursor != toPositionMenuAtCursor) {
        //    RegisterUndo();
        //    _contextObject.toPositionMenuAtCursor = toPositionMenuAtCursor;
        //}

        //if(!toPositionMenuAtCursor) {
        //    bool toOffsetMenu = EditorGUILayout.Toggle("Offset Menu", _contextObject.toOffsetMenu);
        //    if (_contextObject.toOffsetMenu != toOffsetMenu) {
        //        RegisterUndo();
        //        _contextObject.toOffsetMenu = toOffsetMenu;
        //    }
        //}


        //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);
        //}
    }
Beispiel #12
0
    public void OnShowMenu(CtxObject obj)
    {
        if (transform.localScale.x == 1f)
        {
            obj.contextMenu.SetChecked((int)MenuItemID.Small, true);
        }
        else if (transform.localScale.x == 2f)
        {
            obj.contextMenu.SetChecked((int)MenuItemID.Medium, true);
        }
        else
        {
            obj.contextMenu.SetChecked((int)MenuItemID.Large, true);
        }

        obj.contextMenu.SetChecked((int)MenuItemID.Stealth, stealthOn);
        obj.contextMenu.SetChecked((int)MenuItemID.Shield, shieldOn);

        StartCoroutine(CheckTest(obj));
    }
Beispiel #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);
        }
    }
Beispiel #14
0
    /// <summary>
    /// Handles the OnPress event. Normally this will come through NGUI as
    /// by default this component will register itself with UICamera as the
    /// fallthrough event handler. However, if you don't want this to
    /// be the fallthrough handler then set the dontUseFallThrough flag and
    /// call this function directly from your own event handlers.
    /// </summary>
    public void OnPress(bool isPressed)
    {
        if (isPressed)
        {
                #if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_WEBPLAYER
            // For mouse platforms we go through the additional step of filtering
            // out the events that don't match our specified mouse button.
            if (Input.GetMouseButtonDown(menuButton))
                #endif
            {
                if (lastTracked != null)
                {
                    //lastTracked.HideMenu();
                    lastTracked = null;
                }

                tracking = Pick(Input.mousePosition);
            }
        }
        else
        {
            if (tracking)
            {
                        #if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_WEBPLAYER
                if (Input.GetMouseButtonUp(menuButton))
                        #endif
                {
                    CtxObject picked = Pick(Input.mousePosition);
                    if (tracking == picked)
                    {
                        tracking.ShowMenu();
                        lastTracked = tracking;
                    }
                }

                tracking = null;
            }
        }
    }
Beispiel #15
0
    /// <summary>
    /// Shows the context menu associated with this object. If you are handling
    /// your own picking, then you should call this function when this object
    /// is picked.
    /// </summary>
    public void ShowMenu()
    {
        if (contextMenu != null)
        {
            EventDelegate.Add(contextMenu.onSelection, OnMenuSelect);
            EventDelegate.Add(contextMenu.onHide, OnHide, true);

            current = this;
            EventDelegate.Execute(onShow);

            gameObject.SendMessage("OnShowMenu", this, SendMessageOptions.DontRequireReceiver);

            if (menuItems != null && menuItems.Length > 0)
            {
                contextMenu.Show(MenuPosition, menuItems);
            }
            else
            {
                contextMenu.Show(MenuPosition);
            }
        }
    }
Beispiel #16
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);
	}
Beispiel #17
0
    private void MenuSelectionEventHandler() {  // OnMenuSelect()
        selectedItem = CtxMenu.current.selectedItem;

        current = this;
        EventDelegate.Execute(onSelection);

        // OPTIMIZE not needed as I subscribe to EventDelegates rather than implement OnMenuSelection() as an event handler
        gameObject.SendMessage("OnMenuSelection", selectedItem, SendMessageOptions.DontRequireReceiver);
    }
    /// <summary>
    /// Handles the OnPress event. Normally this will come through NGUI as
    /// by default this component will register itself with UICamera as the
    /// fallthrough event handler. However, if you don't want this to
    /// be the fallthrough handler then set the dontUseFallThrough flag and
    /// call this function directly from your own event handlers.
    /// </summary>
    public void OnPress(bool isPressed) {
        if (isPressed) {
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_WEBPLAYER
            // For mouse platforms we go through the additional step of filtering
            // out the events that don't match our specified mouse button.
            if (Input.GetMouseButtonDown(menuButton))
#endif
            {
                //if (lastTracked != null) {    // my change: lastTracked not used
                //    //lastTracked.HideMenu();
                //    lastTracked = null;
                //}

                tracking = Pick(Input.mousePosition);
            }
        }
        else {
            if (tracking) {
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_WEBPLAYER
                if (Input.GetMouseButtonUp(menuButton))
#endif
                {
                    CtxObject picked = Pick(Input.mousePosition);
                    if (tracking == picked) {
                        // if (!GameInput.IsDragging) { // My addition to avoid opening menu when dragging over same object
                        tracking.ShowMenu();
                        //lastTracked = tracking;   // my change: lastTracked not used
                        //}
                    }
                }

                tracking = null;
            }
        }
    }
Beispiel #19
0
    /// <summary>
    /// Shows the context menu associated with this object. If you are handling
    /// your own picking, then you should call this function when this object is picked.
    /// </summary>
    public void ShowMenu() {
        if (contextMenu != null) {
            EventDelegate.Add(contextMenu.onSelection, MenuSelectionEventHandler);
            EventDelegate.Add(contextMenu.onHide, HideMenuEventHandler, true);

            current = this;
            EventDelegate.Execute(onShow);

            // OPTIMIZE not needed as I subscribe to EventDelegates rather than implement OnShowMenu() as an event handler
            gameObject.SendMessage("OnShowMenu", this, SendMessageOptions.DontRequireReceiver);

            if (menuItems != null && menuItems.Length > 0) {
                contextMenu.Show(MenuPosition, menuItems);
            }
            else {
                contextMenu.Show(MenuPosition);
            }
        }
    }
Beispiel #20
0
 public void OnShowMenu(CtxObject obj)
 {
     BuildMenu();
     obj.menuItems = menuItems;
 }
Beispiel #21
0
 public void OnHideMenu(CtxObject obj)
 {
     Debug.Log("Transport menu hidden (object)");
 }
Beispiel #22
0
 public void OnHideMenu(CtxObject obj)
 {
     Debug.Log("Enforcer menu hidden (object)");
 }
Beispiel #23
0
 void Start()
 {
     contextObject   = GetComponent <CtxObject>();
     currentRotation = baseRotation = transform.rotation.eulerAngles;
     currentScale    = baseScale = transform.localScale;
 }
Beispiel #24
0
    private void HideMenuEventHandler() {   // OnHide()
        current = this;
        EventDelegate.Execute(onHide);
        EventDelegate.Remove(contextMenu.onSelection, MenuSelectionEventHandler);    // <-- In case the menu was hidden with no selection made

        // OPTIMIZE not needed as I subscribe to EventDelegates rather than implement OnHideMenu() as an event handler
        gameObject.SendMessage("OnHideMenu", this, SendMessageOptions.DontRequireReceiver);
    }
Beispiel #25
0
	private void OnMenuSelect()
	{
		selectedItem = CtxMenu.current.selectedItem;
		
		current = this;
		EventDelegate.Execute(onSelection);
		
		gameObject.SendMessage("OnMenuSelection", selectedItem, SendMessageOptions.DontRequireReceiver);
	}
Beispiel #26
0
 public void OnHideMenu(CtxObject obj)
 {
     Debug.Log("Spy menu hidden (object)");
 }
 public void OnHideMenu(CtxObject obj)
 {
     Debug.Log("Menu hidden for " + obj.name);
 }
Beispiel #28
0
	void OnHide()
	{
		current = this;
		EventDelegate.Execute(onHide);
		EventDelegate.Remove(contextMenu.onSelection, OnMenuSelect);	// <-- In case the menu was hidden with no selection made

		gameObject.SendMessage("OnHideMenu", this, SendMessageOptions.DontRequireReceiver);
	}
Beispiel #29
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);
    }
Beispiel #30
0
    private void InitializeContextMenu(GameObject ctxObjectGO, MenuPositionMode menuPosition) {    // IMPROVE use of strings

        Profiler.BeginSample("Proper AddComponent allocation", _ctxObject);
        _ctxObject = ctxObjectGO.AddMissingComponent<CtxObject>();
        Profiler.EndSample();

        switch (menuPosition) {
            case MenuPositionMode.Over:
                _ctxObject.toOffsetMenu = false;
                _ctxObject.toPositionMenuAtCursor = false;
                break;
            case MenuPositionMode.Offset:
                _ctxObject.toOffsetMenu = true;
                _ctxObject.toPositionMenuAtCursor = false;
                break;
            case MenuPositionMode.AtCursor:
                _ctxObject.toOffsetMenu = false;
                _ctxObject.toPositionMenuAtCursor = true;
                break;
            case MenuPositionMode.None:
            default:
                throw new NotImplementedException(ErrorMessages.UnanticipatedSwitchValue.Inject(menuPosition));
        }

        // 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 1) to either use the editor to set the items using a CtxMenu dedicated to ships, or 2) have this already dedicated 
        // CtxObject hold the .menuItems that are set programmatically when Show is called. 

        if (_availableSubMenus.Count == Constants.Zero) {
            _availableSubMenus.AddRange(GuiManager.Instance.gameObject.GetSafeComponentsInChildren<CtxMenu>()
                .Where(menu => menu.gameObject.name.Equals("SubMenu")));
            D.Assert(_uniqueSubmenusReqd <= _availableSubMenus.Count);
        }
        if (_generalCtxMenu == null) {
            _generalCtxMenu = GuiManager.Instance.gameObject.GetSafeComponentsInChildren<CtxMenu>()
                .Single(menu => menu.gameObject.name.Equals("GeneralMenu"));
        }

        if (!_generalCtxMenu.items.IsNullOrEmpty()) {
            // There are already populated items in this CtxMenu. In certain corner cases, this can occur when this object initializes itself while
            // another object is still showing the menu. One example: Use a context menu to scuttle a Settlement. The destruction of the settlement
            // immediately changes the system's owner which causes the system's context menu to reinitialize while the Settlement's context menu 
            // has yet to finish hiding. This reinitialization encounters the Settlement's items as they haven't been cleared yet which occurs
            // when finished hiding. Accordingly, we test for this condition by seeing if the menu is still visible.
            if (!_generalCtxMenu.IsVisible) {
                // A hidden CtxMenu should not have any items in its list
                D.Warn("{0}.{1}.CtxMenu.items = {2}.", ctxObjectGO.name, GetType().Name, _generalCtxMenu.items.Select<CtxMenu.Item, string>(i => i.text).Concatenate());
            }
        }
        _ctxObject.contextMenu = _generalCtxMenu;
        // this empty, general purpose CtxMenu will be populated with all menu items held by CtxObject when Show is called
        if (!_ctxObject.menuItems.IsNullOrEmpty()) {
            D.Warn("{0}.{1}.CtxObject.menuItems = {2}.", ctxObjectGO.name, GetType().Name, _ctxObject.menuItems.Select<CtxMenu.Item, string>(i => i.text).Concatenate());
        }
    }
Beispiel #31
0
 public void OnShowMenu(CtxObject obj)
 {
     //Debug.Log("SaucerHandler.OnShowMenu() "+obj);
     obj.SetChecked((int)currentColorScheme, true);
 }
Beispiel #32
0
	/// <summary>
	/// Shows the context menu associated with this object. If you are handling
	/// your own picking, then you should call this function when this object
	/// is picked.
	/// </summary>
	public void ShowMenu()
	{
		if (contextMenu != null)
		{
			EventDelegate.Add(contextMenu.onSelection, OnMenuSelect);
			EventDelegate.Add(contextMenu.onHide, OnHide, true);
			
			current = this;
			EventDelegate.Execute(onShow);
		
			gameObject.SendMessage("OnShowMenu", this, SendMessageOptions.DontRequireReceiver);
			
			if (menuItems != null && menuItems.Length > 0)
				contextMenu.Show(MenuPosition, menuItems);
			else
				contextMenu.Show(MenuPosition);
		}
	}