Merge pull request #13491 from zilongshanren/v3.8

add RadioButton and RadioButtonGroup event type
This commit is contained in:
pandamicro 2015-08-21 09:17:46 +08:00
commit f377a9bff1
3 changed files with 158 additions and 0 deletions

View File

@ -235,6 +235,140 @@ static void extendCheckBox(lua_State* L)
lua_pop(L, 1);
}
static int lua_cocos2dx_RadioButton_addEventListener(lua_State* L)
{
if (nullptr == L)
return 0;
int argc = 0;
RadioButton* self = nullptr;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
if (!tolua_isusertype(L,1,"ccui.RadioButton",0,&tolua_err)) goto tolua_lerror;
#endif
self = static_cast<RadioButton*>(tolua_tousertype(L,1,0));
#if COCOS2D_DEBUG >= 1
if (nullptr == self) {
tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_RadioButton_addEventListener'\n", NULL);
return 0;
}
#endif
argc = lua_gettop(L) - 1;
if (1 == argc)
{
#if COCOS2D_DEBUG >= 1
if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err))
{
goto tolua_lerror;
}
#endif
LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0));
self->addEventListener([=](RadioButton* radioButton,RadioButton::EventType eventType){
LuaStack* stack = LuaEngine::getInstance()->getLuaStack();
stack->pushObject(radioButton, "ccui.RadioButton");
stack->pushInt((int)eventType);
stack->executeFunctionByHandler(handler, 2);
stack->clean();
});
ScriptHandlerMgr::getInstance()->addCustomHandler((void*)self, handler);
return 0;
}
luaL_error(L, "'addEventListener' function of CheckBox has wrong number of arguments: %d, was expecting %d\n", argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(L,"#ferror in function 'addEventListener'.",&tolua_err);
return 0;
#endif
}
static void extendRadioButton(lua_State* L)
{
lua_pushstring(L, "ccui.RadioButton");
lua_rawget(L, LUA_REGISTRYINDEX);
if (lua_istable(L,-1))
{
tolua_function(L, "addEventListener", lua_cocos2dx_RadioButton_addEventListener);
}
lua_pop(L, 1);
}
static int lua_cocos2dx_RadioButtonGroup_addEventListener(lua_State* L)
{
if (nullptr == L)
return 0;
int argc = 0;
RadioButtonGroup* self = nullptr;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
if (!tolua_isusertype(L,1,"ccui.RadioButtonGroup",0,&tolua_err)) goto tolua_lerror;
#endif
self = static_cast<RadioButtonGroup*>(tolua_tousertype(L,1,0));
#if COCOS2D_DEBUG >= 1
if (nullptr == self) {
tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_RadioButtonGroup_addEventListener'\n", NULL);
return 0;
}
#endif
argc = lua_gettop(L) - 1;
if (1 == argc)
{
#if COCOS2D_DEBUG >= 1
if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err))
{
goto tolua_lerror;
}
#endif
LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0));
self->addEventListener([=](RadioButton* radioButton,int index,RadioButtonGroup::EventType eventType){
LuaStack* stack = LuaEngine::getInstance()->getLuaStack();
stack->pushObject(radioButton, "ccui.RadioButton");
stack->pushInt(index);
stack->pushInt((int)eventType);
stack->executeFunctionByHandler(handler, 3);
stack->clean();
});
ScriptHandlerMgr::getInstance()->addCustomHandler((void*)self, handler);
return 0;
}
luaL_error(L, "'addEventListener' function of RadioButtonGroup has wrong number of arguments: %d, was expecting %d\n", argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(L,"#ferror in function 'addEventListener'.",&tolua_err);
return 0;
#endif
}
static void extendRadioButtonGroup(lua_State* L)
{
lua_pushstring(L, "ccui.RadioButtonGroup");
lua_rawget(L, LUA_REGISTRYINDEX);
if (lua_istable(L,-1))
{
tolua_function(L, "addEventListener", lua_cocos2dx_RadioButtonGroup_addEventListener);
}
lua_pop(L, 1);
}
static int lua_cocos2dx_Slider_addEventListener(lua_State* L)
{
if (nullptr == L)
@ -850,6 +984,8 @@ int register_all_cocos2dx_ui_manual(lua_State* L)
return 0;
extendWidget(L);
extendCheckBox(L);
extendRadioButton(L);
extendRadioButtonGroup(L);
extendSlider(L);
extendTextField(L);
extendPageView(L);

View File

@ -40,6 +40,17 @@ ccui.CheckBoxEventType =
unselected = 1,
}
ccui.RadioButtonEventType=
{
selected = 0,
unselected = 1
}
ccui.RadioButtonGroupEventType=
{
select_changed = 0
}
ccui.TextFiledEventType =
{
attach_with_ime = 0,

View File

@ -390,6 +390,9 @@ add_new_testcase(function()
self._uiLayer:addChild(alert)
local radioButtonGroup = ccui.RadioButtonGroup:create()
radioButtonGroup:addEventListener(function(radioButton, index, type)
print("RadioButton" .. index .. "Clicked")
end)
self._uiLayer:addChild(radioButtonGroup)
local NUMBER_OF_BUTTONS = 5
@ -399,7 +402,15 @@ add_new_testcase(function()
local radioButton = ccui.RadioButton:create("cocosui/radio_button_off.png", "cocosui/radio_button_on.png")
local posX = startPosX + BUTTON_WIDTH * i
radioButton:setPosition(cc.p(posX, widgetSize.height / 2.0 + 10))
radioButton:setName("button"..i)
radioButtonGroup:addRadioButton(radioButton)
radioButton:addEventListener(function(radioButton, type)
if type == ccui.RadioButtonEventType.selected then
print("name: = " .. radioButton:getName() .. " selected")
elseif type == ccui.RadioButtonEventType.unselected then
print("name: = " .. radioButton:getName() .. " unselected")
end
end)
self._uiLayer:addChild(radioButton)
end