Files
wnmj-normal/Classes/Games/WNMJ/WN_CNotifyDlg.cpp
2026-03-03 13:56:44 +08:00

302 lines
7.7 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "WN_CNotifyDlg.h"
#include "cocos2d.h"
#include "ui/CocosGUI.h"
#include "cocostudio/CocoStudio.h"
#include "YSAudioEngine.h"
#include "PopScene.h"
using namespace WNMJ_SPACE;
WN_NotifyDlg::WN_NotifyDlg()
{
zeromemory(m_pGangCardItem, sizeof(m_pGangCardItem));
}
WN_NotifyDlg::~WN_NotifyDlg()
{
}
bool WN_NotifyDlg::init()
{
if (!Node::init()) {
return false;
}
// 主界面
auto rool = CSLoader::createNode("Games/WNMJ/NoticeLayer.csb");
this->addChild(rool);
m_pNoticelayer = (Layout*)rool->getChildByName("Panel_bg");
ASSERT(m_pNoticelayer != nullptr);
m_btnGuo = (Button*)m_pNoticelayer->getChildByName("btnGuo");
m_btnGuo->addClickEventListener(CC_CALLBACK_1(WN_NotifyDlg::onEventGuo, this));
m_btnGuo->setVisible(false);
m_btnHu = (Button*)m_pNoticelayer->getChildByName("btnHu");
m_btnHu->addClickEventListener(CC_CALLBACK_1(WN_NotifyDlg::onEventHu, this));
m_btnHu->setVisible(false);
m_btnPeng = (Button*)m_pNoticelayer->getChildByName("btnPeng");
m_btnPeng->addClickEventListener(CC_CALLBACK_1(WN_NotifyDlg::onEventPeng, this));
m_btnPeng->setVisible(false);
m_btnGang = (Button*)m_pNoticelayer->getChildByName("btnGang");
m_btnGang->addClickEventListener(CC_CALLBACK_1(WN_NotifyDlg::onEventGang, this));
m_btnGang->setVisible(false);
return true;
}
void WN_NotifyDlg::onEnter()
{
Node::onEnter();
}
void WN_NotifyDlg::onEnterTransitionDidFinish()
{
Node::onEnterTransitionDidFinish();
}
void WN_NotifyDlg::onExit()
{
Node::onExit();
}
void WN_NotifyDlg::onEventHu(cocos2d::Ref *pSender) // 选择操作
{
YSAudioEngine::Instance().playBtnClickEffect();
if (pSender == nullptr) return;
if ((m_OperateNotify.dwActionMask&WIK_WN_CHI_HU) != 0)
{
CMD_C_OperateCard OperateCard;
OperateCard.dwOperateCode = WIK_WN_CHI_HU;
OperateCard.cbOperateCard = m_OperateNotify.cbActionCard;
EventCustom event(CUSTOM_EVENT_OPER_CARD);
event.setUserData(&OperateCard);
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
}
// 操作完毕后隐藏高级操作界面并重置m_wCurrentUser
CCLOG("WN_NotifyDlg click btnHu hide...");
this->setVisible(false);
}
void WN_NotifyDlg::onEventPeng(cocos2d::Ref *pSender) // 选择操作
{
YSAudioEngine::Instance().playBtnClickEffect();
if (pSender == nullptr) return;
if ((m_OperateNotify.dwActionMask&WIK_WN_PENG) != 0)
{
CMD_C_OperateCard OperateCard;
OperateCard.dwOperateCode = WIK_WN_PENG;
OperateCard.cbOperateCard = m_OperateNotify.cbActionCard;
EventCustom event(CUSTOM_EVENT_OPER_CARD);
event.setUserData(&OperateCard);
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
}
// 操作完毕后,隐藏高级操作界面
CCLOG("WN_NotifyDlg click btnPeng hide...");
this->setVisible(false);
}
// 杠
void WN_NotifyDlg::onEventGang(cocos2d::Ref *pSender) // 选择操作
{
YSAudioEngine::Instance().playBtnClickEffect();
if (pSender == nullptr) return;
// 牌数量
uint8 cbCardCount = m_OperateNotify.GangPaiResult.cbCardCount;
CMD_C_OperateCard OperateCard;
zeromemory(&OperateCard, sizeof(OperateCard));
OperateCard.dwOperateCode = WIK_WN_GANG;
// 只有一个杠牌;
if (cbCardCount == 1)
{
//牌数据
uint8 cbCardData = m_OperateNotify.GangPaiResult.cbCardData[cbCardCount - 1];
OperateCard.cbOperateCard = cbCardData;
EventCustom event(CUSTOM_EVENT_OPER_CARD);
event.setUserData(&OperateCard);
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
cocos2d::log("dwOperateCode = 0x%0x, cbOperateCard = 0x%0x", WIK_WN_GANG, cbCardData);
CCLOG("WN_NotifyDlg click one btnGang hide...");
this->setVisible(false);
}
else if (cbCardCount > 1)
{
m_btnGang->setVisible(false);
// 显示可以杠的牌,让玩家自己选择;
for (int i = 0; i < cbCardCount; i++)
{
uint8 cbCardValue = m_OperateNotify.GangPaiResult.cbCardData[i];
if (WN_CGameLogic::IsValidCard(cbCardValue))
{
m_pGangCardItem[i] = WN_SparrowCard::createWithDirection(cbCardValue, SP_SELFSTAND);
if (m_pGangCardItem[i] != nullptr)
{
m_pGangCardItem[i]->setPosition(Vec2(m_btnGang->getPositionX() - (NCMJ_SELF_HAND_CARD_WIDHT + 25)*i, 10));
m_pNoticelayer->addChild(m_pGangCardItem[i]);
// 增加点击事件;
m_pGangCardItem[i]->addClickEventListener([cbCardValue, this](cocos2d::Ref *, Vec2 pos)->bool{
CMD_C_OperateCard OperateCard;
OperateCard.dwOperateCode = WIK_WN_GANG;
OperateCard.cbOperateCard = cbCardValue;
EventCustom event(CUSTOM_EVENT_OPER_CARD);
event.setUserData(&OperateCard);
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
// 操作完毕后隐藏高级操作界面并重置m_wCurrentUser
CCLOG("WN_NotifyDlg click move btnGang hide...");
this->setVisible(false);
m_wCurrentUser = INVALID_CHAIR;
return true;
});
}
}
}
}
}
void WN_NotifyDlg::onEventGuo(cocos2d::Ref *pSender) // 选择操作
{
YSAudioEngine::Instance().playBtnClickEffect();
if (m_OperateNotify.dwActionMask != WIK_WN_NULL)
{
// 当前玩家为自己,直接隐藏操作界面,等待玩家出牌
if (m_wCurrentUser == SELF_VIEW_CHAIRID)
{
CCLOG("WN_NotifyDlg click btnGuo hide...m_wCurrentUser = 0x%0x", m_wCurrentUser);
this->setVisible(false);
return;
}
// 放弃胡牌;
if ((m_OperateNotify.dwActionMask&WIK_WN_CHI_HU) != 0)
{
PopScene::Instance().show(utility::a_u8("你确定要放弃胡牌吗?"), [=](){
CMD_C_OperateCard OperateCard;
OperateCard.dwOperateCode = WIK_WN_NULL;
OperateCard.cbOperateCard = m_OperateNotify.cbActionCard;
EventCustom event(CUSTOM_EVENT_OPER_CARD);
event.setUserData(&OperateCard);
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
// 操作完毕后隐藏高级操作界面并重置m_wCurrentUser
CCLOG("WN_NotifyDlg click btnGuo hide...");
this->setVisible(false);
}, [=](){
// 这里什么都不用做,但是必须有,控制界面显示取消按钮;
});
}
// 放弃碰,杠,吃
else
{
CMD_C_OperateCard OperateCard;
OperateCard.dwOperateCode = WIK_WN_NULL;
OperateCard.cbOperateCard = m_OperateNotify.cbActionCard;
EventCustom event(CUSTOM_EVENT_OPER_CARD);
event.setUserData(&OperateCard);
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
// 操作完毕后隐藏高级操作界面并重置m_wCurrentUser
CCLOG("WN_NotifyDlg click btnGuo hide...");
this->setVisible(false);
}
}
else
{
// 操作完毕后隐藏高级操作界面并重置m_wCurrentUser
CCLOG("WN_NotifyDlg click btnGuo hide...");
this->setVisible(false);
}
}
// 设置高级操作界面
void WN_NotifyDlg::SetNoticeData(CMD_S_OperateNotify * pOperateNotify)
{
if (m_pNoticelayer)
{
// 判断操作类型
memcpy(&m_OperateNotify, pOperateNotify, sizeof(m_OperateNotify));
WORD dwActionMask = pOperateNotify->dwActionMask;
//按钮控制
m_btnPeng->setVisible((dwActionMask&WIK_WN_PENG) != 0 ? true : false);
m_btnGang->setVisible((dwActionMask&WIK_WN_GANG) != 0 ? true : false);
m_btnHu->setVisible((dwActionMask&WIK_WN_CHI_HU) != 0 ? true : false);
m_btnGuo->setVisible((dwActionMask != WIK_WN_NULL) ? true : false);
// 删除杠节点;
for (int i = 0; i < MAX_WEAVE; i++)
{
if (m_pGangCardItem[i] != nullptr)
{
m_pGangCardItem[i]->removeFromParent();
m_pGangCardItem[i] = nullptr;
}
}
CCLOG("WN_NotifyDlg show...");
this->setVisible(true);
}
}
// 隐藏提示界面
void WN_NotifyDlg::HideNotifyDlg(bool isTimeOver/* = false*/)
{
if (m_pNoticelayer)
{
// 判断操作类型
memset(&m_OperateNotify, 0x0, sizeof(m_OperateNotify));
//按钮控制
m_btnPeng->setVisible(false);
m_btnGang->setVisible(false);
m_btnHu->setVisible(false);
m_btnGuo->setVisible(false);
}
// 删除杠节点;
for (int i = 0; i < MAX_WEAVE; i++)
{
if (m_pGangCardItem[i] != nullptr)
{
m_pGangCardItem[i]->removeFromParent();
m_pGangCardItem[i] = nullptr;
}
}
CCLOG("WN_NotifyDlg hide...");
this->setVisible(false);
}