|
From: Markus R. <god...@us...> - 2009-07-29 15:35:58
|
Module: performous
Branch: master
Commit: 3a3638414d016f922731b61d0d05ed9a77f69729
Author: Markus Raab <un...@ma...>
Date: Wed Jul 29 09:28:06 2009 +0200
Search for pictures in path_pictures
---
data/performous.xml | 10 ++++++++++
game/players.cc | 23 ++++++++++++++++++++++-
game/screen_players.cc | 8 ++++++--
3 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/data/performous.xml b/data/performous.xml
index 29dc585..8e894da 100644
--- a/data/performous.xml
+++ b/data/performous.xml
@@ -192,4 +192,14 @@
<long>Where to recursively look for songs.</long>
</locale>
</entry>
+ <entry name="system/path_pictures" type="string_list">
+ <stringvalue>/usr/local/share/games/performous/pictures</stringvalue>
+ <stringvalue>/usr/share/games/performous/pictures</stringvalue>
+ <stringvalue>../pictures/</stringvalue><!-- For Windows where the program is started in bin/ -->
+ <stringvalue>~/.performous/pictures/</stringvalue>
+ <locale name="C">
+ <short>Picture folders</short>
+ <long>Where to look for pictures of players.</long>
+ </locale>
+ </entry>
</performous>
diff --git a/game/players.cc b/game/players.cc
index 93512d4..9eeb442 100644
--- a/game/players.cc
+++ b/game/players.cc
@@ -1,6 +1,10 @@
#include "players.hh"
+#include "fs.hh"
+#include "configuration.hh"
+
#include <fstream>
+#include <iostream>
#include <boost/regex.hpp>
#include <libxml++/libxml++.h>
@@ -67,8 +71,25 @@ void Players::update() {
void Players::addPlayer (std::string const& name, std::string const& picture) {
PlayerItem pi;
pi.name = name;
- pi.path = "";
pi.picture = picture;
+ pi.path = "";
+
+ if (pi.picture != "") // no picture, so don't search path
+ {
+ ConfigItem::StringList const& sl = config["system/path_pictures"].sl();
+ typedef std::set<fs::path> dirs;
+ dirs d;
+ std::transform(sl.begin(), sl.end(), std::inserter(d, d.end()), pathMangle);
+
+ for (dirs::const_iterator it = d.begin(); it != d.end(); ++it) {
+ if (!fs::exists(*it)) continue; // as long as it does not exists
+ pi.path = it->file_string();
+ }
+
+ if (pi.path != "") std::cout << "Found " << pi.picture << " in " << pi.path << std::endl;
+ else std::cout << "Not found " << pi.picture << std::endl;
+ }
+
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
diff --git a/game/screen_players.cc b/game/screen_players.cc
index 7435d5f..0333213 100644
--- a/game/screen_players.cc
+++ b/game/screen_players.cc
@@ -160,8 +160,12 @@ void ScreenPlayers::draw() {
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;
- try { cover = &m_covers[player_display.path + player_display.picture]; } catch (std::exception const&) {}
+ Surface* cover = 0;
+ if (player_display.picture != "")
+ {
+ 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;
|