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 CSignLayer::ProcessMsg(int type, google::protobuf::Message *msg) { if(!isVisible()) { this->setVisible(true); //NOTIFICATION->postNotification(HIDE_MAIN_SCENE); m_pLineEffect->showEffect(); } if (type == SignDataMsg) { SignData *res = (SignData*)msg; m_signData.read(*res); m_gridView->setCountOfCell(m_signData.signList.size()); ReloadGridViewWithSameOffset(m_gridView); m_resignGold = m_signData.resign_gold; //更新阶段签到情况 updateTotoalSign(); //加黄标提示 showTipsOnNextTotalSign(); updateSignDays(); showCheckDayToCenter(); initHeroData(); } else if (type== SignReqMsg) { SignResponse *res = (SignResponse *)msg; CSignRes signRes; signRes.read(*res); switch (res->result()) { case 1: { if (m_bIsReSign)//补签要扣勾玉 { UserData *data = DataCenter::sharedData()->getUser()->getUserData(); data->setRoleGold(data->getRoleGold()-m_resignGold); CSceneManager::sharedSceneManager()->PostMessageA(UPDATE_HERO,0,nullptr,nullptr); } if (res->has_resigngold()) { m_resignGold = res->resigngold(); } //下一个未签的改为已签 int iIndex = autoNextSignStatusChange(); m_signData.resign-= m_bIsReSign; m_signData.sign+=1 ; //普通签到 if(!m_bIsReSign) { m_signData.bCanSign = false; } ReloadGridViewWithSameOffset(m_gridView); updateSignDays(); showCheckDayToCenter(); if(iIndex!=-1) { CSign& sign = m_signData.signList[iIndex]; if(DataCenter::sharedData()->getUser()->getUserData()->getVip()>=sign.vip && sign.vip>0) { sign.prize.num *= 2; } CPopItem *popItem = CPopItem::create(); popItem->signPrize(&sign.prize); popItem->setDescVisiable(true); LayerManager::instance()->push(popItem); //界面关闭后给回一个回调,用于处理阶段签的宝箱 int iIndexTotal = checkTotalBox(); if(iIndexTotal!=-1) { popItem->bindTargetCallBack(this, popitem_selector(CSignLayer::callBackForTotalSignEffect)); } } PlayEffectSound(SFX_407); } break; case 2: { //ShowPopTextTip(GETLANGSTR(240)); CShowToBuyResource* pShow = CShowToBuyResource::create(); pShow->showToBuyResourceByType(ShowBuyResourceAction); } break; case 3: ShowPopTextTip(GETLANGSTR(170)); break; default: break; } } }
void CSmeltArmor::proceesMessage(int type, google::protobuf::Message *msg) { this->setVisible(true); switch (type) { //洗练数据 case SmeltDataRequestMsg: { Armor *res = (Armor*)msg; if(res) { m_armor.armor.atkRange = res->atkrange(); m_armor.armor.hpRange = res->hprange(); m_armor.armor.defRange = res->defrange(); m_armor.armor.IntRange = res->dexrange(); m_armor.armor.hitRange = res->hitrange(); m_armor.armor.critRange = res->critrange(); m_armor.armor.renewRange = res->renewrange(); m_armor.armor.dodgeRange = res->dodgerange(); showSmeltDataToUI(); } }break; //洗练 case SmeltArmorMsg: { SmeltResponse *res = (SmeltResponse*)msg; //1 成功,2 金币不足,3 元宝不足,4 数据错误 if (res->reslut()==1) { //1 攻击addAtk,2 防御addDef,3 血量addHp,4 敏捷addDex,5 命中addHit,6 暴击addCrit,7 回复addRenew,8 闪避addDodge) m_armor.armor.addAtk = res->armor().armor().addatk(); m_armor.armor.addDef = res->armor().armor().adddef(); m_armor.armor.addHp = res->armor().armor().addhp(); m_armor.armor.addDex = res->armor().armor().adddex(); m_armor.armor.addHit = res->armor().armor().addhit(); m_armor.armor.addCrit = res->armor().armor().addcrit(); m_armor.armor.addRenew = res->armor().armor().addrenew(); m_armor.armor.addDodge = res->armor().armor().adddodge(); //更新金钱 UserData *data = DataCenter::sharedData()->getUser()->getUserData(); data->setCoin(data->getCoin() - m_coin); data->setRoleGold(data->getRoleGold() - m_diamond); CSceneManager::sharedSceneManager()->PostMessageA(UPDATE_HERO,0,nullptr,nullptr); CSceneManager::sharedSceneManager()->PostMessageA(UPDATE_ITEM_DATA, 2, nullptr, &m_armor); //播放效果 float fTime = showStrengthEffect(); this->runAction(CCSequence::createWithTwoActions(CCDelayTime::create(fTime), CCCallFunc::create(this, callfunc_selector(CSmeltArmor::showArmorAttr)))); } else if (res->reslut()==2) { //ShowPopTextTip(GETLANGSTR(205)); CShowToBuyResource* pShow = CShowToBuyResource::create(); pShow->showToBuyResourceByType(ShowBuyResourceCoin); } else if (res->reslut()==3) { //ShowPopTextTip(GETLANGSTR(203)); CShowToBuyResource* pShow = CShowToBuyResource::create(); pShow->showToBuyResourceByType(ShowBuyResourceGold); } else if (res->reslut()==4) { ShowPopTextTip(GETLANGSTR(170)); } }break; default: break; } }
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()); } }