mirror of https://github.com/axmolengine/axmol.git
* rename LuaEngine to CCLuaEngine
* add #if LUA_ENGINE * format source files
This commit is contained in:
parent
e9fa8116e9
commit
0739c1f262
|
@ -2,19 +2,19 @@
|
|||
Copyright (c) 2010-2011 cocos2d-x.org
|
||||
Copyright (c) 2008-2010 Ricardo Quesada
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
@ -30,14 +30,16 @@
|
|||
#include "support/data_support/utlist.h"
|
||||
#include "support/data_support/uthash.h"
|
||||
#include "CCArray.h"
|
||||
#include "CCLuaSupport.h"
|
||||
#include "LuaEngine.h"
|
||||
|
||||
#if LUA_ENGINE
|
||||
#include "CCLuaEngine.h"
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace cocos2d
|
||||
{
|
||||
|
||||
|
||||
// data structures
|
||||
|
||||
// A list double-linked list used for "updates with priority"
|
||||
|
@ -92,7 +94,7 @@ CCScheduler::CCScheduler(void)
|
|||
CCScheduler::~CCScheduler(void)
|
||||
{
|
||||
unscheduleAllSelectors();
|
||||
unscheduleScriptFunctions();
|
||||
unscheduleAllScriptFunctions();
|
||||
pSharedScheduler = NULL;
|
||||
m_scriptFunctions->release();
|
||||
}
|
||||
|
@ -104,33 +106,33 @@ CCScheduler* CCScheduler::sharedScheduler(void)
|
|||
pSharedScheduler = new CCScheduler();
|
||||
pSharedScheduler->init();
|
||||
}
|
||||
|
||||
|
||||
return pSharedScheduler;
|
||||
}
|
||||
|
||||
bool CCScheduler::init(void)
|
||||
{
|
||||
m_fTimeScale = 1.0f;
|
||||
|
||||
|
||||
// used to trigger CCTimer#update
|
||||
// m_pfnUpdateSelector = &CCScheduler::update;
|
||||
// impMethod = (TICK_IMP) [CCTimer instanceMethodForSelector:updateSelector];
|
||||
|
||||
|
||||
// updates with priority
|
||||
m_pUpdates0List = NULL;
|
||||
m_pUpdatesNegList = NULL;
|
||||
m_pUpdatesPosList = NULL;
|
||||
m_pHashForUpdates = NULL;
|
||||
|
||||
|
||||
// selectors with interval
|
||||
m_pCurrentTarget = NULL;
|
||||
m_bCurrentTargetSalvaged = false;
|
||||
m_pHashForSelectors = NULL;
|
||||
m_bUpdateHashLocked = false;
|
||||
|
||||
|
||||
m_scriptFunctions = CCArray::arrayWithCapacity(20);
|
||||
m_scriptFunctions->retain();
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -147,10 +149,10 @@ void CCScheduler::scheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol *p
|
|||
{
|
||||
assert(pfnSelector);
|
||||
assert(pTarget);
|
||||
|
||||
|
||||
tHashSelectorEntry *pElement = NULL;
|
||||
HASH_FIND_INT(m_pHashForSelectors, &pTarget, pElement);
|
||||
|
||||
|
||||
if (! pElement)
|
||||
{
|
||||
pElement = (tHashSelectorEntry *)calloc(sizeof(*pElement), 1);
|
||||
|
@ -160,7 +162,7 @@ void CCScheduler::scheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol *p
|
|||
pTarget->selectorProtocolRetain();
|
||||
}
|
||||
HASH_ADD_INT(m_pHashForSelectors, target, pElement);
|
||||
|
||||
|
||||
// Is this the 1st element ? Then set the pause level to all the selectors of this target
|
||||
pElement->paused = bPaused;
|
||||
}
|
||||
|
@ -168,7 +170,7 @@ void CCScheduler::scheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol *p
|
|||
{
|
||||
assert(pElement->paused == bPaused);
|
||||
}
|
||||
|
||||
|
||||
if (pElement->timers == NULL)
|
||||
{
|
||||
pElement->timers = ccArrayNew(10);
|
||||
|
@ -178,7 +180,7 @@ void CCScheduler::scheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol *p
|
|||
for (unsigned int i = 0; i < pElement->timers->num; ++i)
|
||||
{
|
||||
CCTimer *timer = (CCTimer*)pElement->timers->arr[i];
|
||||
|
||||
|
||||
if (pfnSelector == timer->m_pfnSelector)
|
||||
{
|
||||
CCLOG("CCSheduler#scheduleSelector. Selector already scheduled.");
|
||||
|
@ -188,39 +190,13 @@ void CCScheduler::scheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol *p
|
|||
}
|
||||
ccArrayEnsureExtraCapacity(pElement->timers, 1);
|
||||
}
|
||||
|
||||
|
||||
CCTimer *pTimer = new CCTimer();
|
||||
pTimer->initWithTarget(pTarget, pfnSelector, fInterval);
|
||||
ccArrayAppendObject(pElement->timers, pTimer);
|
||||
pTimer->release();
|
||||
}
|
||||
|
||||
int CCScheduler::scheduleScriptFunc(int refID, ccTime fInterval, bool bPaused)
|
||||
{
|
||||
CCSchedulerFuncEntry* entry = CCSchedulerFuncEntry::entryWithRefID(refID, fInterval, bPaused);
|
||||
m_scriptFunctions->addObject(entry);
|
||||
|
||||
// CCLOG("CCScheduler::scheduleScriptFunc() - add script entry, handle: %d, refid: %d", entry->getHandle(), refID);
|
||||
return entry->getHandle();
|
||||
}
|
||||
|
||||
void CCScheduler::unscheduleScriptFunc(int handle)
|
||||
{
|
||||
for (int i = m_scriptFunctions->count() - 1; i >= 0; i--)
|
||||
{
|
||||
CCSchedulerFuncEntry* entry = (CCSchedulerFuncEntry*)m_scriptFunctions->objectAtIndex(i);
|
||||
if (entry->getHandle() == handle)
|
||||
{
|
||||
entry->markDeleted();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CCScheduler::unscheduleScriptFunctions()
|
||||
{
|
||||
m_scriptFunctions->removeAllObjects();
|
||||
}
|
||||
|
||||
void CCScheduler::unscheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol *pTarget)
|
||||
{
|
||||
// explicity handle nil arguments when removing an object
|
||||
|
@ -228,19 +204,19 @@ void CCScheduler::unscheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//assert(pTarget);
|
||||
//assert(pfnSelector);
|
||||
|
||||
|
||||
tHashSelectorEntry *pElement = NULL;
|
||||
HASH_FIND_INT(m_pHashForSelectors, &pTarget, pElement);
|
||||
|
||||
|
||||
if (pElement)
|
||||
{
|
||||
for (unsigned int i = 0; i < pElement->timers->num; ++i)
|
||||
{
|
||||
CCTimer *pTimer = (CCTimer*)(pElement->timers->arr[i]);
|
||||
|
||||
|
||||
if (pfnSelector == pTimer->m_pfnSelector)
|
||||
{
|
||||
if (pTimer == pElement->currentTimer && (! pElement->currentTimerSalvaged))
|
||||
|
@ -248,15 +224,15 @@ void CCScheduler::unscheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol
|
|||
pElement->currentTimer->retain();
|
||||
pElement->currentTimerSalvaged = true;
|
||||
}
|
||||
|
||||
|
||||
ccArrayRemoveObjectAtIndex(pElement->timers, i );
|
||||
|
||||
|
||||
// update timerIndex in case we are in tick:, looping over the actions
|
||||
if (pElement->timerIndex >= i)
|
||||
{
|
||||
pElement->timerIndex--;
|
||||
}
|
||||
|
||||
|
||||
if (pElement->timers->num == 0)
|
||||
{
|
||||
if (m_pCurrentTarget == pElement)
|
||||
|
@ -268,7 +244,7 @@ void CCScheduler::unscheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol
|
|||
removeHashElement(pElement);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -278,13 +254,13 @@ void CCScheduler::unscheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol
|
|||
void CCScheduler::priorityIn(tListEntry **ppList, SelectorProtocol *pTarget, int nPriority, bool bPaused)
|
||||
{
|
||||
tListEntry *pListElement = (tListEntry *)malloc(sizeof(*pListElement));
|
||||
|
||||
|
||||
pListElement->target = pTarget;
|
||||
pListElement->priority = nPriority;
|
||||
pListElement->paused = bPaused;
|
||||
pListElement->next = pListElement->prev = NULL;
|
||||
pListElement->markedForDeletion = false;
|
||||
|
||||
|
||||
// empey list ?
|
||||
if (! *ppList)
|
||||
{
|
||||
|
@ -293,7 +269,7 @@ void CCScheduler::priorityIn(tListEntry **ppList, SelectorProtocol *pTarget, int
|
|||
else
|
||||
{
|
||||
bool bAdded = false;
|
||||
|
||||
|
||||
for (tListEntry *pElement = *ppList; pElement; pElement = pElement->next)
|
||||
{
|
||||
if (nPriority < pElement->priority)
|
||||
|
@ -306,23 +282,23 @@ void CCScheduler::priorityIn(tListEntry **ppList, SelectorProtocol *pTarget, int
|
|||
{
|
||||
pListElement->next = pElement;
|
||||
pListElement->prev = pElement->prev;
|
||||
|
||||
|
||||
pElement->prev->next = pListElement;
|
||||
pElement->prev = pListElement;
|
||||
}
|
||||
|
||||
|
||||
bAdded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Not added? priority has the higher value. Append it.
|
||||
if (! bAdded)
|
||||
{
|
||||
DL_APPEND(*ppList, pListElement);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// update hash entry for quick access
|
||||
tHashUpdateEntry *pHashElement = (tHashUpdateEntry *)calloc(sizeof(*pHashElement), 1);
|
||||
pHashElement->target = pTarget;
|
||||
|
@ -335,13 +311,13 @@ void CCScheduler::priorityIn(tListEntry **ppList, SelectorProtocol *pTarget, int
|
|||
void CCScheduler::appendIn(_listEntry **ppList, SelectorProtocol *pTarget, bool bPaused)
|
||||
{
|
||||
tListEntry *pListElement = (tListEntry *)malloc(sizeof(*pListElement));
|
||||
|
||||
|
||||
pListElement->target = pTarget;
|
||||
pListElement->paused = bPaused;
|
||||
pListElement->markedForDeletion = false;
|
||||
|
||||
|
||||
DL_APPEND(*ppList, pListElement);
|
||||
|
||||
|
||||
// update hash entry for quicker access
|
||||
tHashUpdateEntry *pHashElement = (tHashUpdateEntry *)calloc(sizeof(*pHashElement), 1);
|
||||
pHashElement->target = pTarget;
|
||||
|
@ -353,7 +329,7 @@ void CCScheduler::appendIn(_listEntry **ppList, SelectorProtocol *pTarget, bool
|
|||
|
||||
void CCScheduler::scheduleUpdateForTarget(SelectorProtocol *pTarget, int nPriority, bool bPaused)
|
||||
{
|
||||
|
||||
|
||||
tHashUpdateEntry *pHashElement = NULL;
|
||||
HASH_FIND_INT(m_pHashForUpdates, &pTarget, pHashElement);
|
||||
if (pHashElement)
|
||||
|
@ -362,11 +338,11 @@ void CCScheduler::scheduleUpdateForTarget(SelectorProtocol *pTarget, int nPriori
|
|||
assert(pHashElement->entry->markedForDeletion);
|
||||
#endif
|
||||
// TODO: check if priority has changed!
|
||||
|
||||
|
||||
pHashElement->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 (nPriority == 0)
|
||||
|
@ -386,14 +362,14 @@ void CCScheduler::scheduleUpdateForTarget(SelectorProtocol *pTarget, int nPriori
|
|||
void CCScheduler::removeUpdateFromHash(struct _listEntry *entry)
|
||||
{
|
||||
tHashUpdateEntry *element = NULL;
|
||||
|
||||
|
||||
HASH_FIND_INT(m_pHashForUpdates, &entry->target, element);
|
||||
if (element)
|
||||
{
|
||||
// list entry
|
||||
DL_DELETE(*element->list, element->entry);
|
||||
free(element->entry);
|
||||
|
||||
|
||||
// hash entry
|
||||
element->target->selectorProtocolRelease();
|
||||
HASH_DEL(m_pHashForUpdates, element);
|
||||
|
@ -407,7 +383,7 @@ void CCScheduler::unscheduleUpdateForTarget(const SelectorProtocol *pTarget)
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
tHashUpdateEntry *pElement = NULL;
|
||||
HASH_FIND_INT(m_pHashForUpdates, &pTarget, pElement);
|
||||
if (pElement)
|
||||
|
@ -433,10 +409,10 @@ void CCScheduler::unscheduleAllSelectors(void)
|
|||
// pElement may be removed in unscheduleAllSelectorsForTarget
|
||||
pNextElement = (tHashSelectorEntry *)pElement->hh.next;
|
||||
unscheduleAllSelectorsForTarget(pElement->target);
|
||||
|
||||
|
||||
pElement = pNextElement;
|
||||
}
|
||||
|
||||
|
||||
// Updates selectors
|
||||
tListEntry *pEntry, *pTmp;
|
||||
DL_FOREACH_SAFE(m_pUpdates0List, pEntry, pTmp)
|
||||
|
@ -451,8 +427,8 @@ void CCScheduler::unscheduleAllSelectors(void)
|
|||
{
|
||||
unscheduleUpdateForTarget(pEntry->target);
|
||||
}
|
||||
|
||||
unscheduleScriptFunctions();
|
||||
|
||||
unscheduleAllScriptFunctions();
|
||||
}
|
||||
|
||||
void CCScheduler::unscheduleAllSelectorsForTarget(SelectorProtocol *pTarget)
|
||||
|
@ -462,21 +438,21 @@ void CCScheduler::unscheduleAllSelectorsForTarget(SelectorProtocol *pTarget)
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Custom Selectors
|
||||
tHashSelectorEntry *pElement = NULL;
|
||||
HASH_FIND_INT(m_pHashForSelectors, &pTarget, pElement);
|
||||
|
||||
|
||||
if (pElement)
|
||||
{
|
||||
if (ccArrayContainsObject(pElement->timers, pElement->currentTimer)
|
||||
&& (! pElement->currentTimerSalvaged))
|
||||
&& (! pElement->currentTimerSalvaged))
|
||||
{
|
||||
pElement->currentTimer->retain();
|
||||
pElement->currentTimerSalvaged = true;
|
||||
}
|
||||
ccArrayRemoveAllObjects(pElement->timers);
|
||||
|
||||
|
||||
if (m_pCurrentTarget == pElement)
|
||||
{
|
||||
m_bCurrentTargetSalvaged = true;
|
||||
|
@ -486,7 +462,7 @@ void CCScheduler::unscheduleAllSelectorsForTarget(SelectorProtocol *pTarget)
|
|||
removeHashElement(pElement);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// update selector
|
||||
unscheduleUpdateForTarget(pTarget);
|
||||
}
|
||||
|
@ -494,7 +470,7 @@ void CCScheduler::unscheduleAllSelectorsForTarget(SelectorProtocol *pTarget)
|
|||
void CCScheduler::resumeTarget(SelectorProtocol *pTarget)
|
||||
{
|
||||
assert(pTarget != NULL);
|
||||
|
||||
|
||||
// custom selectors
|
||||
tHashSelectorEntry *pElement = NULL;
|
||||
HASH_FIND_INT(m_pHashForSelectors, &pTarget, pElement);
|
||||
|
@ -502,7 +478,7 @@ void CCScheduler::resumeTarget(SelectorProtocol *pTarget)
|
|||
{
|
||||
pElement->paused = false;
|
||||
}
|
||||
|
||||
|
||||
// update selector
|
||||
tHashUpdateEntry *pElementUpdate = NULL;
|
||||
HASH_FIND_INT(m_pHashForUpdates, &pTarget, pElementUpdate);
|
||||
|
@ -516,7 +492,7 @@ void CCScheduler::resumeTarget(SelectorProtocol *pTarget)
|
|||
void CCScheduler::pauseTarget(SelectorProtocol *pTarget)
|
||||
{
|
||||
assert(pTarget != NULL);
|
||||
|
||||
|
||||
// custom selectors
|
||||
tHashSelectorEntry *pElement = NULL;
|
||||
HASH_FIND_INT(m_pHashForSelectors, &pTarget, pElement);
|
||||
|
@ -524,7 +500,7 @@ void CCScheduler::pauseTarget(SelectorProtocol *pTarget)
|
|||
{
|
||||
pElement->paused = true;
|
||||
}
|
||||
|
||||
|
||||
// update selector
|
||||
tHashUpdateEntry *pElementUpdate = NULL;
|
||||
HASH_FIND_INT(m_pHashForUpdates, &pTarget, pElementUpdate);
|
||||
|
@ -538,7 +514,7 @@ void CCScheduler::pauseTarget(SelectorProtocol *pTarget)
|
|||
bool CCScheduler::isTargetPaused(SelectorProtocol *pTarget)
|
||||
{
|
||||
CCAssert( pTarget != NULL, "target must be non nil" );
|
||||
|
||||
|
||||
// Custom selectors
|
||||
tHashSelectorEntry *pElement = NULL;
|
||||
HASH_FIND_INT(m_pHashForSelectors, &pTarget, pElement);
|
||||
|
@ -553,15 +529,15 @@ bool CCScheduler::isTargetPaused(SelectorProtocol *pTarget)
|
|||
void CCScheduler::tick(ccTime dt)
|
||||
{
|
||||
m_bUpdateHashLocked = true;
|
||||
|
||||
|
||||
if (m_fTimeScale != 1.0f)
|
||||
{
|
||||
dt *= m_fTimeScale;
|
||||
}
|
||||
|
||||
|
||||
// Iterate all over the Updates selectors
|
||||
tListEntry *pEntry, *pTmp;
|
||||
|
||||
|
||||
// updates with priority < 0
|
||||
DL_FOREACH_SAFE(m_pUpdatesNegList, pEntry, pTmp)
|
||||
{
|
||||
|
@ -570,7 +546,7 @@ void CCScheduler::tick(ccTime dt)
|
|||
pEntry->target->update(dt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// updates with priority == 0
|
||||
DL_FOREACH_SAFE(m_pUpdates0List, pEntry, pTmp)
|
||||
{
|
||||
|
@ -579,7 +555,7 @@ void CCScheduler::tick(ccTime dt)
|
|||
pEntry->target->update(dt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// updates with priority > 0
|
||||
DL_FOREACH_SAFE(m_pUpdatesPosList, pEntry, pTmp)
|
||||
{
|
||||
|
@ -588,13 +564,13 @@ void CCScheduler::tick(ccTime dt)
|
|||
pEntry->target->update(dt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Interate all over the custom selectors
|
||||
for (tHashSelectorEntry *elt = m_pHashForSelectors; elt != NULL; )
|
||||
{
|
||||
m_pCurrentTarget = elt;
|
||||
m_bCurrentTargetSalvaged = false;
|
||||
|
||||
|
||||
if (! m_pCurrentTarget->paused)
|
||||
{
|
||||
// The 'timers' array may change while inside this loop
|
||||
|
@ -602,9 +578,9 @@ void CCScheduler::tick(ccTime dt)
|
|||
{
|
||||
elt->currentTimer = (CCTimer*)(elt->timers->arr[elt->timerIndex]);
|
||||
elt->currentTimerSalvaged = false;
|
||||
|
||||
|
||||
elt->currentTimer->update(dt);
|
||||
|
||||
|
||||
if (elt->currentTimerSalvaged)
|
||||
{
|
||||
// The currentTimer told the remove itself. To prevent the timer from
|
||||
|
@ -612,22 +588,22 @@ void CCScheduler::tick(ccTime dt)
|
|||
// it. Now that step is done, it's safe to release it.
|
||||
elt->currentTimer->release();
|
||||
}
|
||||
|
||||
|
||||
elt->currentTimer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// elt, at this moment, is still valid
|
||||
// so it is safe to ask this here (issue #490)
|
||||
elt = (tHashSelectorEntry *)elt->hh.next;
|
||||
|
||||
|
||||
// only delete currentTarget if no actions were scheduled during the cycle (issue #481)
|
||||
if (m_bCurrentTargetSalvaged && m_pCurrentTarget->timers->num == 0)
|
||||
{
|
||||
removeHashElement(m_pCurrentTarget);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// delete all updates that are morked for deletion
|
||||
// updates with priority < 0
|
||||
DL_FOREACH_SAFE(m_pUpdatesNegList, pEntry, pTmp)
|
||||
|
@ -637,16 +613,16 @@ void CCScheduler::tick(ccTime dt)
|
|||
this->removeUpdateFromHash(pEntry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// updates with priority == 0
|
||||
DL_FOREACH_SAFE(m_pUpdates0List, pEntry, pTmp)
|
||||
{
|
||||
if (pEntry->markedForDeletion)
|
||||
{
|
||||
// this->removeUpdateFromHash(pEntry);
|
||||
// this->removeUpdateFromHash(pEntry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// updates with priority > 0
|
||||
DL_FOREACH_SAFE(m_pUpdatesPosList, pEntry, pTmp)
|
||||
{
|
||||
|
@ -655,11 +631,12 @@ void CCScheduler::tick(ccTime dt)
|
|||
this->removeUpdateFromHash(pEntry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
m_bUpdateHashLocked = false;
|
||||
|
||||
|
||||
m_pCurrentTarget = NULL;
|
||||
|
||||
|
||||
#if LUA_ENGINE
|
||||
// Interate all script functions
|
||||
for (int i = m_scriptFunctions->count() - 1; i >= 0; i--)
|
||||
{
|
||||
|
@ -675,6 +652,7 @@ void CCScheduler::tick(ccTime dt)
|
|||
CCSchedulerFuncEntry* entry = (CCSchedulerFuncEntry*)m_scriptFunctions->objectAtIndex(i);
|
||||
if (entry->isMarkDeleted()) m_scriptFunctions->removeObjectAtIndex(i);
|
||||
}
|
||||
#endif // LUA_ENGINE
|
||||
}
|
||||
|
||||
void CCScheduler::purgeSharedScheduler(void)
|
||||
|
@ -683,4 +661,34 @@ void CCScheduler::purgeSharedScheduler(void)
|
|||
pSharedScheduler = NULL;
|
||||
}
|
||||
|
||||
|
||||
#if LUA_ENGINE
|
||||
int CCScheduler::scheduleScriptFunc(int functionRefID, ccTime fInterval, bool bPaused)
|
||||
{
|
||||
CCSchedulerFuncEntry* entry = CCSchedulerFuncEntry::entryWithFunctionRefID(functionRefID, fInterval, bPaused);
|
||||
m_scriptFunctions->addObject(entry);
|
||||
return entry->getEntryID();
|
||||
}
|
||||
|
||||
void CCScheduler::unscheduleScriptFunc(int scheduleEntryID)
|
||||
{
|
||||
for (int i = m_scriptFunctions->count() - 1; i >= 0; i--)
|
||||
{
|
||||
CCSchedulerFuncEntry* entry = (CCSchedulerFuncEntry*)m_scriptFunctions->objectAtIndex(i);
|
||||
if (entry->getEntryID() == scheduleEntryID)
|
||||
{
|
||||
entry->markDeleted();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CCScheduler::unscheduleAllScriptFunctions()
|
||||
{
|
||||
m_scriptFunctions->removeAllObjects();
|
||||
}
|
||||
|
||||
#endif // LUA_ENGINE
|
||||
|
||||
} // namespace cocos2d
|
||||
|
||||
|
|
|
@ -25,14 +25,16 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "CCTimer.h"
|
||||
#include "LuaEngine.h"
|
||||
#if LUA_ENGINE
|
||||
#include "CCLuaEngine.h"
|
||||
#endif
|
||||
|
||||
namespace cocos2d
|
||||
{
|
||||
|
||||
CCTimer::CCTimer()
|
||||
: m_pTarget(NULL)
|
||||
, m_refID(0)
|
||||
, m_functionRefID(0)
|
||||
, m_fInterval(0.0f)
|
||||
, m_fElapsed(0.0f)
|
||||
, m_pfnSelector(NULL)
|
||||
|
@ -41,10 +43,12 @@ CCTimer::CCTimer()
|
|||
|
||||
CCTimer::~CCTimer()
|
||||
{
|
||||
if (m_refID)
|
||||
#if LUA_ENGINE
|
||||
if (m_functionRefID)
|
||||
{
|
||||
LuaEngine::sharedEngine()->releaseRefID(m_refID);
|
||||
CCLuaEngine::sharedEngine()->removeLuaFunctionRef(m_functionRefID);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
CCTimer* CCTimer::timerWithTarget(SelectorProtocol *pTarget, SEL_SCHEDULE pfnSelector)
|
||||
|
@ -77,19 +81,19 @@ CCTimer* CCTimer::timerWithTarget(SelectorProtocol *pTarget, SEL_SCHEDULE pfnSel
|
|||
return pTimer;
|
||||
}
|
||||
|
||||
bool CCTimer::initWithScriptFunc(int newRefID, ccTime fSeconds)
|
||||
#if LUA_ENGINE
|
||||
bool CCTimer::initWithScriptFunc(int functionRefID, ccTime fSeconds)
|
||||
{
|
||||
LuaEngine::sharedEngine()->retainRefID(newRefID);
|
||||
if (m_refID)
|
||||
if (m_functionRefID)
|
||||
{
|
||||
LuaEngine::sharedEngine()->releaseRefID(m_refID);
|
||||
CCLuaEngine::sharedEngine()->removeLuaFunctionRef(m_functionRefID);
|
||||
}
|
||||
m_refID = newRefID;
|
||||
m_functionRefID = functionRefID;
|
||||
m_fInterval = fSeconds;
|
||||
m_fElapsed = -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool CCTimer::initWithTarget(SelectorProtocol *pTarget, SEL_SCHEDULE pfnSelector)
|
||||
{
|
||||
|
@ -123,14 +127,15 @@ void CCTimer::update(ccTime dt)
|
|||
(m_pTarget->*m_pfnSelector)(m_fElapsed);
|
||||
m_fElapsed = 0;
|
||||
}
|
||||
if (m_refID)
|
||||
#if LUA_ENGINE
|
||||
if (m_functionRefID)
|
||||
{
|
||||
LuaEngine::sharedEngine()->executeSchedule(m_refID, m_fElapsed);
|
||||
CCLuaEngine::sharedEngine()->executeSchedule(m_functionRefID, m_fElapsed);
|
||||
m_fElapsed = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace cocos2d
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include <assert.h>
|
||||
|
||||
#ifdef LUA_ENGINE
|
||||
#include "LuaEngine.h"
|
||||
#include "CCLuaEngine.h"
|
||||
#endif
|
||||
|
||||
namespace cocos2d {
|
||||
|
@ -63,7 +63,7 @@ CCObject::~CCObject(void)
|
|||
#ifdef LUA_ENGINE
|
||||
if (m_refID != 0)
|
||||
{
|
||||
LuaEngine::sharedEngine()->removeCCObject(this);
|
||||
CCLuaEngine::sharedEngine()->removeCCObject(this);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2011 cocos2d-x.org
|
||||
Copyright (c) 2008-2011 Ricardo Quesada
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
Copyright (c) 2010-2011 cocos2d-x.org
|
||||
Copyright (c) 2008-2011 Ricardo Quesada
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CCMENU_ITEM_H__
|
||||
#define __CCMENU_ITEM_H__
|
||||
|
@ -40,24 +40,25 @@ class CCSprite;
|
|||
#define kCCItemSize 32
|
||||
|
||||
/** @brief CCMenuItem base class
|
||||
*
|
||||
* Subclass CCMenuItem (or any subclass) to create your custom CCMenuItem objects.
|
||||
*/
|
||||
*
|
||||
* Subclass CCMenuItem (or any subclass) to create your custom CCMenuItem objects.
|
||||
*/
|
||||
class CC_DLL CCMenuItem : public CCNode
|
||||
{
|
||||
/** whether or not the item is selected
|
||||
@since v0.8.2
|
||||
*/
|
||||
@since v0.8.2
|
||||
*/
|
||||
CC_PROPERTY_READONLY(bool, m_bIsSelected, IsSelected);
|
||||
CC_PROPERTY(bool, m_bIsEnabled, IsEnabled);
|
||||
public:
|
||||
CCMenuItem()
|
||||
: m_bIsSelected(false)
|
||||
, m_bIsEnabled(false)
|
||||
, m_pListener(NULL)
|
||||
, m_pfnSelector(NULL)
|
||||
: m_bIsSelected(false)
|
||||
, m_bIsEnabled(false)
|
||||
, m_pListener(NULL)
|
||||
, m_pfnSelector(NULL)
|
||||
, m_functionRefID(0)
|
||||
{}
|
||||
virtual ~CCMenuItem() {}
|
||||
virtual ~CCMenuItem();
|
||||
/** Creates a CCMenuItem with a target/selector */
|
||||
static CCMenuItem * itemWithTarget(SelectorProtocol *rec, SEL_MenuHandler selector);
|
||||
/** Initializes a CCMenuItem with a target/selector */
|
||||
|
@ -70,26 +71,31 @@ public:
|
|||
virtual void selected();
|
||||
/** The item was unselected */
|
||||
virtual void unselected();
|
||||
|
||||
#if LUA_ENGINE
|
||||
/** Register a script function, the function is called in activete
|
||||
* If pszFunctionName is NULL, then unregister it.
|
||||
*/
|
||||
virtual void registerScriptHandler(const char* pszFunctionName);
|
||||
|
||||
*/
|
||||
virtual void registerScriptHandler(int functionRefID);
|
||||
virtual void unregisterScriptHandler(void);
|
||||
#endif
|
||||
|
||||
/** set the target/selector of the menu item*/
|
||||
void setTarget(SelectorProtocol *rec, SEL_MenuHandler selector);
|
||||
protected:
|
||||
SelectorProtocol* m_pListener;
|
||||
SEL_MenuHandler m_pfnSelector;
|
||||
std::string m_functionName;
|
||||
#if LUA_ENGINE
|
||||
int m_functionRefID;
|
||||
#endif
|
||||
};
|
||||
|
||||
/** @brief An abstract class for "label" CCMenuItemLabel items
|
||||
Any CCNode that supports the CCLabelProtocol protocol can be added.
|
||||
Supported nodes:
|
||||
- CCBitmapFontAtlas
|
||||
- CCLabelAtlas
|
||||
- CCLabelTTF
|
||||
*/
|
||||
Any CCNode that supports the CCLabelProtocol protocol can be added.
|
||||
Supported nodes:
|
||||
- CCBitmapFontAtlas
|
||||
- CCLabelAtlas
|
||||
- CCLabelTTF
|
||||
*/
|
||||
class CC_DLL CCMenuItemLabel : public CCMenuItem, public CCRGBAProtocol
|
||||
{
|
||||
/** the color that will be used to disable the item */
|
||||
|
@ -98,8 +104,8 @@ class CC_DLL CCMenuItemLabel : public CCMenuItem, public CCRGBAProtocol
|
|||
CC_PROPERTY(CCNode*, m_pLabel, Label);
|
||||
public:
|
||||
CCMenuItemLabel()
|
||||
: m_pLabel(NULL)
|
||||
, m_fOriginalScale(0.0)
|
||||
: m_pLabel(NULL)
|
||||
, m_fOriginalScale(0.0)
|
||||
{}
|
||||
virtual ~CCMenuItemLabel();
|
||||
/** creates a CCMenuItemLabel with a Label, target and selector */
|
||||
|
@ -115,14 +121,14 @@ public:
|
|||
virtual void selected();
|
||||
virtual void unselected();
|
||||
/** Enable or disabled the CCMenuItemFont
|
||||
@warning setIsEnabled changes the RGB color of the font
|
||||
*/
|
||||
@warning setIsEnabled changes the RGB color of the font
|
||||
*/
|
||||
virtual void setIsEnabled(bool enabled);
|
||||
virtual void setOpacity(GLubyte opacity);
|
||||
virtual GLubyte getOpacity();
|
||||
virtual void setColor(const ccColor3B& color);
|
||||
virtual const ccColor3B& getColor();
|
||||
|
||||
|
||||
virtual CCRGBAProtocol* convertToRGBAProtocol() {
|
||||
return (CCRGBAProtocol*)this;
|
||||
}
|
||||
|
@ -132,8 +138,8 @@ protected:
|
|||
};
|
||||
|
||||
/** @brief A CCMenuItemAtlasFont
|
||||
Helper class that creates a MenuItemLabel class with a LabelAtlas
|
||||
*/
|
||||
Helper class that creates a MenuItemLabel class with a LabelAtlas
|
||||
*/
|
||||
class CC_DLL CCMenuItemAtlasFont : public CCMenuItemLabel
|
||||
{
|
||||
public:
|
||||
|
@ -148,8 +154,8 @@ public:
|
|||
};
|
||||
|
||||
/** @brief A CCMenuItemFont
|
||||
Helper class that creates a CCMenuItemLabel class with a Label
|
||||
*/
|
||||
Helper class that creates a CCMenuItemLabel class with a Label
|
||||
*/
|
||||
class CC_DLL CCMenuItemFont : public CCMenuItemLabel
|
||||
{
|
||||
public:
|
||||
|
@ -169,39 +175,39 @@ public:
|
|||
static CCMenuItemFont * itemFromString(const char *value, SelectorProtocol* target, SEL_MenuHandler selector);
|
||||
/** initializes a menu item from a string with a target/selector */
|
||||
bool initFromString(const char *value, SelectorProtocol* target, SEL_MenuHandler selector);
|
||||
|
||||
|
||||
/** set font size
|
||||
* c++ can not overload static and non-static member functions with the same parameter types
|
||||
* so change the name to setFontSizeObj
|
||||
*/
|
||||
* c++ can not overload static and non-static member functions with the same parameter types
|
||||
* so change the name to setFontSizeObj
|
||||
*/
|
||||
void setFontSizeObj(unsigned int s);
|
||||
|
||||
|
||||
/** get font size */
|
||||
unsigned int fontSizeObj();
|
||||
|
||||
|
||||
/** set the font name
|
||||
* c++ can not overload static and non-static member functions with the same parameter types
|
||||
* so change the name to setFontNameObj
|
||||
*/
|
||||
void setFontNameObj(const char* name);
|
||||
|
||||
|
||||
const char* fontNameObj();
|
||||
|
||||
|
||||
protected:
|
||||
void recreateLabel();
|
||||
|
||||
|
||||
unsigned int m_uFontSize;
|
||||
std::string m_strFontName;
|
||||
};
|
||||
|
||||
/** @brief CCMenuItemSprite accepts CCNode<CCRGBAProtocol> objects as items.
|
||||
The images has 3 different states:
|
||||
- unselected image
|
||||
- selected image
|
||||
- disabled image
|
||||
|
||||
@since v0.8.0
|
||||
*/
|
||||
The images has 3 different states:
|
||||
- unselected image
|
||||
- selected image
|
||||
- disabled image
|
||||
|
||||
@since v0.8.0
|
||||
*/
|
||||
class CC_DLL CCMenuItemSprite : public CCMenuItem, public CCRGBAProtocol
|
||||
{
|
||||
/** the image used when the item is not selected */
|
||||
|
@ -212,12 +218,12 @@ class CC_DLL CCMenuItemSprite : public CCMenuItem, public CCRGBAProtocol
|
|||
CC_PROPERTY(CCNode*, m_pDisabledImage, DisabledImage);
|
||||
public:
|
||||
CCMenuItemSprite()
|
||||
:m_pNormalImage(NULL)
|
||||
,m_pSelectedImage(NULL)
|
||||
,m_pDisabledImage(NULL)
|
||||
:m_pNormalImage(NULL)
|
||||
,m_pSelectedImage(NULL)
|
||||
,m_pDisabledImage(NULL)
|
||||
{}
|
||||
/** creates a menu item with a normal and selected image*/
|
||||
static CCMenuItemSprite * itemFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite);
|
||||
static CCMenuItemSprite * itemFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, CCNode* disabledSprite = NULL);
|
||||
/** creates a menu item with a normal and selected image with target/selector */
|
||||
static CCMenuItemSprite * itemFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, SelectorProtocol* target, SEL_MenuHandler selector);
|
||||
/** creates a menu item with a normal,selected and disabled image with target/selector */
|
||||
|
@ -229,27 +235,27 @@ public:
|
|||
virtual const ccColor3B& getColor();
|
||||
virtual void setOpacity(GLubyte opacity);
|
||||
virtual GLubyte getOpacity();
|
||||
|
||||
|
||||
/**
|
||||
@since v0.99.5
|
||||
*/
|
||||
@since v0.99.5
|
||||
*/
|
||||
virtual void selected();
|
||||
virtual void unselected();
|
||||
virtual void setIsEnabled(bool bEnabled);
|
||||
|
||||
|
||||
virtual CCRGBAProtocol* convertToRGBAProtocol() {
|
||||
return (CCRGBAProtocol*)this;
|
||||
}
|
||||
};
|
||||
|
||||
/** @brief CCMenuItemImage accepts images as items.
|
||||
The images has 3 different states:
|
||||
- unselected image
|
||||
- selected image
|
||||
- disabled image
|
||||
|
||||
For best results try that all images are of the same size
|
||||
*/
|
||||
The images has 3 different states:
|
||||
- unselected image
|
||||
- selected image
|
||||
- disabled image
|
||||
|
||||
For best results try that all images are of the same size
|
||||
*/
|
||||
class CC_DLL CCMenuItemImage : public CCMenuItemSprite
|
||||
{
|
||||
public:
|
||||
|
@ -268,9 +274,9 @@ public:
|
|||
};
|
||||
|
||||
/** @brief A CCMenuItemToggle
|
||||
A simple container class that "toggles" it's inner items
|
||||
The inner itmes can be any MenuItem
|
||||
*/
|
||||
A simple container class that "toggles" it's inner items
|
||||
The inner itmes can be any MenuItem
|
||||
*/
|
||||
class CC_DLL CCMenuItemToggle : public CCMenuItem, public CCRGBAProtocol
|
||||
{
|
||||
/** conforms with CCRGBAProtocol protocol */
|
||||
|
@ -280,21 +286,21 @@ class CC_DLL CCMenuItemToggle : public CCMenuItem, public CCRGBAProtocol
|
|||
/** returns the selected item */
|
||||
CC_PROPERTY(unsigned int, m_uSelectedIndex, SelectedIndex);
|
||||
/** CCMutableArray that contains the subitems. You can add/remove items in runtime, and you can replace the array with a new one.
|
||||
@since v0.7.2
|
||||
*/
|
||||
@since v0.7.2
|
||||
*/
|
||||
CC_PROPERTY(CCMutableArray<CCMenuItem*>*, m_pSubItems, SubItems);
|
||||
public:
|
||||
CCMenuItemToggle()
|
||||
: m_cOpacity(0)
|
||||
, m_uSelectedIndex(0)
|
||||
, m_pSubItems(NULL)
|
||||
: m_cOpacity(0)
|
||||
, m_uSelectedIndex(0)
|
||||
, m_pSubItems(NULL)
|
||||
{}
|
||||
virtual ~CCMenuItemToggle();
|
||||
/** creates a menu item from a list of items with a target/selector */
|
||||
static CCMenuItemToggle* itemWithTarget(SelectorProtocol* target, SEL_MenuHandler selector, CCMenuItem* item, ...);
|
||||
/** initializes a menu item from a list of items with a target selector */
|
||||
bool initWithTarget(SelectorProtocol* target, SEL_MenuHandler selector, CCMenuItem* item, va_list args);
|
||||
|
||||
|
||||
// The follow methods offered to lua
|
||||
/** creates a menu item with a item */
|
||||
static CCMenuItemToggle* itemWithItem(CCMenuItem *item);
|
||||
|
@ -302,7 +308,7 @@ public:
|
|||
bool initWithItem(CCMenuItem *item);
|
||||
/** add more menu item */
|
||||
void addSubItem(CCMenuItem *item);
|
||||
|
||||
|
||||
/** return the selected item */
|
||||
CCMenuItem* selectedItem();
|
||||
// super methods
|
||||
|
@ -310,7 +316,7 @@ public:
|
|||
virtual void selected();
|
||||
virtual void unselected();
|
||||
virtual void setIsEnabled(bool var);
|
||||
|
||||
|
||||
virtual CCRGBAProtocol* convertToRGBAProtocol() {
|
||||
return (CCRGBAProtocol*)this;
|
||||
}
|
||||
|
|
|
@ -86,15 +86,17 @@ public:
|
|||
@since v0.99.3
|
||||
*/
|
||||
|
||||
/** Schedule the script function
|
||||
#if LUA_ENGINE
|
||||
/** Schedule the script function, return schedule entry id
|
||||
*/
|
||||
int scheduleScriptFunc(int refid, ccTime fInterval, bool bPaused);
|
||||
|
||||
/** Unschedule the script function
|
||||
/** Unschedule the script function by schedule entry id
|
||||
*/
|
||||
void unscheduleScriptFunc(int handle);
|
||||
void unscheduleScriptFunctions();
|
||||
|
||||
void unscheduleScriptFunc(int scheduleEntryID);
|
||||
void unscheduleAllScriptFunctions();
|
||||
#endif
|
||||
|
||||
void scheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol *pTarget, ccTime fInterval, bool bPaused);
|
||||
|
||||
/** Schedules the 'update' selector for a given target with a given priority.
|
||||
|
|
|
@ -32,55 +32,60 @@
|
|||
|
||||
namespace cocos2d
|
||||
{
|
||||
//
|
||||
// CCTimer
|
||||
//
|
||||
/** @brief Light weight timer */
|
||||
class CC_DLL CCTimer : public CCObject
|
||||
{
|
||||
public:
|
||||
CCTimer(void);
|
||||
~CCTimer();
|
||||
|
||||
/** get interval in seconds */
|
||||
inline ccTime getInterval(void) {
|
||||
return m_fInterval;
|
||||
}
|
||||
/** set interval in seconds */
|
||||
inline void setInterval(ccTime fInterval) {
|
||||
m_fInterval = fInterval;
|
||||
}
|
||||
|
||||
/** Initializes a timer with a target and a selector. */
|
||||
bool initWithTarget(SelectorProtocol *pTarget, SEL_SCHEDULE pfnSelector);
|
||||
|
||||
/** Initializes a timer with a target, a selector and an interval in seconds. */
|
||||
bool initWithTarget(SelectorProtocol *pTarget, SEL_SCHEDULE pfnSelector, ccTime fSeconds);
|
||||
|
||||
bool initWithScriptFunc(int refid, ccTime fSeconds);
|
||||
|
||||
/** triggers the timer */
|
||||
void update(ccTime dt);
|
||||
|
||||
public:
|
||||
/** Allocates a timer with a target and a selector. */
|
||||
static CCTimer* timerWithTarget(SelectorProtocol *pTarget, SEL_SCHEDULE pfnSelector);
|
||||
|
||||
/** Allocates a timer with a script function. */
|
||||
static CCTimer* timerWithScriptFunc(int refid, ccTime fSeconds);
|
||||
|
||||
/** Allocates a timer with a target, a selector and an interval in seconds. */
|
||||
static CCTimer* timerWithTarget(SelectorProtocol *pTarget, SEL_SCHEDULE pfnSelector, ccTime fSeconds);
|
||||
|
||||
public:
|
||||
SEL_SCHEDULE m_pfnSelector;
|
||||
ccTime m_fInterval;
|
||||
int m_refID;
|
||||
|
||||
protected:
|
||||
SelectorProtocol *m_pTarget;
|
||||
ccTime m_fElapsed;
|
||||
};
|
||||
//
|
||||
// CCTimer
|
||||
//
|
||||
/** @brief Light weight timer */
|
||||
class CC_DLL CCTimer : public CCObject
|
||||
{
|
||||
public:
|
||||
CCTimer(void);
|
||||
~CCTimer();
|
||||
|
||||
/** get interval in seconds */
|
||||
inline ccTime getInterval(void) {
|
||||
return m_fInterval;
|
||||
}
|
||||
/** set interval in seconds */
|
||||
inline void setInterval(ccTime fInterval) {
|
||||
m_fInterval = fInterval;
|
||||
}
|
||||
|
||||
/** Initializes a timer with a target and a selector. */
|
||||
bool initWithTarget(SelectorProtocol *pTarget, SEL_SCHEDULE pfnSelector);
|
||||
|
||||
/** Initializes a timer with a target, a selector and an interval in seconds. */
|
||||
bool initWithTarget(SelectorProtocol *pTarget, SEL_SCHEDULE pfnSelector, ccTime fSeconds);
|
||||
|
||||
#if LUA_ENGINE
|
||||
bool initWithScriptFunc(int functionRefID, ccTime fSeconds);
|
||||
#endif
|
||||
|
||||
/** triggers the timer */
|
||||
void update(ccTime dt);
|
||||
|
||||
public:
|
||||
/** Allocates a timer with a target and a selector. */
|
||||
static CCTimer* timerWithTarget(SelectorProtocol *pTarget, SEL_SCHEDULE pfnSelector);
|
||||
|
||||
/** Allocates a timer with a script function. */
|
||||
static CCTimer* timerWithScriptFunc(int refid, ccTime fSeconds);
|
||||
|
||||
/** Allocates a timer with a target, a selector and an interval in seconds. */
|
||||
static CCTimer* timerWithTarget(SelectorProtocol *pTarget, SEL_SCHEDULE pfnSelector, ccTime fSeconds);
|
||||
|
||||
public:
|
||||
SEL_SCHEDULE m_pfnSelector;
|
||||
ccTime m_fInterval;
|
||||
|
||||
#if LUA_ENGINE
|
||||
int m_functionRefID;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
SelectorProtocol *m_pTarget;
|
||||
ccTime m_fElapsed;
|
||||
};
|
||||
|
||||
} // namespace cocos2d
|
||||
|
||||
|
|
|
@ -124,10 +124,6 @@ THE SOFTWARE.
|
|||
#include "ccTypes.h"
|
||||
#include "ccMacros.h"
|
||||
|
||||
#ifdef LUA_ENGINE
|
||||
#include "LuaEngine.h"
|
||||
#endif
|
||||
|
||||
namespace cocos2d {
|
||||
|
||||
const char* cocos2dVersion();
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2011 cocos2d-x.org
|
||||
Copyright (c) 2008-2011 Ricardo Quesada
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
Copyright (c) 2010-2011 cocos2d-x.org
|
||||
Copyright (c) 2008-2011 Ricardo Quesada
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include <cstring>
|
||||
#include "CCMenuItem.h"
|
||||
#include "CCPointExtension.h"
|
||||
|
@ -33,6 +33,10 @@ THE SOFTWARE.
|
|||
|
||||
#include <stdarg.h>
|
||||
|
||||
#if LUA_ENGINE
|
||||
#include "CCLuaEngine.h"
|
||||
#endif
|
||||
|
||||
namespace cocos2d {
|
||||
|
||||
static unsigned int _fontSize = kCCItemSize;
|
||||
|
@ -45,7 +49,7 @@ const unsigned int kZoomActionTag = 0xc0c05002;
|
|||
//
|
||||
// CCMenuItem
|
||||
//
|
||||
CCMenuItem * CCMenuItem::itemWithTarget(SelectorProtocol *rec, SEL_MenuHandler selector)
|
||||
CCMenuItem* CCMenuItem::itemWithTarget(SelectorProtocol *rec, SEL_MenuHandler selector)
|
||||
{
|
||||
CCMenuItem *pRet = new CCMenuItem();
|
||||
pRet->initWithTarget(rec, selector);
|
||||
|
@ -61,6 +65,13 @@ bool CCMenuItem::initWithTarget(SelectorProtocol *rec, SEL_MenuHandler selector)
|
|||
m_bIsSelected = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
CCMenuItem::~CCMenuItem()
|
||||
{
|
||||
#if LUA_ENGINE
|
||||
unregisterScriptHandler();
|
||||
#endif
|
||||
}
|
||||
|
||||
void CCMenuItem::selected()
|
||||
{
|
||||
|
@ -72,18 +83,25 @@ void CCMenuItem::unselected()
|
|||
m_bIsSelected = false;
|
||||
}
|
||||
|
||||
void CCMenuItem::registerScriptHandler(const char* pszFunctionName)
|
||||
#if LUA_ENGINE
|
||||
void CCMenuItem::registerScriptHandler(int functionRefID)
|
||||
{
|
||||
if (pszFunctionName)
|
||||
{
|
||||
this->m_functionName = string(pszFunctionName);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->m_functionName.clear();
|
||||
}
|
||||
unregisterScriptHandler();
|
||||
m_functionRefID = functionRefID;
|
||||
CCLOG("[LUA] ADD function refID: %04d, add CCMenuItem script handler", m_functionRefID);
|
||||
}
|
||||
|
||||
void CCMenuItem::unregisterScriptHandler(void)
|
||||
{
|
||||
if (m_functionRefID)
|
||||
{
|
||||
CCLuaEngine::sharedEngine()->removeLuaFunctionRef(m_functionRefID);
|
||||
CCLOG("[LUA] DEL function refID: %04d, remove CCMenuItem script handler", m_functionRefID);
|
||||
}
|
||||
m_functionRefID = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void CCMenuItem::activate()
|
||||
{
|
||||
if (m_bIsEnabled)
|
||||
|
@ -92,11 +110,13 @@ void CCMenuItem::activate()
|
|||
{
|
||||
(m_pListener->*m_pfnSelector)(this);
|
||||
}
|
||||
|
||||
// if (m_functionName.size() && CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine())
|
||||
// {
|
||||
// CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeCallFuncN(m_functionName.c_str(), this);
|
||||
// }
|
||||
|
||||
#if LUA_ENGINE
|
||||
if (m_functionRefID)
|
||||
{
|
||||
CCLuaEngine::sharedEngine()->executeFunctionByRefID(m_functionRefID, m_uID);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,8 +133,8 @@ bool CCMenuItem::getIsEnabled()
|
|||
CCRect CCMenuItem::rect()
|
||||
{
|
||||
return CCRectMake( m_tPosition.x - m_tContentSize.width * m_tAnchorPoint.x,
|
||||
m_tPosition.y - m_tContentSize.height * m_tAnchorPoint.y,
|
||||
m_tContentSize.width, m_tContentSize.height);
|
||||
m_tPosition.y - m_tContentSize.height * m_tAnchorPoint.y,
|
||||
m_tContentSize.width, m_tContentSize.height);
|
||||
}
|
||||
|
||||
bool CCMenuItem::getIsSelected()
|
||||
|
@ -151,12 +171,12 @@ void CCMenuItemLabel::setLabel(CCNode* var)
|
|||
var->setAnchorPoint(ccp(0, 0));
|
||||
setContentSize(var->getContentSize());
|
||||
}
|
||||
|
||||
|
||||
if (m_pLabel)
|
||||
{
|
||||
removeChild(m_pLabel, true);
|
||||
}
|
||||
|
||||
|
||||
m_pLabel = var;
|
||||
}
|
||||
CCMenuItemLabel * CCMenuItemLabel::itemWithLabel(CCNode*label, SelectorProtocol* target, SEL_MenuHandler selector)
|
||||
|
@ -205,7 +225,7 @@ void CCMenuItemLabel::selected()
|
|||
if(m_bIsEnabled)
|
||||
{
|
||||
CCMenuItem::selected();
|
||||
|
||||
|
||||
CCAction *action = getActionByTag(kZoomActionTag);
|
||||
if (action)
|
||||
{
|
||||
|
@ -215,7 +235,7 @@ void CCMenuItemLabel::selected()
|
|||
{
|
||||
m_fOriginalScale = this->getScale();
|
||||
}
|
||||
|
||||
|
||||
CCAction *zoomAction = CCScaleTo::actionWithDuration(0.1f, m_fOriginalScale * 1.2f);
|
||||
zoomAction->setTag(kZoomActionTag);
|
||||
this->runAction(zoomAction);
|
||||
|
@ -334,10 +354,10 @@ CCMenuItemFont * CCMenuItemFont::itemFromString(const char *value)
|
|||
bool CCMenuItemFont::initFromString(const char *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.c_str(), (float)m_uFontSize);
|
||||
if (CCMenuItemLabel::initWithLabel(label, target, selector))
|
||||
{
|
||||
|
@ -349,7 +369,7 @@ bool CCMenuItemFont::initFromString(const char *value, SelectorProtocol* target,
|
|||
void CCMenuItemFont::recreateLabel()
|
||||
{
|
||||
CCLabelTTF *label = CCLabelTTF::labelWithString(m_pLabel->convertToLabelProtocol()->getString(),
|
||||
m_strFontName.c_str(), (float)m_uFontSize);
|
||||
m_strFontName.c_str(), (float)m_uFontSize);
|
||||
this->setLabel(label);
|
||||
}
|
||||
|
||||
|
@ -390,12 +410,12 @@ void CCMenuItemSprite::setNormalImage(CCNode* var)
|
|||
var->setAnchorPoint(ccp(0, 0));
|
||||
var->setIsVisible(true);
|
||||
}
|
||||
|
||||
|
||||
if (m_pNormalImage)
|
||||
{
|
||||
removeChild(m_pNormalImage, true);
|
||||
}
|
||||
|
||||
|
||||
m_pNormalImage = var;
|
||||
}
|
||||
CCNode * CCMenuItemSprite::getSelectedImage()
|
||||
|
@ -410,12 +430,12 @@ void CCMenuItemSprite::setSelectedImage(CCNode* var)
|
|||
var->setAnchorPoint(ccp(0, 0));
|
||||
var->setIsVisible(false);
|
||||
}
|
||||
|
||||
|
||||
if (m_pSelectedImage)
|
||||
{
|
||||
removeChild(m_pSelectedImage, true);
|
||||
}
|
||||
|
||||
|
||||
m_pSelectedImage = var;
|
||||
}
|
||||
CCNode * CCMenuItemSprite::getDisabledImage()
|
||||
|
@ -430,12 +450,12 @@ void CCMenuItemSprite::setDisabledImage(CCNode* var)
|
|||
var->setAnchorPoint(ccp(0, 0));
|
||||
var->setIsVisible(false);
|
||||
}
|
||||
|
||||
|
||||
if (m_pDisabledImage)
|
||||
{
|
||||
removeChild(m_pDisabledImage, true);
|
||||
}
|
||||
|
||||
|
||||
m_pDisabledImage = var;
|
||||
}
|
||||
//
|
||||
|
@ -444,12 +464,12 @@ void CCMenuItemSprite::setDisabledImage(CCNode* var)
|
|||
void CCMenuItemSprite::setOpacity(GLubyte opacity)
|
||||
{
|
||||
m_pNormalImage->convertToRGBAProtocol()->setOpacity(opacity);
|
||||
|
||||
|
||||
if (m_pSelectedImage)
|
||||
{
|
||||
m_pSelectedImage->convertToRGBAProtocol()->setOpacity(opacity);
|
||||
}
|
||||
|
||||
|
||||
if (m_pDisabledImage)
|
||||
{
|
||||
m_pDisabledImage->convertToRGBAProtocol()->setOpacity(opacity);
|
||||
|
@ -458,12 +478,12 @@ void CCMenuItemSprite::setOpacity(GLubyte opacity)
|
|||
void CCMenuItemSprite::setColor(const ccColor3B& color)
|
||||
{
|
||||
m_pNormalImage->convertToRGBAProtocol()->setColor(color);
|
||||
|
||||
|
||||
if (m_pSelectedImage)
|
||||
{
|
||||
m_pSelectedImage->convertToRGBAProtocol()->setColor(color);
|
||||
}
|
||||
|
||||
|
||||
if (m_pDisabledImage)
|
||||
{
|
||||
m_pDisabledImage->convertToRGBAProtocol()->setColor(color);
|
||||
|
@ -477,9 +497,9 @@ const ccColor3B& CCMenuItemSprite::getColor()
|
|||
{
|
||||
return m_pNormalImage->convertToRGBAProtocol()->getColor();
|
||||
}
|
||||
CCMenuItemSprite * CCMenuItemSprite::itemFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite)
|
||||
CCMenuItemSprite * CCMenuItemSprite::itemFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, CCNode* disabledSprite)
|
||||
{
|
||||
return CCMenuItemSprite::itemFromNormalSprite(normalSprite, selectedSprite, NULL, NULL, NULL);
|
||||
return CCMenuItemSprite::itemFromNormalSprite(normalSprite, selectedSprite, disabledSprite, NULL, NULL);
|
||||
}
|
||||
CCMenuItemSprite * CCMenuItemSprite::itemFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, SelectorProtocol* target, SEL_MenuHandler selector)
|
||||
{
|
||||
|
@ -499,23 +519,23 @@ bool CCMenuItemSprite::initFromNormalSprite(CCNode* normalSprite, CCNode* select
|
|||
setNormalImage(normalSprite);
|
||||
setSelectedImage(selectedSprite);
|
||||
setDisabledImage(disabledSprite);
|
||||
|
||||
|
||||
this->setContentSize(m_pNormalImage->getContentSize());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@since v0.99.5
|
||||
*/
|
||||
@since v0.99.5
|
||||
*/
|
||||
void CCMenuItemSprite::selected()
|
||||
{
|
||||
CCMenuItem::selected();
|
||||
|
||||
|
||||
if (m_pDisabledImage)
|
||||
{
|
||||
m_pDisabledImage->setIsVisible(false);
|
||||
}
|
||||
|
||||
|
||||
if (m_pSelectedImage)
|
||||
{
|
||||
m_pNormalImage->setIsVisible(false);
|
||||
|
@ -530,14 +550,14 @@ void CCMenuItemSprite::selected()
|
|||
void CCMenuItemSprite::unselected()
|
||||
{
|
||||
CCMenuItem::unselected();
|
||||
|
||||
|
||||
m_pNormalImage->setIsVisible(true);
|
||||
|
||||
|
||||
if (m_pSelectedImage)
|
||||
{
|
||||
m_pSelectedImage->setIsVisible(false);
|
||||
}
|
||||
|
||||
|
||||
if (m_pDisabledImage)
|
||||
{
|
||||
m_pDisabledImage->setIsVisible(false);
|
||||
|
@ -547,16 +567,16 @@ void CCMenuItemSprite::unselected()
|
|||
void CCMenuItemSprite::setIsEnabled(bool bEnabled)
|
||||
{
|
||||
CCMenuItem::setIsEnabled(bEnabled);
|
||||
|
||||
|
||||
if (m_pSelectedImage)
|
||||
{
|
||||
m_pSelectedImage->setIsVisible(false);
|
||||
}
|
||||
|
||||
|
||||
if (bEnabled)
|
||||
{
|
||||
m_pNormalImage->setIsVisible(true);
|
||||
|
||||
|
||||
if (m_pDisabledImage)
|
||||
{
|
||||
m_pDisabledImage->setIsVisible(false);
|
||||
|
@ -611,12 +631,12 @@ bool CCMenuItemImage::initFromNormalImage(const char *normalImage, const char *s
|
|||
CCNode *normalSprite = CCSprite::spriteWithFile(normalImage);
|
||||
CCNode *selectedSprite = NULL;
|
||||
CCNode *disabledSprite = NULL;
|
||||
|
||||
|
||||
if (selectedImage)
|
||||
{
|
||||
selectedSprite = CCSprite::spriteWithFile(selectedImage);
|
||||
}
|
||||
|
||||
|
||||
if(disabledImage)
|
||||
{
|
||||
disabledSprite = CCSprite::spriteWithFile(disabledImage);
|
||||
|
@ -730,7 +750,7 @@ void CCMenuItemToggle::activate()
|
|||
void CCMenuItemToggle::setIsEnabled(bool enabled)
|
||||
{
|
||||
CCMenuItem::setIsEnabled(enabled);
|
||||
|
||||
|
||||
if(m_pSubItems && m_pSubItems->count() > 0)
|
||||
{
|
||||
CCMutableArray<CCMenuItem*>::CCMutableArrayIterator it;
|
||||
|
@ -779,5 +799,5 @@ void CCMenuItemToggle::setColor(const ccColor3B& color)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace cocos2d
|
||||
|
|
Loading…
Reference in New Issue