void GameConfig::setAndroidHDEnabled(bool val) { mEnableAndroidHD = val; CCUserDefault* user = CCUserDefault::sharedUserDefault(); user->setBoolForKey(CONFIG_ANDROID_HD_KEY, mEnableAndroidHD); user->flush(); }
void Config::setMute(bool mute) { m_mute = mute; CCUserDefault* ud = CCUserDefault::sharedUserDefault(); ud->setBoolForKey(CONFIG_KEY_MUTE, m_mute); if (m_mute) CocosDenshion::SimpleAudioEngine::sharedEngine()->stopAllEffects(); }
void MCBackpack::loadData() { CCUserDefault *userDefault = CCUserDefault::sharedUserDefault(); loadEffectiveItems(); if (! __icon_loaded) { loadIcons(); } if (MCGameState::sharedGameState()->isSaveFileExists()) { string data = userDefault->getStringForKey(kMCBackpackKey, kMCZero); if (data.size() > 0) { #if MC_DEBUG_SAVEDATA == 1 const char *output = data.c_str(); #else const char *input = data.c_str(); char *output; mc_size_t len = strlen(input); MCBase64Decode((mc_byte_t *) input, len, (mc_byte_t **) &output); #endif JsonBox::Value v; v.loadFromString(output); JsonBox::Object backpack = v.getObject(); /* 加载金钱 */ money_ = backpack[kMCMoneyKey].getInt(); } } else { money_ = 0; } }
void GameConfig::setTutorialProgress(PH::TutorialProgress progress) { tutorialMode = progress; CCUserDefault* user = CCUserDefault::sharedUserDefault(); user->setIntegerForKey(CONFIG_TUTORIAL_PROGRESS, tutorialMode); user->flush(); }
bool LevelScene::init() { SkyLayer *pSkyLayer = SkyLayer::create(); addChild(pSkyLayer); createLevelsLayer(); CCTexture2D *pTexture = CCTextureCache::sharedTextureCache()->addImage("back.png"); SpriteButton *pBackButton = SpriteButton::create(pTexture, this, callfuncO_selector(LevelScene::backClicked)); CCPoint bottomLeft = VisibleRect::leftBottom(); pBackButton->setPosition(ccp(bottomLeft.x + 70, bottomLeft.y + 60)); addChild(pBackButton); //Read preferences CCUserDefault *pUserDefaults = CCUserDefault::sharedUserDefault(); float volume = pUserDefaults->getFloatForKey("volume"); bool sound = pUserDefaults->getBoolForKey("sound"); if (sound) { bool isPlaying = SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying(); if (!isPlaying) SimpleAudioEngine::sharedEngine()->playBackgroundMusic("sounds/music.wav", true); SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(volume); SimpleAudioEngine::sharedEngine()->setEffectsVolume(volume); } return true; }
/** * 清除数据 */ void MCTaskAccessor::erase() { CCUserDefault *userDefault = CCUserDefault::sharedUserDefault(); userDefault->setStringForKey(kMCTasksKey, ""); }
void GameConfig::setSFXEnabled(bool val) { mEnableSFX = val; CCUserDefault* user = CCUserDefault::sharedUserDefault(); user->setBoolForKey(CONFIG_SFX_KEY, mEnableSFX); user->flush(); }
void GameConfig::setBGMEnabled(bool val) { mEnableBGM = val; CCUserDefault* user = CCUserDefault::sharedUserDefault(); user->setBoolForKey(CONFIG_BGM_KEY, mEnableBGM); user->flush(); }
void MCBackpack::saveData() { CCUserDefault *userDefault = CCUserDefault::sharedUserDefault(); saveEffectiveItems(); JsonBox::Object backpack; /* 储存金钱 */ backpack[kMCMoneyKey] = JsonBox::Value(money_); JsonBox::Value backpackValue(backpack); ostringstream outputStream; backpackValue.writeToStream(outputStream); string data = outputStream.str(); #if MC_DEBUG_SAVEDATA == 1 const char *output = data.c_str(); #else const char *input = data.c_str(); char *output; mc_size_t len = strlen(input); MCBase64Encode((mc_byte_t *) input, len, (mc_byte_t **) &output); #endif userDefault->setStringForKey(kMCBackpackKey, output); #if MC_DEBUG_SAVEDATA != 1 delete []output; #endif }
void Memory::saveBasic() { CCUserDefault * def = CCUserDefault::sharedUserDefault(); // Json::Value val(Json::ValueType::objectValue); // val["accountId"] = _accountId; // val["password"] = _passwordHashed; // val["lastServerId"] = _lastServerId; // val["musicOn"] = _musicOn; // val["effectOn"] = _effectOn; // // // Json::Value val2(Json::ValueType::arrayValue); // for (auto tr:_pendingTransactions) // { // Json::Value val3(Json::ValueType::objectValue); // val3["p"] = tr.productId; // val3["t"] = tr.transactionId; // val3["r"] = tr.receipt; // // val2[val2.size()] = val3; // } // val["pendingTransactions"] = val2; // def->setStringForKey("Memory_basic", SSTR(val)); def->flush(); }
void LoginLayer::onClickedLogin(CCObject *sender, TouchEventType event) { if (event == TOUCH_EVENT_ENDED) { SimpleAudioEngine::sharedEngine()->playEffect(BUTTON_CLICK); _msg->setText(""); LoginMeg tmpMeg; tmpMeg.name = _account->getText(); tmpMeg.pwd = _password->getText(); if (tmpMeg.name.empty()) { _msg->setText("请输入联众账号!"); return; } if (tmpMeg.pwd.empty()) { _msg->setText("请输入账号密码!"); return; } CCUserDefault* userDefault = CCUserDefault::sharedUserDefault(); userDefault->setStringForKey(SAVE_H_ACCOUNT, tmpMeg.name); userDefault->setStringForKey(SAVE_H_PASSWORD, tmpMeg.pwd); userDefault->flush(); CCNotificationCenter::sharedNotificationCenter()->postNotification(EVENT_LOGIN2MEG, &tmpMeg); } }
KDvoid Ch3_SavingSimpleData::saveDifficulty ( KDvoid ) { // Save our difficulty CCUserDefault* pDefaults = CCUserDefault::sharedUserDefault ( ); pDefaults->setStringForKey ( "simple_data_difficulty", m_sDifficulty.c_str ( ) ); pDefaults->flush ( ); }
KDvoid Ch3_SavingSimpleData::loadDifficulty ( KDvoid ) { // If a difficulty is set we use that, otherwise we choose Medium CCUserDefault* pDefaults = CCUserDefault::sharedUserDefault ( ); m_sDifficulty = pDefaults->getStringForKey ( "simple_data_difficulty", "Medium" ); this->setDifficultyFromValue ( ); }
bool MainScene::init() { CCSize winSize = Director::getInstance()->getVisibleSize(); if (!CCLayer::init()) { return false; } auto BackGround = Sprite::create("backg.png"); BackGround->setPosition(ccp(winSize.width / 2, winSize.height / 2)); //위치지정 this->addChild(BackGround); CCMenu *MenuMain = CCMenu::create(NULL); //메뉴생성 CCMenu *MenuMain1 = CCMenu::create(NULL); //메뉴생성 CCMenu *MenuMain2 = CCMenu::create(NULL); //메뉴생성 //메뉴아이템 추가 CCMenuItem *item1 = CCMenuItemImage::create("start.png", "start.png", this, menu_selector(MainScene::menuCloseCallback)); CCMenuItem *item2 = CCMenuItemImage::create("rank.png", "rank.png", this, menu_selector(MainScene::RankCloseCallback)); CCMenuItem *item3 = CCMenuItemImage::create("create.png", "create.png", this, menu_selector(MainScene::CreaterMenuCallback)); MenuMain->addChild(item1, 1); //메뉴에 아이템 붙이기 MenuMain1->addChild(item2, 2); MenuMain2->addChild(item3, 3); MenuMain->setPosition(ccp(winSize.width / 2, winSize.height / 2 - 20)); MenuMain1->setPosition(ccp(winSize.width / 2, winSize.height / 2 - 90)); MenuMain2->setPosition(ccp(winSize.width / 2, winSize.height / 2 - 160)); this->addChild(MenuMain, 1); this->addChild(MenuMain1, 2); this->addChild(MenuMain2, 3);//메뉴를 레이어에 추가 CCUserDefault* user = CCUserDefault::sharedUserDefault(); int SaveSw = CCUserDefault::sharedUserDefault()->getIntegerForKey("SaveMake"); if (SaveSw == 0){ user->setIntegerForKey("SaveMake", 1); user->setIntegerForKey("Rank1", 0); user->setIntegerForKey("Rank2", 0); user->setIntegerForKey("Rank3", 0); user->setIntegerForKey("Rank4", 0); user->setIntegerForKey("Rank5", 0); } return true; }
void CCNative::initStore(CCDictionary* dict) { CCArray* keys = dict->allKeys(); CCObject* key; CCUserDefault* userDefault = CCUserDefault::sharedUserDefault(); CCARRAY_FOREACH(keys, key) { const char* keyStr = ((CCString*)key)->getCString(); userDefault->setStringForKey(keyStr, dict->valueForKey(keyStr)->getCString()); } }
void PauseLayer::soundsButtonTapped(CCObject *sender) { CCUserDefault *defaults = CCUserDefault::sharedUserDefault(); CCMenuItemToggle *toggleItem = (CCMenuItemToggle*)sender; if (toggleItem->selectedItem() == menuItemSoundOn) { defaults->setBoolForKey(kSoundsKey, true); Utility::changeVolume(1.0f); } else if (toggleItem->selectedItem() == menuItemSoundOff) { defaults->setBoolForKey(kSoundsKey, false); Utility::changeVolume(0.0f); } }
void GameData::saveSettings() { #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) CCUserDefault* write = CCUserDefault::sharedUserDefault(); write->setBoolForKey("IsExisted", _isExisted); write->setIntegerForKey("HighScore", _highScore); write->flush(); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) JNI_setBool("IsExisted", _isExisted); JNI_setInt("HighScore", _highScore); #endif }
void Config::flush() { CCUserDefault* ud = CCUserDefault::sharedUserDefault(); ud->setBoolForKey(CONFIG_KEY_MUTE, m_mute); ud->setBoolForKey(CONFIG_KEY_HASSAVEDPUZZLE, m_hasSavedPuzzle); ud->setIntegerForKey(CONFIG_KEY_HIGHSCORE, m_highScore); ud->setIntegerForKey(CONFIG_KEY_HIGHLEVEL, m_highLevel); ud->setIntegerForKey(CONFIG_KEY_SAVEDSCORE, m_savedScore); ud->setIntegerForKey(CONFIG_KEY_SAVEDTARGET, m_savedTarget); ud->setIntegerForKey(CONFIG_KEY_SAVEDLEVEL, m_savedLevel); ud->setIntegerForKey(CONFIG_KEY_SAVEDROW, m_savedRow); ud->setIntegerForKey(CONFIG_KEY_SAVEDCOL, m_savedCol); ud->setStringForKey(CONFIG_KEY_SAVEDPUZZLE, m_savedPuzzle); ud->flush(); }
void LocalData::writeRuntimeDataToLocal() { CCUserDefault* userDefault = CCUserDefault::sharedUserDefault(); userDefault->setBoolForKey("hasmusic", RunTimeData::getInstance()->hasMusic); userDefault->setBoolForKey("guiderecord", RunTimeData::getInstance()->isFirstTime); userDefault->setStringForKey("levelStarStr", RunTimeData::getInstance()->levelStars); userDefault->setIntegerForKey("passedLevelNum", RunTimeData::getInstance()->passedLevel); userDefault->setIntegerForKey("totalStarNum", RunTimeData::getInstance()->startNum); userDefault->setIntegerForKey("annihilator", RunTimeData::getInstance()->annihilatorNum); userDefault->setBoolForKey("isFirstTime", RunTimeData::getInstance()->isFirstTime); userDefault->flush(); }
void GameData::saveSettings() { #if (ANDROIDSAVEBYUSERDEFAULT == 1 && CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) JNI_setBool("IsBeginner", gd_isBeginner); JNI_setInt("HighScore", gd_highScore); JNI_setInt("Gold", gd_gold); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) CCUserDefault* write = CCUserDefault::sharedUserDefault(); write->setBoolForKey("IsBeginner", gd_isBeginner); write->setIntegerForKey("HighScore", gd_highScore); write->setIntegerForKey("Gold", gd_gold); write->flush(); #endif }
void GameScene::saveScore() { CCUserDefault* ud = CCUserDefault::sharedUserDefault(); int rank; for( rank=1; rank<= 5 ; ++rank){ char key[4]; sprintf( key, "Score%dth", rank); int score = ud->getIntegerForKey(key,0); if( score < m_score ) break; } for( int i = 5; i > rank ; --i){ char key_src[4]; sprintf( key_src, "Score%dth", i-1); char key_dst[4]; sprintf( key_dst, "Score%dth", i); ud->setIntegerForKey(key_dst, ud->getIntegerForKey(key_src,0)); } char key[4]; sprintf( key, "Score%dth", rank); ud->setIntegerForKey(key, m_score); CCSprite* crown = NULL; switch(rank){ case 1: crown = CCSprite::create("crown_gold.png"); break; case 2: crown = CCSprite::create("crown_silver.png"); break; case 3: crown = CCSprite::create("crown_bronze.png"); break; } if( crown ){ crown->setPosition(ccp(m_winSize.width/2,m_winSize.height * 0.7)); crown->setOpacity(0); crown->setScale(0); this->addChild(crown,kZOrderScore,kTagCrown); CCDelayTime* delay = CCDelayTime::create(0.8f); CCFadeIn* fadein = CCFadeIn::create(0.5f); CCScaleTo* zoomin = CCScaleTo::create(0.5f,1.0f); CCCallFuncN* callfunc = CCCallFuncN::create(this,callfuncN_selector(GameScene::callSkewAnim)); crown->runAction(CCSequence::create(delay, CCSpawn::createWithTwoActions(fadein, zoomin),callfunc,NULL)); } }
bool Memory::loadBasic() { CCUserDefault * def = CCUserDefault::sharedUserDefault(); std::string saved = def->getStringForKey("Memory_basic"); Json::Value val; Json::Reader reader; if (!reader.parse(saved, val)) { M_WARNING("error reading user default"); return false; } // _accountId = val["accountId"].asUInt(); // _passwordHashed = val["password"].asString(); // _lastServerId = val["lastServerId"].asUInt(); // _musicOn = val["musicOn"].asBool(); // _effectOn = val["effectOn"].asBool(); // _weibo_name = val["weiboName"].asString(); // _qq_name = val["qqName"].asString(); // _facebook_name =val["facebookName"].asString(); // // _weibo_id = val["weiboId"].asString(); // _facebook_id = val["facebookId"].asString(); // _qq_id = val["qqId"].asString(); // // _pendingTransactions.clear(); // auto val2 = val["pendingTransactions"]; // if (val2.isArray()) // { // for (auto v : val2) // { // MIAPTransaction tr; // tr.productId = v["p"].asString(); // tr.transactionId = v["t"].asString(); // tr.receipt = v["r"].asString(); // // _pendingTransactions.push_back(tr); // } // } // _userId = 0; return true; }
void MainScene::OnSceneChangedToAppear() { // Audio Setting GooRoomClient& client = GooRoomClient::Instance(); CCUserDefault* userDefault = CCUserDefault::sharedUserDefault(); client.SetBGMOn(userDefault->getBoolForKey("IsBGMOn", true)); client.SetEffectOn(userDefault->getBoolForKey("IsEffectOn", true)); client.SetMessageOn(userDefault->getBoolForKey("IsMessageOn", true)); const float bgmVolume = GooRoomClient::Instance().IsBGMOn() ? BGM_SOUND_NORMAL : 0.f; AudioEngine::Instance()->SetBackgroundVolume(bgmVolume); const float effectVolume = GooRoomClient::Instance().IsEffectOn() ? 0.9f : 0.f; AudioEngine::Instance()->SetEffectVolume(effectVolume); // End Autio Setting AudioEngine::Instance()->PlayBackgroundMusic("bgm/mainScene.mp3"); }
bool MenuScene::init() { SkyLayer *pSkyLayer = SkyLayer::create(); addChild(pSkyLayer); CCRect visibleRect = VisibleRect::getVisibleRect(); CCSprite *pLogo = CCSprite::create("logo.png"); pLogo->setPosition(VisibleRect::center()); addChild(pLogo); CCTexture2D *pTexture = CCTextureCache::sharedTextureCache()->addImage("play.png"); pPlayButton = SpriteButton::create(pTexture, this, callfuncO_selector(MenuScene::playClicked)); pPlayButton->setPosition(ccp(477, 185)); addChild(pPlayButton); pTexture = CCTextureCache::sharedTextureCache()->addImage("about.png"); pInfoButton = SpriteButton::create(pTexture, this, callfuncO_selector(MenuScene::infoClicked)); pInfoButton->setPosition(ccp(visibleRect.origin.x + 205, visibleRect.origin.y + 60)); addChild(pInfoButton); pTexture = CCTextureCache::sharedTextureCache()->addImage("settings.png"); pSettingsButton = SpriteButton::create(pTexture, this, callfuncO_selector(MenuScene::settingsClicked)); pSettingsButton->setPosition(ccp(visibleRect.origin.x + 110, visibleRect.origin.y + 60)); addChild(pSettingsButton); //Read preferences CCUserDefault *pUserDefaults = CCUserDefault::sharedUserDefault(); float volume = pUserDefaults->getFloatForKey("volume"); bool sound = pUserDefaults->getBoolForKey("sound"); if (sound) { bool isPlaying = SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying(); if (!isPlaying) SimpleAudioEngine::sharedEngine()->playBackgroundMusic("sounds/music.wav", true); SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(volume); SimpleAudioEngine::sharedEngine()->setEffectsVolume(volume); } return true; }
void Config::load() { CCUserDefault* ud = CCUserDefault::sharedUserDefault(); m_mute = ud->getBoolForKey(CONFIG_KEY_MUTE); m_hasSavedPuzzle = ud->getBoolForKey(CONFIG_KEY_HASSAVEDPUZZLE); m_highScore = ud->getIntegerForKey(CONFIG_KEY_HIGHSCORE); m_highLevel = ud->getIntegerForKey(CONFIG_KEY_HIGHLEVEL); if (m_hasSavedPuzzle) { m_savedScore = ud->getIntegerForKey(CONFIG_KEY_SAVEDSCORE); m_savedTarget = ud->getIntegerForKey(CONFIG_KEY_SAVEDTARGET); m_savedLevel = ud->getIntegerForKey(CONFIG_KEY_SAVEDLEVEL); m_savedRow = ud->getIntegerForKey(CONFIG_KEY_SAVEDROW); m_savedCol = ud->getIntegerForKey(CONFIG_KEY_SAVEDCOL); m_savedPuzzle = ud->getStringForKey(CONFIG_KEY_SAVEDPUZZLE); } }
bool GameData::load() { #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) CCUserDefault* read = CCUserDefault::sharedUserDefault(); _isExisted = read->getBoolForKey("IsExisted"); if (!_isExisted) { return false; } _highScore = read->getIntegerForKey("HighScore"); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) _isExisted = JNI_getBool("IsExisted", false); if (!_isExisted) { return false; } _highScore = JNI_getInt("HighScore", 0); #endif return true; }
void GameScene::showHighScoreLabel() { CCUserDefault* userDefault = CCUserDefault::sharedUserDefault(); const char* highScorekey = "hightscore"; float highScore = userDefault->getFloatForKey(highScorekey, 99.9); if (gametime != 0) { if (gametime > highScore) { return; } else { highScore = gametime; userDefault->setFloatForKey(highScorekey, highScore); userDefault->flush(); } } const int tagHighScoreLabel = 200; CCString* highScoreString = CCString::createWithFormat("%8.1fs", highScore); CCLabelTTF* highScoreLabel = (CCLabelTTF*)this->getChildByTag(tagHighScoreLabel); if (highScoreLabel) { highScoreLabel->setString(highScoreString->getCString()); } else { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); highScoreLabel = CCLabelTTF::create(highScoreString->getCString(), "Arial", 24.0); highScoreLabel->setPosition(ccp(winSize.width*0.9, winSize.height*0.7)); highScoreLabel->setTag(tagHighScoreLabel); this->addChild(highScoreLabel); } }
void GameConfig::load() { std::string playerUID = PlayerData::getInstance()->player->uid; CCUserDefault* user = CCUserDefault::sharedUserDefault(); showInstanceStage = user->getBoolForKey((playerUID + "_instance_stage").c_str(), false); showSoulExchange = user->getBoolForKey((playerUID + "_soul_exchange").c_str(), false); showShuffleRelation = user->getBoolForKey((playerUID + "_shuffle_relation").c_str(), false); firstTimeNeili = user->getBoolForKey((playerUID + "_first_time_neili").c_str(), true); firstTimeShowInstance = user->getBoolForKey((playerUID + "_first_time_instance").c_str(), true); firstTimeZhuansheng = user->getBoolForKey((playerUID + "_first_time_zhuansheng").c_str(), true); openInstanceStep = user->getIntegerForKey((playerUID + "_open_instance").c_str(), 0); openJueDing10 = user->getBoolForKey((playerUID + "_open_jueding10").c_str(), false); showDragHint = user->getBoolForKey((playerUID + "_show_drag_hint").c_str(), true); showAttrHint = user->getBoolForKey((playerUID + "_show_attr_hint").c_str(), true); }
void MainGameScene::endJudgemnet() { setTouchEnabled(true); for(int i = 1; i <= COL_NUM * ROW_NUM; i++){ Arrow* arrowObj = (Arrow *)this->getChildByTag(i); if( ! arrowObj->getOnFlag()){ //まだ全てONになっていない return; } } //終了 endFlag = true; //ハイスコアであれば保持 CCUserDefault* userDefault = CCUserDefault::sharedUserDefault(); int highScore = userDefault->getFloatForKey(highScoreKey.c_str(),ConstCommon::DEFAULT_HIGH_SCORE_NUM); if( highScore > totalGameCount){ isHighScore = true; userDefault->setFloatForKey(highScoreKey.c_str(), totalGameCount); } //ゲーム回数を記録 int totalAllGameCount = userDefault->getFloatForKey(totalAllGameCountKey.c_str(),0); userDefault->setFloatForKey(totalAllGameCountKey.c_str(), totalAllGameCount+1); userDefault->flush(); //終了アニメーション this->endAnimation(); }
bool GameData::load() { #if (ANDROIDSAVEBYUSERDEFAULT == 1 && CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) gd_isBeginner = JNI_getBool("IsBeginner", true); if (gd_isBeginner) { return false; } gd_highScore = JNI_getInt("HighScore", 0); gd_gold = JNI_getInt("Gold", 0); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) CCUserDefault* read = CCUserDefault::sharedUserDefault(); gd_isBeginner = read->getBoolForKey("IsBeginner", true); if (gd_isBeginner) { return false; } gd_highScore = read->getIntegerForKey("HighScore", 0); gd_gold = read->getIntegerForKey("Gold", 0); #endif return true; }