Ejemplo n.º 1
0
void Senario::clearElements()
{
    for(int i = 0; i < spriteList.size(); i++)
    {
        this->removeChild(spriteList.at(i), true);
    }
    
    for(int i = 0; i < menuList.size(); i++)
    {
        this->removeChild(menuList.at(i), true);
    }
    
    for(int i = 0; i < labelList.size(); i++)
    {
        this->removeChild(labelList.at(i), true);
    }
    
    spriteList.clear();
    menuList.clear();
    labelList.clear();
    
    for(int i = 0; i < animatedStringList->count(); i++)
    {
        AnimatedString* as = (AnimatedString*) animatedStringList->objectAtIndex(i);
        this->removeChild(as->getLabel(), true);
    }
    
    animatedStringList->removeAllObjects();
    CC_SAFE_RELEASE(animatedStringList);
    
    animatedStringList = CCArray::create();
    animatedStringList->retain();
    
    for(int i = 0; i < animatedSpriteList->count(); i++)
    {
        AnimatedSprite* as = (AnimatedSprite*) animatedSpriteList->objectAtIndex(i);
        this->removeChild(as->getSprite(), true);
    }
    
    animatedSpriteList->removeAllObjects();
    CC_SAFE_RELEASE(animatedSpriteList);
    
    animatedSpriteList = CCArray::create();
    animatedSpriteList->retain();
    
    for(int i = 0; i < animatedDialogueList->count(); i++)
    {
        AnimatedDialogue* ad = (AnimatedDialogue*) animatedDialogueList->objectAtIndex(i);
        this->removeChild(ad->getSprite(), true);
    }
    
    animatedDialogueList->removeAllObjects();
    CC_SAFE_RELEASE(animatedDialogueList);
    
    animatedDialogueList = CCArray::create();
    animatedDialogueList->retain();
    
    if(skipButton != NULL)
    {
        CC_SAFE_RELEASE(skipButton);
        skipButton = NULL;
    }
}
Ejemplo n.º 2
0
bool Senario::constructSenarioStage(bool skip)
{
    CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
    ccColor3B colorBlack = ccc3(0, 0, 0);
   // ccColor3B colorYellow = ccc3(225, 219, 108);
    ccColor3B colorBlue = ccc3(0, 0, 255);
    clearElements();
    
    if(slidesList->count() <= curSlide)
    {
        return false;
    }
    
    Slide* slide = (Slide*)slidesList->objectAtIndex(curSlide);
    
    CCArray* elementArray = slide->elementList;
    
    if(slide->isScene)
    {
        
        CCTextureCache::sharedTextureCache()->removeAllTextures();
        CCTextureCache::sharedTextureCache()->purgeSharedTextureCache();
        CCAnimationCache::sharedAnimationCache()->purgeSharedAnimationCache();
        CCDirector::sharedDirector()->purgeCachedData();
        
        backgroundImage = slide->scene_src;
    }
    
    CCSprite* blackScreen = CCSprite::create(backgroundImage.c_str());
    blackScreen->setScale(screenSize.width / blackScreen->boundingBox().size.width);
    blackScreen->setAnchorPoint(ccp(0.5, 0.5));
    blackScreen->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f));
    this->addChild(blackScreen, 1);
    spriteList.push_back(blackScreen);
    
    skipButton = CCSprite::create("skip_button.png");
    skipButton->retain();
    skipButton->setScale(1.0f);
    skipButton->setAnchorPoint(ccp(1, 1));
    skipButton->setPosition(ccp(screenSize.width, screenSize.height));
    this->addChild(skipButton, 2);
    spriteList.push_back(skipButton);
    
    if(slide->hasVideo)
    {
        //Config *c = Config::getConfig();
        if(slide->video_clip.compare("") != 0)
        {
            WrapperClass::getShared()->playVideo(slide->video_clip.c_str());
        }
    }
    
    if(slide->playBGM)
    {
        if(slide->bgm_clip.compare("") != 0)
        {
            SoundtrackManager::PlayBGM(slide->bgm_clip);
        }
    }
    
    if(slide->playSFX)
    {
        if(slide->sfx_clip.compare("") != 0)
        {
            SoundtrackManager::PlaySFX(slide->sfx_clip);
        }
    }
    
    if(GameScene::getThis()->systemConfig->hideSkipButton)
    {
        skipButton->setAnchorPoint(ccp(0, 1));
        skipButton->setPosition(ccp(screenSize.width, screenSize.height));
    }
    
    bool isChoosingOption = false;
    for(int i = 0; i < elementArray->count(); i++)
    {
        Element* ele = (Element*)elementArray->objectAtIndex(i);
        
        /*
         * In the senario stage, there are two types of elements -> sprite and dialogue, treat these two types of elements differently in order to make this display them correctly!
         */
        
        if(ele->type == Element::sprite)
        {
            /*
             * Sprite: only has a picture of the sprite shown on the screen
             * Future: may include animation of the sprite shown on the screen (probably a gif?)
             */
            
            AnimatedSprite* as = AnimatedSprite::create(ele->src.c_str(), ele->fadeIn, ele->fadeOut, true);
            stringstream ss;
            CCSprite* cha = as->getSprite();
            CCSize spriteSize = cha->getContentSize();
            cha->setScale(screenSize.width / spriteSize.width * ele->width / 100.0f);
            cha->setFlipX(true);
            
            cha->setAnchorPoint(ccp(0, 1));
            cha->setPosition(ccp(screenSize.width * (ele->left / 100.0f), screenSize.height * (ele->top / 100.0f)));
            this->addChild(cha, 2);
            spriteList.push_back(cha);
            
            animatedSpriteList->addObject(as);
        }
        else if(ele->type == Element::dialogue)
        {
            /*
             * Dialogue: contains a picture of the background of that dialogue, a name label, a dialogue text and a proceed button
             * Future: may include dialogue functionalities like save, load, auto proceed, text jumper, etc....
             */
            
            AnimatedDialogue* ad = AnimatedDialogue::create(ele->src.c_str(), ele->fadeIn, ele->fadeOut);
            CCSprite* chbox = ad->getSprite();
            CCSize boxSize = chbox->getContentSize();
            chbox->setScale(screenSize.width / boxSize.width * ele->width / 100.0f);
            chbox->setAnchorPoint(ccp(0, 1));
            chbox->setPosition(ccp(screenSize.width * (ele->left / 100.0f), screenSize.height * (ele->top / 100.0f)));
            
            if(ele->isBackground)
            {
                this->addChild(chbox, 3);
                spriteList.push_back(chbox);
                animatedDialogueList->addObject(ad);
                continue;
            }
            
            float heightOff = 80.0f - ele->textOffY;
            float widthOff = 80.0f;
            
            displayTexts(ele->text, screenSize.width * (ele->left / 100.0f) + widthOff, screenSize.height * (ele->top / 100.0f) - heightOff, ele->font.c_str(), (float)ele->fontSize, colorBlack, ele->limitX);
            
            std::stringstream ss;
            ss << ele->text;
            
            heightOff = 40.0f;
            widthOff = 80.0f;
            
            ss.str(std::string());
            ss << ele->name;
            CCLabelTTF* chboxName = CCLabelTTF::create(ss.str().c_str(), ele->font.c_str(), ele->fontSize, CCSizeMake(ss.str().length() * 20.0f, 5.0f), kCCTextAlignmentLeft);
            chboxName->setColor(colorBlue);
            chboxName->setAnchorPoint(ccp(0, 1));
            chboxName->setPosition(ccp(screenSize.width * (ele->left / 100.0f) + widthOff, screenSize.height * (ele->top / 100.0f) - heightOff));
            
            this->addChild(chbox, 3);
            this->addChild(chboxName, 4);
            spriteList.push_back(chbox);
            labelList.push_back(chboxName);
            animatedDialogueList->addObject(ad);
        }
        else if(ele->type == Element::option)
        {
            isChoosingOption = true;
            inOption = true;
            notJump = true;
            
            CCMenuItemImage* selectButton = CCMenuItemImage::create(ele->src.c_str(), ele->srcp.c_str(), this, menu_selector(Senario::selectButtonPressed));
            selectButton->setTag(i);
            selectButton->setAnchorPoint(ccp(0, 1));
            selectButton->setScale(0.6f);
            
            CCMenu* menu = CCMenu::create(selectButton, NULL);
            menu->setPosition(ccp(screenSize.width * (ele->left / 100.0f), screenSize.height * (ele->top / 100.0f)));
            this->addChild(menu, 4);
            menuList.push_back(menu);
        }
    }
    
    if(!isChoosingOption && skip)
    {
        return false;
    }
    
    this->schedule(schedule_selector(Senario::update), 1.0f/60.0f);
    
    return true;
}