Merge branch 'v3' into downloader_decouple_squash

This commit is contained in:
Ricardo Quesada 2015-08-13 11:07:49 -07:00
commit 7047e0fbdb
7 changed files with 85 additions and 70 deletions

View File

@ -98,54 +98,51 @@ void Timer::update(float dt)
{ {
_elapsed = 0; _elapsed = 0;
_timesExecuted = 0; _timesExecuted = 0;
return;
} }
else
// accumulate elapsed time
_elapsed += dt;
// deal with delay
if (_useDelay)
{ {
if (_runForever && !_useDelay) if (_elapsed < _delay)
{//standard timer usage {
_elapsed += dt; return;
if (_elapsed >= _interval)
{
trigger();
_elapsed -= _interval;
}
} }
else trigger(_delay);
{//advanced usage _elapsed = _elapsed - _delay;
_elapsed += dt; _timesExecuted += 1;
if (_useDelay) _useDelay = false;
{ // after delay, the rest time should compare with interval
if( _elapsed >= _delay ) if (!_runForever && _timesExecuted > _repeat)
{ { //unschedule timer
trigger(); cancel();
return;
}
}
_elapsed = _elapsed - _delay; // if _interval == 0, should trigger once every frame
_timesExecuted += 1; float interval = (_interval > 0) ? _interval : _elapsed;
_useDelay = false; while (_elapsed >= interval)
} {
} trigger(interval);
else _elapsed -= interval;
{
if (_elapsed >= _interval)
{
trigger();
_elapsed -= _interval; if (_runForever)
_timesExecuted += 1; {
continue;
} }
} _timesExecuted += 1;
if (_timesExecuted > _repeat)
if (!_runForever && _timesExecuted > _repeat) { //unschedule timer
{ //unschedule timer cancel();
cancel(); break;
}
} }
} }
} }
// TimerTargetSelector // TimerTargetSelector
TimerTargetSelector::TimerTargetSelector() TimerTargetSelector::TimerTargetSelector()
@ -163,11 +160,11 @@ bool TimerTargetSelector::initWithSelector(Scheduler* scheduler, SEL_SCHEDULE se
return true; return true;
} }
void TimerTargetSelector::trigger() void TimerTargetSelector::trigger(float dt)
{ {
if (_target && _selector) if (_target && _selector)
{ {
(_target->*_selector)(_elapsed); (_target->*_selector)(dt);
} }
} }
@ -194,11 +191,11 @@ bool TimerTargetCallback::initWithCallback(Scheduler* scheduler, const ccSchedul
return true; return true;
} }
void TimerTargetCallback::trigger() void TimerTargetCallback::trigger(float dt)
{ {
if (_callback) if (_callback)
{ {
_callback(_elapsed); _callback(dt);
} }
} }
@ -220,11 +217,11 @@ bool TimerScriptHandler::initWithScriptHandler(int handler, float seconds)
return true; return true;
} }
void TimerScriptHandler::trigger() void TimerScriptHandler::trigger(float dt)
{ {
if (0 != _scriptHandler) if (0 != _scriptHandler)
{ {
SchedulerScriptData data(_scriptHandler,_elapsed); SchedulerScriptData data(_scriptHandler,dt);
ScriptEvent event(kScheduleEvent,&data); ScriptEvent event(kScheduleEvent,&data);
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
} }

View File

@ -57,7 +57,7 @@ public:
void setupTimerWithInterval(float seconds, unsigned int repeat, float delay); void setupTimerWithInterval(float seconds, unsigned int repeat, float delay);
virtual void trigger() = 0; virtual void trigger(float dt) = 0;
virtual void cancel() = 0; virtual void cancel() = 0;
/** triggers the timer */ /** triggers the timer */
@ -86,7 +86,7 @@ public:
inline SEL_SCHEDULE getSelector() const { return _selector; }; inline SEL_SCHEDULE getSelector() const { return _selector; };
virtual void trigger() override; virtual void trigger(float dt) override;
virtual void cancel() override; virtual void cancel() override;
protected: protected:
@ -106,7 +106,7 @@ public:
inline const ccSchedulerFunc& getCallback() const { return _callback; }; inline const ccSchedulerFunc& getCallback() const { return _callback; };
inline const std::string& getKey() const { return _key; }; inline const std::string& getKey() const { return _key; };
virtual void trigger() override; virtual void trigger(float dt) override;
virtual void cancel() override; virtual void cancel() override;
protected: protected:
@ -123,7 +123,7 @@ public:
bool initWithScriptHandler(int handler, float seconds); bool initWithScriptHandler(int handler, float seconds);
inline int getScriptHandler() const { return _scriptHandler; }; inline int getScriptHandler() const { return _scriptHandler; };
virtual void trigger() override; virtual void trigger(float dt) override;
virtual void cancel() override; virtual void cancel() override;
private: private:

View File

@ -37,6 +37,7 @@
-- --
-- @function [parent=#Timer] trigger -- @function [parent=#Timer] trigger
-- @param self -- @param self
-- @param #float dt
-- @return Timer#Timer self (return value: cc.Timer) -- @return Timer#Timer self (return value: cc.Timer)
-------------------------------- --------------------------------

View File

@ -15149,18 +15149,21 @@ int lua_cocos2dx_Timer_trigger(lua_State* tolua_S)
#endif #endif
argc = lua_gettop(tolua_S)-1; argc = lua_gettop(tolua_S)-1;
if (argc == 0) if (argc == 1)
{ {
double arg0;
ok &= luaval_to_number(tolua_S, 2,&arg0, "cc.Timer:trigger");
if(!ok) if(!ok)
{ {
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Timer_trigger'", nullptr); tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Timer_trigger'", nullptr);
return 0; return 0;
} }
cobj->trigger(); cobj->trigger(arg0);
lua_settop(tolua_S, 1); lua_settop(tolua_S, 1);
return 1; return 1;
} }
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Timer:trigger",argc, 0); luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Timer:trigger",argc, 1);
return 0; return 0;
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1

View File

@ -109,7 +109,8 @@ static const int CC_EDIT_BOX_PADDING = 5;
textField.hidden = true; textField.hidden = true;
textField.returnKeyType = UIReturnKeyDefault; textField.returnKeyType = UIReturnKeyDefault;
[textField addTarget:self action:@selector(textChanged) forControlEvents:UIControlEventEditingChanged]; [textField addTarget:self action:@selector(textChanged:) forControlEvents:UIControlEventEditingChanged];
self.textField = textField; self.textField = textField;
self.editBox = editBox; self.editBox = editBox;
@ -189,8 +190,13 @@ static const int CC_EDIT_BOX_PADDING = 5;
/** /**
* Called each time when the text field's text has changed. * Called each time when the text field's text has changed.
*/ */
- (void)textChanged - (void)textChanged:(UITextField*)textField
{ {
int maxLength = getEditBoxImplIOS()->getMaxLength();
if (textField.text.length > maxLength) {
textField.text = [textField.text substringToIndex:maxLength];
}
cocos2d::ui::EditBoxDelegate *pDelegate = getEditBoxImplIOS()->getDelegate(); cocos2d::ui::EditBoxDelegate *pDelegate = getEditBoxImplIOS()->getDelegate();
if (pDelegate != NULL) if (pDelegate != NULL)
{ {
@ -287,18 +293,25 @@ static const int CC_EDIT_BOX_PADDING = 5;
*/ */
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{ {
if (getEditBoxImplIOS()->getMaxLength() < 0) int maxLength = getEditBoxImplIOS()->getMaxLength();
if (maxLength < 0)
{ {
return YES; return YES;
} }
// Prevent crashing undo bug http://stackoverflow.com/questions/433337/set-the-maximum-character-length-of-a-uitextfield
if(range.length + range.location > textField.text.length)
{
return NO;
}
NSUInteger oldLength = textField.text.length; NSUInteger oldLength = textField.text.length;
NSUInteger replacementLength = string.length; NSUInteger replacementLength = string.length;
NSUInteger rangeLength = range.length; NSUInteger rangeLength = range.length;
NSUInteger newLength = oldLength - rangeLength + replacementLength; NSUInteger newLength = oldLength - rangeLength + replacementLength;
return newLength <= getEditBoxImplIOS()->getMaxLength(); return newLength <= maxLength;
} }
@end @end

View File

@ -6388,6 +6388,7 @@
], ],
"lua": [ "lua": [
"cocos/scripting/lua-bindings/CMakeLists.txt", "cocos/scripting/lua-bindings/CMakeLists.txt",
"cocos/scripting/lua-bindings/auto/api/AbstractCheckButton.lua",
"cocos/scripting/lua-bindings/auto/api/Action.lua", "cocos/scripting/lua-bindings/auto/api/Action.lua",
"cocos/scripting/lua-bindings/auto/api/ActionCamera.lua", "cocos/scripting/lua-bindings/auto/api/ActionCamera.lua",
"cocos/scripting/lua-bindings/auto/api/ActionEase.lua", "cocos/scripting/lua-bindings/auto/api/ActionEase.lua",

View File

@ -135,7 +135,7 @@ void SchedulerPauseResumeAll::onEnter()
sprite->setPosition(VisibleRect::center()); sprite->setPosition(VisibleRect::center());
this->addChild(sprite); this->addChild(sprite);
sprite->runAction(RepeatForever::create(RotateBy::create(3.0, 360))); sprite->runAction(RepeatForever::create(RotateBy::create(3.0, 360)));
sprite->setTag(123);
scheduleUpdate(); scheduleUpdate();
schedule(CC_SCHEDULE_SELECTOR(SchedulerPauseResumeAll::tick1), 0.5f); schedule(CC_SCHEDULE_SELECTOR(SchedulerPauseResumeAll::tick1), 0.5f);
schedule(CC_SCHEDULE_SELECTOR(SchedulerPauseResumeAll::tick2), 1.0f); schedule(CC_SCHEDULE_SELECTOR(SchedulerPauseResumeAll::tick2), 1.0f);
@ -175,20 +175,16 @@ void SchedulerPauseResumeAll::pause(float dt)
// should have only 2 items: ActionManager, self // should have only 2 items: ActionManager, self
CCASSERT(_pausedTargets.size() == 2, "Error: pausedTargets should have only 2 items"); CCASSERT(_pausedTargets.size() == 2, "Error: pausedTargets should have only 2 items");
unschedule(CC_SCHEDULE_SELECTOR(SchedulerPauseResumeAll::tick1)); // because target 'this' has been paused above, so use another node(tag:123) as target
unschedule(CC_SCHEDULE_SELECTOR(SchedulerPauseResumeAll::tick2)); getChildByTag(123)->scheduleOnce([this](float dt)
// because pauseAllTargets above, should resumeTarget before add new scheduler {
scheduler->resumeTarget(this); this->resume(dt);
scheduleOnce(CC_SCHEDULE_SELECTOR(SchedulerPauseResumeAll::resume), 2.0f); }, 2.0f, "test resume");
} }
void SchedulerPauseResumeAll::resume(float dt) void SchedulerPauseResumeAll::resume(float dt)
{ {
log("Resuming"); log("Resuming");
schedule(CC_SCHEDULE_SELECTOR(SchedulerPauseResumeAll::tick1), 0.5f);
schedule(CC_SCHEDULE_SELECTOR(SchedulerPauseResumeAll::tick2), 1.0f);
auto director = Director::getInstance(); auto director = Director::getInstance();
director->getScheduler()->resumeTargets(_pausedTargets); director->getScheduler()->resumeTargets(_pausedTargets);
_pausedTargets.clear(); _pausedTargets.clear();
@ -228,6 +224,7 @@ void SchedulerPauseResumeAllUser::onEnter()
auto sprite = Sprite::create("Images/grossinis_sister1.png"); auto sprite = Sprite::create("Images/grossinis_sister1.png");
sprite->setPosition(Vec2(s.width/2, s.height/2)); sprite->setPosition(Vec2(s.width/2, s.height/2));
sprite->setTag(123);
this->addChild(sprite); this->addChild(sprite);
sprite->runAction(RepeatForever::create(RotateBy::create(3.0, 360))); sprite->runAction(RepeatForever::create(RotateBy::create(3.0, 360)));
@ -260,8 +257,11 @@ void SchedulerPauseResumeAllUser::pause(float dt)
log("Pausing, tick1 and tick2 should be called three times"); log("Pausing, tick1 and tick2 should be called three times");
auto director = Director::getInstance(); auto director = Director::getInstance();
_pausedTargets = director->getScheduler()->pauseAllTargetsWithMinPriority(Scheduler::PRIORITY_NON_SYSTEM_MIN); _pausedTargets = director->getScheduler()->pauseAllTargetsWithMinPriority(Scheduler::PRIORITY_NON_SYSTEM_MIN);
getScheduler()->resumeTarget(this); // because target 'this' has been paused above, so use another node(tag:123) as target
scheduleOnce(CC_SCHEDULE_SELECTOR(SchedulerPauseResumeAllUser::resume), 2.0f); getChildByTag(123)->scheduleOnce([this](float dt)
{
this->resume(dt);
}, 2.0f, "test resume");
} }
void SchedulerPauseResumeAllUser::resume(float dt) void SchedulerPauseResumeAllUser::resume(float dt)