void CCNativeWin32::showAlertViewWithLuaListener(LUA_FUNCTION listener) { /* wstring title(m_alertViewTitle.begin(), m_alertViewTitle.end()); wstring message(m_alertViewMessage.begin(), m_alertViewMessage.end()); int button = MessageBox(NULL, message.c_str(), title.c_str(), MB_OKCANCEL); */ WCHAR *wszTitleBuf; WCHAR *wszMessageBuf; int titleBufLen = MultiByteToWideChar(CP_UTF8, 0, m_alertViewTitle.c_str(), -1, NULL, 0); int messageBufLen = MultiByteToWideChar(CP_UTF8, 0, m_alertViewMessage.c_str(), -1, NULL, 0); wszTitleBuf = new WCHAR[titleBufLen+1]; wszMessageBuf = new WCHAR[messageBufLen+1]; memset(wszTitleBuf, 0, sizeof(WCHAR)*(titleBufLen + 1) ); memset(wszMessageBuf, 0, sizeof(WCHAR)*(messageBufLen + 1) ); MultiByteToWideChar(CP_UTF8, 0, m_alertViewTitle.c_str(), -1, wszTitleBuf, titleBufLen); MultiByteToWideChar(CP_UTF8, 0, m_alertViewMessage.c_str(),-1, wszMessageBuf, messageBufLen); int button = MessageBox(NULL,wszMessageBuf, wszTitleBuf, MB_OKCANCEL); delete [] wszTitleBuf; delete [] wszMessageBuf; CCLuaValueDict event; event["action"] = CCLuaValue::stringValue("clicked"); if (button == IDOK || button == IDYES) { event["buttonIndex"] = CCLuaValue::intValue(1); } else { event["buttonIndex"] = CCLuaValue::intValue(2); } CCLuaStack* stack = CCLuaEngine::defaultEngine()->getLuaStack(); stack->pushCCLuaValueDict(event); stack->executeFunctionByHandler(listener, 1); }
void CCNativeWin32::showAlertViewWithLuaListener(LUA_FUNCTION listener) { wstring title(m_alertViewTitle.begin(), m_alertViewTitle.end()); wstring message(m_alertViewMessage.begin(), m_alertViewMessage.end()); int button = MessageBox(NULL, message.c_str(), title.c_str(), MB_OKCANCEL); CCLuaValueDict event; event["action"] = CCLuaValue::stringValue("clicked"); if (button == IDOK || button == IDYES) { event["buttonIndex"] = CCLuaValue::intValue(1); } else { event["buttonIndex"] = CCLuaValue::intValue(2); } CCLuaStack* stack = CCLuaEngine::defaultEngine()->getLuaStack(); stack->pushCCLuaValueDict(event); stack->executeFunctionByHandler(listener, 1); }
void CCHTTPRequest::update(float dt) { if (m_state == kCCHTTPRequestStateInProgress) { #if CC_LUA_ENGINE_ENABLED > 0 if (m_listener) { CCLuaValueDict dict; dict["name"] = CCLuaValue::stringValue("inprogress"); dict["dltotal"] = CCLuaValue::floatValue((float)m_dltotal); dict["dlnow"] = CCLuaValue::floatValue((float)m_dlnow); dict["ultotal"] = CCLuaValue::floatValue((float)m_ultotal); dict["ulnow"] = CCLuaValue::floatValue((float)m_ulnow); dict["request"] = CCLuaValue::ccobjectValue(this, "CCHTTPRequest"); CCLuaStack *stack = CCLuaEngine::defaultEngine()->getLuaStack(); stack->clean(); stack->pushCCLuaValueDict(dict); stack->executeFunctionByHandler(m_listener, 1); } #endif return; } CCDirector::sharedDirector()->getScheduler()->unscheduleAllForTarget(this); if (m_curlState != kCCHTTPRequestCURLStateIdle) { CCDirector::sharedDirector()->getScheduler()->scheduleSelector(schedule_selector(CCHTTPRequest::checkCURLState), this, 0, false); } if (m_state == kCCHTTPRequestStateCompleted) { CCLOG("CCHTTPRequest[0x%04x] - request completed", m_id); if (m_delegate) m_delegate->requestFinished(this); } else { CCLOG("CCHTTPRequest[0x%04x] - request failed", m_id); if (m_delegate) m_delegate->requestFailed(this); } #if CC_LUA_ENGINE_ENABLED > 0 if (m_listener) { CCLuaValueDict dict; switch (m_state) { case kCCHTTPRequestStateCompleted: dict["name"] = CCLuaValue::stringValue("completed"); break; case kCCHTTPRequestStateCancelled: dict["name"] = CCLuaValue::stringValue("cancelled"); break; case kCCHTTPRequestStateFailed: dict["name"] = CCLuaValue::stringValue("failed"); break; default: dict["name"] = CCLuaValue::stringValue("unknown"); } dict["request"] = CCLuaValue::ccobjectValue(this, "CCHTTPRequest"); CCLuaStack *stack = CCLuaEngine::defaultEngine()->getLuaStack(); stack->clean(); stack->pushCCLuaValueDict(dict); stack->executeFunctionByHandler(m_listener, 1); } #endif }