Merge pull request #9709 from htlxyz/v3_origin

modify widget interface for lua
This commit is contained in:
minggo 2014-12-30 18:32:20 +08:00
commit 70a29a8470
9 changed files with 356 additions and 0 deletions

View File

@ -54,3 +54,27 @@ function Layer:removeTouch()
self:setTouchEnabled(false)
return self
end
function Layer:onKeypad(callback)
self:registerScriptKeypadHandler(callback)
self:setKeyboardEnabled(true)
return self
end
function Layer:removeKeypad()
self:unregisterScriptKeypadHandler()
self:setKeyboardEnabled(false)
return self
end
function Layer:onAccelerate(callback)
self:registerScriptAccelerateHandler(callback)
self:setAccelerometerEnabled(true)
return self
end
function Layer:removeAccelerate()
self:unregisterScriptAccelerateHandler()
self:setAccelerometerEnabled(false)
return self
end

View File

@ -0,0 +1,40 @@
--[[
Copyright (c) 2011-2014 chukong-inc.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
]]
local CheckBox = ccui.CheckBox
function CheckBox:onEvent(callback)
self:addEventListener(function(sender, eventType)
local event = {}
if eventType == 0 then
event.name = "selected"
else
event.name = "unselected"
end
event.target = sender
callback(event)
end)
return self
end

View File

@ -0,0 +1,41 @@
--[[
Copyright (c) 2011-2014 chukong-inc.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
]]
local EditBox = ccui.EditBox
function EditBox:onEditHandler(callback)
self:registerScriptEditBoxHandler(function(name, sender)
local event = {}
event.name = name
event.target = sender
callback(event)
end)
return self
end
function EditBox:removeEditHandler()
self:unregisterScriptEditBoxHandler()
return self
end

View File

@ -0,0 +1,68 @@
--[[
Copyright (c) 2011-2014 chukong-inc.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
]]
local ListView = ccui.ListView
function ListView:onEvent(callback)
self:addEventListener(function(sender, eventType)
local event = {}
if eventType == 0 then
event.name = "ON_SELECTED_ITEM_START"
else
event.name = "ON_SELECTED_ITEM_END"
end
event.target = sender
callback(event)
end)
return self
end
function ListView:onScroll(callback)
self:addScrollViewEventListener(function(sender, eventType)
local event = {}
if eventType == 0 then
event.name = "SCROLL_TO_TOP"
elseif eventType == 1 then
event.name = "SCROLL_TO_BOTTOM"
elseif eventType == 2 then
event.name = "SCROLL_TO_LEFT"
elseif eventType == 3 then
event.name = "SCROLL_TO_RIGHT"
elseif eventType == 4 then
event.name = "SCROLLING"
elseif eventType == 5 then
event.name = "BOUNCE_TOP"
elseif eventType == 6 then
event.name = "BOUNCE_BOTTOM"
elseif eventType == 7 then
event.name = "BOUNCE_LEFT"
elseif eventType == 8 then
event.name = "BOUNCE_RIGHT"
end
event.target = sender
callback(event)
end)
return self
end

View File

@ -0,0 +1,38 @@
--[[
Copyright (c) 2011-2014 chukong-inc.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
]]
local PageView = ccui.PageView
function PageView:onEvent(callback)
self:addEventListener(function(sender, eventType)
local event = {}
if eventType == 0 then
event.name = "TURNING"
end
event.target = sender
callback(event)
end)
return self
end

View File

@ -0,0 +1,56 @@
--[[
Copyright (c) 2011-2014 chukong-inc.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
]]
local ScrollView = ccui.ScrollView
function ScrollView:onEvent(callback)
self:addEventListener(function(sender, eventType)
local event = {}
if eventType == 0 then
event.name = "SCROLL_TO_TOP"
elseif eventType == 1 then
event.name = "SCROLL_TO_BOTTOM"
elseif eventType == 2 then
event.name = "SCROLL_TO_LEFT"
elseif eventType == 3 then
event.name = "SCROLL_TO_RIGHT"
elseif eventType == 4 then
event.name = "SCROLLING"
elseif eventType == 5 then
event.name = "BOUNCE_TOP"
elseif eventType == 6 then
event.name = "BOUNCE_BOTTOM"
elseif eventType == 7 then
event.name = "BOUNCE_LEFT"
elseif eventType == 8 then
event.name = "BOUNCE_RIGHT"
end
event.target = sender
callback(event)
end)
return self
end
ScrollView.onScroll = ScrollView.onEvent

View File

@ -0,0 +1,38 @@
--[[
Copyright (c) 2011-2014 chukong-inc.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
]]
local Slider = ccui.Slider
function Slider:onEvent(callback)
self:addEventListener(function(sender, eventType)
local event = {}
if eventType == 0 then
event.name = "ON_PERCENTAGE_CHANGED"
end
event.target = sender
callback(event)
end)
return self
end

View File

@ -0,0 +1,44 @@
--[[
Copyright (c) 2011-2014 chukong-inc.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
]]
local TextField = ccui.TextField
function TextField:onEvent(callback)
self:addEventListener(function(sender, eventType)
local event = {}
if eventType == 0 then
event.name = "ATTACH_WITH_IME"
elseif eventType == 1 then
event.name = "DETACH_WITH_IME"
elseif eventType == 2 then
event.name = "INSERT_TEXT"
elseif eventType == 3 then
event.name = "DELETE_BACKWARD"
end
event.target = sender
callback(event)
end)
return self
end

View File

@ -45,6 +45,13 @@ require("cocos.framework.extends.SpriteEx")
require("cocos.framework.extends.LayerEx")
require("cocos.framework.extends.MenuEx")
require("cocos.framework.extends.UIWidget")
require("cocos.framework.extends.UICheckBox")
require("cocos.framework.extends.UIEditBox")
require("cocos.framework.extends.UIListView")
require("cocos.framework.extends.UIPageView")
require("cocos.framework.extends.UIScrollView")
require("cocos.framework.extends.UISlider")
require("cocos.framework.extends.UITextField")
require("cocos.framework.package_support")