本文整理汇总了C++中CCUserDefault::setStringForKey方法的典型用法代码示例。如果您正苦于以下问题:C++ CCUserDefault::setStringForKey方法的具体用法?C++ CCUserDefault::setStringForKey怎么用?C++ CCUserDefault::setStringForKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCUserDefault
的用法示例。
在下文中一共展示了CCUserDefault::setStringForKey方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: backpackValue
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
}
示例2:
/**
* 清除数据
*/
void
MCTaskAccessor::erase()
{
CCUserDefault *userDefault = CCUserDefault::sharedUserDefault();
userDefault->setStringForKey(kMCTasksKey, "");
}
示例3: onClickedLogin
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);
}
}
示例4:
KDvoid Ch3_SavingSimpleData::saveDifficulty ( KDvoid )
{
// Save our difficulty
CCUserDefault* pDefaults = CCUserDefault::sharedUserDefault ( );
pDefaults->setStringForKey ( "simple_data_difficulty", m_sDifficulty.c_str ( ) );
pDefaults->flush ( );
}
示例5: initStore
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());
}
}
示例6: writeRuntimeDataToLocal
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();
}
示例7: flush
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();
}
示例8: effectiveItemsValue
void
MCBackpack::saveEffectiveItems()
{
CCUserDefault *userDefault = CCUserDefault::sharedUserDefault();
JsonBox::Array effectiveItems;
/* 道具 */
effectiveItems.push_back(JsonBox::Value((int) healthPotion_->count));
effectiveItems.push_back(JsonBox::Value((int) physicalPotion_->count));
effectiveItems.push_back(JsonBox::Value((int) fireballTrapWide_->count));
effectiveItems.push_back(JsonBox::Value((int) fireballTrapDamage_->count));
effectiveItems.push_back(JsonBox::Value((int) curseTrapWide_->count));
effectiveItems.push_back(JsonBox::Value((int) curseTrapDamage_->count));
effectiveItems.push_back(JsonBox::Value((int) paralysisTrapWide_->count));
effectiveItems.push_back(JsonBox::Value((int) paralysisTrapDamage_->count));
effectiveItems.push_back(JsonBox::Value((int) fogTrapWide_->count));
effectiveItems.push_back(JsonBox::Value((int) fogTrapDamage_->count));
effectiveItems.push_back(JsonBox::Value((int) flashTrapWide_->count));
effectiveItems.push_back(JsonBox::Value((int) flashTrapDamage_->count));
JsonBox::Value effectiveItemsValue(effectiveItems);
ostringstream outputStream;
effectiveItemsValue.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(kMCEffectiveItemsKey, output);
#if MC_DEBUG_SAVEDATA != 1
delete []output;
#endif
}
示例9: storeData
void Logic::storeData() {
CCUserDefault *u = CCUserDefault::sharedUserDefault();
u->setStringForKey("loginName", loginName);
u->setStringForKey("nickname", nickname);
u->setIntegerForKey("uid", uid);
}
示例10: requestFinished
void SGWelComeLayer::requestFinished(int msgid, CCObject *data)
{
CCLOG("收到数据");
switch (msgid)
{
case MSG_HTTP_FAST_LOGIN:
{
std::string serverip = CCUserDefault::sharedUserDefault()->getStringForKey("serverip");
short serverpost = (short)CCUserDefault::sharedUserDefault()->getIntegerForKey("serverpost");
//记录服务器ip和端口号
SGMainManager::shareMain()->setServerInfo(CCString::create(serverip.c_str()) , serverpost);
//连接socket
SGSocketClient::sharedSocketClient()->startConn(serverip.c_str() , serverpost);
}
break;
case MSG_HTTP_LOGIN:
{
int isLogin = SGMainManager::shareMain()->getIsFBLogin();
if (isLogin != 1 || !SGMainManager::shareMain()->getIsFbAutologin())
{
std::string serverip = CCUserDefault::sharedUserDefault()->getStringForKey("serverip");
int serverpost = CCUserDefault::sharedUserDefault()->getIntegerForKey("serverpost");
SGSocketClient::sharedSocketClient()->startConn(serverip.c_str() ,(short)serverpost);
}
else
{
SGMainManager::shareMain()->setIsFbAutologin(false);
}
}
break;
case MSg_HTTP_SERVERLIST:
{
SGServerListLayer *box = SGServerListLayer::create(this, (CCArray *)data, SGServerListLayerComeFromFirst);
SGMainManager::shareMain()->showBox(box,false);
}
break;
case MSG_HTTP_UPDATE_SERVER_STATE:
{
CCDictionary *dict = (CCDictionary*)data;
CCString *serverIp = (CCString*)dict->objectForKey("serverIp");
CCString *serverPost = (CCString*)dict->objectForKey("serverPost");
CCString *serverId = (CCString*)dict->objectForKey("serverId");
CCString *serverShowId = (CCString*)dict->objectForKey("serverShowId");
CCString* serverName = (CCString*)dict->objectForKey("serverName");
//保存即将登陆的服务器的描述
serverDes = ((CCString * )dict->objectForKey("serverDes") )->m_sString;
//save ip and post of server
CCUserDefault::sharedUserDefault()->setIntegerForKey("serverid",serverId->intValue());
CCUserDefault::sharedUserDefault()->setIntegerForKey("serverShowId", serverShowId->intValue());
CCUserDefault::sharedUserDefault()->setStringForKey("serverip", serverIp->getCString());
CCUserDefault::sharedUserDefault()->setIntegerForKey("serverpost", serverPost->intValue());
CCUserDefault::sharedUserDefault()->setStringForKey("servername", serverName->getCString());
CCUserDefault::sharedUserDefault()->flush();
CCLog("最新服务器 ip=%s\n post=%s\n id=%s\n name=%s",serverIp->getCString(),serverPost->getCString(),serverId->getCString(),serverName->getCString());
changeServerbtn->setFont(serverName->getCString());
CCUserDefault::sharedUserDefault()->setStringForKey("servername", serverName->getCString());
//如果是维护中 则不再登陆。
short serverState = (short)( ( (CCString *)dict->objectForKey("serverState") )->intValue() );
if (1 != serverState)
{
;
}
//提示不能登陆的详细信息。
else
{
SGMainManager::shareMain()->showMessage(serverDes.c_str());
}
//MM: 即使维护中,也尝试登录,101用户会自动放过。
this->realLogin();
}
break;
case MSg_HTTP_LASTESTSERVER:
{
CCDictionary *dict = (CCDictionary*)data;
CCString *serverIp = (CCString*)dict->objectForKey("serverIp");
CCString *serverPost = (CCString*)dict->objectForKey("serverPost");
CCString *serverId = (CCString*)dict->objectForKey("serverId");
CCString* serverName = (CCString*)dict->objectForKey("serverName");
//保存即将登陆的服务器的描述
serverDes = ((CCString * )dict->objectForKey("serverDes") )->m_sString;
//save ip and post of server
CCUserDefault::sharedUserDefault()->setIntegerForKey("serverid",serverId->intValue());
CCUserDefault::sharedUserDefault()->setStringForKey("serverip", serverIp->getCString());
CCUserDefault::sharedUserDefault()->setIntegerForKey("serverpost", serverPost->intValue());
CCUserDefault::sharedUserDefault()->setStringForKey("servername", serverName->getCString());
CCUserDefault::sharedUserDefault()->flush();
CCLog("最新服务器 ip=%s\n post=%s\n id=%s\n name=%s",serverIp->getCString(),serverPost->getCString(),serverId->getCString(),serverName->getCString());
//.........这里部分代码省略.........