Example #1
0
/*
 *  初始化
 */
bool LoginLayer::init() {
    if (!CCLayer::init()) {
        return false;
    }
    
    NetConnection* pNetConnection = NetConnection::getInstance();
    pNetConnection->setHandleNetDataDelegate(this);
    
    unsigned int server_id = CCUserDefault::sharedUserDefault()->getIntegerForKey(LOGIN_SERVER_KEY, 0);
    /* 更改服务器名 */
    if (0 == server_id) {
        pNetConnection->setUUU(HTTP_SERVER_URL); /* 默认新浪服务器 */
        m_pGameState->setServerId(0);
    } else {
        pNetConnection->setUUU(HTTP_SERVER_URL1); /* 研发服务器 */
        m_pGameState->setServerId(1);
    }
    /* 初始化UI组件 */
    _initComponent();
    
    return true;
}
Example #2
0
void LoginLayer::option(CCObject* pSender) {
    for (int i = 0; i < 5; ++i) {
        CCSprite* spBtnBg = (CCSprite*)this->getChildByTag(SVRBG_SELECT + i);
        spBtnBg->setVisible(false);
        CCLabelTTF* svrName = (CCLabelTTF*)this->getChildByTag(SVR_NAME + i);
        svrName->setColor(ccc3(227, 168, 105));
        svrName->setScale(1);
    }
    CCMenuItemImage* pItemImage = (CCMenuItemImage*)pSender;
    
    switch (pItemImage->getTag() - SVRBG_NORMAL) {
        case 0:
        {
            NetConnection* pNetConnection = NetConnection::getInstance();
            
            pNetConnection->setUUU(HTTP_SERVER_URL);
            CCUserDefault::sharedUserDefault()->setIntegerForKey(LOGIN_SERVER_KEY, 0);
            CCUserDefault::sharedUserDefault()->flush();
            
            m_pGameState->setServerId(0);
            
            CCSprite* spBtnBg =  (CCSprite*)this->getChildByTag(SVRBG_SELECT);
            spBtnBg->setVisible(true);
            CCLabelTTF* svrName = (CCLabelTTF*)this->getChildByTag(SVR_NAME);
            svrName->setColor(ccc3(255, 215, 0));
            svrName->setScale(1.1);
        }
            break;
        case 1:
        {
            NetConnection* pNetConnection = NetConnection::getInstance();
            pNetConnection->setUUU(HTTP_SERVER_URL1);
            CCUserDefault::sharedUserDefault()->setIntegerForKey(LOGIN_SERVER_KEY, 1);
            CCUserDefault::sharedUserDefault()->flush();
            
            m_pGameState->setServerId(1);
            
            CCSprite* spBtnBg =  (CCSprite*)this->getChildByTag(SVRBG_SELECT + 1);
            spBtnBg->setVisible(true);
            CCLabelTTF* svrName = (CCLabelTTF*)this->getChildByTag(SVR_NAME + 1);
            svrName->setColor(ccc3(255, 215, 0));
            svrName->setScale(1.1);
        }
            break;
        case 2:
        {
            CCSprite* spBtnBg =  (CCSprite*)this->getChildByTag(SVRBG_SELECT+2);
            spBtnBg->setVisible(true);
            CCLabelTTF* svrName = (CCLabelTTF*)this->getChildByTag(SVR_NAME+2);
            svrName->setColor(ccc3(255, 215, 0));
            svrName->setScale(1.1);
        }
            break;
        case 3:
        {
            CCSprite* spBtnBg =  (CCSprite*)this->getChildByTag(SVRBG_SELECT+3);
            spBtnBg->setVisible(true);
            CCLabelTTF* svrName = (CCLabelTTF*)this->getChildByTag(SVR_NAME+2);
            svrName->setColor(ccc3(255, 215, 0));
            svrName->setScale(1.1);
        }
            break;
        case 4:
        {
            CCSprite* spBtnBg =  (CCSprite*)this->getChildByTag(SVRBG_SELECT+4);
            spBtnBg->setVisible(true);
            CCLabelTTF* svrName = (CCLabelTTF*)this->getChildByTag(SVR_NAME+2);
            svrName->setColor(ccc3(255, 215, 0));
            svrName->setScale(1.1);
        }
            break;
        default:
            CCAssert(false, "invalid server");
            break;
    }
}