Beispiel #1
0
        ///** Updates all listeners
        // *  1) Removes all listener items that have been marked as 'removed' when dispatching event.
        // *  2) Adds all listener items that have been marked as 'added' when dispatching event.
        // */
        void UpdateListeners(CCEvent forEvent)
        {
            Debug.Assert(inDispatch > 0, "If program goes here, there should be events to dispatch.");

            if (forEvent.Type == CCEventType.TOUCH)
            {
                UpdateListeners(CCEventListenerTouchOneByOne.LISTENER_ID);
                UpdateListeners(CCEventListenerTouchAllAtOnce.LISTENER_ID);
            }
            else
            {
                UpdateListeners(CCEventDispatcher.GetListenerID(forEvent));
            }

            if (inDispatch > 1)
            {
                return;
            }

            Debug.Assert(inDispatch == 1, "_inDispatch should be 1 here.");


            List <string> lmKeysToRemove = new List <string>();

            foreach (string lv in listenerMap.Keys)
            {
                if (listenerMap[lv].IsEmpty)
                {
                    lmKeysToRemove.Add(lv);
                }
            }

            foreach (string key in lmKeysToRemove)
            {
                priorityDirtyFlagMap.Remove(key);
                listenerMap[key] = null;
                listenerMap.Remove(key);
            }

            if (toBeAddedListeners.Count > 0)
            {
                foreach (var listener in toBeAddedListeners)
                {
                    ForceAddEventListener(listener);
                }
                toBeAddedListeners.Clear();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Dispatches the event
        /// Also removes all EventListeners marked for deletion from the event dispatcher list.
        /// </summary>
        /// <param name="eventToDispatch"></param>
        public void DispatchEvent(CCEvent eventToDispatch)
        {
            if (!IsEnabled)
            {
                return;
            }

            UpdateDirtyFlagForSceneGraph();

            inDispatch++;

            if (eventToDispatch.Type == CCEventType.TOUCH)
            {
                DispatchTouchEvent((CCEventTouch)eventToDispatch);
                inDispatch--;
                return;
            }


            var listenerID = CCEventDispatcher.GetListenerID(eventToDispatch);

            SortEventListeners(listenerID);

            if (listenerMap.ContainsKey(listenerID))
            {
                var listeners = listenerMap [listenerID];

                Func <CCEventListener, bool> onEvent = delegate(CCEventListener listener)
                {
                    eventToDispatch.CurrentTarget = listener.SceneGraphPriority;
                    listener.OnEvent(eventToDispatch);
                    return(eventToDispatch.IsStopped);
                };

                DispatchEventToListeners(listeners, onEvent);
            }

            UpdateListeners(eventToDispatch);
            inDispatch--;
        }