local optionsOverlay = nil local optItems = { } local optsCurrentItem = 0 local optsAnim = nil local optsControlSmackButton = nil local optsControlJumpButton = nil local optsXButtonGfx = nil local optsOButtonGfx = nil local optsSquareButtonGfx = nil -- TODO: -- add rows of data (#. score level) (normal font) - 10 max -- add 2 'buttons' (X Friends) (O Back) -- load the contents from a file -- write data to a file -- support reading from PSN leaderboard service function optionsSetString( textObj, prefix, option ) local optionStr = '\nOFF' if option == true then optionStr = '\nON' end textObj:setString( prefix .. optionStr ) end function setupControlDisplay() if MOAIEnvironment.osBrand == "PSM" then layer:removeProp( optsControlSmackButton ) layer:removeProp( optsControlJumpButton ) end if CURRENT_CONTROL_CFG == 0 then optsControlSmackButton:setDeck(optsSquareButtonGfx) optsControlJumpButton:setDeck(optsXButtonGfx) else optsControlSmackButton:setDeck(optsXButtonGfx) optsControlJumpButton:setDeck(optsOButtonGfx) end if MOAIEnvironment.osBrand == "PSM" then layer:insertProp( optsControlSmackButton ) layer:insertProp( optsControlJumpButton ) end end function optionsSetup() inputCallback = optionsOnInput local optsOverlayGfx = MOAIGfxQuad2D.new() optsOverlayGfx:setTexture( BLACK_BOX_IMAGE ) optsOverlayGfx:setRect( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT ) optsOverlay = MOAIProp2D.new() optsOverlay:setDeck( optsOverlayGfx ) optsOverlay:setColor( 0, 0, 0, 0.8 ) optsOverlay:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE_MINUS_SRC_ALPHA ) optsOverlay:setPriority( 10 ) local optsMusic = MOAITextBox.new () optsMusic:setFont ( font ) optsMusic:setRect ( 0, 0, 500, 70 ) optsMusic:setLoc( 230, 100 ) optsMusic:setAlignment ( MOAITextBox.CENTER_JUSTIFY ) optsMusic:setColor ( 0.8, 0.98, 0.55, 1 ) optionsSetString( optsMusic, "MUSIC", CURRENT_MUSIC_ON ) optsMusic:setPriority( 11 ) local optsSFX = MOAITextBox.new () optsSFX:setFont ( font ) optsSFX:setRect ( 0, 0, 500, 80 ) optsSFX:setLoc( 230, 200 ) optsSFX:setAlignment ( MOAITextBox.CENTER_JUSTIFY ) optsSFX:setColor ( 0.8, 0.98, 0.55, 1 ) optionsSetString( optsSFX, "SFX", CURRENT_SFX_ON ) optsSFX:setPriority( 11 ) local optsControls = MOAITextBox.new () optsControls:setFont ( font ) optsControls:setRect ( 0, 0, 500, 40 ) optsControls:setLoc( 230, 300 ) optsControls:setAlignment ( MOAITextBox.CENTER_JUSTIFY ) optsControls:setColor ( 0.8, 0.98, 0.55, 1 ) optsControls:setString( "CONTROLS" ) optsControls:setPriority( 11 ) local optsSmackText = MOAITextBox.new () optsSmackText:setFont ( font ) optsSmackText:setRect ( 0, 0, 300, 40 ) optsSmackText:setLoc( 366, 335 ) optsSmackText:setAlignment ( MOAITextBox.LEFT_JUSTIFY ) optsSmackText:setColor ( 0.8, 0.98, 0.55, 1 ) optsSmackText:setString( "SMACK" ) optsSmackText:setPriority( 11 ) local optsJumpText = MOAITextBox.new () optsJumpText:setFont ( font ) optsJumpText:setRect ( 0, 0, 300, 40 ) optsJumpText:setLoc( 544, 335 ) optsJumpText:setAlignment ( MOAITextBox.LEFT_JUSTIFY ) optsJumpText:setColor ( 0.8, 0.98, 0.55, 1 ) optsJumpText:setString( "JUMP" ) optsJumpText:setPriority( 11 ) optsXButtonGfx = MOAIGfxQuad2D.new() optsXButtonGfx:setTexture( UI_CONFIRM_IMAGE ) optsXButtonGfx:setRect( 0, 0, 44, 44 ) optsXButtonGfx:setUVRect ( 0, 0, 1, 1 ) optsControlSmackButton = MOAIProp2D.new() optsControlSmackButton:setDeck( optsXButtonGfx ) optsControlSmackButton:setPriority( 11 ) layer:insertProp( optsControlSmackButton ) optsControlSmackButton:setLoc( 322, 335 ) optsOButtonGfx = MOAIGfxQuad2D.new() optsOButtonGfx:setTexture( UI_BACK_IMAGE ) optsOButtonGfx:setRect( 0, 0, 44, 44 ) optsOButtonGfx:setUVRect ( 0, 0, 1, 1 ) optsControlJumpButton = MOAIProp2D.new() optsControlJumpButton:setDeck( optsOButtonGfx ) optsControlJumpButton:setPriority( 11 ) layer:insertProp( optsControlJumpButton ) optsControlJumpButton:setLoc( 500, 335 ) optsSquareButtonGfx = MOAIGfxQuad2D.new() optsSquareButtonGfx:setTexture( UI_SQR_BUTTON_IMAGE ) optsSquareButtonGfx:setRect( 0, 0, 44, 44 ) optsSquareButtonGfx:setUVRect ( 0, 0, 1, 1 ) layer:insertProp( optsOverlay ) layer:insertProp( optsMusic ) layer:insertProp( optsSFX ) layer:insertProp( optsControls ) layer:insertProp( optsSmackText ) layer:insertProp( optsJumpText ) optsCurrentItem = 0 optItems = { optsMusic, optsSFX, optsControls } optsActiveFadeOut() setupScreenWithTitle( "OPTIONS", 11 ) setupControlDisplay() -- initialize values -- allocate resources -- spin up threads end function optionsTeardown() layer:clear() -- spin down threads -- clean up resources end local optsCanFade = true function optsActiveFadeOut() if optsCanFade then optsAnim = optItems[optsCurrentItem+1]:seekColor(0.8, 0.98, 0.55, 0.25, 1, MOAIEaseType.LINEAR) optsAnim:setListener( MOAIAction.EVENT_STOP, optsActiveFadeIn ) end end function optsActiveFadeIn() if optsCanFade then optsAnim = optItems[optsCurrentItem+1]:seekColor(0.8, 0.98, 0.55, 1, 1, MOAIEaseType.LINEAR) optsAnim:setListener( MOAIAction.EVENT_STOP, optsActiveFadeOut ) end end function optionsOnInput( key, isDown ) if (key == KEY_CONFIRM) and not isDown then SFX["MENU_SELECT"]:play() if optsCurrentItem == 0 then CURRENT_MUSIC_ON = not CURRENT_MUSIC_ON optionsSetString( optItems[optsCurrentItem+1], "MUSIC", CURRENT_MUSIC_ON ) if CURRENT_MUSIC_ON then backgroundMusic:setVolume(MUSIC_VOLUME) else backgroundMusic:setVolume(0.0) end elseif optsCurrentItem == 1 then CURRENT_SFX_ON = not CURRENT_SFX_ON optionsSetString( optItems[optsCurrentItem+1], "SFX", CURRENT_SFX_ON ) if CURRENT_SFX_ON then for k, v in pairs(SFX) do if v.audioID ~= nil then -- my spatula_airtime hack breaks things v:setVolume(1.0) end end else for k, v in pairs(SFX) do if v.audioID ~= nil then -- my spatula_airtime hack breaks things v:setVolume(0.0) end end end elseif optsCurrentItem == 2 then print("Toggle control scheme") if CURRENT_CONTROL_CFG == 0 then CURRENT_CONTROL_CFG = 1 else CURRENT_CONTROL_CFG = 0 end setupControlDisplay() else print( "INVALID STATE FOR optsCurrentItem: " .. tostring(optsCurrentItem) ) end elseif key == KEY_CANCEL and not isDown then -- z SFX["MENU_BACK"]:play() writeSettings() changeGameState(GAME_STATE_MENU) elseif key == KEY_DOWN and not isDown then SFX["MENU_MOVE_L"]:play() optsCanFade = false optsAnim:stop() optsCanFade = true optItems[optsCurrentItem+1]:setColor( 0.8, 0.98, 0.55, 1 ) optsCurrentItem = (optsCurrentItem + 1) % #optItems optsActiveFadeOut() elseif key == KEY_UP and not isDown then SFX["MENU_MOVE_R"]:play() optsCanFade = false optsAnim:stop() optsCanFade = true optItems[optsCurrentItem+1]:setColor( 0.8, 0.98, 0.55, 1 ) if optsCurrentItem - 1 < 0 then optsCurrentItem = #optItems - 1 -- stupid C# lua interpreter has modulus results that are negative? wtf? else optsCurrentItem = optsCurrentItem - 1 end optsActiveFadeOut() end end