Files
wnmj-normal/Classes/Games/DDZ/DDZ_SmallCardSprite.cpp

196 lines
6.3 KiB
C++
Raw Normal View History

2026-03-03 13:56:44 +08:00
#include "DDZ_SmallCardSprite.h"
#include "CardDefine.h"
#include "cocostudio/CocoStudio.h"
using namespace cocostudio;
///////////////////////////////////////////////////////////////////////////
DDZSmallCardSprite::DDZSmallCardSprite() : m_pRootPanel(NULL)
{
}
DDZSmallCardSprite:: ~DDZSmallCardSprite()
{
}
DDZSmallCardSprite* DDZSmallCardSprite::create(uint8 cbCardData)
{
DDZSmallCardSprite *pRet = new DDZSmallCardSprite();
if (pRet && pRet->init(cbCardData))
{
pRet->autorelease();
return pRet;
}
CC_SAFE_DELETE(pRet);
return NULL;
}
bool DDZSmallCardSprite::init(uint8 cbCardData)
{
if (!Node::init())
{
return false;
}
//m_ClientLogic.SetLaiZi(nLaiZiCard);
//<2F><><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_pRootPanel = CSLoader::createNode("Games/DDZ/SmallCardSprite.csb");
this->addChild(m_pRootPanel);
this->ignoreAnchorPointForPosition(false);
this->setAnchorPoint(Vec2::ZERO);
this->setContentSize(m_pRootPanel->getContentSize());
//<2F>󶨽<EFBFBD><F3B6A8BD><EFBFBD>Ԫ<EFBFBD><D4AA>
_imgCardBack = static_cast<Sprite*>(m_pRootPanel->getChildByName("imgCardBack"));
CC_ASSERT(_imgCardBack != nullptr);
//<2F><>ֵ
_imgCardNum = static_cast<Sprite*>(m_pRootPanel->getChildByName("imgCardNum"));
CC_ASSERT(_imgCardNum != nullptr);
//<2F><>ɫ
_imgCardColor = static_cast<Sprite*>(m_pRootPanel->getChildByName("imgCardColor"));
CC_ASSERT(_imgCardColor != nullptr);
_imgCardMark = static_cast<Sprite*>(m_pRootPanel->getChildByName("imgCardMark"));
CC_ASSERT(_imgCardMark != nullptr);
//<2F>DZ<EFBFBD>
_imgCardCorner = static_cast<Sprite*>(m_pRootPanel->getChildByName("imgCardCorner"));
CC_ASSERT(_imgCardCorner != nullptr);
SpriteFrameCache* pSpriteFrameCache = SpriteFrameCache::getInstance();
pSpriteFrameCache->addSpriteFramesWithFile("Games/DDZ/Table/PinCard.plist");
updateUIData(cbCardData);
return true;
}
void DDZSmallCardSprite::updateUIData(uint8 cbCardData)
{
SpriteFrameCache* pSpriteFrameCache = SpriteFrameCache::getInstance();
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ʊ<EFBFBD>
if (cbCardData == 0)
{
_imgCardNum->setVisible(false);
_imgCardColor->setVisible(false);
_imgCardMark->setVisible(false);
_imgCardCorner->setVisible(false);
_imgCardBack->setSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("sCardBack.png"));
}
else
{
_imgCardNum->setVisible(true);
_imgCardColor->setVisible(true);
_imgCardMark->setVisible(true);
_imgCardCorner->setVisible(false);
int nCardColor = m_ClientLogic.GetCardColor(cbCardData);
int nCardValue = m_ClientLogic.GetCardValue(cbCardData);
_imgCardBack->setSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("sCardFront.png"));
//if (m_ClientLogic.IsLaiZiCard(cbCardData))
//{
// if (nCardColor == CCLR_DIAMONDS || nCardColor == CCLR_HEART) //<2F><><EFBFBD><EFBFBD><E9A1A2><EFBFBD><EFBFBD>
// {
// _imgCardNum->setSpriteFrame(pSpriteFrameCache->getSpriteFrameByName(StringUtils::format("sCardNum1%d.png", nCardValue)));
// }
// else if (nCardColor == CCLR_PLUM || nCardColor == CCLR_SPADE) //÷<><C3B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// {
// _imgCardNum->setSpriteFrame(pSpriteFrameCache->getSpriteFrameByName(StringUtils::format("sCardNum2%d.png", nCardValue)));
// }
// else
// {
// //<2F><><EFBFBD><EFBFBD>
// _imgCardNum->setSpriteFrame(pSpriteFrameCache->getSpriteFrameByName(StringUtils::format("sCardNum1%d.png", nCardValue)));
// }
// _imgCardColor->setSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("sCardColor4.png"));
// _imgCardMark->setSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("bCardColor14.png"));
//}
//else
{
if (nCardColor == CCLR_DIAMONDS || nCardColor == CCLR_HEART) //<2F><><EFBFBD><EFBFBD><E9A1A2><EFBFBD><EFBFBD>
{
SpriteFrame* pCardNumSpriteFrame = pSpriteFrameCache->getSpriteFrameByName(StringUtils::format("sCardNum1%d.png", nCardValue));
CC_ASSERT(pCardNumSpriteFrame!=nullptr);
_imgCardNum->setSpriteFrame(pCardNumSpriteFrame);
if (nCardColor == CCLR_DIAMONDS)//<2F><><EFBFBD><EFBFBD>
{
_imgCardColor->setSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("sCardColor0.png"));
_imgCardMark->setSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("bCardColor10.png"));
}
else //<2F><><EFBFBD><EFBFBD>
{
_imgCardColor->setSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("sCardColor2.png"));
_imgCardMark->setSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("bCardColor12.png"));
}
//if (nCardValue >= CVAL_J && nCardValue <= CVAL_K)
//{
// SpriteFrame* pCardColorSpriteFrame = pSpriteFrameCache->getSpriteFrameByName(StringUtils::format("sCardColor1%d.png", nCardValue - 6));
// CC_ASSERT(pCardColorSpriteFrame != nullptr);
// _imgCardMark->setSpriteFrame(pCardColorSpriteFrame);
//}
}
else if (nCardColor == CCLR_PLUM || nCardColor == CCLR_SPADE) //÷<><C3B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
SpriteFrame* pCardNumSpriteFrame = pSpriteFrameCache->getSpriteFrameByName(StringUtils::format("sCardNum2%d.png", nCardValue));
CC_ASSERT(pCardNumSpriteFrame != nullptr);
_imgCardNum->setSpriteFrame(pCardNumSpriteFrame);
if (nCardColor == CCLR_PLUM) //÷<><C3B7>
{
_imgCardColor->setSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("sCardColor1.png"));
_imgCardMark->setSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("bCardColor11.png"));
}
else //<2F><><EFBFBD><EFBFBD>
{
_imgCardColor->setSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("sCardColor3.png"));
_imgCardMark->setSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("bCardColor13.png"));
}
//if (nCardValue >= CVAL_J && nCardValue <= CVAL_K)
//{
// SpriteFrame* pCardColorSpriteFrame = pSpriteFrameCache->getSpriteFrameByName(StringUtils::format("sCardColor2%d.png", nCardValue - 6));
// CC_ASSERT(pCardColorSpriteFrame != nullptr);
// _imgCardMark->setSpriteFrame(pCardColorSpriteFrame);
//}
}
else if (nCardColor == CCLR_JOKER) //<2F><><EFBFBD><EFBFBD>
{
_imgCardColor->setVisible(false);
if (nCardValue == CVAL_LITTLE_JOKER)
{
_imgCardNum->setSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("sCardNum214.png"));
_imgCardMark->setSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("sCardColor28.png"));
}
else if (nCardValue == CVAL_BIG_JOKER)
{
_imgCardNum->setSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("sCardNum114.png"));
_imgCardMark->setSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("sCardColor18.png"));
}
}
}
}
}
void DDZSmallCardSprite::onEnter()
{
Node::onEnter();
}
void DDZSmallCardSprite::onExit()
{
Node::onExit();
}
void DDZSmallCardSprite::onEnterTransitionDidFinish()
{
Node::onEnterTransitionDidFinish();
}