96 lines
1.7 KiB
C++
96 lines
1.7 KiB
C++
#include "RadioCtrl.h"
|
|
#include "MissionWeiXin.h"
|
|
#include "SimpleAudioEngine.h"
|
|
#include "UserInfo.h"
|
|
#include "YSAudioEngine.h"
|
|
|
|
RadioGroup::RadioGroup()
|
|
{
|
|
m_list.clear();
|
|
m_isRadioMode = false;
|
|
m_isAudio = false;
|
|
}
|
|
|
|
RadioGroup::~RadioGroup()
|
|
{
|
|
m_list.clear();
|
|
}
|
|
|
|
void RadioGroup::setRadioMode(bool isMust)
|
|
{
|
|
m_isRadioMode = isMust;
|
|
}
|
|
|
|
void RadioGroup::AddCheckBox(CheckBox* ref)
|
|
{
|
|
if (ref)
|
|
{
|
|
m_list.pushBack(ref);
|
|
|
|
ref->addEventListener(CC_CALLBACK_2(RadioGroup::onClickCheckBox, this));
|
|
}
|
|
}
|
|
|
|
void RadioGroup::setDelauftSelect(cocos2d::Ref* widget)
|
|
{
|
|
onClickCheckBox(widget, CheckBox::EventType::SELECTED);
|
|
}
|
|
|
|
void RadioGroup::setDelauftSelect(int index)
|
|
{
|
|
onClickCheckBox(m_list.at(index), CheckBox::EventType::SELECTED);
|
|
}
|
|
|
|
void RadioGroup::setDelauftSelect(int index, bool isMust)
|
|
{
|
|
m_isRadioMode = isMust;
|
|
onClickCheckBox(m_list.at(index), CheckBox::EventType::SELECTED);
|
|
}
|
|
|
|
void RadioGroup::onClickCheckBox(cocos2d::Ref* widget, CheckBox::EventType type)
|
|
{
|
|
if (m_isAudio) // µÚÒ»´Î²»²¥·Å
|
|
{
|
|
YSAudioEngine::Instance().playBtnClickEffect();
|
|
}
|
|
else
|
|
{
|
|
m_isAudio = true;
|
|
}
|
|
|
|
if (widget == nullptr) return;
|
|
|
|
CheckBox* pcheckbox = (CheckBox*)widget;
|
|
|
|
if (type == CheckBox::EventType::SELECTED)
|
|
{
|
|
//CheckBox* p = m_list.at(0);
|
|
pcheckbox->setEnabled(!m_isRadioMode);
|
|
|
|
for (Vector<CheckBox*>::const_iterator it = m_list.begin(); it != m_list.end(); ++it)
|
|
{
|
|
CheckBox* chb = *it;
|
|
|
|
if (chb && chb != pcheckbox)
|
|
{
|
|
chb->setSelected(false);
|
|
chb->setEnabled(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
cocos2d::Ref* RadioGroup::getCurrentSelect()
|
|
{
|
|
for (Vector<CheckBox*>::const_iterator it = m_list.begin(); it != m_list.end(); ++it)
|
|
{
|
|
CheckBox* chb = *it;
|
|
|
|
if (chb && chb->isSelected())
|
|
{
|
|
return chb;
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
} |