void DelayedDispatcher::update(float deltaTime) { //Use a separate vector for calling, as called events can modify this vector std::vector<EventTuple> eventsToCall; for(EventTuple& tuple : events) { std::get<0>(tuple) -= deltaTime; if(std::get<0>(tuple) < 0) { eventsToCall.push_back(tuple); } } for(EventTuple& tuple : eventsToCall) { #if VERBOSE_GENERAL_INFO CCLOG("Launching event %s", std::get<1>(tuple).c_str()); #endif Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(std::get<1>(tuple), std::get<2>(tuple)); IFEXIST(std::get<2>(tuple))->release(); } if(events.size() > 0) { events.erase(std::remove_if(events.begin(), events.end(), [](const EventTuple& tuple) { return std::get<0>(tuple) < 0; }), events.end()); } //Use a separate vector for calling, as called func can modify this vector std::vector<FuncTuple> funcsToCall; for(FuncTuple& tuple : funcs) { std::get<0>(tuple) -= deltaTime; if(std::get<0>(tuple) < 0) { funcsToCall.push_back(tuple); } } for(FuncTuple& tuple : funcsToCall) { cocos2d::EventCustom* event = EventCustom::create(std::get<3>(tuple), std::get<2>(tuple)); #if VERBOSE_GENERAL_INFO CCLOG("Launching func named %s", std::get<3>(tuple).c_str()); #endif std::get<1>(tuple)(event); IFEXIST(std::get<2>(tuple))->release(); } if(funcs.size() > 0) { funcs.erase(std::remove_if(funcs.begin(), funcs.end(), [](const FuncTuple& tuple) { return std::get<0>(tuple) < 0; }), funcs.end()); } }
void InputLabel::exitBoxEditingWillBegin(ui::EditBox* editBox) { if(locks.size() == 0 && !isOpened && delegate->isEnabled()) { CCLOG("editing will begin InputLabel"); if(linkTo != NULL) { //A password should be cleared when you begin editing. That's the default behavior on iOS, and we can't easily go around anyway, since UITextField.secureEntry force this behavior delegate->setText(isUnedited() || isPassword ? "" : linkTo->getLabelValue()); if(isPassword) { linkTo->setLabelValue(""); IFEXIST(passwordText)->autorelease(); passwordText = new CCString(); } linkTo->setVisible(false); } } }
void InputLabel::editBoxEditingDidEnd(ui::EditBox* editBox) { CCLOG("Edit Box editing did end"); if(isOpened) { //on dealloc, the isOpened flag will be false to prevent this code from being executed (could be used for a cancel method too) isOpened = false; if(linkTo != NULL) { if(strlen(delegate->getText()) > 0) { if(isPassword) { IFEXIST(passwordText)->autorelease(); passwordText = new CCString(delegate->getText()); std::string bulletString; for(int i = 0; i < (int)strlen(delegate->getText()); i++) { bulletString.append("●"); } linkTo->setLabelValue(bulletString.c_str()); } else { linkTo->setLabelValue(delegate->getText()); } } else { linkTo->setLabelValue(initialText->getCString()); } delegate->setText(""); linkTo->setVisible(true); } CCDictionary* param = this->getEventInfos(); param->setObject(Screate(this->getLabelValue()), "Text"); Director::getInstance()->getEventDispatcher()->dispatchCustomEvent("TextAdded", param); } delegate->detachWithIME(); }
void DelayedDispatcher::funcAfterDelay(std::function<void(cocos2d::EventCustom*)> func, Ref* userData, float delay, std::string eventName) { DelayedDispatcher* instance = getInstance(); IFEXIST(userData)->retain(); instance->funcs.push_back(FuncTuple(delay, func, userData, eventName)); }
void DelayedDispatcher::eventAfterDelay(std::string eventName, Ref* userData, float delay) { DelayedDispatcher* instance = getInstance(); IFEXIST(userData)->retain(); instance->events.push_back(EventTuple(delay, eventName, userData)); }