//cocos2dx 是单线程的 单你要执行两个动作是要开辟一个线程
void HelloWorld:: testArray(){
    auto str1=__String::create("String1");
    auto str2=__String::create("String2");
    auto str3=__String::create("String3");
    auto str4=__String::create("String4");
    auto str5=__String::create("String5");
    __Array* array=__Array::create();
    
    auto temp=__Array::create();
    array->addObject(str1);
    array->addObject(str2);
    array->addObject(str3);
    array->addObject(str4);
    array->addObject(str5);
    
    for (int i=0; i<array->count(); i++) {
        //删除一个对象时不能再对数组进行遍历因为删除一个对象时,下一个对象会自动填充前一个位置 而i++会向后走,就会遍历不到往前移动的哪一个对象。解决办法  ,在外面定义一个临时数组 当你要删除哪个是把 那个放入临时数组 最后遍历临时数组进行删除。
        auto str=(__String*)array->objectAtIndex(i);
        log("str::%s",str->getCString());
        if (i==2) {
            temp->addObject(array->getObjectAtIndex(i));
        }
    }
    for (int i=0; i<temp->count(); i++) {
        auto str=(__String*)temp->objectAtIndex(i);
        log("str::%s",str->getCString());
        array->removeObject(temp->objectAtIndex(i));
        
    }
}
bool PrincessRewardCommand::handleRecieve(cocos2d::CCDictionary *dict){
    if (dict->valueForKey("cmd")->compare(PRINCESS_REWARD) != 0)
        return false;
    CCDictionary* params = _dict(dict->objectForKey("params"));
    if(params==NULL) return false;
    const CCString *pStr = params->valueForKey("errorCode");
    if (pStr->compare("")!=0) {;
        CCCommonUtils::flyText(_lang(pStr->getCString()).c_str());
    }else{
        if(params->objectForKey("reward")){
            auto arr = dynamic_cast<CCArray*>(params->objectForKey("reward"));
            if (arr->count() > 0) {
                auto layer = dynamic_cast<ImperialScene*>(SceneController::getInstance()->getCurrentLayerByLevel(LEVEL_SCENE));
                if (layer) {
                    layer->m_princessRwdArr = arr;
                }
                auto dict = dynamic_cast<CCDictionary*>(arr->objectAtIndex(0));
                int type = -1;
                if (dict->objectForKey("type")) {
                    type = dict->valueForKey("type")->intValue();
                }
                CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(MSG_PrincessRwd, Integer::create(type));
            }
            else
                CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(MSG_PrincessRwdNull);
        }
        else
            CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(MSG_PrincessRwdNull);
    }
    return true;
}
Beispiel #3
0
void RKObjectListView::contextMenuEvent (QContextMenuEvent* event) {
	RK_TRACE (APP);

	menu_object = objectAtIndex (indexAt (event->pos ()));
	bool suppress = false;
	emit (aboutToShowContextMenu (menu_object, &suppress));

	if (!suppress) menu->popup (event->globalPos ());
}
void IsometryNode::Each(CCNode* node,const std::function<void(CCNode* node)>&  func)
{
    auto children = node->getChildren();
    if(children == nullptr)
    {
        return;
    }
    
    for(size_t i = 0; i < children->count(); i++)
    {
        auto cur = (CCNode*)children->objectAtIndex(i);
        func(cur);
        Each(cur, func);
    }
}
Beispiel #5
0
void EnemyInfoController::initEnemyData(CCDictionary* dict)
{
    auto arr = dynamic_cast<CCArray*>(dict->objectForKey("enemy"));
    if(arr==NULL) {
        return;
    }
    CCDictionary* item = NULL;
    m_enemyInfos.clear();
    for (int i=0; i<arr->count(); i++) {
        item = _dict(arr->objectAtIndex(i));
        EnemyInfo info = EnemyInfo(item);
        m_enemyInfos.push_back(info);
    }
    m_ignorInfos.clear();
    std::string ignoreStr = GlobalData::shared()->playerInfo.uid + "WTIgnoreList";
    std::string ignoreList = CCUserDefault::sharedUserDefault()->getStringForKey(ignoreStr.c_str(), "");
    vector<std::string> vector1;
    CCCommonUtils::splitString(ignoreList, "|", vector1);
    int num = vector1.size();
    for (int i = 0; i < num; i++) {
        for (int j = 0; j < m_enemyInfos.size(); j++) {
            if (m_enemyInfos[j].uuid == vector1[i]) {
                m_ignorInfos.push_back(m_enemyInfos[j]);
                break;
            }
        }
    }
    ignoreList = "";
    for (int i = 0; i<m_ignorInfos.size(); i++) {
        ignoreList.append(m_ignorInfos[i].uuid);
        if (i != m_ignorInfos.size() - 1) {
            ignoreList.append("|");
        }
    }
    m_ignorInfos.clear();
    CCUserDefault::sharedUserDefault()->setStringForKey(ignoreStr.c_str(), ignoreList.c_str());
    CCUserDefault::sharedUserDefault()->flush();
}
Beispiel #6
0
bool WinPointsUseCommand::handleRecieve(cocos2d::CCDictionary *dict)
{
    if (dict->valueForKey("cmd")->compare(WIN_POINTS_USE) != 0)
        return false;
    CCDictionary *params=_dict(dict->objectForKey("params"));
    if (!params) {
        return false;
    }
    const CCString *pStr = params->valueForKey("errorCode");
    if (pStr->compare("")!=0) {
        CCCommonUtils::flyText((_lang(pStr->getCString()).c_str()));
    }else{
        int itemId = params->valueForKey("itemId")->intValue();
        if (params->objectForKey("remainPoints")) {
            long remainPoints = params->valueForKey("remainPoints")->doubleValue();
            GlobalData::shared()->playerInfo.winPoint = remainPoints;
        }
        if(params && params->objectForKey("itemEffectObj"))
        {
            auto effectObj = _dict(params->objectForKey("itemEffectObj"));
            
            if (effectObj->objectForKey("oldStatus")) {//删除该状态的作用
                int reStatusId = effectObj->valueForKey("oldStatus")->intValue();
                if (GlobalData::shared()->statusMap.find(reStatusId) != GlobalData::shared()->statusMap.end()) {
                    GlobalData::shared()->statusMap[reStatusId] = 0;
                }
            }
            
            if (effectObj->objectForKey("effectState")) {
                auto stateDict = _dict(effectObj->objectForKey("effectState"));
                CCDictElement* element;
                CCDICT_FOREACH(stateDict, element)
                {
                    string key = element->getStrKey();
                    int effectId = atoi(key.c_str());
                    if(effectId>=PLAYER_PROTECTED_TIME1 && effectId<=PLAYER_PROTECTED_TIME5){
                        GlobalData::shared()->playerInfo.protectTimeStamp = stateDict->valueForKey(key)->doubleValue();
                        if(SceneController::getInstance()->currentSceneId == SCENE_ID_WORLD){
                            WorldMapView::instance()->m_map->updateDynamicMap(WorldController::getInstance()->selfPoint);
                        }
                    }
                    double time = stateDict->valueForKey(key)->doubleValue()/1000;
                    if (time>0) {
                        time = GlobalData::shared()->changeTime(time);
                    }
                    if (key!="startTime") {
                        GlobalData::shared()->statusMap[atoi(key.c_str())] = time;
                    }
                    auto info = ToolController::getInstance()->getToolInfoById(itemId);
                    map<int, CCDictionary* >::iterator it = ToolController::getInstance()->m_statusItems.find(info.type2);
                    CCObject* obj = element->getObject();
                    CCString* str = (CCString*)obj;
                    if(info.type==4){
                        if(it!=ToolController::getInstance()->m_statusItems.end()){
                            auto dic = it->second;
                            if(!dic->objectForKey("startTime")){
                                dic->setObject(CCString::create(CC_ITOA(WorldController::getInstance()->getTime())), "startTime");
                            }else if(key!="" && key!="startTime"){
                                dic->setObject(CCString::create(str->getCString()), "endTime");
                            }else if(key=="startTime"){
                                dic->setObject(CCString::create(str->getCString()), "startTime");
                            }
                            ToolController::getInstance()->m_statusItems[info.type2] = dic;
                        }else{
                            auto infoDic = CCDictionary::create();
                            infoDic->retain();
                            if(key!="" && key!="startTime"){
                                infoDic->setObject(CCString::create(str->getCString()), "endTime");
                            }else if(key=="startTime"){
                                infoDic->setObject(CCString::create(str->getCString()), "startTime");
                            }
                            ToolController::getInstance()->m_statusItems[info.type2] = infoDic;
                        }
                    }
                    if (effectObj->objectForKey("status")) {
                        auto arr = dynamic_cast<CCArray*>(effectObj->objectForKey("status"));
                        if (arr) {
                            CCDictionary *item = NULL;
                            for (int i=0; i<arr->count(); i++) {
                                item = _dict(arr->objectAtIndex(i));
                                auto effState = stateEffect();
                                effState.effectId = item->valueForKey("effNum")->intValue();
                                effState.value = item->valueForKey("effVal")->intValue();
                                effState.stateId = item->valueForKey("stateId")->intValue();
                                
                                if (GlobalData::shared()->effectStateMap.find(effState.effectId) != GlobalData::shared()->effectStateMap.end()) {//去除重复的stateId
                                    vector<stateEffect>::iterator it = GlobalData::shared()->effectStateMap[effState.effectId].begin();
                                    for (; it != GlobalData::shared()->effectStateMap[effState.effectId].end(); it++) {
                                        if (effState.stateId == it->stateId) {
                                            GlobalData::shared()->effectStateMap[effState.effectId].erase(it);
                                            break;
                                        }
                                    }
                                }
                                GlobalData::shared()->effectStateMap[effState.effectId].push_back(effState);
                            }
                        }
                    }
                }
            }