void CTopLayer::onEnter() { BaseLayer::onEnter(); this->setTouchPriority(-100); UserData *user = DataCenter::sharedData()->getUser()->getUserData(); m_coinLabel = (CLabel*)m_ui->getChildByTag(13); m_coinLabel->setString(ToString(user->getCoin())); m_moneyLabel = (CLabel*)m_ui->getChildByTag(14); m_moneyLabel->setString(ToString(user->getRoleGold())); // m_foodLabel = (CLabel*)m_ui->getChildByTag(17); //m_foodLabel->setString(ToString(user->getRoleFood())); m_foodLabel->setString(ToString(user->getFriends())); CLabel *action = (CLabel*)(m_ui->findWidgetById("action")); action->setString(CCString::createWithFormat("%d/%d",user->getRoleAction(),user->getActionLimit())->getCString()); CButton* add_food = (CButton*)m_ui->findWidgetById("btn_add_food"); CButton* add_copper = (CButton*)m_ui->findWidgetById("btn_add_copper"); CButton* add_soul = (CButton*)m_ui->findWidgetById("btn_add_soul"); CButton* add_gold = (CButton*)m_ui->findWidgetById("btn_add_gold"); CButton* add_friendship = (CButton*)m_ui->findWidgetById("btn_add_friendship"); add_food->getSelectedImage()->setScale(1.1f); add_copper->getSelectedImage()->setScale(1.1f); add_soul->getSelectedImage()->setScale(1.1f); add_gold->getSelectedImage()->setScale(1.1f); add_friendship->getSelectedImage()->setScale(1.1f); add_food->setOnClickListener(this, ccw_click_selector(CTopLayer::onAddResourceBtn)); add_copper->setOnClickListener(this, ccw_click_selector(CTopLayer::onAddResourceBtn)); add_soul->setOnClickListener(this, ccw_click_selector(CTopLayer::onAddResourceBtn)); add_gold->setOnClickListener(this, ccw_click_selector(CTopLayer::onAddResourceBtn)); add_friendship->setOnClickListener(this, ccw_click_selector(CTopLayer::onAddResourceBtn)); CSceneManager::sharedSceneManager()->addMsgObserver(UPDATE_HERO,this,GameMsghandler_selector(CTopLayer::updateRoleProperty)); //绑定场景隐藏和显示的消息 NOTIFICATION->addObserver(this, callfuncO_selector(CTopLayer::show), SHOW_TOP_LAYER, nullptr); NOTIFICATION->addObserver(this, callfuncO_selector(CTopLayer::hide), HIDE_TOP_LAYER, nullptr); CImageView *coin = (CImageView*)(m_ui->findWidgetById("coin")); CCAnimation *coinAnim = AnimationManager::sharedAction()->getAnimation("7033"); coinAnim->setDelayPerUnit(0.3f); coin->runAction(CCRepeatForever::create(CCAnimate::create(coinAnim))); CImageView *gold = (CImageView*)(m_ui->findWidgetById("gold")); CCAnimation *goldAnim = AnimationManager::sharedAction()->getAnimation("7034"); goldAnim->setDelayPerUnit(0.3f); gold->runAction(CCRepeatForever::create(CCAnimate::create(goldAnim))); }
void CTopLayer::updateRoleProperty(const TMessage& tMsg) { UserData *user = DataCenter::sharedData()->getUser()->getUserData(); CCScaleTo* sc1 = CCScaleTo::create(0.15f,1.3f); CCScaleTo* sc2 = CCScaleTo::create(0.35f,1.0f); CCSequence* sqes = CCSequence::create(sc1,sc2,nullptr); if (user->getCoin()!=atoi(m_coinLabel->getString())) { CProgressLabel *prolab = CProgressLabel::create(); prolab->setLabel(m_coinLabel); prolab->changeValueTo(user->getCoin(),0.5f); CCSequence* sqes1 = (CCSequence*)sqes->copy(); m_coinLabel->runAction(sqes1); this->addChild(prolab); CLabel *label = (CLabel*)m_ui->getChildByTag(130); int coin = user->getCoin()-atoi(m_coinLabel->getString()); changeLabel(label, coin); } if (user->getRoleGold()!=atoi(m_moneyLabel->getString())) { CProgressLabel *prolab = CProgressLabel::create(); prolab->setLabel(m_moneyLabel); prolab->changeValueTo(user->getRoleGold(),0.5f); CCSequence* sqes1 = (CCSequence*)sqes->copy(); m_moneyLabel->runAction(sqes1); this->addChild(prolab); CLabel *label = (CLabel*)m_ui->getChildByTag(140); int coin = user->getRoleGold()-atoi(m_moneyLabel->getString()); changeLabel(label, coin); } /* if (user->getRoleFood()!=atoi(m_foodLabel->getString())) { CProgressLabel *prolab = CProgressLabel::create(); prolab->setLabel(m_foodLabel); prolab->changeValueTo(user->getRoleFood(),0.5f); CCSequence* sqes1 = (CCSequence*)sqes->copy(); m_foodLabel->runAction(sqes1); this->addChild(prolab); CLabel *label = (CLabel*)m_ui->getChildByTag(170); int coin = user->getRoleFood()-atoi(m_foodLabel->getString()); changeLabel(label, coin); } */ if (user->getFriends()!=atoi(m_foodLabel->getString())) { CProgressLabel *prolab = CProgressLabel::create(); prolab->setLabel(m_foodLabel); prolab->changeValueTo(user->getFriends(),0.5f); CCSequence* sqes1 = (CCSequence*)sqes->copy(); m_foodLabel->runAction(sqes1); this->addChild(prolab); CLabel *label = (CLabel*)m_ui->getChildByTag(170); int coin = user->getFriends()-atoi(m_foodLabel->getString()); changeLabel(label, coin); } CLabel *action = (CLabel*)(m_ui->findWidgetById("action")); if (user->getRoleAction()!=atoi(action->getString())) { CCSequence* sqes2 = (CCSequence*)sqes->copy(); action->runAction(sqes2); action->setString(CCString::createWithFormat("%d/%d",user->getRoleAction(), user->getActionLimit())->getCString()); } }