Exemple #1
0
        /** Unschedules all selectors for a given target.
         *   This also includes the "update" selector.
         *   @since v0.99.3
         */
        public void unscheduleAllSelectorsForTarget(SelectorProtocol target)
        {
            // explicit NULL handling
            if (target == null)
            {
                return;
            }

            // custom selectors
            if (m_pHashForSelectors.ContainsKey(target))
            {
                tHashSelectorEntry element = m_pHashForSelectors[target];

                if (element.timers.Contains(element.currentTimer))
                {
                    element.currentTimerSalvaged = true;
                }
                element.timers.Clear();

                if (m_pCurrentTarget == element)
                {
                    m_bCurrentTargetSalvaged = true;
                }
                else
                {
                    removeHashElement(element);
                }
            }

            // update selector
            unscheduleUpdateForTarget(target);
        }
Exemple #2
0
        public static CCMenuItem itemWithTarget(SelectorProtocol rec, SEL_MenuHandler selector)
        {
            CCMenuItem cCMenuItem = new CCMenuItem();

            cCMenuItem.initWithTarget(rec, selector);
            return(cCMenuItem);
        }
Exemple #3
0
        // update specific

        private void priorityIn(List <tListEntry> list, SelectorProtocol target, int nPriority, bool bPaused)
        {
            tListEntry listElement = new tListEntry();

            listElement.target            = target;
            listElement.priority          = nPriority;
            listElement.paused            = bPaused;
            listElement.markedForDeletion = false;

            // list will not be empty, because it is new in init()
            int index = 0;

            foreach (tListEntry element in list)
            {
                if (nPriority < element.priority)
                {
                    break;
                }

                ++index;
            }

            // Can not throw exception, because index in [0, count]
            list.Insert(index, listElement);

            // update hash entry for quick access
            tHashUpdateEntry hashElement = new tHashUpdateEntry();

            hashElement.target = target;
            hashElement.list   = list;
            hashElement.entry  = listElement;
            m_pHashForUpdates.Add(target, hashElement);
        }
        /// <summary>
        /// Creates a CCMenuItem with a target/selector
        /// </summary>
        /// <param name="rec"></param>
        /// <param name="selector"></param>
        /// <returns></returns>
        public static CCMenuItem itemWithTarget(SelectorProtocol rec, SEL_MenuHandler selector)
        {
            CCMenuItem pRet = new CCMenuItem();
            pRet.initWithTarget(rec, selector);

            return pRet;
        }
        public static CCMenuItemLabel itemWithLabel(CCNode label, SelectorProtocol target, SEL_MenuHandler selector)
        {
            CCMenuItemLabel cCMenuItemLabel = new CCMenuItemLabel();

            cCMenuItemLabel.initWithLabel(label, target, selector);
            return(cCMenuItemLabel);
        }
    /** Schedules the 'update' selector for a given target with a given priority.
     *       The 'update' selector will be called every frame.
     *       The lower the priority, the earlier it is called.
     *       @since v0.99.3
     */

    public void ScheduleUpdateForTarget(SelectorProtocol targt, int priority, bool paused)
    {
        HashUpdateEntry element;

        if (m_pHashForUpdates.TryGetValue(targt, out element))
        {
            Debug.Assert(element.Entry.MarkedForDeletion);

            // TODO: check if priority has changed!
            element.Entry.MarkedForDeletion = false;

            return;
        }

        // most of the updates are going to be 0, that's way there
        // is an special list for updates with priority 0
        if (priority == 0)
        {
            AppendIn(m_pUpdates0List, targt, paused);
        }
        else if (priority < 0)
        {
            PriorityIn(m_pUpdatesNegList, targt, priority, paused);
        }
        else
        {
            PriorityIn(m_pUpdatesPosList, targt, priority, paused);
        }
    }
 /// <summary>
 ///  creates a menu item from a string and atlas. Use it with MenuItemToggle
 /// </summary>
 public static CCMenuItemAtlasFont itemFromString(string value, string charMapFile, int itemWidth, int itemHeight, char startCharMap, SelectorProtocol target, SEL_MenuHandler selector)
 {
     CCMenuItemAtlasFont pRet = new CCMenuItemAtlasFont();
     pRet.initFromString(value, charMapFile, itemWidth, itemHeight, startCharMap, target, selector);
     //pRet->autorelease();
     return pRet;
 }
    /** Unschedules all selectors for a given target.
     *       This also includes the "update" selector.
     *       @since v0.99.3
     */

    public void UnscheduleAllSelectorsForTarget(SelectorProtocol target)
    {
        // explicit NULL handling
        if (target == null)
        {
            return;
        }

        // custom selectors
        HashSelectorEntry element;

        if (m_pHashForSelectors.TryGetValue(target, out element))
        {
            if (element.Timers.Contains(element.CurrentTimer))
            {
                element.CurrentTimerSalvaged = true;
            }
            element.Timers.Clear();

            if (m_pCurrentTarget == element)
            {
                m_bCurrentTargetSalvaged = true;
            }
            else
            {
                RemoveHashElement(element);
            }
        }

        // update selector
        UnscheduleUpdateForTarget(target);
    }
 public CCMenuItem()
 {
     m_bIsSelected = false;
     m_bIsEnabled = false;
     m_pListener = null;
     m_pfnSelector = null;
 }
        public static CCMenuItemFont itemFromString(string value, SelectorProtocol target, SEL_MenuHandler selector)
        {
            CCMenuItemFont cCMenuItemFont = new CCMenuItemFont();

            cCMenuItemFont.initFromString(value, target, selector);
            return(cCMenuItemFont);
        }
Exemple #11
0
        public static CCMenuItemToggle itemWithTarget(SelectorProtocol target, SEL_MenuHandler selector, params CCMenuItem[] items)
        {
            CCMenuItemToggle cCMenuItemToggle = new CCMenuItemToggle();

            cCMenuItemToggle.initWithTarget(target, selector, items);
            return(cCMenuItemToggle);
        }
Exemple #12
0
        /** Schedules the 'update' selector for a given target with a given priority.
         *   The 'update' selector will be called every frame.
         *   The lower the priority, the earlier it is called.
         *   @since v0.99.3
         */
        public void scheduleUpdateForTarget(SelectorProtocol targt, int nPriority, bool bPaused)
        {
            tHashUpdateEntry hashElement = null;

            if (m_pHashForUpdates.ContainsKey(targt))
            {
                // TODO: check if priority has changed!

                hashElement = m_pHashForUpdates[targt];
                hashElement.entry.markedForDeletion = false;
            }

            // most of the updates are going to be 0, that's way there
            // is an special list for updates with priority 0
            if (nPriority == 0)
            {
                appendIn(m_pUpdates0List, targt, bPaused);
            }
            else if (nPriority < 0)
            {
                priorityIn(m_pUpdatesNegList, targt, nPriority, bPaused);
            }
            else
            {
                priorityIn(m_pUpdatesPosList, targt, nPriority, bPaused);
            }
        }
Exemple #13
0
        private void priorityIn(List <tListEntry> list, SelectorProtocol target, int nPriority, bool bPaused)
        {
            tListEntry item = new tListEntry
            {
                target            = target,
                priority          = nPriority,
                paused            = bPaused,
                markedForDeletion = false
            };
            int index = 0;

            foreach (tListEntry entry2 in list)
            {
                if (nPriority < entry2.priority)
                {
                    break;
                }
                index++;
            }
            list.Insert(index, item);
            tHashUpdateEntry entry3 = new tHashUpdateEntry
            {
                target = target,
                list   = list,
                entry  = item
            };

            this.m_pHashForUpdates.Add(target, entry3);
        }
Exemple #14
0
 public void unscheduleSelector(SEL_SCHEDULE selector, SelectorProtocol target)
 {
     if (((selector != null) && (target != null)) && this.m_pHashForSelectors.ContainsKey(target))
     {
         tHashSelectorEntry element = this.m_pHashForSelectors[target];
         for (int i = 0; i < element.timers.Count; i++)
         {
             CCTimer timer = element.timers[i];
             if (selector == timer.m_pfnSelector)
             {
                 if ((timer == element.currentTimer) && !element.currentTimerSalvaged)
                 {
                     element.currentTimerSalvaged = true;
                 }
                 element.timers.RemoveAt(i);
                 if (element.timerIndex >= i)
                 {
                     element.timerIndex--;
                 }
                 if (element.timers.Count == 0)
                 {
                     if (this.m_pCurrentTarget == element)
                     {
                         this.m_bCurrentTargetSalvaged = true;
                         return;
                     }
                     this.removeHashElement(element);
                 }
                 return;
             }
         }
     }
 }
Exemple #15
0
 public CCMenuItem()
 {
     this.m_bIsSelected = false;
     this.m_bIsEnabled  = false;
     this.m_pListener   = null;
     this.m_pfnSelector = null;
 }
 /// <summary>
 /// creates a menu item from a string with a target/selector
 /// </summary>
 public static CCMenuItemFont itemFromString(string value, SelectorProtocol target, SEL_MenuHandler selector)
 {
     CCMenuItemFont pRet = new CCMenuItemFont();
     pRet.initFromString(value, target, selector);
     //pRet->autorelease();
     return pRet;
 }
Exemple #17
0
 public void setTargetCallback(SelectorProtocol pSel)
 {
     if (pSel != m_pSelectorTarget)
     {
         m_pSelectorTarget = pSel;
     }
 }
Exemple #18
0
        /// <summary>
        /// creates a menu item from a string with a target/selector
        /// </summary>
        public static CCMenuItemFont itemFromString(string value, SelectorProtocol target, SEL_MenuHandler selector)
        {
            CCMenuItemFont pRet = new CCMenuItemFont();

            pRet.initFromString(value, target, selector);
            //pRet->autorelease();
            return(pRet);
        }
        /// <summary>
        ///  creates a menu item from a string and atlas. Use it with MenuItemToggle
        /// </summary>
        public static CCMenuItemAtlasFont ItemFromString(string value, string charMapFile, int itemWidth, int itemHeight, char startCharMap,
                                                         SelectorProtocol target, SEL_MenuHandler selector)
        {
            var pRet = new CCMenuItemAtlasFont();

            pRet.InitFromString(value, charMapFile, itemWidth, itemHeight, startCharMap, target, selector);
            return(pRet);
        }
Exemple #20
0
        /// <summary>
        /// Creates a CCMenuItem with a target/selector
        /// </summary>
        /// <param name="rec"></param>
        /// <param name="selector"></param>
        /// <returns></returns>
        public static CCMenuItem itemWithTarget(SelectorProtocol rec, SEL_MenuHandler selector)
        {
            CCMenuItem pRet = new CCMenuItem();

            pRet.initWithTarget(rec, selector);

            return(pRet);
        }
Exemple #21
0
 public bool isTargetPaused(SelectorProtocol target)
 {
     if (target == null)
     {
         return(false);
     }
     return(this.m_pHashForSelectors.ContainsKey(target) && this.m_pHashForSelectors[target].paused);
 }
 /// <summary>
 /// initializes a menu item from a string and atlas with a target/selector
 /// </summary>
 public bool InitFromString(string value, string charMapFile, int itemWidth, int itemHeight, char startCharMap, SelectorProtocol target,
                            SEL_MenuHandler selector)
 {
     // CCAssert( value != NULL && strlen(value) != 0, "value length must be greater than 0");
     var label = new CCLabelAtlas(value, charMapFile, itemWidth, itemHeight, startCharMap);
     base.InitWithLabel(label, selector);
     return true;
 }
        public bool initFromString(string value, SelectorProtocol target, SEL_MenuHandler selector)
        {
            this.m_strFontName = CCMenuItem._fontName;
            this.m_uFontSize   = CCMenuItem._fontSize;
            CCLabelTTF cCLabelTTF = CCLabelTTF.labelWithString(value, this.m_strFontName, (float)((float)this.m_uFontSize));

            base.initWithLabel(cCLabelTTF, target, selector);
            return(true);
        }
 protected bool initWithLabel(CCNode label, SelectorProtocol target, SEL_MenuHandler selector)
 {
     base.initWithTarget(target, selector);
     this.m_fOriginalScale = 1f;
     this.m_tColorBackup   = new ccColor3B(Microsoft.Xna.Framework.Color.White);
     this.DisabledColor    = new ccColor3B(126, 126, 126);
     this.Label            = label;
     return(true);
 }
        /// <summary>
        /// creates a menu item with a normal,selected  and disabled image with target/selector
        /// </summary>
        /// <param name="normalSprite"></param>
        /// <param name="selectedSprite"></param>
        /// <param name="disabledSprite"></param>
        /// <param name="target"></param>
        /// <param name="selector"></param>
        /// <returns></returns>
        public static CCMenuItemSprite itemFromNormalSprite(CCNode normalSprite, CCNode selectedSprite, CCNode disabledSprite,
                                                            SelectorProtocol target, SEL_MenuHandler selector)
        {
            CCMenuItemSprite pRet = new CCMenuItemSprite();

            pRet.initFromNormalSprite(normalSprite, selectedSprite, disabledSprite, target, selector);
            //pRet->autorelease();
            return(pRet);
        }
 /// <summary>
 /// Initializes a CCMenuItem with a target/selector
 /// </summary>
 /// <param name="rec"></param>
 /// <param name="selector"></param>
 /// <returns></returns>
 public bool initWithTarget(SelectorProtocol rec, SEL_MenuHandler selector)
 {
     anchorPoint = new CCPoint(0.5f, 0.5f);
     m_pListener = rec;
     m_pfnSelector = selector;
     m_bIsEnabled = true;
     m_bIsSelected = false;
     return true;
 }
Exemple #27
0
 public bool initWithTarget(SelectorProtocol pSelectorTarget, SEL_CallFuncN selector)
 {
     if (!base.initWithTarget(pSelectorTarget))
     {
         return(false);
     }
     this.m_pCallFuncN = selector;
     return(true);
 }
Exemple #28
0
 public bool initWithTarget(SelectorProtocol rec, SEL_MenuHandler selector)
 {
     this.anchorPoint   = new CCPoint(0.5f, 0.5f);
     this.m_pListener   = rec;
     this.m_pfnSelector = selector;
     this.m_bIsEnabled  = true;
     this.m_bIsSelected = false;
     return(true);
 }
Exemple #29
0
 public bool initWithTarget(SelectorProtocol pSelectorTarget, SEL_CallFuncO selector, CCObject pObject)
 {
     if (!base.initWithTarget(pSelectorTarget))
     {
         return(false);
     }
     this.m_pObject    = pObject;
     this.m_pCallFuncO = selector;
     return(true);
 }
        /// <summary>
        /// creates a menu item with a normal and selected image with target/selector
        /// </summary>
        public static CCMenuItemImage itemFromNormalImage(string normalImage, string selectedImage, string disabledImage, SelectorProtocol target, SEL_MenuHandler selector)
        {
            CCMenuItemImage pRet = new CCMenuItemImage();
            if (pRet.initFromNormalImage(normalImage, selectedImage, disabledImage, target, selector))
            {
                return pRet;
            }

            return null;
        }
Exemple #31
0
        public static CCCallFuncND actionWithTarget(SelectorProtocol pSelectorTarget, SEL_CallFuncND selector, object d)
        {
            CCCallFuncND cCCallFuncND = new CCCallFuncND();

            if (cCCallFuncND != null && cCCallFuncND.initWithTarget(pSelectorTarget, selector, d))
            {
                return(cCCallFuncND);
            }
            return(null);
        }
Exemple #32
0
        public static CCCallFuncN actionWithTarget(SelectorProtocol pSelectorTarget, SEL_CallFuncN selector)
        {
            CCCallFuncN cCCallFuncN = new CCCallFuncN();

            if (cCCallFuncN != null && cCCallFuncN.initWithTarget(pSelectorTarget, selector))
            {
                return(cCCallFuncN);
            }
            return(null);
        }
Exemple #33
0
 public bool initWithTarget(SelectorProtocol pSelectorTarget, SEL_CallFuncND selector, object d)
 {
     if (!base.initWithTarget(pSelectorTarget))
     {
         return(false);
     }
     this.m_pData       = d;
     this.m_pCallFuncND = selector;
     return(true);
 }
Exemple #34
0
        public static CCCallFuncO actionWithTarget(SelectorProtocol pSelectorTarget, SEL_CallFuncO selector, CCObject pObject)
        {
            CCCallFuncO cCCallFuncO = new CCCallFuncO();

            if (cCCallFuncO != null && cCCallFuncO.initWithTarget(pSelectorTarget, selector, pObject))
            {
                return(cCCallFuncO);
            }
            return(null);
        }
        // todo
        //public static CCCallFuncN actionWithScriptFuncName(string pszFuncName) 
        //{
        //    CCCallFuncN pRet = new CCCallFuncN();

        //    if (pRet && pRet->initWithScriptFuncName(pszFuncName)) {
        //        pRet->autorelease();
        //        return pRet;
        //    }

        //    CC_SAFE_DELETE(pRet);
        //    return NULL;
        //}

        public bool initWithTarget(SelectorProtocol pSelectorTarget, SEL_CallFuncN selector) 
        {
	        if (base.initWithTarget(pSelectorTarget)) 
            {
		        m_pCallFuncN = selector;
		        return true;
	        }

	        return false;
        }
Exemple #36
0
        public static CCCallFuncO actionWithTarget(SelectorProtocol pSelectorTarget, SEL_CallFuncO selector, CCObject pObject)
        {
            CCCallFuncO pRet = new CCCallFuncO();

            if (pRet != null && pRet.initWithTarget(pSelectorTarget, selector, pObject))
            {
                return pRet;
            }

            return null;
        }
Exemple #37
0
 public virtual void activate()
 {
     if (this.m_bIsEnabled)
     {
         SelectorProtocol mPListener = this.m_pListener;
         if (this.m_pfnSelector != null)
         {
             this.m_pfnSelector(this);
         }
     }
 }
        public static CCCallFuncN actionWithTarget(SelectorProtocol pSelectorTarget, SEL_CallFuncN selector)
        {
            CCCallFuncN pRet = new CCCallFuncN();

            if (pRet != null && pRet.initWithTarget(pSelectorTarget, selector))
            {
                return pRet;
            }

            return null;
        }
        public static CCCallFuncN actionWithTarget(SelectorProtocol pSelectorTarget, SEL_CallFuncN selector)
        {
            CCCallFuncN pRet = new CCCallFuncN();

            if (pRet != null && pRet.initWithTarget(pSelectorTarget, selector))
            {
                return(pRet);
            }

            return(null);
        }
        // todo
        //public static CCCallFuncO actionWithScriptFuncName(string pszFuncName)
        //{
        //    CCCallFuncO pRet = new CCCallFuncO();

        //    if (pRet != null && pRet.initWithScriptFuncName(pszFuncName)) {
        //        return pRet;
        //    }

        //    return null;
        //}

        public bool initWithTarget(SelectorProtocol pSelectorTarget, SEL_CallFuncO selector, CCObject pObject)
        {
            if (base.initWithTarget(pSelectorTarget)) 
            {
		        m_pObject = pObject;
		        m_pCallFuncO = selector;
		        return true;
	        }

	        return false;
        }
Exemple #41
0
        public static CCCallFunc actionWithTarget(SelectorProtocol pSelectorTarget, SEL_CallFunc selector)
        {
            CCCallFunc cCCallFunc = new CCCallFunc();

            if (cCCallFunc == null || !cCCallFunc.initWithTarget(pSelectorTarget))
            {
                return(null);
            }
            cCCallFunc.m_pCallFunc = selector;
            return(cCCallFunc);
        }
 /// <summary>
 /// initializes a menu item from a string and atlas with a target/selector
 /// </summary>
 public bool initFromString(string value, string charMapFile, int itemWidth, int itemHeight, char startCharMap, SelectorProtocol target, SEL_MenuHandler selector)
 {
     // CCAssert( value != NULL && strlen(value) != 0, "value length must be greater than 0");
     CCLabelAtlas label = new CCLabelAtlas();
     label.initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap);
     //label->autorelease();
     if (base.initWithLabel(label, target, selector))
     {
         // do something ?
     }
     return true;
 }
        // todo
        //public static CCCallFuncND actionWithScriptFuncName(string pszFuncName, object d) 
        //{
        //    CCCallFuncND pRet = new CCCallFuncND();

        //    if (pRet != null && pRet.initWithScriptFuncName(pszFuncName)) 
        //    {
        //        pRet.m_pData = d;
        //        return pRet;
        //    }
	        
        //    return null;
        //}


        public bool initWithTarget(SelectorProtocol pSelectorTarget,
		        SEL_CallFuncND selector, object d) 
        {
	        if (base.initWithTarget(pSelectorTarget)) 
            {
		        m_pData = d;
		        m_pCallFuncND = selector;
		        return true;
	        }

	        return false;
        }
        public static CCCallFunc actionWithTarget(SelectorProtocol pSelectorTarget, SEL_CallFunc selector)
        {
	        CCCallFunc pRet = new CCCallFunc();

	        if (pRet != null && pRet.initWithTarget(pSelectorTarget)) 
            {
		        pRet.m_pCallFunc = selector;
		        return pRet;
	        }

	        return null;
        }
         public static CCCallFuncND actionWithTarget(SelectorProtocol pSelectorTarget,
		        SEL_CallFuncND selector, object d) 
         {
	        CCCallFuncND pRet = new CCCallFuncND();

	        if (pRet != null && pRet.initWithTarget(pSelectorTarget, selector, d)) 
            {
		        return pRet;
	        }

	        return null;
        }
Exemple #46
0
 public CCTimer(CCScheduler scheduler, SelectorProtocol target, SEL_SCHEDULE selector, float seconds, uint repeat, float delay)
 {
     _scheduler = scheduler;
     Target = target;
     Selector = selector;
     Elapsed = -1;
     OriginalInterval = seconds;
     Interval = seconds;
     m_fDelay = delay;
     m_bUseDelay = delay > 0f;
     m_nRepeat = repeat;
     m_bRunForever = m_nRepeat == uint.MaxValue;
 }
        /** initializes a menu item from a string with a target/selector */
        public bool initFromString(string value, SelectorProtocol target, SEL_MenuHandler selector)
        {
            //CCAssert( value != NULL && strlen(value) != 0, "Value length must be greater than 0");

            m_strFontName = _fontName;
            m_uFontSize = _fontSize;

            CCLabelTTF label = CCLabelTTF.labelWithString(value, m_strFontName, (float)m_uFontSize);
            if (base.initWithLabel(label, target, selector))
            {
                // do something ?
            }

            return true;
        }
Exemple #48
0
    public void ResumeTarget(SelectorProtocol target)
    {
        Debug.Assert(target != null);

        // custom selectors
        HashSelectorEntry element;
        if (m_pHashForSelectors.TryGetValue(target, out element))
        {
            element.Paused = false;
        }

        // Update selector
        HashUpdateEntry elementUpdate;
        if (m_pHashForUpdates.TryGetValue(target, out elementUpdate))
        {
            elementUpdate.Entry.Paused = false;
        }
    }
        /// <summary>
        /// initializes a menu item with a normal, selected  and disabled image with target/selector
        /// </summary>
        public bool initFromNormalSprite(CCNode normalSprite, CCNode selectedSprite, CCNode disabledSprite,
                                    SelectorProtocol target, SEL_MenuHandler selector)
        {
            if (normalSprite == null)
            {
                throw new ArgumentNullException("normalSprite");
            }

            initWithTarget(target, selector);

            NormalImage = normalSprite;
            SelectedImage = selectedSprite;
            DisabledImage = disabledSprite;

            contentSize = m_pNormalImage.contentSize;

            return true;
        }
 /// <summary>
 /// creates a menu item with a normal,selected  and disabled image with target/selector
 /// </summary>
 /// <param name="normalSprite"></param>
 /// <param name="selectedSprite"></param>
 /// <param name="disabledSprite"></param>
 /// <param name="target"></param>
 /// <param name="selector"></param>
 /// <returns></returns>
 public static CCMenuItemSprite itemFromNormalSprite(CCNode normalSprite, CCNode selectedSprite, CCNode disabledSprite,
                                                 SelectorProtocol target, SEL_MenuHandler selector)
 {
     CCMenuItemSprite pRet = new CCMenuItemSprite();
     pRet.initFromNormalSprite(normalSprite, selectedSprite, disabledSprite, target, selector);
     //pRet->autorelease();
     return pRet;
 }
Exemple #51
0
    /*
    unsigned int CCScheduler::scheduleScriptFunc(unsigned int nHandler, float fInterval, bool bPaused)
    {
        CCSchedulerScriptHandlerEntry* pEntry = CCSchedulerScriptHandlerEntry::create(nHandler, fInterval, bPaused);
        if (!m_pScriptHandlerEntries)
        {
            m_pScriptHandlerEntries = CCArray::create(20);
            m_pScriptHandlerEntries->retain();
        }
        m_pScriptHandlerEntries->addObject(pEntry);
        return pEntry->getEntryId();
    }

    void CCScheduler::unscheduleScriptEntry(unsigned int uScheduleScriptEntryID)
    {
        for (int i = m_pScriptHandlerEntries->count() - 1; i >= 0; i--)
        {
            CCSchedulerScriptHandlerEntry* pEntry = static_cast<CCSchedulerScriptHandlerEntry*>(m_pScriptHandlerEntries->objectAtIndex(i));
            if (pEntry->getEntryId() == uScheduleScriptEntryID)
            {
                pEntry->markedForDeletion();
                break;
            }
        }
    }
    */
    public void UnscheduleUpdateForTarget(SelectorProtocol target)
    {
        if (target == null)
        {
            return;
        }

        HashUpdateEntry element;
        if (m_pHashForUpdates.TryGetValue(target, out element))
        {
            if (m_bUpdateHashLocked)
            {
                element.Entry.MarkedForDeletion = true;
            }
            else
            {
                RemoveUpdateFromHash(element.Entry);
            }
        }
    }
Exemple #52
0
    /** The scheduled method will be called every 'interval' seconds.
     If paused is YES, then it won't be called until it is resumed.
     If 'interval' is 0, it will be called every frame, but if so, it's recommended to use 'scheduleUpdateForTarget:' instead.
     If the selector is already scheduled, then only the interval parameter will be updated without re-scheduling it again.
     repeat let the action be repeated repeat + 1 times, use kCCRepeatForever to let the action run continuously
     delay is the amount of time the action will wait before it'll start

     @since v0.99.3, repeat and delay added in v1.1
     */
    public void ScheduleSelector(SEL_SCHEDULE selector, SelectorProtocol target, float interval, bool paused,
                                        uint repeat,
                                        float delay)
    {
        Debug.Assert(selector != null);
        Debug.Assert(target != null);

        HashSelectorEntry element;

        if (!m_pHashForSelectors.TryGetValue(target, out element))
        {
            element = new HashSelectorEntry { Target = target };
            m_pHashForSelectors[target] = element;

            // Is this the 1st element ? Then set the pause level to all the selectors of this target
            element.Paused = paused;
        }
        else
        {
            Debug.Assert(element.Paused == paused);
        }

        if (element.Timers == null)
        {
            element.Timers = new List<CCTimer>();
        }
        else
        {
            foreach (var timer in element.Timers)
            {
                if (selector == timer.Selector)
                {
                    Debug.WriteLine("CCSheduler#scheduleSelector. Selector already scheduled. Updating interval from: {0} to {1}", timer.Interval, interval);
                    timer.Interval = interval;
                    return;
                }
            }
        }

        element.Timers.Add(new CCTimer(this, target, selector, interval, repeat, delay));
    }
Exemple #53
0
    /** Schedules the 'update' selector for a given target with a given priority.
         The 'update' selector will be called every frame.
         The lower the priority, the earlier it is called.
         @since v0.99.3
         */
    public void ScheduleUpdateForTarget(SelectorProtocol targt, int priority, bool paused)
    {
        HashUpdateEntry element;

        if (m_pHashForUpdates.TryGetValue(targt, out element))
        {
            Debug.Assert(element.Entry.MarkedForDeletion);

            // TODO: check if priority has changed!
            element.Entry.MarkedForDeletion = false;

            return;
        }

        // most of the updates are going to be 0, that's way there
        // is an special list for updates with priority 0
        if (priority == 0)
        {
            AppendIn(m_pUpdates0List, targt, paused);
        }
        else if (priority < 0)
        {
            PriorityIn(m_pUpdatesNegList, targt, priority, paused);
        }
        else
        {
            PriorityIn(m_pUpdatesPosList, targt, priority, paused);
        }
    }
Exemple #54
0
    /** Unschedules all selectors for a given target.
         This also includes the "update" selector.
         @since v0.99.3
         */
    public void UnscheduleAllSelectorsForTarget(SelectorProtocol target)
    {
        // explicit NULL handling
        if (target == null)
        {
            return;
        }

        // custom selectors
        HashSelectorEntry element;

        if (m_pHashForSelectors.TryGetValue(target, out element))
        {
            if (element.Timers.Contains(element.CurrentTimer))
            {
                element.CurrentTimerSalvaged = true;
            }
            element.Timers.Clear();

            if (m_pCurrentTarget == element)
            {
                m_bCurrentTargetSalvaged = true;
            }
            else
            {
                RemoveHashElement(element);
            }
        }

        // update selector
        UnscheduleUpdateForTarget(target);
    }
Exemple #55
0
    /** Unschedule a selector for a given target.
         If you want to unschedule the "update", use unscheudleUpdateForTarget.
         @since v0.99.3
         */
    public void UnscheduleSelector(SEL_SCHEDULE selector, SelectorProtocol target)
    {
        // explicity handle nil arguments when removing an object
        if (selector == null || target == null)
        {
            return;
        }

        HashSelectorEntry element;
        if (m_pHashForSelectors.TryGetValue(target, out element))
        {
            for (int i = 0; i < element.Timers.Count; i++)
            {
                var timer = element.Timers[i];

                if (selector == timer.Selector)
                {
                    if (timer == element.CurrentTimer && (!element.CurrentTimerSalvaged))
                    {
                        element.CurrentTimerSalvaged = true;
                    }

                    element.Timers.RemoveAt(i);

                    // update timerIndex in case we are in tick:, looping over the actions
                    if (element.TimerIndex >= i)
                    {
                        element.TimerIndex--;
                    }

                    if (element.Timers.Count == 0)
                    {
                        if (m_pCurrentTarget == element)
                        {
                            m_bCurrentTargetSalvaged = true;
                        }
                        else
                        {
                            RemoveHashElement(element);
                        }
                    }

                    return;
                }
            }
        }
    }
Exemple #56
0
    private void PriorityIn(LinkedList<ListEntry> list, SelectorProtocol target, int priority, bool paused)
    {
        var listElement = new ListEntry
        {
            Target = target,
            Priority = priority,
            Paused = paused,
            MarkedForDeletion = false
        };

        if (list.First == null)
        {
            list.AddFirst(listElement);
        }
        else
        {
            bool added = false;
            for (LinkedListNode<ListEntry> node = list.First; node != null; node = node.Next)
            {
                if (priority < node.Value.Priority)
                {
                    list.AddBefore(node, listElement);
                    added = true;
                    break;
                }
            }

            if (!added)
            {
                list.AddLast(listElement);
            }
        }

        // update hash entry for quick access
        var hashElement = new HashUpdateEntry
        {
            Target = target,
            List = list,
            Entry = listElement
        };

        m_pHashForUpdates.Add(target, hashElement);
    }
Exemple #57
0
    private void AppendIn(LinkedList<ListEntry> list, SelectorProtocol target, bool paused)
    {
        var listElement = new ListEntry
        {
            Target = target,
            Paused = paused,
            MarkedForDeletion = false
        };

        list.AddLast(listElement);

        // update hash entry for quicker access
        var hashElement = new HashUpdateEntry
        {
            Target = target,
            List = list,
            Entry = listElement
        };

        m_pHashForUpdates.Add(target, hashElement);
    }
Exemple #58
0
    public void PauseTarget(SelectorProtocol target)
    {
        Debug.Assert(target != null);

        // custom selectors
        HashSelectorEntry entry;
        if (m_pHashForSelectors.TryGetValue(target, out entry))
        {
            entry.Paused = true;
        }

        // Update selector
        HashUpdateEntry updateEntry;
        if (m_pHashForUpdates.TryGetValue(target, out updateEntry))
        {
            updateEntry.Entry.Paused = true;
        }
    }
Exemple #59
0
 /** Initializes a timer with a target, a selector and an interval in seconds.
  *  Target is not needed in c#, it is just for compatibility.
  */
 public CCTimer(CCScheduler scheduler, SelectorProtocol target, SEL_SCHEDULE selector, float seconds)
     : this(scheduler, target, selector, seconds, 0, 0)
 {
 }
 /// <summary>
 /// creates a menu item with a normal and selected image with target/selector
 /// </summary>
 /// <param name="normalSprite"></param>
 /// <param name="selectedSprite"></param>
 /// <param name="target"></param>
 /// <param name="selector"></param>
 /// <returns></returns>
 public static CCMenuItemSprite itemFromNormalSprite(CCNode normalSprite, CCNode selectedSprite,
                                                 SelectorProtocol target, SEL_MenuHandler selector)
 {
     return itemFromNormalSprite(normalSprite, selectedSprite, null, target, selector);
 }