|
From: Markus R. <god...@us...> - 2009-07-29 15:34:22
|
Module: performous
Branch: hiscore
Commit: 43dbba757fffda37d8629e84b70b48f517b7f0e4
Author: Markus Raab <un...@ma...>
Date: Fri Jul 24 19:15:02 2009 +0200
Now name from Players is taken
BUG: always the first name
independend from selection
---
game/highscore.cc | 3 +++
game/highscore.hh | 4 +++-
game/main.cc | 2 +-
game/screen_sing.cc | 9 +++++----
game/screen_sing.hh | 10 ++++++----
5 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/game/highscore.cc b/game/highscore.cc
index 559aab2..17768f0 100644
--- a/game/highscore.cc
+++ b/game/highscore.cc
@@ -115,6 +115,9 @@ void HighScore::save()
void HighScore::addNewHighscore(std::string name, int score)
{
+ // do not allow invalid name
+ if (name == "") return;
+
HighScoreItem hsi;
hsi.name = name;
hsi.score = score;
diff --git a/game/highscore.hh b/game/highscore.hh
index 032eb14..bed7ab8 100644
--- a/game/highscore.hh
+++ b/game/highscore.hh
@@ -50,7 +50,9 @@ class HighScore {
if (score < 500) return false;
return score > m_scores[2].score;
}
- /**Add a new entry to the highscore.*/
+ /**Add a new entry to the highscore.
+ It will do nothing on empty name.
+ */
void addNewHighscore(std::string name, int score);
private:
static const int m_maxEntries = 10;
diff --git a/game/main.cc b/game/main.cc
index 53744a6..dd7f5be 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -138,7 +138,7 @@ void mainLoop() {
Window window(config["graphic/window_width"].i(), config["graphic/window_height"].i(), config["graphic/fullscreen"].b(), config["graphic/fs_width"].i(), config["graphic/fs_height"].i());
sm.addScreen(new ScreenIntro("Intro", audio, capture));
sm.addScreen(new ScreenSongs("Songs", audio, songs));
- sm.addScreen(new ScreenSing("Sing", audio, capture));
+ sm.addScreen(new ScreenSing("Sing", audio, capture, players));
sm.addScreen(new ScreenPractice("Practice", audio, capture));
sm.addScreen(new ScreenConfiguration("Configuration", audio));
sm.addScreen(new ScreenPlayers("Players", audio, players));
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index bc49fd7..8460735 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -70,7 +70,7 @@ void ScreenSing::manageEvent(SDL_Event event) {
if (key == SDLK_ESCAPE || key == SDLK_q) sm->activateScreen("Songs");
else if (key == SDLK_RETURN) {
if (m_score_window.get()) sm->activateScreen("Songs"); // Score window visible -> Enter quits
- else if (status == Song::FINISHED) m_score_window.reset(new ScoreWindow(*m_engine, *m_song)); // Song finished, but no score window -> show it
+ else if (status == Song::FINISHED) m_score_window.reset(new ScoreWindow(*m_engine, *m_song, m_allplayers)); // Song finished, but no score window -> show it
}
else if (key == SDLK_SPACE || key == SDLK_PAUSE) m_audio.togglePause();
if (m_score_window.get()) return;
@@ -179,7 +179,7 @@ void ScreenSing::draw() {
}
else if (!m_audio.isPlaying() || (status == Song::FINISHED && m_audio.getLength() - time < 3.0)) {
m_quitTimer.setValue(QUIT_TIMEOUT);
- m_score_window.reset(new ScoreWindow(*m_engine, *m_song));
+ m_score_window.reset(new ScoreWindow(*m_engine, *m_song, m_allplayers));
}
}
@@ -208,8 +208,9 @@ void ScreenSing::drawScores() {
}
}
-ScoreWindow::ScoreWindow(Engine& e, Song const& song):
+ScoreWindow::ScoreWindow(Engine& e, Song const& song, Players & allplayers):
m_song(song),
+ m_allplayers(allplayers),
m_pos(0.8, 2.0),
m_bg(getThemePath("score_window.svg")),
m_scoreBar(getThemePath("score_bar_bg.svg"), getThemePath("score_bar_fg.svg"), ProgressBar::VERTICAL, 0.0, 0.0, false),
@@ -240,7 +241,7 @@ ScoreWindow::ScoreWindow(Engine& e, Song const& song):
ScreenManager* sm = ScreenManager::getSingletonPtr();
// show the players screen
sm->activateScreen("Players");
- hi.addNewHighscore(getenv ("USER"), score);
+ hi.addNewHighscore(m_allplayers.current().name, score);
}
}
try {
diff --git a/game/screen_sing.hh b/game/screen_sing.hh
index 0e55ce7..e5bdda5 100644
--- a/game/screen_sing.hh
+++ b/game/screen_sing.hh
@@ -21,12 +21,13 @@
class ScoreWindow {
public:
/// constructor
- ScoreWindow(Engine & e, Song const& song);
+ ScoreWindow(Engine & e, Song const& song, Players & players);
/// draws ScoreWindow
void draw();
private:
Song const& m_song;
+ Players & m_allplayers;
AnimValue m_pos;
Surface m_bg;
ProgressBar m_scoreBar;
@@ -40,8 +41,8 @@ class ScoreWindow {
class ScreenSing: public Screen {
public:
/// constructor
- ScreenSing(std::string const& name, Audio& audio, Capture& capture):
- Screen(name), m_audio(audio), m_capture(capture), m_latencyAV()
+ ScreenSing(std::string const& name, Audio& audio, Capture& capture, Players & allplayers):
+ Screen(name), m_audio(audio), m_capture(capture), m_allplayers(allplayers), m_latencyAV()
{}
void enter();
void exit();
@@ -56,9 +57,10 @@ class ScreenSing: public Screen {
private:
void drawScores();
Audio& m_audio;
+ Capture& m_capture;
+ Players& m_allplayers;
boost::shared_ptr<Song> m_song; /// Pointer to the current song
boost::scoped_ptr<ScoreWindow> m_score_window;
- Capture& m_capture;
boost::scoped_ptr<ProgressBar> m_progress;
boost::scoped_ptr<Surface> m_background;
boost::scoped_ptr<Video> m_video;
|