Ejemplo n.º 1
0
void ConfirmLayer::createLayersContent() {
    GameModel* gameModel = GameModel::getInstance();
    
    Face* backgroundFade = new Face();
    backgroundFade->initWithFile(ANI_BACKGROUND_FADE);
    backgroundFade->setPosition(Point(gameModel->getDisplayResolutionSize().width / 2, gameModel->getDisplayResolutionSize().height / 2));
    backgroundFade->setOpacity(0);
    this->mainLayer->addChild(backgroundFade);
    this->backgroundFade = backgroundFade;
    {
        FiniteTimeAction* fadeIn = FadeIn::create(0.5f);
        backgroundFade->registerState(STATE_FADE_IN, fadeIn);
        
        FiniteTimeAction* fadeOut = FadeOut::create(0.5f);
        backgroundFade->registerState(STATE_FADE_OUT, fadeOut);
    }
    
    Face* menuFace = new Face();
    menuFace->initWithSpriteFrameName(ANI_BOX_CONFIRM);
    menuFace->setPosition(Point(gameModel->getDisplayResolutionSize().width / 2, -500));
    this->mainLayer->addChild(menuFace);
    this->menuFace = menuFace;
    Size menuFaceSize = menuFace->getContentSize();
    
    UGMenu* optionMenu = UGMenu::create();
    optionMenu->setPosition(Point::ZERO);
    menuFace->addChild(optionMenu);
    {
        Label* confirmLabel = Label::createWithBMFont(FONT_GAME_SMALL, TXT_CONFIRM_TEXT);
        confirmLabel->setPosition(menuFaceSize.width / 2, menuFaceSize.height / 2);
        this->menuFace->addChild(confirmLabel);
    }
    {
        FiniteTimeAction* move1 = MoveTo::create(0, menuFace->getPosition());
        FiniteTimeAction* move2 = MoveTo::create(0.5f, Point(gameModel->getDisplayResolutionSize().width / 2, gameModel->getDisplayResolutionSize().height / 2));
        FiniteTimeAction* move3 = CallFunc::create(CC_CALLBACK_0(ConfirmLayer::onOptionBoardMoveUpDone, this));
        FiniteTimeAction* move123 = Sequence::create(move1, move2, move3, NULL);
        menuFace->registerState(STATE_MOVE_UP, move123);
        
        FiniteTimeAction* move4 = MoveTo::create(0, Point(gameModel->getDisplayResolutionSize().width / 2, gameModel->getDisplayResolutionSize().height / 2));
        FiniteTimeAction* move5 = MoveTo::create(0.5f, menuFace->getPosition());
        FiniteTimeAction* move6 = CallFunc::create(CC_CALLBACK_0(ConfirmLayer::onOptionBoardMoveDownDone, this));
        FiniteTimeAction* move456 = Sequence::create(move4, move5, move6, NULL);
        menuFace->registerState(STATE_MOVE_DOWN, move456);
        
        MenuItemSprite* okButton = Utils::createButton((char*) TXT_OK, 16, ANI_BUTTON_SMALL, ANI_BUTTON_SMALL);
        okButton->setCallback(CC_CALLBACK_1(ConfirmLayer::onOkButtonClick, this));
        okButton->setPosition(Point(menuFaceSize.width / 2 - 129, 0));
        okButton->setEnabled(false);
        optionMenu->addChild(okButton);
        this->okButton = okButton;
        
        MenuItemSprite* cancelButton = Utils::createButton((char*) TXT_CANCEL, 16, ANI_BUTTON_SMALL, ANI_BUTTON_SMALL);
        cancelButton->setCallback(CC_CALLBACK_1(ConfirmLayer::onCancelButtonClick, this));
        cancelButton->setPosition(Point(menuFaceSize.width / 2 + 129, 0));
        cancelButton->setEnabled(false);
        optionMenu->addChild(cancelButton);
        this->cancelButton = cancelButton;
    }
}
Ejemplo n.º 2
0
void PadLayer::createLayersContent() {
    GameModel* gameModel = GameModel::getInstance();
    Size displayResolutionSize = gameModel->getDisplayResolutionSize();
    
    this->padA = new Face();
    this->padA->initWithFile(ANI_BUTTON_A);
    this->padA->setPosition(Point(displayResolutionSize.width - CONF_PAD_PADDING_X, CONF_PAD_PADDING_Y) +
                                           Point(CONF_RANGE_TO_TOUCH, 0));
    this->addChild(this->padA);
    this->padA->setOpacity(100);
    
    this->padB = new Face();
    this->padB->initWithFile(ANI_BUTTON_B);
    this->padB->setPosition(Point(displayResolutionSize.width - CONF_PAD_PADDING_X, CONF_PAD_PADDING_Y) +
                      Point(-CONF_RANGE_TO_TOUCH, 0));
    this->addChild(padB);
    this->padB->setOpacity(100);
}
Ejemplo n.º 3
0
void ChapterScene::createLayersContent() {
    GameModel* gameModel = GameModel::getInstance();
    Size displayResolutionSize = gameModel->getDisplayResolutionSize();
    
    Face* backgroundFace = new Face();
    backgroundFace->initWithFile(ANI_BACKGROUND);
    backgroundFace->setScale(CONF_FAKE_1);
    backgroundFace->setPosition(displayResolutionSize.width / 2, displayResolutionSize.height / 2);
    this->backgroundLayer->addChild(backgroundFace);
    
    Face* chapterTitle = new Face();
    chapterTitle->initWithSpriteFrameName(ANI_CHAPTER_TITLE);
    chapterTitle->setPosition(displayResolutionSize.width / 2, displayResolutionSize.height - chapterTitle->getContentSize().height / 2 - 20);
    this->mainLayer->addChild(chapterTitle);
    
    UGMenu* mainMenu = UGMenu::create();
    mainMenu->setPosition(Point::ZERO);
    this->mainLayer->addChild(mainMenu);
    
    MenuItemSprite* backButton = Utils::createButton((char*) TXT_BACK, 16, ANI_BUTTON, ANI_BUTTON);
    backButton->setCallback(CC_CALLBACK_1(ChapterScene::backButtonClick, this));
    backButton->setPosition(gameModel->getDisplayResolutionSize().width / 2, 20 + backButton->getContentSize().height / 2);
    mainMenu->addChild(backButton);
    this->nodes->setObject(backButton, NODE_BUTTON_BACK);
    
    // create chapters
    this->chapterLayer = UGLayerColor::create();
    float totalChapterSize = gameModel->getMapData()->getLevelSize();
    float distancePerChapter = CONF_DISTANCE_PER_CHAPTER;
    float totalChapterWidth = (totalChapterSize - 1) * distancePerChapter;
    
    Face* chapterTemp = new Face();
    chapterTemp->initWithSpriteFrameName(ANI_BOX_CHAPTER);
    this->chapterTempSize = chapterTemp->getContentSize();
    
    this->chapterLayer->setContentSize(Size(totalChapterWidth + this->chapterTempSize.width, displayResolutionSize.height / 2));
    this->chapterLayer->setPosition(displayResolutionSize.width / 2 - this->chapterTempSize.width / 2, displayResolutionSize.height / 2 - this->chapterLayer->getContentSize().height / 2);
    this->chapterLayerOffset = this->chapterLayer->getPosition();
    this->mainLayer->addChild(this->chapterLayer);
    
    float posX = this->chapterTempSize.width / 2;
    float posY = this->chapterLayer->getContentSize().height / 2;
    for (int i = 0; i < totalChapterSize; i++) {
        Face* levelBox = new Face();
        if (!gameModel->checkLevelLock(i + 1)) {
            levelBox->initWithSpriteFrameName(ANI_BOX_CHAPTER);
            levelBox->setTag(i + 1);
            {
                int chapter = gameModel->getMapData()->getChapter(i + 1);
                int chapterLevel = gameModel->getMapData()->getChapterLevel(i + 1);
                char mapPath[200];
                sprintf(mapPath, DOC_BG_MAP, chapter, chapterLevel);
                
                SpriteFrameCache* sfc = SpriteFrameCache::getInstance();
                sfc->addSpriteFramesWithFile(mapPath);
                char bg1Path[200];
                sprintf(bg1Path, ANI_MAP, chapter, chapterLevel, 1);

                Face* chapterThumb = new Face();
                chapterThumb->initWithSpriteFrameName(bg1Path);
                chapterThumb->setPosition(levelBox->getContentSize().width / 2, levelBox->getContentSize().height / 2 - 10);
                chapterThumb->setTextureRect(Rect(0, 0, 160, 115));
                levelBox->addChild(chapterThumb);
                
                string levelName = gameModel->getMapData()->getLevelName(i + 1);
                char levelNameChar[200];
                sprintf(levelNameChar, "%s", levelName.data());
                Label* levelNameLabel = Label::createWithBMFont(FONT_GAME_SMALL, levelNameChar);
                levelNameLabel->setPosition(chapterThumb->getPosition() + Point(0, chapterThumb->getContentSize().height / 2 + 12));
                levelBox->addChild(levelNameLabel);
            }
        } else {
            levelBox->setTag(-1);
            levelBox->initWithSpriteFrameName(ANI_BOX_CHAPTER_LOCK);
        }
        
        levelBox->setPosition(posX, posY);
        posX = posX + distancePerChapter;
        this->chapterLayer->addChild(levelBox);
    }
    
    // add parent button for share layer
    this->shareLayer->getParentButtons()->pushBack((MenuItemSprite*) this->nodes->objectForKey(NODE_BUTTON_BACK));
}