axmol/samples/Lua/TestLua/Resources/luaScript/mainMenu.lua

209 lines
6.8 KiB
Lua
Raw Normal View History

require "luaScript/tests"
require "luaScript/helper"
require "luaScript/testResource"
2012-08-23 16:10:50 +08:00
------------------------
local LINE_SPACE = 40
local CurPos = {x = 0, y = 0}
local BeginPos = {x = 0, y = 0}
-- create scene
local function CreateTestScene(nIdx)
CCDirector:sharedDirector():purgeCachedData()
local scene = nil
if nIdx == Test_Table.TEST_ACTIONS then
scene = ActionsTest()
elseif nIdx == Test_Table.TEST_TRANSITIONS then
scene = TransitionsTest()
elseif nIdx == Test_Table.TEST_PROGRESS_ACTIONS then
scene = ProgressActionsTest()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_EFFECTS then
scene = EffectsTest()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_CLICK_AND_MOVE then
scene = ClickAndMoveTest()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_ROTATE_WORLD then
scene = RotateWorldTest()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_PARTICLE then
scene = ParticleTest()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_EASE_ACTIONS then
scene = EaseActionsTest()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_MOTION_STREAK then
scene = MotionStreakTest()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_DRAW_PRIMITIVES then
scene = DrawPrimitivesTest()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_COCOSNODE then
scene = CocosNodeTest()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_TOUCHES then
scene = TouchesTest()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_MENU then
scene = MenuTestMain()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_ACTION_MANAGER then
scene = ActionManagerTestMain()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_LAYER then
scene = LayerTestMain()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_SCENE then
scene = SceneTestMain()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_PARALLAX then
scene = ParallaxTestMain()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_TILE_MAP then
scene = TileMapTestMain()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_INTERVAL then
scene = IntervalTestMain()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_CHIPMUNKACCELTOUCH then
--#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)
-- pScene = new ChipmunkAccelTouchTestScene()
--#else
--#ifdef MARMALADEUSECHIPMUNK
--#if (MARMALADEUSECHIPMUNK == 1)
-- pScene = new ChipmunkAccelTouchTestScene();
--#endif
-- break;
--#endif
--#endif
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_LABEL then
2013-03-26 18:18:37 +08:00
scene = LabelTest()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_TEXT_INPUT then
elseif nIdx == Test_Table.TEST_SPRITE then
2013-03-11 13:49:09 +08:00
scene = SpriteTest()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_SCHEDULER then
elseif nIdx == Test_Table.TEST_RENDERTEXTURE then
2013-04-05 17:13:46 +08:00
scene = RenderTextureTestMain()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_TEXTURE2D then
scene = Texture2dTestMain()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_BOX2D then
elseif nIdx == Test_Table.TEST_BOX2DBED then
elseif nIdx == Test_Table.TEST_EFFECT_ADVANCE then
scene = EffectAdvancedTestMain()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_ACCELEROMRTER then
--#if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA)
-- elseif nIdx == Test_Table.TEST_KEYPAD then
-- pScene = new KeypadTestScene()
--#endif
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_COCOSDENSHION then
2013-04-06 14:32:46 +08:00
scene = CocosDenshionTestMain()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_PERFORMANCE then
scene = PerformanceTest()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_ZWOPTEX then
2013-04-05 23:34:46 +08:00
scene = ZwoptexTestMain()
--#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)
-- bada don't support libcurl
--#if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA)
-- elseif nIdx == Test_Table.TEXT_CURL then
2012-08-23 16:10:50 +08:00
--#endif
--#endif
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_USERDEFAULT then
elseif nIdx == Test_Table.TEST_BUGS then
elseif nIdx == Test_Table.TEST_FONTS then
2013-04-06 14:00:17 +08:00
scene = FontTestMain()
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_CURRENT_LANGUAGE then
--#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)
-- elseif nIdx == Test_Table.TEST_TEXTURECACHE then pScene = new TextureCacheTestScene()
--#endif
2012-08-23 16:10:50 +08:00
elseif nIdx == Test_Table.TEST_EXTENSIONS then
elseif nIdx == Test_Table.TEST_SHADER then
elseif nIdx == Test_Table.TEST_MUTITOUCH then
end
2012-08-23 16:10:50 +08:00
return scene
2012-08-23 16:10:50 +08:00
end
-- create menu
function CreateTestMenu()
local menuLayer = CCLayer:create()
2012-08-23 16:10:50 +08:00
local function closeCallback()
CCDirector:sharedDirector():endToLua()
end
2012-08-23 16:10:50 +08:00
local function menuCallback(tag)
2012-09-11 17:13:20 +08:00
print(tag)
local Idx = tag - 10000
local testScene = CreateTestScene(Idx)
if testScene then
CCDirector:sharedDirector():replaceScene(testScene)
end
end
-- add close menu
local s = CCDirector:sharedDirector():getWinSize()
local CloseItem = CCMenuItemImage:create(s_pPathClose, s_pPathClose)
CloseItem:registerScriptTapHandler(closeCallback)
CloseItem:setPosition(ccp(s.width - 30, s.height - 30))
2012-08-23 16:10:50 +08:00
local CloseMenu = CCMenu:create()
CloseMenu:setPosition(0, 0)
CloseMenu:addChild(CloseItem)
menuLayer:addChild(CloseMenu)
2012-08-23 16:10:50 +08:00
-- add menu items for tests
2012-08-23 16:10:50 +08:00
local MainMenu = CCMenu:create()
for index, labelName in pairs(Test_Name) do
local testLabel = CCLabelTTF:create(labelName, "Arial", 24)
2012-08-23 16:10:50 +08:00
local testMenuItem = CCMenuItemLabel:create(testLabel)
testMenuItem:registerScriptTapHandler(menuCallback)
testMenuItem:setPosition(ccp(s.width / 2, (s.height - (index + 1) * LINE_SPACE)))
2012-08-27 11:43:47 +08:00
MainMenu:addChild(testMenuItem, index + 10000, index + 10000)
2012-08-23 16:10:50 +08:00
end
MainMenu:setContentSize(CCSizeMake(s.width, (Test_Table.TESTS_COUNT + 1) * (LINE_SPACE)))
MainMenu:setPosition(CurPos.x, CurPos.y)
menuLayer:addChild(MainMenu)
2012-08-23 16:10:50 +08:00
-- handling touch events
2012-08-23 16:10:50 +08:00
local function onTouchBegan(x, y)
BeginPos = {x = x, y = y}
2012-08-23 16:10:50 +08:00
-- CCTOUCHBEGAN event must return true
return true
end
local function onTouchMoved(x, y)
local nMoveY = y - BeginPos.y
local curPosx, curPosy = MainMenu:getPosition()
local nextPosy = curPosy + nMoveY
local winSize = CCDirector:sharedDirector():getWinSize()
if nextPosy < 0 then
MainMenu:setPosition(0, 0)
return
end
if nextPosy > ((Test_Table.TESTS_COUNT + 1) * LINE_SPACE - winSize.height) then
MainMenu:setPosition(0, ((Test_Table.TESTS_COUNT + 1) * LINE_SPACE - winSize.height))
return
end
MainMenu:setPosition(curPosx, nextPosy)
BeginPos = {x = x, y = y}
CurPos = {x = curPosx, y = nextPosy}
2012-08-23 16:10:50 +08:00
end
local function onTouch(eventType, x, y)
if eventType == "began" then
2012-08-23 16:10:50 +08:00
return onTouchBegan(x, y)
elseif eventType == "moved" then
2012-08-23 16:10:50 +08:00
return onTouchMoved(x, y)
end
end
menuLayer:setTouchEnabled(true)
2012-08-23 16:10:50 +08:00
menuLayer:registerScriptTouchHandler(onTouch)
return menuLayer
end