dialog.lua 1.38 KB
--[[
@Author  : z_h
@Date    : 2016-06-20 10:00:19
@Content : 
--]]

local director = cc.Director:getInstance()
local size = director:getWinSize()
local dispatcher = director:getEventDispatcher()

module("dialog", package.seeall)

ZORDER_APP = 100
ZORDER_POP = 1000

uinode = function(path, ...)
    local creator = function() return cc.CSLoader:createNode(path) end
    local cls_name = string.format("uinode(%s)", path)
    local cls = class(cls_name, creator, ...)

    return cls
end

uilayer = function(path, ...)
    local creator = function()
        local node = cc.CSLoader:createNode(path):setContentSize(size)
        ccui.Helper:doLayout(node)
        return node
    end
    local cls_name = string.format("uilayer(%s)", path)
    local cls = class(cls_name, creator, ...)

    return cls
end


local _bg = nil
local _stack = {}
local _scene = nil


local function attachToScene(scene)
    _scene = scene
    _stack = {}
    if tolua.isnull(_bg) then
        _bg = cc.LayerColor:create(cc.c4b(0, 0, 0, 200))
        local listener = cc.EventListenerTouchOneByOne:create()
        listener:registerScriptHandler(function() return true end,
                cc.Handler.EVENT_TOUCH_BEGAN)
        listener:setSwallowTouches(true)
        dispatcher:addEventListenerWithSceneGraphPriority(listener, _bg)
    end
    _bg:retain()
    if _bg:getParent() then
        _bg:removeFromParent(true)
    end
end