//if (m_plugins.ContainsKey (name))
        public bool dispatchEvent(GameEvent evt)
        {        //
            if (!_dispatcherMap.ContainsKey(evt.type))
            {
                return(false);
            }
            uint type = evt.type;

            List <Action <GameEvent> > removeListenerFuns = null;

            if (_removeMap.Count > 0 && _removeMap.ContainsKey(type))
            {
                removeListenerFuns = _removeMap[type];
            }

            _processFlag = true;

            //DebugTrace.print( "dispatchEvent:" + evt.type );

            List <Action <GameEvent> > actFuns = _dispatcherMap[type];

            for (int i = 0; i < actFuns.Count; i++)
            {
                //DebugTrace.print( "process idx["+i+"]" );
                Action <GameEvent> func = actFuns[i]  as Action <GameEvent>;
                if (removeListenerFuns != null && removeListenerFuns.IndexOf(func) >= 0)
                {
                    continue;
                }

                if (evt.immediately)
                {
                    func(evt);
                }
                else
                {
                    this.eventDelegate.addEventTask(evt, func);
                }
            }

            if (evt.GC_FLAG)
            {
                GameEvent.free(evt);
            }

            _processFlag = false;

            if (removeListenerFuns != null && removeListenerFuns.Count > 0)
            {
                foreach (Action <GameEvent> func in actFuns)
                {
                    removeListener(removeListenerFuns, func);
                }

                _removeMap.Clear();
            }

            return(true);
        }
Beispiel #2
0
        public bool dispatchEvent(GameEvent evt)
        {
            bool flag = !this._dispatcherMap.ContainsKey(evt.type);
            bool result;

            if (flag)
            {
                result = false;
            }
            else
            {
                uint type = evt.type;
                List <Action <GameEvent> > list = null;
                bool flag2 = this._removeMap.Count > 0 && this._removeMap.ContainsKey(type);
                if (flag2)
                {
                    list = this._removeMap[type];
                }
                this._processFlag = true;
                List <Action <GameEvent> > list2 = this._dispatcherMap[type];
                for (int i = 0; i < list2.Count; i++)
                {
                    Action <GameEvent> action = list2[i];
                    bool flag3 = list != null && list.IndexOf(action) >= 0;
                    if (!flag3)
                    {
                        bool immediately = evt.immediately;
                        if (immediately)
                        {
                            action(evt);
                        }
                        else
                        {
                            this.eventDelegate.addEventTask(evt, action);
                        }
                    }
                }
                bool gC_FLAG = evt.GC_FLAG;
                if (gC_FLAG)
                {
                    GameEvent.free(evt);
                }
                this._processFlag = false;
                bool flag4 = list != null && list.Count > 0;
                if (flag4)
                {
                    foreach (Action <GameEvent> current in list2)
                    {
                        this.removeListener(list, current);
                    }
                    this._removeMap.Clear();
                }
                result = true;
            }
            return(result);
        }