2013-08-14 21:35:55 +08:00
|
|
|
require "Cocos2d"
|
|
|
|
|
2013-04-01 17:35:27 +08:00
|
|
|
CC_CONTENT_SCALE_FACTOR = function()
|
2013-08-14 21:35:55 +08:00
|
|
|
return cc.Director:getInstance():getContentScaleFactor()
|
2013-04-01 17:35:27 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
CC_POINT_PIXELS_TO_POINTS = function(pixels)
|
2013-08-14 21:35:55 +08:00
|
|
|
return cc.p(pixels.x/CC_CONTENT_SCALE_FACTOR(), pixels.y/CC_CONTENT_SCALE_FACTOR())
|
2013-04-01 17:35:27 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
CC_POINT_POINTS_TO_PIXELS = function(points)
|
2013-08-14 21:35:55 +08:00
|
|
|
return cc.p(points.x*CC_CONTENT_SCALE_FACTOR(), points.y*CC_CONTENT_SCALE_FACTOR())
|
2013-04-01 17:35:27 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-08-23 16:10:50 +08:00
|
|
|
-- cclog
|
|
|
|
cclog = function(...)
|
|
|
|
print(string.format(...))
|
|
|
|
end
|
|
|
|
|
|
|
|
-- change table to enum type
|
|
|
|
function CreateEnumTable(tbl, index)
|
2013-04-05 16:13:04 +08:00
|
|
|
local enumTable = {}
|
|
|
|
local enumIndex = index or -1
|
|
|
|
for i, v in ipairs(tbl) do
|
|
|
|
enumTable[v] = enumIndex + i
|
|
|
|
end
|
|
|
|
return enumTable
|
2012-08-23 16:10:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
-- back menu callback
|
|
|
|
local function MainMenuCallback()
|
2014-01-06 22:19:40 +08:00
|
|
|
Helper.usePhysics = false
|
2013-08-14 21:35:55 +08:00
|
|
|
local scene = cc.Scene:create()
|
2013-04-05 16:13:04 +08:00
|
|
|
scene:addChild(CreateTestMenu())
|
2012-08-23 16:10:50 +08:00
|
|
|
|
2013-08-14 21:35:55 +08:00
|
|
|
cc.Director:getInstance():replaceScene(scene)
|
2012-08-23 16:10:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
-- add the menu item for back to main menu
|
|
|
|
function CreateBackMenuItem()
|
2013-08-14 21:35:55 +08:00
|
|
|
local label = cc.LabelTTF:create("MainMenu", "Arial", 20)
|
|
|
|
local MenuItem = cc.MenuItemLabel:create(label)
|
2013-04-05 16:13:04 +08:00
|
|
|
MenuItem:registerScriptTapHandler(MainMenuCallback)
|
2012-08-23 16:10:50 +08:00
|
|
|
|
2013-08-14 21:35:55 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
|
|
|
local Menu = cc.Menu:create()
|
2012-08-23 16:10:50 +08:00
|
|
|
Menu:addChild(MenuItem)
|
|
|
|
Menu:setPosition(0, 0)
|
|
|
|
MenuItem:setPosition(s.width - 50, 25)
|
|
|
|
|
2013-04-05 16:13:04 +08:00
|
|
|
return Menu
|
2012-08-23 16:10:50 +08:00
|
|
|
end
|
2013-03-13 17:45:09 +08:00
|
|
|
|
|
|
|
Helper = {
|
2013-04-05 16:13:04 +08:00
|
|
|
index = 1,
|
|
|
|
createFunctioinTable = nil,
|
|
|
|
currentLayer = nil,
|
|
|
|
titleLabel = nil,
|
|
|
|
subtitleLabel = nil
|
2013-03-13 17:45:09 +08:00
|
|
|
}
|
|
|
|
function Helper.nextAction()
|
2013-04-05 16:13:04 +08:00
|
|
|
Helper.index = Helper.index + 1
|
|
|
|
if Helper.index > table.getn(Helper.createFunctionTable) then
|
|
|
|
Helper.index = 1
|
|
|
|
end
|
2013-03-13 17:45:09 +08:00
|
|
|
|
2013-04-05 16:13:04 +08:00
|
|
|
return Helper.newScene()
|
2013-03-13 17:45:09 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function Helper.backAction()
|
2013-04-05 16:13:04 +08:00
|
|
|
Helper.index = Helper.index - 1
|
|
|
|
if Helper.index == 0 then
|
|
|
|
Helper.index = table.getn(Helper.createFunctionTable)
|
|
|
|
end
|
2013-03-13 17:45:09 +08:00
|
|
|
|
2013-04-05 16:13:04 +08:00
|
|
|
return Helper.newScene()
|
2013-03-13 17:45:09 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function Helper.restartAction()
|
2013-04-05 16:13:04 +08:00
|
|
|
return Helper.newScene()
|
2013-03-13 17:45:09 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function Helper.newScene()
|
2014-01-06 22:19:40 +08:00
|
|
|
local scene
|
|
|
|
if Helper.usePhysics then
|
|
|
|
scene = cc.Scene:createWithPhysics()
|
|
|
|
else
|
|
|
|
scene = cc.Scene:create()
|
|
|
|
end
|
2013-04-05 16:13:04 +08:00
|
|
|
Helper.currentLayer = Helper.createFunctionTable[Helper.index]()
|
|
|
|
scene:addChild(Helper.currentLayer)
|
2013-03-13 17:45:09 +08:00
|
|
|
scene:addChild(CreateBackMenuItem())
|
|
|
|
|
2013-08-14 21:35:55 +08:00
|
|
|
cc.Director:getInstance():replaceScene(scene)
|
2013-03-13 17:45:09 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function Helper.initWithLayer(layer)
|
2013-04-05 16:13:04 +08:00
|
|
|
Helper.currentLayer = layer
|
2013-03-26 18:14:14 +08:00
|
|
|
|
2013-08-14 21:35:55 +08:00
|
|
|
local size = cc.Director:getInstance():getWinSize()
|
|
|
|
Helper.titleLabel = cc.LabelTTF:create("", "Arial", 28)
|
2013-03-13 17:45:09 +08:00
|
|
|
layer:addChild(Helper.titleLabel, 1)
|
|
|
|
Helper.titleLabel:setPosition(size.width / 2, size.height - 50)
|
|
|
|
|
2013-08-14 21:35:55 +08:00
|
|
|
Helper.subtitleLabel = cc.LabelTTF:create("", "Thonburi", 16)
|
2013-03-13 17:45:09 +08:00
|
|
|
layer:addChild(Helper.subtitleLabel, 1)
|
|
|
|
Helper.subtitleLabel:setPosition(size.width / 2, size.height - 80)
|
|
|
|
|
|
|
|
-- menu
|
2013-08-14 21:35:55 +08:00
|
|
|
local item1 = cc.MenuItemImage:create(s_pPathB1, s_pPathB2)
|
|
|
|
local item2 = cc.MenuItemImage:create(s_pPathR1, s_pPathR2)
|
|
|
|
local item3 = cc.MenuItemImage:create(s_pPathF1, s_pPathF2)
|
2013-03-13 17:45:09 +08:00
|
|
|
item1:registerScriptTapHandler(Helper.backAction)
|
|
|
|
item2:registerScriptTapHandler(Helper.restartAction)
|
|
|
|
item3:registerScriptTapHandler(Helper.nextAction)
|
|
|
|
|
2013-08-14 21:35:55 +08:00
|
|
|
local menu = cc.Menu:create()
|
2013-03-13 17:45:09 +08:00
|
|
|
menu:addChild(item1)
|
|
|
|
menu:addChild(item2)
|
|
|
|
menu:addChild(item3)
|
2013-08-14 21:35:55 +08:00
|
|
|
menu:setPosition(cc.p(0, 0))
|
|
|
|
item1:setPosition(cc.p(size.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2))
|
|
|
|
item2:setPosition(cc.p(size.width / 2, item2:getContentSize().height / 2))
|
|
|
|
item3:setPosition(cc.p(size.width / 2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2))
|
2013-03-13 17:45:09 +08:00
|
|
|
layer:addChild(menu, 1)
|
|
|
|
|
2013-08-14 21:35:55 +08:00
|
|
|
local background = cc.Layer:create()
|
2013-03-13 17:45:09 +08:00
|
|
|
layer:addChild(background, -10)
|
|
|
|
end
|
2013-04-03 10:20:12 +08:00
|
|
|
|
2013-04-03 11:59:17 +08:00
|
|
|
function createTestLayer(title, subtitle)
|
2013-08-14 21:35:55 +08:00
|
|
|
local layer = cc.Layer:create()
|
2013-04-03 10:20:12 +08:00
|
|
|
Helper.initWithLayer(layer)
|
|
|
|
local titleStr = title == nil and "No title" or title
|
|
|
|
local subTitleStr = subtitle == nil and "" or subtitle
|
|
|
|
Helper.titleLabel:setString(titleStr)
|
|
|
|
Helper.subtitleLabel:setString(subTitleStr)
|
|
|
|
return layer
|
|
|
|
end
|