|
From: Tapio V. <aa...@us...> - 2010-05-17 17:00:54
|
Module: performous
Branch: master
Commit: a64e3237b3a865651b0730627c0e2b58790375a9
Author: Tapio Vierros <tap...@gm...>
Date: Mon Apr 12 20:48:04 2010 +0300
Easy creation of "pop-up" messages for InstrumentGraph.
---
game/dancegraph.cc | 5 +++--
game/guitargraph.cc | 8 +++++---
game/instrumentgraph.cc | 27 ++++-----------------------
game/instrumentgraph.hh | 46 +++++++++++++++++++++++++++++++++++++++++-----
4 files changed, 53 insertions(+), 33 deletions(-)
diff --git a/game/dancegraph.cc b/game/dancegraph.cc
index 66c0ce7..814dfcf 100644
--- a/game/dancegraph.cc
+++ b/game/dancegraph.cc
@@ -234,8 +234,9 @@ void DanceGraph::engine() {
// Check if a long streak goal has been reached
if (m_streak >= getNextBigStreak(m_bigStreak)) {
- m_streakPopup.setTarget(1.0);
m_bigStreak = getNextBigStreak(m_bigStreak);
+ m_popups.push_back(Popup(boost::lexical_cast<std::string>(unsigned(m_bigStreak)) + "\nStreak!",
+ glutil::Color(1.0f, 0.0, 0.0), 1.0, m_popupText.get()));
}
}
@@ -475,5 +476,5 @@ void DanceGraph::drawInfo(double time, double offsetX, Dimensions dimensions) {
m_text.draw(boost::lexical_cast<std::string>(unsigned(m_streak)) + "/"
+ boost::lexical_cast<std::string>(unsigned(m_longestStreak)));
}
- drawPopups(time, offsetX, dimensions);
+ drawPopups(offsetX);
}
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 54e41ff..367784b 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -270,9 +270,10 @@ void GuitarGraph::engine() {
}
// Check if a long streak goal has been reached
if (m_streak >= getNextBigStreak(m_bigStreak)) {
- m_streakPopup.setTarget(1.0);
m_bigStreak = getNextBigStreak(m_bigStreak);
m_starmeter += streakStarBonus;
+ m_popups.push_back(Popup(boost::lexical_cast<std::string>(unsigned(m_bigStreak)) + "\nStreak!",
+ glutil::Color(1.0f, 0.0, 0.0), 1.0, m_popupText.get()));
}
// During GodMode, correctness is full, no matter what
if (m_starpower.get() > 0.01) m_correctness.setTarget(1.0, true);
@@ -288,7 +289,8 @@ void GuitarGraph::activateStarpower() {
if (canActivateStarpower()) {
m_starmeter = 0;
m_starpower.setValue(1.0);
- m_godmodePopup.setTarget(1.0);
+ m_popups.push_back(Popup("God Mode\nActivated!",
+ glutil::Color(0.3f, 0.0f, 1.0f), 0.666, m_popupText.get(), "Mistakes ignored!", &m_text));
}
}
@@ -884,7 +886,7 @@ void GuitarGraph::drawInfo(double time, double offsetX, Dimensions dimensions) {
}
}
}
- drawPopups(time, offsetX, dimensions);
+ drawPopups(offsetX);
}
/// Draw a bar for drum bass pedal/note
diff --git a/game/instrumentgraph.cc b/game/instrumentgraph.cc
index af627c4..bef10a3 100644
--- a/game/instrumentgraph.cc
+++ b/game/instrumentgraph.cc
@@ -1,28 +1,9 @@
#include "instrumentgraph.hh"
-void InstrumentGraph::drawPopups(double time, double offsetX, Dimensions dimensions) {
- // Draw streak pop-up for long streak intervals
- double streakAnim = m_streakPopup.get();
- if (streakAnim > 0.0) {
- double s = 0.2 * (1.0 + streakAnim);
- glColor4f(1.0f, 0.0f, 0.0f, 1.0 - streakAnim);
- m_popupText->render(boost::lexical_cast<std::string>(unsigned(m_bigStreak)) + "\nStreak!");
- m_popupText->dimensions().center(0.1).middle(offsetX).stretch(s,s);
- m_popupText->draw();
- if (streakAnim > 0.999) m_streakPopup.setTarget(0.0, true);
- }
- // Draw godmode activation pop-up
- double godAnim = m_godmodePopup.get();
- if (godAnim > 0.0) {
- float a = 1.0 - godAnim;
- float s = 0.2 * (1.0 + godAnim);
- glColor4f(0.3f, 0.0f, 1.0f, a);
- m_popupText->render("God Mode\nActivated!");
- m_popupText->dimensions().center(0.1).middle(offsetX).stretch(s,s);
- m_popupText->draw();
- m_text.dimensions.screenBottom(-0.02).middle(-0.12 + offsetX);
- m_text.draw("Mistakes ignored!", 1.0 - godAnim);
- if (godAnim > 0.999) m_godmodePopup.setTarget(0.0, true);
+void InstrumentGraph::drawPopups(double offsetX) {
+ for (Popups::iterator it = m_popups.begin(); it != m_popups.end(); ) {
+ if (!it->draw(offsetX)) { it = m_popups.erase(it); continue; }
+ ++it;
}
}
diff --git a/game/instrumentgraph.hh b/game/instrumentgraph.hh
index 5f032ca..8cff589 100644
--- a/game/instrumentgraph.hh
+++ b/game/instrumentgraph.hh
@@ -12,6 +12,44 @@
#include "glutil.hh"
#include "fs.hh"
+class Popup {
+ public:
+ /// Constructor
+ Popup(std::string msg, glutil::Color c, double speed, SvgTxtThemeSimple* popupText, std::string info = "", SvgTxtTheme* infoText = NULL):
+ m_msg(msg), m_color(c), m_anim(AnimValue(0.0, speed)), m_popupText(popupText), m_info(info), m_infoText(infoText)
+ {
+ m_anim.setTarget(1.0, false);
+ }
+ /// Draw the popup
+ /// Returns false if it is expired
+ bool draw(double offsetX) {
+ double anim = m_anim.get();
+ if (anim > 0.0 && m_popupText) {
+ float s = 0.2 * (1.0 + anim);
+ float a = 1.0 - anim;
+ m_color.a = a;
+ glColor4fv(m_color);
+ m_popupText->render(m_msg);
+ m_popupText->dimensions().center(0.1).middle(offsetX).stretch(s,s);
+ m_popupText->draw();
+ if (m_info != "" && m_infoText) {
+ m_infoText->dimensions.screenBottom(-0.02).middle(-0.12 + offsetX);
+ m_infoText->draw(m_info, a);
+ }
+ if (anim > 0.999) m_anim.setTarget(0.0, true);
+ } else return false;
+ return true;
+ }
+ private:
+ std::string m_msg; /// Popup text
+ glutil::Color m_color; /// Color
+ AnimValue m_anim; /// Animation timer
+ SvgTxtThemeSimple* m_popupText; /// Font for popup
+ std::string m_info; /// Text to show in the bottom
+ SvgTxtTheme* m_infoText; /// Font for the additional text
+};
+
+
class Song;
class InstrumentGraph {
@@ -23,8 +61,6 @@ class InstrumentGraph {
m_cx(0.0, 0.2), m_width(0.5, 0.4),
m_text(getThemePath("sing_timetxt.svg"), config["graphic/text_lod"].f()),
m_correctness(0.0, 5.0),
- m_streakPopup(0.0, 1.0),
- m_godmodePopup(0.0, 0.666),
m_score(),
m_scoreFactor(),
m_streak(),
@@ -64,15 +100,15 @@ class InstrumentGraph {
};
typedef std::vector<Event> Events;
Events m_events;
+ typedef std::vector<Popup> Popups;
+ Popups m_popups;
- void drawPopups(double time, double offsetX, Dimensions dimensions);
+ void drawPopups(double offsetX);
SvgTxtTheme m_text;
boost::scoped_ptr<SvgTxtThemeSimple> m_popupText;
AnimValue m_correctness;
- AnimValue m_streakPopup; /// for animating the popup
- AnimValue m_godmodePopup; /// for animating the popup
double m_score; /// unnormalized scores
double m_scoreFactor; /// normalization factor
double m_starmeter; /// when this is high enough, GodMode becomes available
|