Esempio n. 1
0
void CScores::OnRequestSuccess()
{
	m_listview->Clear();
	SC_ScoreList_h scores = SC_ScoresController_GetScores(m_scoresController);
	unsigned int count = SC_ScoreList_GetScoresCount(scores);
	int index;
	char buf[128];
	for (unsigned int i = 0; i < count; i++)
	{
		/* Get the i-th score */
		SC_Score_h score = SC_ScoreList_GetScore(scores, i);
		
		/* Get login of the score's user */
		SC_User_h user = SC_Score_GetUser(score);
		const char* login = SC_String_GetData(SC_User_GetLogin(user));
		sprintf(buf, "%d. %s", (int)SC_Score_GetRank(score), login);
		index = m_listview->AddItem(NULL, buf);
		m_listview->SetItemCaptionRighti(index, (int)SC_Score_GetResult(score));
		//Get OS type from Minor Result
		int OSindex = (int)SC_Score_GetMinorResult(score);
		if (OSindex < 0 && OSindex > 22)
			OSindex = 0;
		m_listview->SetItemSubtext(index, g_OScaptions[OSindex]);
	}
	if (m_curuserrank > 0)
	{
		if (m_curuserrank <= SC_PAGE_SCORES_COUNT && m_curuserrank < (int)m_listview->get_itemscount() + 1)
		{
			CGUIListItem *li = m_listview->get_item(m_curuserrank - 1);
			li->fontcolor = 0xff0000ff;
			m_listview->MoveItemToCenter(m_curuserrank - 1);
			FinishWait();
		}
		else
		{
			// Loading user score if rank > SC_PAGE_SCORES_COUNT
			// See OnRequestSuccessUser()
			SC_UserController_RequestUserDetail(m_userController);
			StartWait("Loading current user details");
		}
	}
	else
	{
		FinishWait();
	}	
	
}
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);
}