2013-04-03 16:29:16 +08:00
|
|
|
local kTagMenu = 1
|
|
|
|
local kTagMenu0 = 0
|
|
|
|
local kTagMenu1 = 1
|
|
|
|
|
|
|
|
local MID_CALLBACK = 1000
|
|
|
|
local MID_CALLBACK2 = 1001
|
|
|
|
local MID_DISABLED = 1002
|
|
|
|
local MID_ENABLE = 1003
|
|
|
|
local MID_CONFIG = 1004
|
|
|
|
local MID_QUIT = 1005
|
|
|
|
local MID_OPACITY = 1006
|
|
|
|
local MID_ALIGN = 1007
|
|
|
|
local MID_CALLBACK3 = 1008
|
|
|
|
local MID_BACKCALLBACK = 1009
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- MenuLayerMainMenu
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function MenuLayerMainMenu()
|
|
|
|
local m_disabledItem = nil
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local ret = cc.Layer:create()
|
2013-04-03 16:29:16 +08:00
|
|
|
ret:setTouchEnabled(true)
|
2013-08-20 13:44:37 +08:00
|
|
|
ret:setTouchMode(cc.TOUCHES_ONE_BY_ONE )
|
2013-04-03 16:29:16 +08:00
|
|
|
|
2013-04-05 16:13:04 +08:00
|
|
|
-- Font Item
|
2013-08-20 13:44:37 +08:00
|
|
|
local spriteNormal = cc.Sprite:create(s_MenuItem, cc.rect(0,23*2,115,23))
|
|
|
|
local spriteSelected = cc.Sprite:create(s_MenuItem, cc.rect(0,23*1,115,23))
|
|
|
|
local spriteDisabled = cc.Sprite:create(s_MenuItem, cc.rect(0,23*0,115,23))
|
2013-04-03 16:29:16 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local item1 = cc.MenuItemSprite:create(spriteNormal, spriteSelected, spriteDisabled)
|
2013-04-03 16:29:16 +08:00
|
|
|
|
|
|
|
local function menuCallback(sender)
|
|
|
|
cclog("menuCallback...")
|
2014-01-15 23:31:00 +08:00
|
|
|
tolua.cast(ret:getParent(), "cc.LayerMultiplex"):switchTo(1)
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
item1:registerScriptTapHandler(menuCallback)
|
|
|
|
-- Image Item
|
|
|
|
local function menuCallback2(sender)
|
2014-01-15 23:31:00 +08:00
|
|
|
tolua.cast(ret:getParent(), "cc.LayerMultiplex"):switchTo(2)
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local item2 = cc.MenuItemImage:create(s_SendScore, s_PressSendScore)
|
2013-04-03 16:29:16 +08:00
|
|
|
item2:registerScriptTapHandler(menuCallback2)
|
|
|
|
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-04-03 16:29:16 +08:00
|
|
|
local schedulerEntry = nil
|
2013-08-20 13:44:37 +08:00
|
|
|
local scheduler = cc.Director:getInstance():getScheduler()
|
2013-04-03 16:29:16 +08:00
|
|
|
local function allowTouches(dt)
|
2013-08-20 13:44:37 +08:00
|
|
|
local pDirector = cc.Director:getInstance()
|
|
|
|
--pDirector:getTouchDispatcher():setPriority(cc.MENU_HANDLER_PRIORITY +1, ret)
|
2013-05-23 15:39:41 +08:00
|
|
|
if nil ~= schedulerEntry then
|
|
|
|
scheduler:unscheduleScriptEntry(schedulerEntry)
|
|
|
|
schedulerEntry = nil
|
|
|
|
end
|
2013-04-03 16:29:16 +08:00
|
|
|
cclog("TOUCHES ALLOWED AGAIN")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-04-05 16:13:04 +08:00
|
|
|
local function menuCallbackDisabled(sender)
|
2013-04-03 16:29:16 +08:00
|
|
|
-- hijack all touch events for 5 seconds
|
2013-08-20 13:44:37 +08:00
|
|
|
local pDirector = cc.Director:getInstance()
|
|
|
|
--pDirector:getTouchDispatcher():setPriority(cc.MENU_HANDLER_PRIORITY -1, ret)
|
2013-04-03 16:29:16 +08:00
|
|
|
schedulerEntry = scheduler:scheduleScriptFunc(allowTouches, 5, false)
|
|
|
|
cclog("TOUCHES DISABLED FOR 5 SECONDS")
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Label Item (LabelAtlas)
|
2013-08-20 13:44:37 +08:00
|
|
|
local labelAtlas = cc.LabelAtlas:_create("0123456789", "fonts/labelatlas.png", 16, 24, string.byte('.'))
|
|
|
|
local item3 = cc.MenuItemLabel:create(labelAtlas)
|
2013-04-03 16:29:16 +08:00
|
|
|
item3:registerScriptTapHandler(menuCallbackDisabled)
|
2013-08-20 13:44:37 +08:00
|
|
|
item3:setDisabledColor( cc.c3b(32,32,64) )
|
|
|
|
item3:setColor( cc.c3b(200,200,255) )
|
2013-04-03 16:29:16 +08:00
|
|
|
|
2013-04-05 16:13:04 +08:00
|
|
|
local function menuCallbackEnable(sender)
|
2013-04-03 16:29:16 +08:00
|
|
|
m_disabledItem:setEnabled(not m_disabledItem:isEnabled() )
|
|
|
|
end
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-04-03 16:29:16 +08:00
|
|
|
-- Font Item
|
2013-08-20 13:44:37 +08:00
|
|
|
local item4 = cc.MenuItemFont:create("I toggle enable items")
|
2013-04-03 16:29:16 +08:00
|
|
|
item4:registerScriptTapHandler(menuCallbackEnable)
|
|
|
|
|
|
|
|
item4:setFontSizeObj(20)
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.MenuItemFont:setFontName("Marker Felt")
|
2013-04-03 16:29:16 +08:00
|
|
|
|
|
|
|
local function menuCallbackConfig(sender)
|
2014-01-15 23:31:00 +08:00
|
|
|
tolua.cast(ret:getParent(), "cc.LayerMultiplex"):switchTo(3)
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
-- Label Item (cc.LabelBMFont)
|
|
|
|
local label = cc.LabelBMFont:create("configuration", "fonts/bitmapFontTest3.fnt")
|
|
|
|
local item5 = cc.MenuItemLabel:create(label)
|
2013-04-03 16:29:16 +08:00
|
|
|
item5:registerScriptTapHandler(menuCallbackConfig)
|
|
|
|
|
|
|
|
-- Testing issue #500
|
|
|
|
item5:setScale( 0.8 )
|
|
|
|
|
|
|
|
-- Events
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.MenuItemFont:setFontName("Marker Felt")
|
2013-04-03 16:29:16 +08:00
|
|
|
local function menuCallbackBugsTest(pSender)
|
2014-01-15 23:31:00 +08:00
|
|
|
tolua.cast(ret:getParent(), "cc.LayerMultiplex"):switchTo(4)
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Bugs Item
|
2013-11-19 14:32:17 +08:00
|
|
|
local item6 = cc.MenuItemFont:create("Bugs")
|
|
|
|
item6:registerScriptTapHandler(menuCallbackBugsTest)
|
2013-04-03 16:29:16 +08:00
|
|
|
|
|
|
|
local function onQuit(sender)
|
|
|
|
cclog("onQuit item is clicked.")
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Font Item
|
2013-11-19 14:32:17 +08:00
|
|
|
local item7 = cc.MenuItemFont:create("Quit")
|
|
|
|
item7:registerScriptTapHandler(onQuit)
|
2013-04-03 16:29:16 +08:00
|
|
|
|
|
|
|
local function menuMovingCallback(pSender)
|
2014-01-15 23:31:00 +08:00
|
|
|
tolua.cast(ret:getParent(), "cc.LayerMultiplex"):switchTo(5)
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
|
|
|
|
2013-11-19 14:32:17 +08:00
|
|
|
local item8 = cc.MenuItemFont:create("Remove menu item when moving")
|
|
|
|
item8:registerScriptTapHandler(menuMovingCallback)
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local color_action = cc.TintBy:create(0.5, 0, -255, -255)
|
2013-04-03 16:29:16 +08:00
|
|
|
local color_back = color_action:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local seq = cc.Sequence:create(color_action, color_back)
|
2013-11-19 14:32:17 +08:00
|
|
|
item7:runAction(cc.RepeatForever:create(seq))
|
2013-04-03 16:29:16 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local menu = cc.Menu:create()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-04-03 16:29:16 +08:00
|
|
|
menu:addChild(item1)
|
|
|
|
menu:addChild(item2)
|
|
|
|
menu:addChild(item3)
|
|
|
|
menu:addChild(item4)
|
|
|
|
menu:addChild(item5)
|
|
|
|
menu:addChild(item6)
|
|
|
|
menu:addChild(item7)
|
|
|
|
menu:addChild(item8)
|
|
|
|
|
|
|
|
menu:alignItemsVertically()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-04-03 16:29:16 +08:00
|
|
|
-- elastic effect
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-04-03 16:29:16 +08:00
|
|
|
local i = 0
|
|
|
|
local child = nil
|
|
|
|
local pArray = menu:getChildren()
|
2013-08-20 13:44:37 +08:00
|
|
|
local len = table.getn(pArray)
|
2013-04-03 16:29:16 +08:00
|
|
|
local pObject = nil
|
|
|
|
for i = 0, len-1 do
|
2013-08-20 13:44:37 +08:00
|
|
|
pObject = pArray[i + 1]
|
2013-04-03 16:29:16 +08:00
|
|
|
if pObject == nil then
|
|
|
|
break
|
|
|
|
end
|
2014-01-15 23:31:00 +08:00
|
|
|
child = tolua.cast(pObject, "cc.Node")
|
2013-08-23 16:12:59 +08:00
|
|
|
local dstPointX, dstPointY = child:getPosition()
|
2013-04-03 16:29:16 +08:00
|
|
|
local offset = s.width/2 + 50
|
|
|
|
if i % 2 == 0 then
|
|
|
|
offset = 0-offset
|
|
|
|
end
|
2013-08-20 13:44:37 +08:00
|
|
|
child:setPosition( cc.p( dstPointX + offset, dstPointY) )
|
|
|
|
child:runAction( cc.EaseElasticOut:create(cc.MoveBy:create(2, cc.p(dstPointX - offset,0)), 0.35) )
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
m_disabledItem = item3
|
|
|
|
item3:retain()
|
|
|
|
|
|
|
|
m_disabledItem:setEnabled( false )
|
|
|
|
|
|
|
|
ret:addChild(menu)
|
2013-08-20 13:44:37 +08:00
|
|
|
menu:setPosition(cc.p(s.width/2, s.height/2))
|
2013-04-03 16:29:16 +08:00
|
|
|
|
2013-05-23 15:39:41 +08:00
|
|
|
-- local schedulerEntry = nil
|
2013-04-03 16:29:16 +08:00
|
|
|
local function onNodeEvent(event)
|
|
|
|
if event == "exit" then
|
|
|
|
if (schedulerEntry ~= nil) then
|
2013-04-05 16:13:04 +08:00
|
|
|
scheduler:unscheduleScriptEntry(schedulerEntry)
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
|
|
|
if m_disabledItem ~= nil then
|
2013-05-23 15:39:41 +08:00
|
|
|
-- m_disabledItem:release()
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ret:registerScriptHandler(onNodeEvent)
|
|
|
|
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- MenuLayer2
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function MenuLayer2()
|
2013-08-20 13:44:37 +08:00
|
|
|
local ret = cc.Layer:create()
|
2013-04-03 16:29:16 +08:00
|
|
|
local m_centeredMenu = nil
|
|
|
|
local m_alignedH = false
|
|
|
|
|
|
|
|
local function alignMenusH()
|
|
|
|
local i = 0
|
|
|
|
for i=0, 1 do
|
2014-01-15 23:31:00 +08:00
|
|
|
local menu = tolua.cast(ret:getChildByTag(100+i), "cc.Menu")
|
2013-04-03 16:29:16 +08:00
|
|
|
menu:setPosition( m_centeredMenu )
|
|
|
|
if i==0 then
|
|
|
|
-- TIP: if no padding, padding = 5
|
|
|
|
menu:alignItemsHorizontally()
|
2013-08-23 16:12:59 +08:00
|
|
|
local x, y = menu:getPosition()
|
2013-08-20 13:44:37 +08:00
|
|
|
menu:setPosition( cc.pAdd(cc.p(x, y), cc.p(0,30)) )
|
2013-04-05 16:13:04 +08:00
|
|
|
else
|
2013-04-03 16:29:16 +08:00
|
|
|
-- TIP: but padding is configurable
|
|
|
|
menu:alignItemsHorizontallyWithPadding(40)
|
2013-08-23 16:12:59 +08:00
|
|
|
local x, y = menu:getPosition()
|
2013-08-20 13:44:37 +08:00
|
|
|
menu:setPosition( cc.pSub(cc.p(x, y), cc.p(0,30)) )
|
2013-04-05 16:13:04 +08:00
|
|
|
end
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function alignMenusV()
|
|
|
|
local i = 0
|
|
|
|
for i=0, 1 do
|
2014-01-15 23:31:00 +08:00
|
|
|
local menu = tolua.cast(ret:getChildByTag(100+i), "cc.Menu")
|
2013-04-03 16:29:16 +08:00
|
|
|
menu:setPosition( m_centeredMenu )
|
|
|
|
if i==0 then
|
|
|
|
-- TIP: if no padding, padding = 5
|
2013-04-05 16:13:04 +08:00
|
|
|
menu:alignItemsVertically()
|
2013-08-23 16:12:59 +08:00
|
|
|
local x, y = menu:getPosition()
|
2013-08-20 13:44:37 +08:00
|
|
|
menu:setPosition( cc.pAdd(cc.p(x, y), cc.p(100,0)) )
|
2013-04-05 16:13:04 +08:00
|
|
|
else
|
2013-04-03 16:29:16 +08:00
|
|
|
-- TIP: but padding is configurable
|
2013-04-05 16:13:04 +08:00
|
|
|
menu:alignItemsVerticallyWithPadding(40)
|
2013-08-23 16:12:59 +08:00
|
|
|
local x, y = menu:getPosition()
|
2013-08-20 13:44:37 +08:00
|
|
|
menu:setPosition( cc.pSub(cc.p(x, y), cc.p(100,0)) )
|
2013-04-05 16:13:04 +08:00
|
|
|
end
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function menuCallback(sender)
|
2014-01-15 23:31:00 +08:00
|
|
|
tolua.cast(ret:getParent(), "cc.LayerMultiplex"):switchTo(0)
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local function menuCallbackOpacity(tag, sender)
|
2014-01-15 23:31:00 +08:00
|
|
|
local menu = tolua.cast(sender:getParent(), "cc.Menu")
|
2013-04-03 16:29:16 +08:00
|
|
|
local opacity = menu:getOpacity()
|
|
|
|
if opacity == 128 then
|
|
|
|
menu:setOpacity(255)
|
|
|
|
else
|
2013-04-05 16:13:04 +08:00
|
|
|
menu:setOpacity(128)
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function menuCallbackAlign(sender)
|
|
|
|
m_alignedH = not m_alignedH
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-04-03 16:29:16 +08:00
|
|
|
if m_alignedH then
|
|
|
|
alignMenusH()
|
|
|
|
else
|
2013-04-05 16:13:04 +08:00
|
|
|
alignMenusV()
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local i = 0
|
|
|
|
for i=0, 1 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local item1 = cc.MenuItemImage:create(s_PlayNormal, s_PlaySelect)
|
2013-04-03 16:29:16 +08:00
|
|
|
item1:registerScriptTapHandler(menuCallback)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local item2 = cc.MenuItemImage:create(s_HighNormal, s_HighSelect)
|
2013-04-03 16:29:16 +08:00
|
|
|
item2:registerScriptTapHandler(menuCallbackOpacity)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local item3 = cc.MenuItemImage:create(s_AboutNormal, s_AboutSelect)
|
2013-04-03 16:29:16 +08:00
|
|
|
item3:registerScriptTapHandler(menuCallbackAlign)
|
|
|
|
|
|
|
|
item1:setScaleX( 1.5 )
|
|
|
|
item2:setScaleX( 0.5 )
|
|
|
|
item3:setScaleX( 0.5 )
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local menu = cc.Menu:create()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-04-03 16:29:16 +08:00
|
|
|
menu:addChild(item1)
|
|
|
|
menu:addChild(item2)
|
|
|
|
menu:addChild(item3)
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
|
|
|
menu:setPosition(cc.p(s.width/2, s.height/2))
|
2013-04-03 16:29:16 +08:00
|
|
|
|
|
|
|
menu:setTag( kTagMenu )
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-04-03 16:29:16 +08:00
|
|
|
ret:addChild(menu, 0, 100+i)
|
2013-08-23 16:12:59 +08:00
|
|
|
local x, y = menu:getPosition()
|
2013-08-20 13:44:37 +08:00
|
|
|
m_centeredMenu = cc.p(x, y)
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
m_alignedH = true
|
|
|
|
alignMenusH()
|
|
|
|
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- MenuLayer3
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function MenuLayer3()
|
|
|
|
local m_disabledItem = nil
|
2013-08-20 13:44:37 +08:00
|
|
|
local ret = cc.Layer:create()
|
2013-04-03 16:29:16 +08:00
|
|
|
local function menuCallback(sender)
|
2014-01-15 23:31:00 +08:00
|
|
|
tolua.cast(ret:getParent(), "cc.LayerMultiplex"):switchTo(0)
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local function menuCallback2(sender)
|
|
|
|
cclog("Label clicked. Toogling AtlasSprite")
|
|
|
|
m_disabledItem:setEnabled( not m_disabledItem:isEnabled() )
|
|
|
|
m_disabledItem:stopAllActions()
|
|
|
|
end
|
|
|
|
|
|
|
|
local function menuCallback3(sender)
|
|
|
|
cclog("MenuItemSprite clicked")
|
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.MenuItemFont:setFontName("Marker Felt")
|
|
|
|
cc.MenuItemFont:setFontSize(28)
|
2013-04-03 16:29:16 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local label = cc.LabelBMFont:create("Enable AtlasItem", "fonts/bitmapFontTest3.fnt")
|
|
|
|
local item1 = cc.MenuItemLabel:create(label)
|
2013-04-03 16:29:16 +08:00
|
|
|
item1:registerScriptTapHandler(menuCallback2)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local item2 = cc.MenuItemFont:create("--- Go Back ---")
|
2013-04-03 16:29:16 +08:00
|
|
|
item2:registerScriptTapHandler(menuCallback)
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local spriteNormal = cc.Sprite:create(s_MenuItem, cc.rect(0,23*2,115,23))
|
|
|
|
local spriteSelected = cc.Sprite:create(s_MenuItem, cc.rect(0,23*1,115,23))
|
|
|
|
local spriteDisabled = cc.Sprite:create(s_MenuItem, cc.rect(0,23*0,115,23))
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local item3 = cc.MenuItemSprite:create(spriteNormal, spriteSelected, spriteDisabled)
|
2013-04-03 16:29:16 +08:00
|
|
|
item3:registerScriptTapHandler(menuCallback3)
|
|
|
|
m_disabledItem = item3
|
|
|
|
item3:retain()
|
|
|
|
m_disabledItem:setEnabled( false )
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local menu = cc.Menu:create()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-04-03 16:29:16 +08:00
|
|
|
menu:addChild(item1)
|
|
|
|
menu:addChild(item2)
|
|
|
|
menu:addChild(item3)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
menu:setPosition( cc.p(0,0) )
|
2013-04-03 16:29:16 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
item1:setPosition( cc.p(s.width/2 - 150, s.height/2) )
|
|
|
|
item2:setPosition( cc.p(s.width/2 - 200, s.height/2) )
|
|
|
|
item3:setPosition( cc.p(s.width/2, s.height/2 - 100) )
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local jump = cc.JumpBy:create(3, cc.p(400,0), 50, 4)
|
|
|
|
item2:runAction( cc.RepeatForever:create(cc.Sequence:create( jump, jump:reverse())))
|
2013-04-03 16:29:16 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local spin1 = cc.RotateBy:create(3, 360)
|
2014-01-15 23:31:00 +08:00
|
|
|
local spin2 = tolua.cast(spin1:clone(), "cc.ActionInterval")
|
|
|
|
local spin3 = tolua.cast(spin1:clone(), "cc.ActionInterval")
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
item1:runAction( cc.RepeatForever:create(spin1) )
|
|
|
|
item2:runAction( cc.RepeatForever:create(spin2) )
|
|
|
|
item3:runAction( cc.RepeatForever:create(spin3) )
|
2013-04-05 16:13:04 +08:00
|
|
|
|
|
|
|
ret:addChild( menu )
|
2013-04-03 16:29:16 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
menu:setPosition(cc.p(0,0))
|
2013-04-03 16:29:16 +08:00
|
|
|
|
|
|
|
local function onNodeEvent(event)
|
|
|
|
if event == "exit" then
|
|
|
|
if m_disabledItem ~= nil then
|
2013-05-23 15:39:41 +08:00
|
|
|
--m_disabledItem:release()
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ret:registerScriptHandler(onNodeEvent)
|
|
|
|
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- MenuLayer4
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function MenuLayer4()
|
2013-08-20 13:44:37 +08:00
|
|
|
local ret = cc.Layer:create()
|
|
|
|
cc.MenuItemFont:setFontName("American Typewriter")
|
|
|
|
cc.MenuItemFont:setFontSize(18)
|
|
|
|
local title1 = cc.MenuItemFont:create("Sound")
|
2013-04-03 16:29:16 +08:00
|
|
|
title1:setEnabled(false)
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.MenuItemFont:setFontName( "Marker Felt" )
|
|
|
|
cc.MenuItemFont:setFontSize(34)
|
|
|
|
local item1 = cc.MenuItemToggle:create(cc.MenuItemFont:create( "On" ))
|
2013-04-03 16:29:16 +08:00
|
|
|
|
|
|
|
local function menuCallback(tag, sender)
|
2014-01-15 23:31:00 +08:00
|
|
|
cclog("selected item: tag: %d, index:%d", tag, tolua.cast(sender, "cc.MenuItemToggle"):getSelectedIndex() )
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local function backCallback(tag, sender)
|
2014-01-15 23:31:00 +08:00
|
|
|
tolua.cast(ret:getParent(), "cc.LayerMultiplex"):switchTo(0)
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
item1:registerScriptTapHandler(menuCallback)
|
2013-08-20 13:44:37 +08:00
|
|
|
item1:addSubItem(cc.MenuItemFont:create( "Off"))
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.MenuItemFont:setFontName( "American Typewriter" )
|
|
|
|
cc.MenuItemFont:setFontSize(18)
|
|
|
|
local title2 = cc.MenuItemFont:create( "Music" )
|
2013-04-03 16:29:16 +08:00
|
|
|
title2:setEnabled(false)
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.MenuItemFont:setFontName( "Marker Felt" )
|
|
|
|
cc.MenuItemFont:setFontSize(34)
|
|
|
|
local item2 = cc.MenuItemToggle:create(cc.MenuItemFont:create( "On" ))
|
2013-04-03 16:29:16 +08:00
|
|
|
item2:registerScriptTapHandler(menuCallback)
|
2013-08-20 13:44:37 +08:00
|
|
|
item2:addSubItem(cc.MenuItemFont:create( "Off"))
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.MenuItemFont:setFontName( "American Typewriter" )
|
|
|
|
cc.MenuItemFont:setFontSize(18)
|
|
|
|
local title3 = cc.MenuItemFont:create( "Quality" )
|
2013-04-03 16:29:16 +08:00
|
|
|
title3:setEnabled( false )
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.MenuItemFont:setFontName( "Marker Felt" )
|
|
|
|
cc.MenuItemFont:setFontSize(34)
|
|
|
|
local item3 = cc.MenuItemToggle:create(cc.MenuItemFont:create( "High" ))
|
2013-04-03 16:29:16 +08:00
|
|
|
item3:registerScriptTapHandler(menuCallback)
|
2013-08-20 13:44:37 +08:00
|
|
|
item3:addSubItem(cc.MenuItemFont:create( "Low" ))
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.MenuItemFont:setFontName( "American Typewriter" )
|
|
|
|
cc.MenuItemFont:setFontSize(18)
|
|
|
|
local title4 = cc.MenuItemFont:create( "Orientation" )
|
2013-04-03 16:29:16 +08:00
|
|
|
title4:setEnabled(false)
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.MenuItemFont:setFontName( "Marker Felt" )
|
|
|
|
cc.MenuItemFont:setFontSize(34)
|
|
|
|
local item4 = cc.MenuItemToggle:create(cc.MenuItemFont:create( "Off"),
|
|
|
|
cc.MenuItemFont:create( "33%" ),
|
|
|
|
cc.MenuItemFont:create( "66%" ),
|
|
|
|
cc.MenuItemFont:create( "100%"))
|
2013-04-03 16:29:16 +08:00
|
|
|
item4:registerScriptTapHandler(menuCallback)
|
|
|
|
|
|
|
|
-- you can change the one of the items by doing this
|
|
|
|
item4:setSelectedIndex( 2 )
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.MenuItemFont:setFontName( "Marker Felt" )
|
|
|
|
cc.MenuItemFont:setFontSize( 34 )
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local label = cc.LabelBMFont:create( "go back", "fonts/bitmapFontTest3.fnt" )
|
|
|
|
local back = cc.MenuItemLabel:create(label)
|
2013-04-03 16:29:16 +08:00
|
|
|
back:registerScriptTapHandler(backCallback)
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local menu = cc.Menu:create()
|
2013-04-03 16:29:16 +08:00
|
|
|
|
|
|
|
menu:addChild(title1)
|
|
|
|
menu:addChild(title2)
|
|
|
|
menu:addChild(item1 )
|
|
|
|
menu:addChild(item2 )
|
|
|
|
menu:addChild(title3)
|
|
|
|
menu:addChild(title4)
|
|
|
|
menu:addChild(item3 )
|
|
|
|
menu:addChild(item4 )
|
|
|
|
menu:addChild(back )
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
menu:alignItemsInColumns(2, 2, 2, 2, 1)
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-05-23 15:39:41 +08:00
|
|
|
ret:addChild(menu)
|
2013-04-03 16:29:16 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
|
|
|
menu:setPosition(cc.p(s.width/2, s.height/2))
|
2013-04-03 16:29:16 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
-- BugsTest
|
|
|
|
local function BugsTest()
|
2013-08-20 13:44:37 +08:00
|
|
|
local ret = cc.Layer:create()
|
2013-04-03 16:29:16 +08:00
|
|
|
local function issue1410MenuCallback(tag, pSender)
|
2014-01-15 23:31:00 +08:00
|
|
|
local menu = tolua.cast(pSender:getParent(), "cc.Menu")
|
2013-11-18 22:16:49 +08:00
|
|
|
menu:setEnabled(false)
|
|
|
|
menu:setEnabled(true)
|
2013-04-03 16:29:16 +08:00
|
|
|
cclog("NO CRASHES")
|
|
|
|
end
|
|
|
|
|
|
|
|
local function issue1410v2MenuCallback(tag, pSender)
|
2014-01-15 23:31:00 +08:00
|
|
|
local menu = tolua.cast(pSender:getParent(), "cc.Menu")
|
2013-11-18 22:16:49 +08:00
|
|
|
menu:setEnabled(true)
|
|
|
|
menu:setEnabled(false)
|
2013-04-03 16:29:16 +08:00
|
|
|
cclog("NO CRASHES. AND MENU SHOULD STOP WORKING")
|
|
|
|
end
|
|
|
|
|
|
|
|
local function backMenuCallback(tag, pSender)
|
2014-01-15 23:31:00 +08:00
|
|
|
tolua.cast(ret:getParent(), "cc.LayerMultiplex"):switchTo(0)
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local issue1410 = cc.MenuItemFont:create("Issue 1410")
|
2013-04-03 16:29:16 +08:00
|
|
|
issue1410:registerScriptTapHandler(issue1410MenuCallback)
|
2013-08-20 13:44:37 +08:00
|
|
|
local issue1410_2 = cc.MenuItemFont:create("Issue 1410 #2")
|
2013-04-03 16:29:16 +08:00
|
|
|
issue1410_2:registerScriptTapHandler(issue1410v2MenuCallback)
|
2013-08-20 13:44:37 +08:00
|
|
|
local back = cc.MenuItemFont:create("Back")
|
2013-04-03 16:29:16 +08:00
|
|
|
back:registerScriptTapHandler(backMenuCallback)
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local menu = cc.Menu:create()
|
2013-04-03 16:29:16 +08:00
|
|
|
menu:addChild(issue1410)
|
|
|
|
menu:addChild(issue1410_2)
|
|
|
|
menu:addChild(back)
|
|
|
|
ret:addChild(menu)
|
|
|
|
menu:alignItemsVertically()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
|
|
|
menu:setPosition(cc.p(s.width/2, s.height/2))
|
2013-04-03 16:29:16 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function RemoveMenuItemWhenMove()
|
2013-08-20 13:44:37 +08:00
|
|
|
local ret = cc.Layer:create()
|
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local label = cc.LabelTTF:create("click item and move, should not crash", "Arial", 20)
|
|
|
|
label:setPosition(cc.p(s.width/2, s.height - 30))
|
2013-04-03 16:29:16 +08:00
|
|
|
ret:addChild(label)
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local item = cc.MenuItemFont:create("item 1")
|
2013-04-03 16:29:16 +08:00
|
|
|
item:retain()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local back = cc.MenuItemFont:create("go back")
|
2013-04-03 16:29:16 +08:00
|
|
|
local function goBack(tag, pSender)
|
2014-01-15 23:31:00 +08:00
|
|
|
tolua.cast(ret:getParent(), "cc.LayerMultiplex"):switchTo(0)
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
back:registerScriptTapHandler(goBack)
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local menu = cc.Menu:create()
|
2013-04-03 16:29:16 +08:00
|
|
|
menu:addChild(item)
|
|
|
|
menu:addChild(back)
|
|
|
|
|
|
|
|
ret:addChild(menu)
|
|
|
|
menu:alignItemsVertically()
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
menu:setPosition(cc.p(s.width/2, s.height/2))
|
2013-04-05 16:13:04 +08:00
|
|
|
|
2013-04-03 16:29:16 +08:00
|
|
|
ret:setTouchEnabled(true)
|
2013-05-23 15:39:41 +08:00
|
|
|
--[[
|
2013-04-03 16:29:16 +08:00
|
|
|
local function onNodeEvent(event)
|
|
|
|
if event == "enter" then
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Director:getInstance():getTouchDispatcher():addTargetedDelegate(ret, -129, false)
|
2013-04-03 16:29:16 +08:00
|
|
|
elseif event == "exit" then
|
2013-05-23 15:39:41 +08:00
|
|
|
-- item:release()
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ret:registerScriptHandler(onNodeEvent)
|
2013-05-23 15:39:41 +08:00
|
|
|
]]--
|
2013-04-03 16:29:16 +08:00
|
|
|
|
|
|
|
local function onTouchEvent(eventType, x, y)
|
|
|
|
if eventType == "began" then
|
|
|
|
return true
|
|
|
|
elseif eventType == "moved" then
|
|
|
|
if item ~= nil then
|
2013-08-20 13:44:37 +08:00
|
|
|
item:removeFromParent(true)
|
2013-05-23 15:39:41 +08:00
|
|
|
--item:release()
|
|
|
|
--item = nil
|
2013-04-03 16:29:16 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-05-23 15:39:41 +08:00
|
|
|
ret:registerScriptTouchHandler(onTouchEvent,false,-129,false)
|
2013-04-03 16:29:16 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
function MenuTestMain()
|
|
|
|
cclog("MenuTestMain")
|
2013-08-20 13:44:37 +08:00
|
|
|
local scene = cc.Scene:create()
|
2013-04-03 16:29:16 +08:00
|
|
|
|
|
|
|
local pLayer1 = MenuLayerMainMenu()
|
|
|
|
local pLayer2 = MenuLayer2()
|
|
|
|
|
|
|
|
local pLayer3 = MenuLayer3()
|
|
|
|
local pLayer4 = MenuLayer4()
|
2013-11-19 14:32:17 +08:00
|
|
|
local pLayer5 = BugsTest()
|
|
|
|
local pLayer6 = RemoveMenuItemWhenMove()
|
2013-04-03 16:29:16 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.LayerMultiplex:create(pLayer1,
|
|
|
|
pLayer2,
|
|
|
|
pLayer3,
|
|
|
|
pLayer4,
|
|
|
|
pLayer5,
|
2013-11-19 14:32:17 +08:00
|
|
|
pLayer6 )
|
2013-04-03 16:29:16 +08:00
|
|
|
|
2013-04-05 16:13:04 +08:00
|
|
|
scene:addChild(layer, 0)
|
2013-04-03 16:29:16 +08:00
|
|
|
scene:addChild(CreateBackMenuItem())
|
|
|
|
return scene
|
|
|
|
end
|