void ConversationScene::speaking(string name, string text, const bool showHead) { _status = CONVER_STATUS::DIALOGUE; #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) if (name.length() > 0) GBKToUTF(name); GBKToUTF(text); #endif if (name.length() == 0) _speakLayer->showText(text); else if (showHead) _speakLayer->showTextWithNameAndHead(name, text); else _speakLayer->showTextWithName(name, text); }
void ChoiceLayer::setChoices(vector<string> choices) { size_t btnCount = getChildrenCount(); size_t choiceCount = choices.size(); float btnHeight = GlobalConfig::getInstance()->getChoiceMenuFontSize() + 10; float spaceBetweenBtn = btnHeight; float deltaUnit = btnHeight + spaceBetweenBtn; float initHeight = choiceCount % 2 == 0 ? spaceBetweenBtn*0.5 + (choiceCount / 2 - 1)*deltaUnit : spaceBetweenBtn + btnHeight*0.5 + ((choiceCount - 1) / 2 - 1)*deltaUnit; if (choiceCount > btnCount) for (int i = btnCount; i<choices.size(); i++) { auto btn = createButton(i, choices[i]); } for (int i = 0; i < choiceCount; i++) { auto btn = (ControlButton*)getChildByTag(i); string choice = choices.at(i); btn->setPosition(Vec2(0, initHeight - i*deltaUnit)); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) GBKToUTF(choice); #endif btn->setTitleForState(choice, Control::State::NORMAL); btn->setOpacity(255); } }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { string windowTile = "É¢Óð"; #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) GBKToUTF(windowTile); #endif glview = GLView::create(windowTile); glview->setFrameSize(800, 600); director->setOpenGLView(glview); } // turn on display FPS director->setDisplayStats(false); // set FPS. the default value is 1.0/60 if you don't call this director->setAnimationInterval(1.0 / 60); // create a scene. it's an autorelease object //auto scene = HelloWorld::createScene(); auto scene = MainMenuScene::createScene(); // run director->runWithScene(scene); return true; }
ControlButton* ChoiceLayer::createButton(int idx, string title) { string choiceBtnBg = GlobalConfig::getInstance()->getChoiceMenuBgPath(); Size screenSize = Director::getInstance()->getVisibleSize(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) GBKToUTF(title); #endif auto button = ControlButton::create(title, GlobalConfig::getInstance()->getChoiceMenuFontName(), GlobalConfig::getInstance()->getChoiceMenuFontSize()); button->addTargetWithActionForControlEvents(this, cccontrol_selector(ChoiceLayer::choicesCallback), Control::EventType::TOUCH_UP_INSIDE); button->setBackgroundSpriteForState(Scale9Sprite::create(choiceBtnBg), Control::State::NORMAL); button->setPreferredSize(Size(screenSize.width*0.6, GlobalConfig::getInstance()->getChoiceMenuFontSize() + 10)); button->setOpacity(0); button->setTitleColorForState(GlobalConfig::getInstance()->getChoiceMenuFontColor(), Control::State::NORMAL); addChild(button, 0, idx); return button; }
bool MonsterLayer::init() { CCAssert(CCLayer::init(),"CCLayer init failed!"); int iPlayerCount = m_data->size(); this->setTouchEnabled(true); CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,1,false); float fScreenWidth = CCDirector::sharedDirector()->getVisibleSize().width; float fScreenHeight = CCDirector::sharedDirector()->getVisibleSize().height; for (int i = 0;i<iPlayerCount;++i) { string name = m_data->at(i)->getName(); char pName[MAX_FILE_PATH_LENGTH]; #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) GBKToUTF(name); #endif sprintf(pName,MONSTER_DIR_PATH,name.c_str()); CCSprite *pSprite = CCSprite::create(pName); CCAssert(pSprite,"Get Monster sprite failed!"); float fPlayerWidth = pSprite->getContentSize().width; float fPlayerHeight = pSprite->getContentSize().height; float xpos = fScreenWidth*0.5+(i-iPlayerCount*0.5+0.5)*fPlayerWidth; float ypos = fScreenHeight*0.6; pSprite->setPosition(ccp(xpos,ypos)); pSprite->setOpacity(0); addChild(pSprite,0,i); m_monsters->addObject(pSprite); m_originalPos.insert(make_pair(i,ccp(xpos,ypos))); //HP Bar CCProgressTimer *hpBarTimer = CCProgressTimer::create(CCSprite::create(MONSTER_HP_BAR_PATH)); hpBarTimer->setType(kCCProgressTimerTypeBar); hpBarTimer->setMidpoint(ccp(0,0)); hpBarTimer->setPercentage(100); hpBarTimer->setBarChangeRate(ccp(1,0)); hpBarTimer->setPosition(ccp(pSprite->getPositionX(), pSprite->getPositionY() + fPlayerHeight*0.5 + hpBarTimer->getContentSize().height*0.5)); hpBarTimer->setOpacity(0); addChild(hpBarTimer,1,iPlayerCount+i); } //Damage number m_pFont = CCLabelBMFont::create("0",FONT_PATH); m_pFont->setColor(ccYELLOW); m_pFont->setOpacity(0); addChild(m_pFont,4); //Magic matrix tag m_magicTag = CCSprite::create(MAGIC_BTN_PATH); m_magicTag->setOpacity(0); m_magicTag->setPosition(ccp(750,550)); addChild(m_magicTag); m_magicPointer = CCSprite::create(MAGIC_UNAVA_PATH); m_magicPointer->setOpacity(0); m_magicPointer->setPosition(ccp(750,550)); addChild(m_magicPointer); m_magicAva = CCTextureCache::sharedTextureCache()->addImage(MAGIC_AVA_PATH); m_magicUnava = CCTextureCache::sharedTextureCache()->addImage(MAGIC_UNAVA_PATH); m_longHPBar = CCProgressTimer::create(CCSprite::create(LONG_HP_BAR)); m_longHPBar->setType(kCCProgressTimerTypeBar); m_longHPBar->setMidpoint(ccp(0,0)); m_longHPBar->setPercentage(100); m_longHPBar->setBarChangeRate(ccp(1,0)); m_longHPBar->setOpacity(0); m_longHPBar->setPosition(ccp(fScreenWidth*0.5,fScreenHeight*0.3)); addChild(m_longHPBar,2); m_timeBarEmpty = CCSprite::create(TIME_BAR_EMPTY); m_timeBarEmpty->setOpacity(0); m_timeBarEmpty->setPosition(ccp(fScreenWidth*0.5,fScreenHeight*0.7)); addChild(m_timeBarEmpty,2); m_timeBarFull = CCProgressTimer::create(CCSprite::create(TIME_BAR_FULL)); m_timeBarFull->setType(kCCProgressTimerTypeBar); m_timeBarFull->setMidpoint(ccp(0,0)); m_timeBarFull->setPercentage(100); m_timeBarFull->setBarChangeRate(ccp(1,0)); m_timeBarFull->setOpacity(0); m_timeBarFull->setPosition(ccp(fScreenWidth*0.5,fScreenHeight*0.7)); addChild(m_timeBarFull,2); CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache(); cache->addSpriteFramesWithFile(BUBBLE_PLIST_PATH,BUBBLE_TEXTURE_PATH); return true; }