コード例 #1
0
ファイル: MyMenuItem.cpp プロジェクト: JoregeSanz/MyRepo
MyMenuItem* MyMenuItem::create(const char *normalImage, CCObject* target, SEL_MenuHandler selector)
{
    MyMenuItem *pobSprite = new MyMenuItem();
    if (pobSprite && pobSprite->initWithNormalImage(normalImage, normalImage, normalImage, target, selector))
    {
        pobSprite->setScale(g_fResScale);
        pobSprite->isDefaultAction = true;
        pobSprite->runAction(MenuAction::defaultMenuAction());
        pobSprite->autorelease();
        
        
        return pobSprite;
    }
    CC_SAFE_DELETE(pobSprite);
    
    return NULL;

}
コード例 #2
0
ファイル: ThirdServerScene.cpp プロジェクト: itita/2-z-q-x-
void ThirdServerScene::initServerInfo(SeverInfoBean* bean) {
    this->removeChildByTag(serverInfoLayerTag,true);
    selectBean = bean;
    CCLayer* serverInfoLayer = CCLayer::create();
    serverInfoLayer->setTag(serverInfoLayerTag);
    serverInfoLayer->setPosition(ccp(0,0));
    
    this->cacheServerId = bean->serverId;
    char str[30] = {0};
    
    sprintf(str,"s%d_ititaId",bean->serverId);
    std::string ititaId = CCUserDefault::sharedUserDefault()->getStringForKey(str,"");
    bool ititaIdFlag = false;
    if (ititaId.compare("") != 0 && ititaId.compare(PulsarNative::getDeviceId()) != 0) {
        ititaIdFlag = true;
    }
    
    MyMenuItem* leftButton = MyMenuItem::create(CCSprite::createWithSpriteFrameName("serverButton.png"),NULL,NULL);
    leftButton->setAnchorPoint(ccp(1,0.5));
    //    leftButton->setPosition(ccp(winSize.width+100,240));
    leftButton->setPosition(ccp(winSize.width+422,240));
    leftButton->runAction(CCSequence::create(CCDelayTime::create(0.1),CCEaseElasticOut::create(CCMoveTo::create(0.3,ccp(winSize.width+100,240)),1),NULL));
    
    CCSprite* registLabel;
    if (ititaIdFlag) {
        registLabel = CCSprite::createWithSpriteFrameName("serverSwitchLabel.png");
        leftButton->setTarget(this,menu_selector(ThirdServerScene::toLogin));
    } else {
        registLabel = CCSprite::createWithSpriteFrameName("serverBindLabel.png");
        leftButton->setTarget(this,menu_selector(ThirdServerScene::toRegister));
    }
    registLabel->setAnchorPoint(ccp(0,0.5));
    registLabel->setPosition(ccp(30,leftButton->getContentSize().height/2));
    leftButton->addChild(registLabel);
    
    
    
    MyMenuItem* rightButton = MyMenuItem::create(CCSprite::createWithSpriteFrameName("serverButton.png"),this,menu_selector(ThirdServerScene::fastEnterGameWait));
    rightButton->setAnchorPoint(ccp(1,0.5));
    //    rightButton->setPosition(ccp(winSize.width+20,330));
    rightButton->setPosition(ccp(winSize.width+342,330));
    rightButton->runAction(CCSequence::create(CCEaseElasticOut::create(CCMoveTo::create(0.3,ccp(winSize.width+20,330)),1),NULL));
    
    CCSprite* newLabel;
    if (ititaIdFlag) {
        newLabel = CCSprite::createWithSpriteFrameName("serverEnterGame.png");
    } else {
        newLabel = CCSprite::createWithSpriteFrameName("serverFastStartLabel.png");
    }
    newLabel->setAnchorPoint(ccp(0,0.5));
    newLabel->setPosition(ccp(30,rightButton->getContentSize().height/2));
    rightButton->addChild(newLabel);
    
    MyPriorityMenu* menu = MyPriorityMenu::create(-501,leftButton,rightButton,NULL);
    menu->setPosition(ccp(0,0));
    serverInfoLayer->addChild(menu);
    
//    sprintf(str,"s%d_nickname",bean->serverId);
//    std::string nickname = CCUserDefault::sharedUserDefault()->getStringForKey(str,"");
//    
//    if (nickname.compare("") != 0) {
//        CCLabelTTF* id = CCLabelTTF::create("ID:","Arial",40);
//        id->setColor(ccc3(255,222,0));
//        
//        CCLabelTTF* nicknameLabel = CCLabelTTF::create(nickname.c_str(),"Arial",40);
//        float locx = id->getContentSize().width+nicknameLabel->getContentSize().width;
//        id->setAnchorPoint(ccp(0,0.5));
//        id->setPosition(ccp(winSize.width-locx/2-180,400));
//        nicknameLabel->setAnchorPoint(ccp(0,0.5));
//        nicknameLabel->setPosition(ccp(winSize.width-locx/2+id->getContentSize().width-190,400));
//        serverInfoLayer->addChild(id);
//        serverInfoLayer->addChild(nicknameLabel);
//    }
    
    CCLayer* layer = CCLayer::create();
    
    CCLabelTTF* label = CCLabelTTF::create(bean->getServerName()->getCString(),"Arial",33);
    label->setPosition(ccp(224,2));
    layer->addChild(label);
    label->setTag(serverNameLabelTag);
    
    CCLabelTTF* stateLabel =CCLabelTTF::create(bean->getServerStatus()->getCString(),"Arial",30);
    stateLabel->setPosition(ccp(340,0));
    if (bean->getServerStatus()->compare("正常") == 0 || bean->getServerStatus()->compare("推荐") == 0) {
        stateLabel->setColor(ccc3(0,255,0));
    } else if (bean->getServerStatus()->compare("繁忙") == 0) {
        stateLabel->setColor(ccc3(255,255,0));
    } else if (bean->getServerStatus()->compare("火爆") == 0) {
        stateLabel->setColor(ccc3(167,87,168));
    } else {
        stateLabel->setColor(ccc3(166,166,166));
    }
    
    
    layer->addChild(stateLabel);
    
    CCSprite* serverBack = CCSprite::createWithSpriteFrameName("serverCurentServerBack.png");
    //    serverBack->setPosition(ccp(winSize.width+35,48));
    serverBack->setPosition(ccp(winSize.width+357,48));
    serverBack->runAction(CCSequence::create(CCDelayTime::create(0.3),CCEaseElasticOut::create(CCMoveTo::create(0.3,ccp(winSize.width+35,48)),1),NULL));
    serverBack->setAnchorPoint(ccp(1,0.5));
    serverInfoLayer->addChild(serverBack);
    
    //    layer->setPosition(ccp(winSize.width-380,45));
    layer->setPosition(ccp(winSize.width-58,45));
    layer->runAction(CCSequence::create(CCDelayTime::create(0.3),CCEaseElasticOut::create(CCMoveTo::create(0.3,ccp(winSize.width-380,45)),1),NULL));
    serverInfoLayer->addChild(layer);
    
    MyMenuItem* selectServerButton = MyMenuItem::create(CCSprite::createWithSpriteFrameName("serverButton.png"),this,menu_selector(ThirdServerScene::toServerList));
    
    CCSprite* selectServerLabel = CCSprite::createWithSpriteFrameName("serverSelectButton.png");
    selectServerLabel->setAnchorPoint(ccp(0,0.5));
    selectServerLabel->setPosition(ccp(30,rightButton->getContentSize().height/2));
    
    
    selectServerButton->setAnchorPoint(ccp(1,0.5));
    //    selectServerButton->setPosition(winSize.width+130,150);
    selectServerButton->setPosition(ccp(winSize.width+452,150));
    selectServerButton->runAction(CCSequence::create(CCDelayTime::create(0.2),CCEaseElasticOut::create(CCMoveTo::create(0.3,ccp(winSize.width+130,150)),1),NULL));
    selectServerButton->addChild(selectServerLabel);
    menu->addChild(selectServerButton);
    
    this->addChild(serverInfoLayer,2);
}