2014-03-10 15:32:48 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_CONTENT_SCALE_FACTOR = function()
|
2014-03-10 15:32:48 +08:00
|
|
|
return cc.Director:getInstance():getContentScaleFactor()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_POINT_PIXELS_TO_POINTS = function(pixels)
|
|
|
|
return cc.p(pixels.x/AX_CONTENT_SCALE_FACTOR(), pixels.y/AX_CONTENT_SCALE_FACTOR())
|
2014-03-10 15:32:48 +08:00
|
|
|
end
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_POINT_POINTS_TO_PIXELS = function(points)
|
|
|
|
return cc.p(points.x*AX_CONTENT_SCALE_FACTOR(), points.y*AX_CONTENT_SCALE_FACTOR())
|
2014-03-10 15:32:48 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- cclog
|
|
|
|
cclog = function(...)
|
|
|
|
print(string.format(...))
|
|
|
|
end
|
|
|
|
|
|
|
|
-- change table to enum type
|
|
|
|
function CreateEnumTable(tbl, index)
|
|
|
|
local enumTable = {}
|
|
|
|
local enumIndex = index or -1
|
|
|
|
for i, v in ipairs(tbl) do
|
|
|
|
enumTable[v] = enumIndex + i
|
|
|
|
end
|
|
|
|
return enumTable
|
|
|
|
end
|
|
|
|
|
|
|
|
Helper = {
|
|
|
|
index = 1,
|
|
|
|
createFunctioinTable = nil,
|
|
|
|
currentLayer = nil,
|
|
|
|
titleLabel = nil,
|
2019-11-14 15:13:20 +08:00
|
|
|
subtitleLabel = nil,
|
|
|
|
restartTestItem = nil
|
2014-03-10 15:32:48 +08:00
|
|
|
}
|
2015-05-15 09:28:03 +08:00
|
|
|
|
2014-03-10 15:32:48 +08:00
|
|
|
function Helper.nextAction()
|
|
|
|
Helper.index = Helper.index + 1
|
2020-10-25 16:14:44 +08:00
|
|
|
if Helper.index > #(Helper.createFunctionTable) then
|
2014-03-10 15:32:48 +08:00
|
|
|
Helper.index = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
return Helper.newScene()
|
|
|
|
end
|
|
|
|
|
|
|
|
function Helper.backAction()
|
|
|
|
Helper.index = Helper.index - 1
|
|
|
|
if Helper.index == 0 then
|
2020-10-25 16:14:44 +08:00
|
|
|
Helper.index = #(Helper.createFunctionTable)
|
2014-03-10 15:32:48 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
return Helper.newScene()
|
|
|
|
end
|
|
|
|
|
|
|
|
function Helper.restartAction()
|
|
|
|
return Helper.newScene()
|
|
|
|
end
|
|
|
|
|
|
|
|
function Helper.newScene()
|
2014-05-16 17:19:02 +08:00
|
|
|
local scene
|
|
|
|
if Helper.usePhysics then
|
|
|
|
scene = cc.Scene:createWithPhysics()
|
|
|
|
else
|
|
|
|
scene = cc.Scene:create()
|
|
|
|
end
|
2014-03-10 15:32:48 +08:00
|
|
|
Helper.currentLayer = Helper.createFunctionTable[Helper.index]()
|
|
|
|
scene:addChild(Helper.currentLayer)
|
|
|
|
scene:addChild(CreateBackMenuItem())
|
|
|
|
|
|
|
|
cc.Director:getInstance():replaceScene(scene)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Helper.initWithLayer(layer)
|
|
|
|
Helper.currentLayer = layer
|
|
|
|
|
2016-12-13 16:31:31 +08:00
|
|
|
local size = cc.Director:getInstance():getOpenGLView():getVisibleRect()
|
2014-04-11 15:25:18 +08:00
|
|
|
Helper.titleLabel = cc.Label:createWithTTF("", s_arialPath, 28)
|
2014-03-12 17:51:34 +08:00
|
|
|
Helper.titleLabel:setAnchorPoint(cc.p(0.5, 0.5))
|
2014-03-10 15:32:48 +08:00
|
|
|
layer:addChild(Helper.titleLabel, 1)
|
|
|
|
Helper.titleLabel:setPosition(size.width / 2, size.height - 50)
|
|
|
|
|
2014-04-11 15:25:18 +08:00
|
|
|
Helper.subtitleLabel = cc.Label:createWithTTF("", s_thonburiPath, 16)
|
2014-03-12 17:51:34 +08:00
|
|
|
Helper.subtitleLabel:setAnchorPoint(cc.p(0.5, 0.5))
|
2014-03-10 15:32:48 +08:00
|
|
|
layer:addChild(Helper.subtitleLabel, 1)
|
|
|
|
Helper.subtitleLabel:setPosition(size.width / 2, size.height - 80)
|
|
|
|
|
|
|
|
-- menu
|
|
|
|
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)
|
|
|
|
item1:registerScriptTapHandler(Helper.backAction)
|
|
|
|
item2:registerScriptTapHandler(Helper.restartAction)
|
|
|
|
item3:registerScriptTapHandler(Helper.nextAction)
|
2019-11-14 15:13:20 +08:00
|
|
|
Helper.restartTestItem = item2
|
2014-03-10 15:32:48 +08:00
|
|
|
|
|
|
|
local menu = cc.Menu:create()
|
|
|
|
menu:addChild(item1)
|
|
|
|
menu:addChild(item2)
|
|
|
|
menu:addChild(item3)
|
|
|
|
menu:setPosition(cc.p(0, 0))
|
2016-12-13 16:31:31 +08:00
|
|
|
item1:setPosition(cc.p(size.width / 2 - item2:getContentSize().width * 2, size.y + item2:getContentSize().height / 2))
|
|
|
|
item2:setPosition(cc.p(size.width / 2, size.y + item2:getContentSize().height / 2))
|
|
|
|
item3:setPosition(cc.p(size.width / 2 + item2:getContentSize().width * 2, size.y + item2:getContentSize().height / 2))
|
2014-03-10 15:32:48 +08:00
|
|
|
layer:addChild(menu, 1)
|
|
|
|
|
|
|
|
local background = cc.Layer:create()
|
|
|
|
layer:addChild(background, -10)
|
|
|
|
end
|
|
|
|
|
2015-05-15 09:28:03 +08:00
|
|
|
-- back menu callback
|
|
|
|
local function MainMenuCallback()
|
|
|
|
local scene = cc.Scene:create()
|
|
|
|
scene:addChild(CreateTestMenu())
|
|
|
|
Helper.usePhysics = false
|
2019-07-02 09:29:20 +08:00
|
|
|
cc.Director:getInstance():getRenderer():setDepthTest(false)
|
2015-05-15 09:28:03 +08:00
|
|
|
cc.Director:getInstance():replaceScene(scene)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- add the menu item for back to main menu
|
|
|
|
function CreateBackMenuItem()
|
|
|
|
local label = cc.Label:createWithTTF("MainMenu", s_arialPath, 20)
|
|
|
|
label:setAnchorPoint(cc.p(0.5, 0.5))
|
|
|
|
local MenuItem = cc.MenuItemLabel:create(label)
|
|
|
|
MenuItem:registerScriptTapHandler(MainMenuCallback)
|
|
|
|
|
2016-12-13 16:31:31 +08:00
|
|
|
local s = cc.Director:getInstance():getOpenGLView():getVisibleRect()
|
2015-05-15 09:28:03 +08:00
|
|
|
local Menu = cc.Menu:create()
|
|
|
|
Menu:addChild(MenuItem)
|
|
|
|
Menu:setPosition(0, 0)
|
2016-12-13 16:31:31 +08:00
|
|
|
MenuItem:setPosition(s.width - 50, s.y + 25)
|
2015-05-15 09:28:03 +08:00
|
|
|
|
|
|
|
return Menu
|
|
|
|
end
|
|
|
|
|
2014-03-10 15:32:48 +08:00
|
|
|
function createTestLayer(title, subtitle)
|
|
|
|
local layer = cc.Layer:create()
|
|
|
|
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
|
2015-06-03 18:12:21 +08:00
|
|
|
|
|
|
|
TestCastScene = {
|
|
|
|
index = 1,
|
|
|
|
createFunctioinTable = nil,
|
|
|
|
titleLabel = nil,
|
|
|
|
subtitleLabel = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestCastScene.nextAction()
|
|
|
|
TestCastScene.index = TestCastScene.index + 1
|
2020-10-25 16:14:44 +08:00
|
|
|
if TestCastScene.index > #(TestCastScene.createFunctionTable) then
|
2015-06-03 18:12:21 +08:00
|
|
|
TestCastScene.index = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
return TestCastScene.newScene()
|
|
|
|
end
|
|
|
|
|
|
|
|
function TestCastScene.backAction()
|
|
|
|
TestCastScene.index = TestCastScene.index - 1
|
|
|
|
if TestCastScene.index == 0 then
|
2020-10-25 16:14:44 +08:00
|
|
|
TestCastScene.index = #(TestCastScene.createFunctionTable)
|
2015-06-03 18:12:21 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
return TestCastScene.newScene()
|
|
|
|
end
|
|
|
|
|
|
|
|
function TestCastScene.restartAction()
|
|
|
|
return TestCastScene.newScene()
|
|
|
|
end
|
|
|
|
|
|
|
|
function TestCastScene.newScene()
|
|
|
|
local scene = TestCastScene.createFunctionTable[TestCastScene.index]()
|
|
|
|
scene:addChild(CreateBackMenuItem())
|
|
|
|
cc.Director:getInstance():replaceScene(scene)
|
|
|
|
end
|
|
|
|
|
|
|
|
function TestCastScene.initWithLayer(scene)
|
2017-03-31 10:20:08 +08:00
|
|
|
local size = cc.Director:getInstance():getVisibleSize()
|
|
|
|
local origin = cc.Director:getInstance():getVisibleOrigin()
|
|
|
|
|
2015-06-03 18:12:21 +08:00
|
|
|
TestCastScene.titleLabel = cc.Label:createWithTTF("", s_arialPath, 28)
|
|
|
|
TestCastScene.titleLabel:setAnchorPoint(cc.p(0.5, 0.5))
|
|
|
|
scene:addChild(TestCastScene.titleLabel, 1)
|
2017-03-31 10:20:08 +08:00
|
|
|
TestCastScene.titleLabel:setPosition(origin.x + size.width / 2, origin.y + size.height - 50)
|
2015-06-03 18:12:21 +08:00
|
|
|
|
|
|
|
TestCastScene.subtitleLabel = cc.Label:createWithTTF("", s_thonburiPath, 16)
|
|
|
|
TestCastScene.subtitleLabel:setAnchorPoint(cc.p(0.5, 0.5))
|
|
|
|
scene:addChild(TestCastScene.subtitleLabel, 1)
|
2017-03-31 10:20:08 +08:00
|
|
|
TestCastScene.subtitleLabel:setPosition(origin.x + size.width / 2, origin.y + size.height - 80)
|
2015-06-03 18:12:21 +08:00
|
|
|
|
|
|
|
-- menu
|
|
|
|
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)
|
|
|
|
item1:registerScriptTapHandler(TestCastScene.backAction)
|
|
|
|
item2:registerScriptTapHandler(TestCastScene.restartAction)
|
|
|
|
item3:registerScriptTapHandler(TestCastScene.nextAction)
|
2017-03-31 10:20:08 +08:00
|
|
|
|
2015-06-03 18:12:21 +08:00
|
|
|
local menu = cc.Menu:create()
|
|
|
|
menu:addChild(item1)
|
|
|
|
menu:addChild(item2)
|
|
|
|
menu:addChild(item3)
|
|
|
|
menu:setPosition(cc.p(0, 0))
|
2017-04-06 16:18:28 +08:00
|
|
|
item1:setPosition(cc.p(origin.x + size.width / 2 - item2:getContentSize().width * 2, origin.y + size.height + item2:getContentSize().height / 2))
|
|
|
|
item2:setPosition(cc.p(origin.x + size.width / 2, origin.y + size.height + item2:getContentSize().height / 2))
|
|
|
|
item3:setPosition(cc.p(origin.x + size.width / 2 + item2:getContentSize().width * 2, origin.y + size.height + item2:getContentSize().height / 2))
|
2015-06-03 18:12:21 +08:00
|
|
|
scene:addChild(menu, 1)
|
|
|
|
|
|
|
|
local background = cc.Layer:create()
|
|
|
|
scene:addChild(background, -10)
|
|
|
|
end
|