Beispiel #1
0
//英雄显示位置
void BattleUI::CreateHeroEvent(int cfgId, int idx)
{

    auto layout_Bottom = m_RootWidget->getChildByName<Layout*>("Layout_Bottom");
    
    string btn_Name = StringUtils::format("Btn_Skill%d", idx);
    auto Btn_Hero = layout_Bottom->getChildByName<Button*>(btn_Name);
    Btn_Hero->setVisible(true);
    
    auto lbar_Name = StringUtils::format("LBar_State%d", idx);
    auto lbar_State = Btn_Hero->getChildByName<LoadingBar*>(lbar_Name);
    lbar_State->setPercent(100);
    
    CfgDataRow dataRow(cfgId);
    auto textName = StringUtils::format("Text_Name%d", idx);
    
    auto text_Name = Btn_Hero->getChildByName<Text*>(textName);
    
    auto skillId = dataRow.GetValue(CfgField::SkillID_V)->asValueVector().begin()->asInt();
    CfgDataRow skillDataRow(skillId);
    auto langId = skillDataRow.GetValue(CfgField::Name)->asInt();
    auto langText = MultiLanguage::getInstance()->GetText(langId);
    text_Name->setString(langText);
    
    auto attack_Speed = dataRow.GetValue(CfgField::Spd_F)->asFloat();
    attack_Speed = 10 / attack_Speed;
    
    Armature* armature = CreateHeroArmature(cfgId);
    
    string pbName = StringUtils::format("HeroSkillSchedule%d", idx);
    auto playName = skillDataRow.GetValue(CfgField::SkillAtksfxID_S)->asString();
    
    auto isGetKong = UserData::getInstance()->Check_VI_Fun(UserDataEnum::TalentList, Value((int)CfgIdEnum::TalentEliminateCD));
    auto progressBar = new ProgressBar();
    progressBar->SetScheduleName(pbName);
    progressBar->SetTotalTime(attack_Speed, isGetKong);
    progressBar->SetLoadingBar(lbar_State);
    
    m_VecProgressBar->push_back(progressBar);
    
    progressBar->SetCallBack([=]()
       {
           progressBar->Restart();
           if (armature->getAnimation()->getAnimationData()->getMovement(playName) == nullptr)
           {
               CCLOGERROR("Armature:%s, not %s", armature->getName().c_str(), playName.c_str());
           }else if(m_IsPlayAnim)
           {
               armature->setVisible(true);
               armature->getAnimation()->play(playName);
           }
           
           if (m_MonsterArmature != nullptr && m_IsPlayAnim)
           {
               m_MonsterArmature->getAnimation()->play(m_Beating);
           }
           
           auto attackResult = BattleData::getInstance()->HeroAttack(cfgId);
           if (attackResult == -1)
           {
               BattleFinish(true);

           }else if(attackResult > 0)
           {
               BufferEffect(attackResult);
           }

           if (!BattleData::getInstance()->m_HeroAutoAttack)
           {
               m_RootWidget->unschedule(pbName);
           }
       });
    
    Btn_Hero->addClickEventListener([this, progressBar, pbName](Ref* sender)
        {
            if(progressBar->GetRemainTime() == progressBar->GetTotalTime())
            {
                m_RootWidget->schedule([this, progressBar](float f)
                   {
                       progressBar->Update(f);
                       
                   }, pbName);
            }
        });
    
    m_RootWidget->schedule([this, progressBar](float f)
       {
           progressBar->Update(f);
           
       }, pbName);
    
    if (BattleData::getInstance()->m_HeroAutoAttack)
    {
        progressBar->Resume();
    }
    
    UIUtils::getInstance()->showProperImg(Btn_Hero, cfgId);
    
}