function setupMMText( textStr, xOffset, yOffset ) textToAdd = MOAITextBox.new () textToAdd:setFont ( font ) textToAdd:setRect ( 0, 0, 240, 40 ) textToAdd:setLoc( xOffset, yOffset ) textToAdd:setAlignment ( MOAITextBox.CENTER_JUSTIFY ) layer:insertProp ( textToAdd ) textToAdd:setColor ( 0.8, 0.98, 0.55, 1 ) textToAdd:setString( textStr ) textToAdd:setPriority( 3 ) MOAIPSM.setTextBoxShadow( textToAdd.textBoxID ) end mmEntryInterval = 60 mmStartNewGameY = 120 mmLeaderboardsY = mmStartNewGameY + mmEntryInterval mmOptionsY = mmLeaderboardsY + mmEntryInterval mmTutorialY = mmOptionsY + mmEntryInterval mmCreditsY = mmTutorialY + mmEntryInterval --mmExitY = mmEntryInterval * 6 local cursorLoc = mmStartNewGameY local mmHighlightProp = nil local mmBurger1Prop = nil local mmBurger2Prop = nil function mainMenuSetup() local mmBackgroundGfx = MOAIGfxQuad2D.new() mmBackgroundGfx:setTexture( MM_BACKGROUND ) mmBackgroundGfx:setRect( 0, 0, 580, 544 ) mmBackgroundGfx:setUVRect ( 0, 0, 1, 1 ) local mmBackground = MOAIProp2D.new() mmBackground:setDeck( mmBackgroundGfx ) layer:insertProp( mmBackground ) mmBackground:setLoc( 190, 0 ) mmBackground:setPriority( 1 ) setupMMText( "Play", 360, mmStartNewGameY ) setupMMText( "Options", 360, mmOptionsY ) setupMMText( "Leaderboards", 360, mmLeaderboardsY ) setupMMText( "How to Play", 360, mmTutorialY ) setupMMText( "Credits", 360, mmCreditsY ) -- setupMMText( "Exit", 500, mmExitY ) local mmHighlightGfx = MOAIGfxQuad2D.new() mmHighlightGfx:setTexture( MM_HIGHLIGHT ) mmHighlightGfx:setRect( 0, 0, 410, 99 ) mmHighlightGfx:setUVRect ( 0, 0, 1, 1 ) mmHighlight = MOAIProp2D.new() mmHighlight:setDeck( mmHighlightGfx ) mmHighlight:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE_MINUS_SRC_ALPHA ) mmHighlight:setLoc( 275, cursorLoc - 30 ) mmHighlight:setPriority( 2 ) if MOAIEnvironment.osBrand == "PSM" then mmHighlight:setColor( 1.0, 1.0, 1.0, 0.5 ) else mmHighlight:setColor( 0.5, 0.5, 0.5, 0.5 ) end layer:insertProp( mmHighlight ) local burger1Gfx = MOAIGfxQuad2D.new () burger1Gfx:setTexture( BBQ_BURGER ) burger1Gfx:setRect( 0, 0, 30, 26 ) burger1Gfx:setUVRect ( 0, 0, 1, 1 ) mmBurger1Prop = MOAIProp2D.new() mmBurger1Prop:setDeck( burger1Gfx ) layer:insertProp( mmBurger1Prop ) mmBurger1Prop:setLoc( 285, cursorLoc + 5 ) mmBurger1Prop:setPriority( 2 ) mmBurger2Prop = MOAIProp2D.new() mmBurger2Prop:setDeck( burger1Gfx ) layer:insertProp( mmBurger2Prop ) mmBurger2Prop:setLoc( 650, cursorLoc + 5 ) mmBurger2Prop:setPriority( 2 ) setupScreenWithTitle( "MAIN MENU", 0 ) inputCallback = mainMenuOnInput -- initialize values -- allocate resources -- spin up threads end function mainMenuTeardown() layer:clear() -- spin down threads -- clean up resources end function mainMenuTeardownText() layer:clear() local mmBackgroundGfx = MOAIGfxQuad2D.new() mmBackgroundGfx:setTexture( MM_BACKGROUND ) mmBackgroundGfx:setRect( 0, 0, 580, 544 ) mmBackgroundGfx:setUVRect ( 0, 0, 1, 1 ) local mmBackground = MOAIProp2D.new() mmBackground:setDeck( mmBackgroundGfx ) layer:insertProp( mmBackground ) mmBackground:setLoc( 190, 0 ) mmBackground:setPriority( 1 ) end function mainMenuOnInput( key, isDown ) if (key == KEY_CONFIRM or key == KEY_PAUSE) and not isDown then SFX["MENU_SELECT"]:play() if cursorLoc == mmStartNewGameY then -- this sucks changeGameState(GAME_STATE_CHARACTER_SELECT) elseif cursorLoc == mmOptionsY then changeGameState(GAME_STATE_OPTIONS) elseif cursorLoc == mmLeaderboardsY then changeGameState(GAME_STATE_LEADERBOARDS) elseif cursorLoc == mmTutorialY then changeGameState(GAME_STATE_TUTORIAL) elseif cursorLoc == mmCreditsY then changeGameState(GAME_STATE_CREDITS) -- elseif cursorLoc == mmExitY then -- os.exit() else print("Error: invalid cursorY: " .. tostring(cursorY)) end elseif key == KEY_DOWN and not isDown then SFX["MENU_MOVE_L"]:play() if cursorLoc < mmCreditsY then cursorLoc = cursorLoc + mmEntryInterval mmHighlight:moveLoc( 0, mmEntryInterval ) mmBurger1Prop:moveLoc( 0, mmEntryInterval ) mmBurger2Prop:moveLoc( 0, mmEntryInterval ) end elseif key == KEY_UP and not isDown then SFX["MENU_MOVE_R"]:play() if cursorLoc > mmStartNewGameY then cursorLoc = cursorLoc - mmEntryInterval mmHighlight:moveLoc( 0, -mmEntryInterval ) mmBurger1Prop:moveLoc( 0, -mmEntryInterval ) mmBurger2Prop:moveLoc( 0, -mmEntryInterval ) end elseif key == KEY_CANCEL and not isDown then SFX["MENU_BACK"]:play() changeGameState(GAME_STATE_SPLASH) end end