|
From: Stefano A. <xa...@us...> - 2010-01-18 11:55:24
|
Module: performous
Branch: master
Commit: 8070d24b199338279710bfc23100c78fd70f7845
Author: Xaldyz <xa...@us...>
Date: Mon Jan 18 12:55:15 2010 +0100
Added support for FlashMessage. Example to how to use it in "take screenshot" in main.cc. Alpha version
---
game/main.cc | 2 +
game/screen.hh | 20 +++++++++++++++
game/screenmanager.cc | 63 ++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 84 insertions(+), 1 deletions(-)
diff --git a/game/main.cc b/game/main.cc
index 81c20ae..e19b5d6 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -64,6 +64,7 @@ static void checkEvents_SDL(ScreenManager& sm, Window& window) {
}
if (keypressed == SDLK_PRINT || keypressed == SDLK_F12) {
g_take_screenshot = true;
+ sm.FlashMessage(_("Screenshot taken!"));
continue;
}
if (keypressed == SDLK_F4 && modifier & KMOD_ALT) {
@@ -170,6 +171,7 @@ void mainLoop(std::string const& songlist) {
// Draw
window.blank();
sm.getCurrentScreen()->draw();
+ sm.FlashMessages();
// Display (and wait until next frame)
window.swap();
if (config["graphic/fps"].b()) {
diff --git a/game/screen.hh b/game/screen.hh
index d9f3939..118d309 100644
--- a/game/screen.hh
+++ b/game/screen.hh
@@ -1,6 +1,8 @@
#pragma once
#include "singleton.hh"
+#include "animvalue.hh"
+#include "opengl_text.hh"
#include <boost/ptr_container/ptr_map.hpp>
#include <SDL.h>
#include <string>
@@ -44,6 +46,19 @@ class ScreenManager: public Singleton <ScreenManager> {
Screen* getCurrentScreen() { return currentScreen; };
/// returns pointer to Screen for given name
Screen* getScreen(std::string const& name);
+
+ /// Get time to fade in/out the message
+ float getFadeTime();
+ /// Get time the message have to been showned
+ float getShowTime();
+ /// Set time to fade in/out the message
+ bool setFadeTime(float fadeTime);
+ /// Set time the message have to been showned
+ bool setShowTime(float showTime);
+ /// Set a messag to flash in current screen
+ void FlashMessage(std::string const& name);
+ /// Flash messages in current screen
+ void FlashMessages();
/// sets finished to true
void finished() { m_finished=true; };
@@ -52,9 +67,14 @@ class ScreenManager: public Singleton <ScreenManager> {
private:
bool m_finished;
+ float m_timeToFade;
+ float m_timeToShow;
typedef boost::ptr_map<std::string, Screen> screenmap_t;
screenmap_t screens;
Screen* newScreen;
Screen* currentScreen;
+ AnimValue m_messagePopup;
+ SvgTxtTheme m_textMessage;
+ std::string m_message;
};
diff --git a/game/screenmanager.cc b/game/screenmanager.cc
index b007e8f..0fa7d75 100644
--- a/game/screenmanager.cc
+++ b/game/screenmanager.cc
@@ -1,10 +1,17 @@
#include "screen.hh"
+#include "fs.hh"
#include <stdexcept>
template<> ScreenManager* Singleton<ScreenManager>::ms_Singleton = NULL;
-ScreenManager::ScreenManager(): m_finished(false), currentScreen() {}
+ScreenManager::ScreenManager(): m_finished(false), currentScreen(), m_messagePopup(0.0, 1.0), m_textMessage(getThemePath("sing_timetxt.svg")) {
+ m_timeToFade = 1.0f;
+ m_timeToShow = 3.0f;
+
+ m_messagePopup.setTarget(100.0);
+ m_textMessage.dimensions.fixedWidth(0.5).right(0.5).screenTop(0.01);
+}
void ScreenManager::activateScreen(std::string const& name) {
newScreen = getScreen(name);
@@ -27,3 +34,57 @@ Screen* ScreenManager::getScreen(std::string const& name) {
}
}
+float ScreenManager::getFadeTime(){ return m_timeToFade; }
+float ScreenManager::getShowTime(){ return m_timeToFade; }
+
+bool ScreenManager::setFadeTime(float fadeTime){
+ if (fadeTime * 2 > m_timeToShow){ //fade in + fade out
+ m_timeToFade = m_timeToShow / 2;
+ return false;
+ } else {
+ m_timeToFade = fadeTime;
+ return true;
+ }
+}
+
+bool ScreenManager::setShowTime(float showTime){
+ if (showTime < m_timeToFade * 2){
+ m_timeToShow = m_timeToFade / 2;
+ return false;
+ } else {
+ m_timeToShow = showTime;
+ return true;
+ }
+}
+
+void ScreenManager::FlashMessages() {
+ double time = m_messagePopup.get();
+ if (time > 0.0){
+ bool haveToFadeIn = time < (m_timeToFade);
+ bool haveToFadeOut = time > (m_messagePopup.getTarget() - m_timeToFade);
+ bool haveToStop = time > (m_messagePopup.getTarget() - 0.001);
+ float fadeValue = 1.0f;
+ if (haveToFadeOut){
+ fadeValue = float((m_messagePopup.getTarget() - time) / m_timeToFade);
+ glColor4f(1.0f, 1.0f, 1.0f, (fadeValue));
+
+ if(haveToStop){
+ m_messagePopup.setTarget(0.0, true);
+ }
+ }else if (haveToFadeIn){
+ fadeValue = float(time / m_timeToFade);
+
+ glColor4f(1.0f, 1.0f, 1.0f, fadeValue);
+ }
+
+ m_textMessage.draw(m_message, fadeValue);
+
+ if (haveToFadeIn || haveToFadeOut) glColor3f(1.0f, 1.0f, 1.0f);
+ }
+}
+
+void ScreenManager::FlashMessage(std::string const& message) {
+ m_messagePopup.setTarget(m_timeToShow);
+ m_messagePopup.setValue(0);
+ m_message = message;
+}
|