void ScoreLoopThread::LoadLeaderboard(AppData_t *app, SC_ScoresSearchList_t searchList, unsigned int count) { /* Create a ScoresController */ SC_Error_t rc = SC_Client_CreateScoresController(app->client, &app->scoresController, LoadLeaderboardCompletionCallback, app); if (rc != SC_OK) { HandleError(app, rc); return; } /* Configure the Controller */ rc = SC_ScoresController_SetSearchList(app->scoresController, searchList); if (rc != SC_OK) { SC_ScoresController_Release(app->scoresController); /* Cleanup Controller */ HandleError(app, rc); return; } SC_Range_t range; range.offset = 0; range.length = count; /* Load the Leaderboard for the given score and count */ rc = SC_ScoresController_LoadScores(app->scoresController, range); if (rc != SC_OK) { SC_ScoresController_Release(app->scoresController); /* Cleanup Controller */ HandleError(app, rc); return; } qDebug() << "Loading Leaderboard..."; }
void ScoreLoopThread::LoadLeaderboardAroundScore(AppData_t *app, SC_Score_h score, SC_ScoresSearchList_t searchList, unsigned int count) { /* Create a ScoresController */ SC_Error_t rc = SC_Client_CreateScoresController(app->client, &app->scoresController, LoadLeaderboardCompletionCallback, app); if (rc != SC_OK) { HandleError(app, rc); return; } /* Configure the Controller */ SC_ScoresController_SetMode(app->scoresController, SC_Score_GetMode(score)); rc = SC_ScoresController_SetSearchList(app->scoresController, searchList); if (rc != SC_OK) { SC_ScoresController_Release(app->scoresController); /* Cleanup Controller */ HandleError(app, rc); return; } /* Load the Leaderboard for the given score and count */ rc = SC_ScoresController_LoadScoresAroundScore(app->scoresController, score, count); if (rc != SC_OK) { SC_ScoresController_Release(app->scoresController); /* Cleanup Controller */ HandleError(app, rc); return; } qDebug() << "Loading Leaderboard..."; }
CScores::~CScores() { UnLoad(); if (m_scoresController) SC_ScoresController_Release(m_scoresController); if (m_scoreController) SC_ScoreController_Release(m_scoreController); if (m_rankingController) SC_RankingController_Release(m_rankingController); if (m_userController) SC_UserController_Release(m_userController); }
void ScoreLoopThread::LoadLeaderboardCompletionCallback(void *userData, SC_Error_t completionStatus) { /* Get the application from userData argument */ AppData_t *app = (AppData_t *) userData; /* Check completion status */ if (completionStatus != SC_OK) { SC_ScoresController_Release(app->scoresController); /* Cleanup Controller */ HandleError(app, completionStatus); return; } /* Just log the scores here for demonstration purposes */ SC_ScoreList_h scoreList = SC_ScoresController_GetScores(app->scoresController); if (scoreList == NULL) { SC_ScoresController_Release(app->scoresController); /* Cleanup Controller */ HandleError(app, SC_NOT_FOUND); return; } qDebug() << "Done loading Leaderboard"; /* Get the score formatter here - remember that you need to add a * scoreloop/SLScoreFormatter.strings file to your asset files in order to retrieve a formatter. */ SC_ScoreFormatter_h scoreFormatter = SC_Client_GetScoreFormatter(app->client); if (!scoreFormatter) { SC_ScoresController_Release(app->scoresController); /* Cleanup Controller */ HandleError(app, SC_NOT_FOUND); return; } QVariantList leaderboardData; unsigned int i, numScores = SC_ScoreList_GetCount(scoreList); for (i = 0; i < numScores; ++i) { SC_Score_h score = SC_ScoreList_GetAt(scoreList, i); SC_User_h user = SC_Score_GetUser(score); SC_String_h login = user ? SC_User_GetLogin(user) : NULL; SC_String_h formattedScore; /* Format the score - we take ownership of string */ int rc = SC_ScoreFormatter_FormatScore(scoreFormatter, score, SC_SCORE_FORMAT_DEFAULT, &formattedScore); if (rc != SC_OK) { HandleError(app, rc); return; } qDebug() << " Rank: " << SC_Score_GetRank(score) << ", Result: " << SC_String_GetData(formattedScore) << ", User: "******"<unknown>"); QVariantMap scoreData; scoreData["rank"] = SC_Score_GetRank(score); scoreData["formattedScore"] = SC_String_GetData(formattedScore); scoreData["username"] = login ? SC_String_GetData(login) : "<unknown>"; leaderboardData.append(scoreData); /* Release the string */ SC_String_Release(formattedScore); } emit(instance()->LoadLeaderboardCompleted(leaderboardData)); /* Cleanup Controller */ SC_ScoresController_Release(app->scoresController); /* Set an Award as achieved here just for demonstration purposes */ //AchieveAward(app, SCORELOOP_AN_AWARD_ID); }