lbOverlay = nil local lbRows = { } function lbAddRow( rowNum ) local yOffset = 70 local rowNumText = MOAITextBox.new () rowNumText:setFont ( font ) rowNumText:setRect ( 0, 0, 400, 40 ) rowNumText:setLoc( -150, yOffset + rowNum * 40 ) rowNumText:setAlignment ( MOAITextBox.RIGHT_JUSTIFY ) rowNumText:setColor ( 0.8, 0.98, 0.55, 1 ) rowNumText:setString( tostring(rowNum) .. "." ) rowNumText:setPriority( 11 ) local scoreText = MOAITextBox.new () scoreText:setFont ( font ) scoreText:setRect ( 0, 0, 400, 40 ) scoreText:setLoc( -10, yOffset + rowNum * 40 ) scoreText:setAlignment ( MOAITextBox.RIGHT_JUSTIFY ) scoreText:setColor ( 0.8, 0.98, 0.55, 1 ) scoreText:setString( "40,000" ) scoreText:setPriority( 11 ) local levelText = MOAITextBox.new () levelText:setFont ( font ) levelText:setRect ( 0, 0, 300, 40 ) levelText:setLoc( 365, yOffset + rowNum * 40 ) levelText:setAlignment ( MOAITextBox.RIGHT_JUSTIFY ) levelText:setColor ( 0.8, 0.98, 0.55, 1 ) levelText:setString( "80" ) levelText:setPriority( 11 ) table.insert( lbRows, { rowNumText, scoreText, levelText } ) layer:insertProp( rowNumText ) layer:insertProp( scoreText ) layer:insertProp( levelText ) end function lbSetupRow( rowNum, rowData ) local currentVisualRow = lbRows[rowNum] if rowData ~= nil and rowData[1] ~= nil then currentVisualRow[2]:setString( tostring(rowData[1]) ) currentVisualRow[3]:setString( tostring(rowData[2]) ) else layer:removeProp( currentVisualRow[1] ) layer:removeProp( currentVisualRow[2] ) layer:removeProp( currentVisualRow[3] ) end end -- TODO: -- support reading from PSN leaderboard service function leaderboardsSetup() inputCallback = leaderboardsOnInput local lbOverlayGfx = MOAIGfxQuad2D.new() lbOverlayGfx:setTexture( BLACK_BOX_IMAGE ) lbOverlayGfx:setRect( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT ) lbOverlay = MOAIProp2D.new() lbOverlay:setDeck( lbOverlayGfx ) lbOverlay:setColor( 0, 0, 0, 0.8 ) lbOverlay:setBlendMode( MOAIProp2D.GL_SRC_ALPHA, MOAIProp2D.GL_ONE_MINUS_SRC_ALPHA ) lbOverlay:setPriority( 10 ) local lbScoreTitle = MOAITextBox.new () lbScoreTitle:setFont ( font ) lbScoreTitle:setRect ( 0, 0, 500, 40 ) lbScoreTitle:setLoc( 100, 75 ) lbScoreTitle:setAlignment ( MOAITextBox.CENTER_JUSTIFY ) lbScoreTitle:setColor ( 1, 1, 1, 1 ) lbScoreTitle:setString( "Score" ) lbScoreTitle:setPriority( 11 ) local lbLevelTitle = MOAITextBox.new () lbLevelTitle:setFont ( font ) lbLevelTitle:setRect ( 0, 0, 500, 40 ) lbLevelTitle:setLoc( 400, 75 ) lbLevelTitle:setAlignment ( MOAITextBox.CENTER_JUSTIFY ) lbLevelTitle:setColor ( 1, 1, 1, 1 ) lbLevelTitle:setString( "Level" ) lbLevelTitle:setPriority( 11 ) layer:insertProp( lbOverlay ) layer:insertProp( lbScoreTitle ) layer:insertProp( lbLevelTitle ) lbRows = { } for i = 1, 10 do lbAddRow( i ) lbSetupRow( i, CURRENT_LEADERBOARD_DATA[i] ) end setupScreenWithTitle( "LEADERBOARD", 11, true, false ) -- initialize values -- allocate resources -- spin up threads end function leaderboardsTeardown() layer:clear() -- spin down threads -- clean up resources end function leaderboardsOnInput( key, isDown ) if (key == KEY_CONFIRM) and not isDown then if MOAIEnvironment.osBrand ~= "PSM" then SFX["MENU_BACK"]:play() changeGameState(GAME_STATE_MENU) end elseif key == KEY_CANCEL and not isDown then -- z SFX["MENU_BACK"]:play() changeGameState(GAME_STATE_MENU) end end