add Cocos Studio support

This commit is contained in:
dualface 2014-12-29 13:41:21 +08:00
parent 653b15b4b8
commit 82c40ca5e8
1 changed files with 41 additions and 0 deletions

View File

@ -5,6 +5,18 @@ function ViewBase:ctor(app, name)
self:enableNodeEvents()
self.app_ = app
self.name_ = name
-- check CSB resource file
local res = rawget(self.class, "RESOURCE_FILENAME")
if res then
self:createResoueceNode(res)
end
local binding = rawget(self.class, "RESOURCE_BINDING")
if res and binding then
self:createResoueceBinding(binding)
end
if self.onCreate then self:onCreate() end
end
@ -16,6 +28,35 @@ function ViewBase:getName()
return self.name_
end
function ViewBase:getResourceNode()
return self.resourceNode_
end
function ViewBase:createResoueceNode(resourceFilename)
if self.resourceNode_ then
self.resourceNode_:removeSelf()
self.resourceNode_ = nil
end
self.resourceNode_ = cc.CSLoader:createNode(resourceFilename)
assert(self.resourceNode_, string.format("ViewBase:createResoueceNode() - load resouce node from file \"%s\" failed", resourceFilename))
self:addChild(self.resourceNode_)
end
function ViewBase:createResoueceBinding(binding)
assert(self.resourceNode_, "ViewBase:createResoueceBinding() - not load resource node")
for nodeName, nodeBinding in pairs(binding) do
local node = self.resourceNode_:getChildByName(nodeName)
if nodeBinding.varname then
self[nodeBinding.varname] = node
end
for _, event in ipairs(nodeBinding.events or {}) do
if event.event == "touch" then
node:onTouch(handler(self, self[event.method]))
end
end
end
end
function ViewBase:showWithScene(transition, time, more)
self:setVisible(true)
local scene = display.newScene(self.name_)