|
From: Markus R. <god...@us...> - 2009-07-29 15:34:45
|
Module: performous
Branch: hiscore
Commit: c12838d7aa61dc4c5e1de5dbdd00f59e6e3f1b44
Author: Markus Raab <un...@ma...>
Date: Tue Jul 28 10:34:46 2009 +0200
Loading pictures works
---
game/players.cc | 21 ++++++++++++++++++---
game/players.hh | 10 +++++++---
game/screen_players.cc | 7 ++-----
3 files changed, 27 insertions(+), 11 deletions(-)
diff --git a/game/players.cc b/game/players.cc
index 2ae321d..93512d4 100644
--- a/game/players.cc
+++ b/game/players.cc
@@ -29,7 +29,15 @@ void Players::load() {
{
xmlpp::Element& element = dynamic_cast<xmlpp::Element&>(**it);
xmlpp::Attribute* a = element.get_attribute("name");
- addPlayer(a->get_value());
+ xmlpp::NodeSet n2 = element.find("picture");
+ std::string picture;
+ if (!n2.empty()) // optional picture element
+ {
+ xmlpp::Element& element2 =dynamic_cast<xmlpp::Element&>(**n2.begin());
+ xmlpp::TextNode* tn = element2.get_child_text();
+ picture = tn->get_content();
+ }
+ addPlayer(a->get_value(), picture);
}
}
@@ -42,6 +50,11 @@ void Players::save() {
{
xmlpp::Element* player = players->add_child("player");
player->set_attribute("name", it->name);
+ if (it->picture != "")
+ {
+ xmlpp::Element* picture = player->add_child("picture");
+ picture->add_child_text(it->picture);
+ }
}
doc.write_to_file_formatted(m_filename, "UTF-8");
@@ -51,9 +64,11 @@ void Players::update() {
if (m_dirty) filter_internal();
}
-void Players::addPlayer (std::string const& name) {
+void Players::addPlayer (std::string const& name, std::string const& picture) {
PlayerItem pi;
pi.name = name;
+ pi.path = "";
+ pi.picture = picture;
players_t::const_iterator it = std::find(m_players.begin(), m_players.end(), pi);
if (it != m_players.end()) return; // dont do anything, player exists
@@ -104,7 +119,7 @@ int main(int argc, char** argv)
for (size_t i=0; i<p.size(); i++)
{
- std::cout << p[i].name << std::endl;
+ std::cout << p[i].name << " picture: " << p[i].picture << std::endl;
}
return 0;
diff --git a/game/players.hh b/game/players.hh
index e956828..924b13a 100644
--- a/game/players.hh
+++ b/game/players.hh
@@ -15,9 +15,10 @@
*/
struct PlayerItem {
std::string name; /// unique name, link to highscore
+ std::string path; /// a path to a picture shown
+ std::string picture; /// + the filename for it
/* Future ideas
std::string displayedName; /// artist name, short name, nick (can be changed)
- std::string picture; /// a path to a picture shown
std::map<std::string, int> scores; /// map between a Song and the highest score the Player achieved
*/
@@ -63,10 +64,13 @@ class Players: boost::noncopyable {
}
void save();
void update();
- void addPlayer (std::string const& name);
+ void addPlayer (std::string const& name, std::string const& picture = "");
/// const array access
- PlayerItem operator[](std::size_t pos) const { return m_filtered[pos]; }
+ PlayerItem operator[](std::size_t pos) const {
+ if (pos < m_filtered.size()) return m_filtered[pos];
+ else return PlayerItem();
+ }
/// number of songs
size_t size() const { return m_filtered.size(); };
/// true if empty
diff --git a/game/screen_players.cc b/game/screen_players.cc
index 872c0bf..7435d5f 100644
--- a/game/screen_players.cc
+++ b/game/screen_players.cc
@@ -158,13 +158,10 @@ void ScreenPlayers::draw() {
int baseidx = spos + 1.5; --baseidx; // Round correctly
double shift = spos - baseidx;
for (int i = -2; i < 5; ++i) {
+ PlayerItem player_display = m_players[baseidx + i];
if (baseidx + i < 0 || baseidx + i >= int(ss)) continue;
Surface* cover = NULL;
- /*
- Song& song_display = m_players[baseidx + i];
- // Fetch cover image from cache or try loading it
- if (!song_display.cover.empty()) try { cover = &m_covers[song_display.path + song_display.cover]; } catch (std::exception const&) {}
- */
+ try { cover = &m_covers[player_display.path + player_display.picture]; } catch (std::exception const&) {}
Surface& s = (cover ? *cover : *m_emptyCover);
double diff = (i == 0 ? (0.5 - fabs(shift)) * 0.07 : 0.0);
double y = 0.27 + 0.5 * diff;
|