205 lines
5.9 KiB
C++
205 lines
5.9 KiB
C++
|
|
|
|||
|
|
#include "DZ_SmallCardSprite.h"
|
|||
|
|
#include "CardDefine.h"
|
|||
|
|
#include "cocostudio/CocoStudio.h"
|
|||
|
|
using namespace cocostudio;
|
|||
|
|
|
|||
|
|
///////////////////////////////////////////////////////////////////////////
|
|||
|
|
DZSmallCardSprite::DZSmallCardSprite() : m_pRootPanel(NULL),
|
|||
|
|
m_bCardShoot(false), m_bCardSelect(false), m_bSelectEnabled(true), m_bMustShoot(false), m_cbCardData(0)
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
DZSmallCardSprite:: ~DZSmallCardSprite()
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
DZSmallCardSprite* DZSmallCardSprite::create(uint8 cbCardData)
|
|||
|
|
{
|
|||
|
|
DZSmallCardSprite *pRet = new DZSmallCardSprite();
|
|||
|
|
if (pRet && pRet->init(cbCardData))
|
|||
|
|
{
|
|||
|
|
pRet->autorelease();
|
|||
|
|
return pRet;
|
|||
|
|
}
|
|||
|
|
CC_SAFE_DELETE(pRet);
|
|||
|
|
return NULL;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
bool DZSmallCardSprite::init(uint8 cbCardData)
|
|||
|
|
{
|
|||
|
|
if (!LayerColor::init())
|
|||
|
|
{
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
|||
|
|
m_pRootPanel = CSLoader::createNode("Games/DaZha/SmallCardSprite.csb");
|
|||
|
|
CC_ASSERT(m_pRootPanel!=nullptr);
|
|||
|
|
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);
|
|||
|
|
|
|||
|
|
SpriteFrameCache* pSpriteFrameCache = SpriteFrameCache::getInstance();
|
|||
|
|
pSpriteFrameCache->addSpriteFramesWithFile("Games/DaZha/Table/PinCard.plist");
|
|||
|
|
|
|||
|
|
updateUIData(cbCardData);
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DZSmallCardSprite::updateUIData(uint8 cbCardData)
|
|||
|
|
{
|
|||
|
|
SpriteFrameCache* pSpriteFrameCache = SpriteFrameCache::getInstance();
|
|||
|
|
|
|||
|
|
m_cbCardData = cbCardData;
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ʊ<EFBFBD>;
|
|||
|
|
if (cbCardData == 0)
|
|||
|
|
{
|
|||
|
|
_imgCardNum->setVisible(false);
|
|||
|
|
_imgCardColor->setVisible(false);
|
|||
|
|
_imgCardMark->setVisible(false);
|
|||
|
|
|
|||
|
|
_imgCardBack->setSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("sCardBack.png"));
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
_imgCardNum->setVisible(true);
|
|||
|
|
_imgCardColor->setVisible(true);
|
|||
|
|
_imgCardMark->setVisible(true);
|
|||
|
|
|
|||
|
|
int nCardColor = m_ClientLogic.GetCardColor(cbCardData);
|
|||
|
|
int nCardValue = m_ClientLogic.GetCardValue(cbCardData);
|
|||
|
|
_imgCardBack->setSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("sCardFront.png"));
|
|||
|
|
|
|||
|
|
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) //÷<EFBFBD><EFBFBD><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 DZSmallCardSprite::onEnter()
|
|||
|
|
{
|
|||
|
|
LayerColor::onEnter();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DZSmallCardSprite::onExit()
|
|||
|
|
{
|
|||
|
|
LayerColor::onExit();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DZSmallCardSprite::onEnterTransitionDidFinish()
|
|||
|
|
{
|
|||
|
|
LayerColor::onEnterTransitionDidFinish();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>;
|
|||
|
|
void DZSmallCardSprite::shootCard()
|
|||
|
|
{
|
|||
|
|
toNormal();
|
|||
|
|
|
|||
|
|
m_bCardShoot = true;
|
|||
|
|
this->runAction(MoveBy::create(0.1f, Vec2(0, 20)));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>;
|
|||
|
|
void DZSmallCardSprite::downCard()
|
|||
|
|
{
|
|||
|
|
toNormal();
|
|||
|
|
|
|||
|
|
m_bCardShoot = false;
|
|||
|
|
this->runAction(MoveBy::create(0.1f, Vec2(0, -20)));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>;
|
|||
|
|
void DZSmallCardSprite::toGray()
|
|||
|
|
{
|
|||
|
|
m_bCardSelect = true;
|
|||
|
|
m_pRootPanel->setColor(Color3B(126, 126, 126));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>;
|
|||
|
|
void DZSmallCardSprite::toNormal()
|
|||
|
|
{
|
|||
|
|
m_bCardSelect = false;
|
|||
|
|
m_pRootPanel->setColor(Color3B(255, 255, 255));
|
|||
|
|
}
|