//
//  LandLordsMakeNewRoom.hpp
//  MalaGame39
//
//  Created by work on 2016/12/19.
//
//
 
#ifndef LandLordsMakeNewRoom_hpp
#define LandLordsMakeNewRoom_hpp
 
#include <stdio.h>
#include <cocos2d.h>
#include "ui/cocosGUI.h"
#include <cocostudio/CocoStudio.h>
using namespace cocos2d::ui;
 
class LandLordsMakeNewRoom : public cocos2d::Layer
{
private:
    cocos2d::Node* m_rootNode;
    Button* m_return;
//    long long m_ruleNum;
    RadioButton* m_boomButton[];
    RadioButton* m_numberButton[];
    int m_ruleNum[] = {,,,,,};
public:
    bool init();
    void onEnter();
    void onExit();
    void buttonReturnCallback(Ref *senderz, cocos2d::extension::Control::EventType controlEvent);
//    void onChangedRadioButtonOneSelect(RadioButton* radioButton, RadioButton::EventType type);
//    void onChangedRadioButtonTwoSelect(RadioButton* radioButton, RadioButton::EventType type);
//    void onChangedRadioButtonThreeSelect(RadioButton* radioButton, RadioButton::EventType type);
//    void onChangedRadioButtonFourSelect(RadioButton* radioButton, RadioButton::EventType type);
    void buttonMakeNewRoomCallback(Ref *senderz, cocos2d::extension::Control::EventType controlEvent);
    void onChangedRadioButtonBoomBgSelect(RadioButton* radioButton, RadioButton::EventType type);
    void onChangedRadioButtonChooseBgSelect(RadioButton* radioButton, RadioButton::EventType type);
    void setLayerData(GameRuleData& rule);
    void checkBoxCallback(CheckBox* sender,CheckBoxEventType type);
    CREATE_FUNC(LandLordsMakeNewRoom);
};
 
 
#endif /* LandLordsMakeNewRoom_hpp */
 
 
 //
//  LandLordsMakeNewRoom.cpp
//  MalaGame39
//
//  Created by work on 2016/12/19.
//
//
 
#include "LandLordsMakeNewRoom.hpp"
#include "cocos-ext.h"
#include <stdio.h>
USING_NS_CC;
using namespace cocos2d::ui;
using namespace cocos2d::extension;
bool LandLordsMakeNewRoom::init()
{
    if (!Layer::init()) {
        return false;
    }
    
    Sprite* bg = Sprite::create("LandLord/LandLordsmake_room_bg.png");//背景图片
    bg->setPosition(Vec2(,));
    this->addChild(bg);
    
    
    auto Relieve=cocos2d::ui::Scale9Sprite::createWithSpriteFrameName("friend_fight_x.png");
    auto m_buttonRelieve = ControlButton::create(Relieve);
    m_buttonRelieve->setPosition( 991.5,644.8);
    m_buttonRelieve->addTargetWithActionForControlEvents(this, cccontrol_selector(LandLordsMakeNewRoom::buttonReturnCallback), Control::EventType::TOUCH_UP_INSIDE);//按钮点击事件
    this->addChild(m_buttonRelieve);
    
    
    auto share=cocos2d::ui::Scale9Sprite::createWithSpriteFrameName("make_btn.png");
    auto m_buttonShare = ControlButton::create(share);
    m_buttonShare->setPosition( ,);
    m_buttonShare->addTargetWithActionForControlEvents(this, cccontrol_selector(LandLordsMakeNewRoom::buttonMakeNewRoomCallback), Control::EventType::TOUCH_UP_INSIDE);
    this->addChild(m_buttonShare);
 
    
    CheckBox* checkBox[] = {nullptr};
    for (int i=;i<;i++){
        //for循环创建4个复选按钮
        checkBox[i] = CheckBox::create("LandLord/make_room_unselected.png",//未选中时的显示图片
                                       "LandLord/make_room_unselected.png",//点击checkBox后触摸没有松开时的图片
                                       "LandLord/make_room_select.png",//选中时的显示图片
                                       "LandLord/make_room_select.png",//从选中到未选中切换过程中,触摸没有松开时的显示图片
                                       "LandLord/make_room_select.png");
        
         checkBox[i]->::LandLordsMakeNewRoom::setPosition(,-(i*));
         checkBox[i]->setTag(i+);
         checkBox[i]->addEventListenerCheckBox(this ,checkboxselectedeventselector(LandLordsMakeNewRoom::checkBoxCallback));
         this->addChild(checkBox[i]);
        
    }
    
    
 
    for (int i = ; i<; i++) {//单选(按钮)
        m_boomButton[i] = RadioButton::create("make_room_unselected.png", "make_room_select.png", Widget::TextureResType::PLIST);
        m_boomButton[i]->setPosition(Vec2(+(*i), ));
        m_boomButton[i]->setTag(i+);
        m_boomButton[i]->addEventListener(CC_CALLBACK_2(LandLordsMakeNewRoom::onChangedRadioButtonBoomBgSelect,this));
        this->addChild(m_boomButton[i]);
    }
 
    
    
    int number[] = {,,};//局数单选
    for (int i = ; i<; i++) {
        m_numberButton[i] = RadioButton::create("make_room_unselected.png", "make_room_select.png", Widget::TextureResType::PLIST);
        m_numberButton[i]->setPosition(Vec2(+*i+, ));
        m_numberButton[i]->setTag(i+);
        m_numberButton[i]->addEventListener(CC_CALLBACK_2(::LandLordsMakeNewRoom::onChangedRadioButtonChooseBgSelect,this));
        this->addChild(m_numberButton[i]);
        auto label = Label::createWithSystemFont(StringUtils::format("%d局(房卡x%d)",number[i],i+), "", );
        label->setColor(Color3B::YELLOW);
        label->setPosition(Vec2(+*i+, ));
        this->addChild(label);
    }
    
    m_boomButton[]->setSelected(true);//默认第一个单选按钮为选中
    m_numberButton[]->setSelected(true);
    
    PublicMethod::addLayerTouchShield(this);
 
    return true;
}
void LandLordsMakeNewRoom::onEnter()
{
    Layer::onEnter();
}
void LandLordsMakeNewRoom::onExit()
{
    Layer::onExit();
}
 
void LandLordsMakeNewRoom::onChangedRadioButtonBoomBgSelect(RadioButton* radioButton, RadioButton::EventType type)
{
    
    if (radioButton == nullptr) {
        return;
    }
    
    int tag = ((RadioButton*)radioButton)->getTag();//获取按钮当前的tag值
    
    for (int i=; i<; i++) {//for循环实现单选
        m_boomButton[i]->setSelected(false);//先让全部按钮设为处于未选中状态
        if (i+==tag) {//通过tag值进入判断
            m_boomButton[i]->setSelected(true);//让当前按钮为选中
            m_ruleNum[]=tag-;
        }
    }
    
}
void LandLordsMakeNewRoom::onChangedRadioButtonChooseBgSelect(RadioButton* radioButton, RadioButton::EventType type)
{
    if (radioButton == nullptr) {
        return;
    }
    
    int tag = ((RadioButton*)radioButton)->getTag();
    
    for (int i=; i<; i++) {
        m_numberButton[i]->setSelected(false);
        if (i+==tag) {
            m_numberButton[i]->setSelected(true);
            m_ruleNum[]=tag-;
        }
    }
} //复选按钮的实现方法
void LandLordsMakeNewRoom::checkBoxCallback(CheckBox* sender,CheckBoxEventType type)
{
    int tag = sender->getTag();//同样需要拿到当前checkBox的tag值
    if(type==CHECKBOX_STATE_EVENT_SELECTED){//判断check的状态(选中状态)
        CCLOG("sender:%d",tag);
        m_ruleNum[tag-]=;
//在这里可做其他操作
    }
    else if(type==CHECKBOX_STATE_EVENT_UNSELECTED)//为未选中状态
    {
        m_ruleNum[tag-]=;
    }
 
}
void LandLordsMakeNewRoom::buttonReturnCallback(Ref *senderz, Control::EventType controlEvent)
{
        removeFromParent();//移除当前图层
    
}

cocos2dx 3.x (单选,多选,复选checkBox按钮的实现) RadioButton的更多相关文章

  1. [原创]纯JS实现网页中多选复选框checkbox和单选radio的美化效果

    图片素材: 最终效果图: <html><title> 纯JS实现网页中多选复选框checkbox和单选radio的美化效果</title><head>& ...

  2. CSS学习笔记三:自定义单选框,复选框,开关

    一点一点学习CCS,这次学习了如何自定义单选框,复选框以及开关. 一.单选框 1.先写好body里面的样式,先写几个框 <body> <div class="radio-1 ...

  3. 自动化测试-15.selenium单选框与复选框状态判断

    本篇主要介绍单选框和复选框的操作 一.认识单选框和复选框 1.先认清楚单选框和复选框长什么样 2.各位小伙伴看清楚哦,上面的单选框是圆的:下图复选框是方的,这个是业界的标准,要是开发小伙伴把图标弄错了 ...

  4. 2.12 单选框和复选框(radiobox、checkbox)

    2.12 单选框和复选框(radiobox.checkbox) 本篇主要介绍单选框和复选框的操作一.认识单选框和复选框    1.先认清楚单选框和复选框长什么样 2.各位小伙伴看清楚哦,上面的单选框是 ...

  5. Selenium2学习(十五)-- 单选框和复选框(radiobox、checkbox)

    本篇主要介绍单选框和复选框的操作 一.认识单选框和复选框 1.先认清楚单选框和复选框长什么样 2.各位小伙伴看清楚哦,上面的单选框是圆的:下图复选框是方的,这个是业界的标准,要是开发小伙伴把图标弄错了 ...

  6. 微信小程序-修改单选框和复选框大小的方法

    方法有两种: 一:采用css的zoom属性 zoom缩放会将元素保持在左上角,并且会有毛边,可能会稍稍改变元素原来的形状. 二:采用css3的transform:scale属性 zoom缩放会将元素保 ...

  7. iOS开发-UITableView单选多选/复选实现1

    TableView怎样实现单选或者多选呢? 我们的直接思路是改动某一个Cell的样式就可以, 那么改动样式须要通过改动相应的数据, 从这里能够判断我们须要给Cell相应的数据设置一个标志位, 当选中的 ...

  8. HTML--使用单选框、复选框,让用户选择

    在使用表单设计调查表时,为了减少用户的操作,使用选择框是一个好主意,html中有两种选择框,即单选框和复选框,两者的区别是单选框中的选项用户只能选择一项,而复选框中用户可以任意选择多项,甚至全选.请看 ...

  9. Selenium3+python自动化 单选框和复选框

    一.认识单选框和复选框 1.先认清楚单选框和复选框长什么样 2.各位小伙伴看清楚哦,上面的单选框是圆的:下图复选框是方的,这个是业界的标准,要是开发小伙伴把图标弄错了,可以先抽他了. 二.radio和 ...

  10. jQuery获取单选框(复选框)选中的状态

    jQuery 获取单选框(复选框)选中的状态 <input type="checkbox" name="" id="choose"/& ...

随机推荐

  1. Android真机调试 Android.Util.AndroidRuntimeException: You cannot combine custom titles with other title features

    参考连接:http://blog.csdn.net/scyatcs/article/details/9003285 Android.Util.AndroidRuntimeException: You ...

  2. [Repost]Events and Signals in PyQt4

    Reference:http://zetcode.com/gui/pyqt4/eventsandsignals/ Events and Signals in PyQt4 In this part of ...

  3. ASP.NET4.5Web API及非同步程序开发系列(3)

    接着上一篇博客的内容做一个补充,正好是一个大哥提出来的,我们看看一个有趣的现象. 请求相关问题的补充: 我们先在Controller中的定义一个我们在前一篇博客中已经测试过的方法如下: public ...

  4. [C++][数据结构][算法]单链式结构的深拷贝

    深拷贝(deep-copy),区别于浅拷贝,表示复制所有数据,而不是像浅拷贝一般只复制指针.深拷贝的数据不会因原始数据被delete后而消失. 单链式结构可以实现单链表,栈,队列,树等数据结构.掌握了 ...

  5. 【Android】achartengine的柱状图和饼状图的使用

    本文介绍了android中如何使用achartengine绘制饼图和柱状图,请分别尝试饼图和柱状图,曲线图. 先看效果图: 先看看获取数据: Workbook workbook = Workbook. ...

  6. RStudio技巧01_美化RStudio的帮助页面

    R中的package及其函数实在太多,经常遇到不会使用或者忘记如何使用的的package和函数,所以总会查阅帮助文档,在Rstudio中提供了专门的help面板,当遇到不懂的package或者函数时只 ...

  7. BZOJ 2431 & DP

    题意:求逆序对数量为k的长度为n的排列的个数 SOL: 显然我们可以对最后一位数字进行讨论,判断其已经产生多少逆序对数量,然后对于前n-1位同样考虑---->每一个长度的排列我们都可以看做是相同 ...

  8. BZOJ1097: [POI2007]旅游景点atr

    ..k次最短路后,考虑如何满足先走一些点 用状压dp,每一个点考虑它所需要经过的点a[i],当当前走过的点包含a[i]时,i 这个点才可以到达. 写的时候用记忆化搜索. #include<bit ...

  9. db2 import export load

    DB2中所谓的数据移动,包括: 1. 数据的导入(Import) 2. 数据的导出(Export) 3. 数据的装入(Load) 导入和装入都是利用DB2的相关命令把某种格式的文件中的数据保存到数据库 ...

  10. Hibernate学习笔记5

    hql语句的查询(hibernate query language) hql和sql语句的区别sql:语言关系型数据库里面的通用查询,结构化查询语言,查看的是表以及表的列hql是hibernate中独 ...