コード例 #1
0
ファイル: OsuUserStatsScreen.cpp プロジェクト: McKay42/McOsu
void OsuUserStatsScreen::rebuildScoreButtons(UString playerName)
{
	// since this score list can grow very large, UI elements are not cached, but rebuilt completely every time

	// hard reset (delete)
	m_scores->getContainer()->clear();
	m_scoreButtons.clear();

	// TODO: optimize db accesses by caching a hashmap from md5hash -> OsuBeatmap*, currently it just does a loop over all diffs of all beatmaps (for every score here)
	OsuDatabase *db = m_osu->getSongBrowser()->getDatabase();
	std::vector<OsuDatabase::Score*> scores = db->getPlayerPPScores(playerName).ppScores;
	for (int i=scores.size()-1; i>=std::max(0, (int)scores.size() - osu_ui_top_ranks_max.getInt()); i--)
	{
		const float weight = OsuDatabase::getWeightForIndex(scores.size()-1-i);

		OsuBeatmapDifficulty *diff = db->getBeatmapDifficulty(scores[i]->md5hash);

		UString title = "...";
		if (diff != NULL)
		{
			title = diff->artist;
			title.append(" - ");
			title.append(diff->title);
			title.append(" [");
			title.append(diff->name);
			title.append("]");
		}

		OsuUISongBrowserScoreButton *button = new OsuUISongBrowserScoreButton(m_osu, NULL, 0, 0, 300, 100, "", OsuUISongBrowserScoreButton::STYLE::TOP_RANKS);
		button->setScore(*scores[i], scores.size()-i, title, weight);
		button->setClickCallback( fastdelegate::MakeDelegate(this, &OsuUserStatsScreen::onScoreClicked) );

		m_scoreButtons.push_back(button);
		m_scores->getContainer()->addBaseUIElement(button);
	}

	m_userButton->setText(playerName);
	m_osu->getOptionsMenu()->setUsername(playerName); // force update textbox to avoid shutdown inconsistency
	m_userButton->updateUserStats();

	updateLayout();
}