Пример #1
0
        /// <summary>
        /// Force adding an event listener
        /// ** Note ** force add an event listener which will ignore whether it's in dispatching.
        /// <see cref=">AddEventListener"/>
        /// </summary>
        /// <param name="listener"></param>
        internal void ForceAddEventListener(CCEventListener listener)
        {
            CCEventListenerVector listeners = new CCEventListenerVector();
            var listenerID = listener.ListenerID;

            if (!listenerMap.ContainsKey(listenerID))
            {
                listeners = new CCEventListenerVector();
                listenerMap.Add(listenerID, listeners);
            }
            else
            {
                listeners = listenerMap[listenerID];
            }

            listeners.PushBack(listener);

            if (listener.FixedPriority == 0)
            {
                SetDirty(listenerID, DirtyFlag.SCENE_GRAPH_PRIORITY);

                var node = listener.SceneGraphPriority;
                Debug.Assert(node != null, "Invalid scene graph priority!");

                AssociateNodeAndEventListener(node, listener);

                if (node.IsRunning)
                {
                    Resume(node);
                }
            }
            else
            {
                SetDirty(listenerID, DirtyFlag.FIXED_PRIORITY);
            }
        }
Пример #2
0
        /// <summary>
        /// Force adding an event listener
        /// ** Note ** force add an event listener which will ignore whether it's in dispatching.
        /// <see cref=">AddEventListener"/>
        /// </summary>
        /// <param name="listener"></param>
        internal void ForceAddEventListener(CCEventListener listener)
        {
            CCEventListenerVector listeners = new CCEventListenerVector();
            var listenerID = listener.ListenerID;
            if (!listenerMap.ContainsKey(listenerID))
            {

                listeners = new CCEventListenerVector();
                listenerMap.Add(listenerID, listeners);
            }
            else
            {
                listeners = listenerMap[listenerID];;
            }

            listeners.PushBack(listener);

            if (listener.FixedPriority == 0)
            {
                SetDirty(listenerID, DirtyFlag.SCENE_GRAPH_PRIORITY);

                var node = listener.SceneGraphPriority;
                Debug.Assert(node != null, "Invalid scene graph priority!");

                AssociateNodeAndEventListener(node, listener);

                if (node.IsRunning)
                {
                    Resume(node);
                }
            }
            else
            {
                SetDirty(listenerID, DirtyFlag.FIXED_PRIORITY);
            }
        }
Пример #3
0
        /// <summary>
        /// Dispatches event to listeners with a specified listener type
        /// </summary>
        /// <param name="listeners"></param>
        /// <param name="onEvent"></param>
        void DispatchEventToListeners(CCEventListenerVector listeners,  Func<CCEventListener, bool> onEvent)
        {
            bool shouldStopPropagation = false;
            var fixedPriorityListeners = listeners.FixedPriorityListeners;
            var sceneGraphPriorityListeners = listeners.SceneGraphPriorityListeners;

            int i = 0;
            // priority < 0
            if (fixedPriorityListeners != null)
            {
                Debug.Assert (listeners.Gt0Index <= fixedPriorityListeners.Count, "Out of range exception!");

                if (fixedPriorityListeners.Count > 0)
                {
                    for (; i < listeners.Gt0Index; ++i)
                    {
                        var l = fixedPriorityListeners[i];
                        if (l.IsEnabled && !l.IsPaused && l.IsRegistered && onEvent(l))
                        {
                            shouldStopPropagation = true;
                            break;
                        }
                    }
                }
            }

            if (sceneGraphPriorityListeners != null)
            {
                if (!shouldStopPropagation)
                {
                    // priority == 0, scene graph priority
                    foreach (var l in sceneGraphPriorityListeners)
                    {
                        if (l.IsEnabled && !l.IsPaused && l.IsRegistered && onEvent(l))
                        {
                            shouldStopPropagation = true;
                            break;
                        }
                    }
                }
            }

            if (fixedPriorityListeners != null)
            {
                if (!shouldStopPropagation)
                {
                    // priority > 0
                    var size = fixedPriorityListeners.Count;
                    for (; i < size; ++i)
                    {
                        var l = fixedPriorityListeners[i];

                        if (l.IsEnabled && !l.IsPaused && l.IsRegistered && onEvent(l))
                        {
                            shouldStopPropagation = true;
                            break;
                        }
                    }
                }
            }

        }
Пример #4
0
        /// <summary>
        /// Dispatches event to listeners with a specified listener type
        /// </summary>
        /// <param name="listeners"></param>
        /// <param name="onEvent"></param>
        void DispatchEventToListeners(CCEventListenerVector listeners, Func <CCEventListener, bool> onEvent)
        {
            bool shouldStopPropagation       = false;
            var  fixedPriorityListeners      = listeners.FixedPriorityListeners;
            var  sceneGraphPriorityListeners = listeners.SceneGraphPriorityListeners;

            int i = 0;

            // priority < 0
            if (fixedPriorityListeners != null)
            {
                Debug.Assert(listeners.Gt0Index <= fixedPriorityListeners.Count, "Out of range exception!");

                if (fixedPriorityListeners.Count > 0)
                {
                    for (; i < listeners.Gt0Index; ++i)
                    {
                        var l = fixedPriorityListeners[i];
                        if (l.IsEnabled && !l.IsPaused && l.IsRegistered && onEvent(l))
                        {
                            shouldStopPropagation = true;
                            break;
                        }
                    }
                }
            }

            if (sceneGraphPriorityListeners != null)
            {
                if (!shouldStopPropagation)
                {
                    // priority == 0, scene graph priority
                    foreach (var l in sceneGraphPriorityListeners)
                    {
                        if (l.IsEnabled && !l.IsPaused && l.IsRegistered && onEvent(l))
                        {
                            shouldStopPropagation = true;
                            break;
                        }
                    }
                }
            }

            if (fixedPriorityListeners != null)
            {
                if (!shouldStopPropagation)
                {
                    // priority > 0
                    var size = fixedPriorityListeners.Count;
                    for (; i < size; ++i)
                    {
                        var l = fixedPriorityListeners[i];

                        if (l.IsEnabled && !l.IsPaused && l.IsRegistered && onEvent(l))
                        {
                            shouldStopPropagation = true;
                            break;
                        }
                    }
                }
            }
        }