#include "SparrowCardBase.h" #include "cocos2d.h" #include "ui/CocosGUI.h" #include "cocostudio/CocoStudio.h" SparrowCardBase* SparrowCardBase::s_pInstance = nullptr; bool SparrowCardBase::init() { if (!Node::init()) { return false; } m_pRootNode = static_cast(CSLoader::createNode("Games/Sparrow/SparrowCardNode.csb")); CC_ASSERT(m_pRootNode != nullptr); this->addChild(m_pRootNode); for (int i = 0; i < 4; i++) { m_HandCard[i] = (ImageView*)m_pRootNode->getChildByName(StringUtils::format("HandCard_%d", i)); CC_ASSERT(m_HandCard[i] != nullptr); m_OutCard[i] = (ImageView*)m_pRootNode->getChildByName(StringUtils::format("OutCard_%d", i)); CC_ASSERT(m_OutCard[i] != nullptr); } m_SelfShowCard = (ImageView*)m_pRootNode->getChildByName("SelfCard"); CC_ASSERT(m_SelfShowCard != nullptr); return true; } void SparrowCardBase::clear() { } // 场景退出回调 void SparrowCardBase::onExit() { Node::onExit(); } // 根据类型获取麻将牌 ImageView* SparrowCardBase::GetSparrowCard(EN_SPARROW_TYPE sptype) { ImageView* card = nullptr; // 站立牌 if (sptype >= SP_OPPSTAND && sptype <= SP_LSTAND) { card = (ImageView*)m_HandCard[sptype]->clone(); } // 丢弃牌 else if (sptype >= SP_O_OUT && sptype <= SP_L_OUT) { card = (ImageView*)m_OutCard[sptype - SP_O_OUT]->clone(); } else if (sptype == SP_SELF_SHOW) { card = (ImageView*)m_SelfShowCard->clone(); } else if (SP_ENDCARD == sptype) { card = (ImageView*)m_OutCard[0]->clone(); } if (card) { if ((SP_OPPSTAND != sptype) || (SP_RSTAND != sptype) || (SP_LSTAND != sptype)) { auto value = (ImageView*)card->getChildByName("value"); if (value) value->setVisible(false); } } return card; }