|
From: Lasse Kärkkäi. <tr...@us...> - 2010-01-06 20:24:13
|
Module: performous
Branch: master
Commit: 1f6fc9cf0806efe32f71670253a5186b773e918c
Author: Lasse Karkkainen <tro...@tr...>
Date: Wed Jan 6 22:21:43 2010 +0200
Remove an old hack used to ignore repeated escape keypress events (needs another fix).
Forward events to screens even when handled as game controllers (to allow in-song navigation to work).
(Q) no longer works as quit.
Singing (performing) screen event handling completely rewritten:
- Uses nav system, so that controllers can be used instead of keyboard for basic functionality
- Latency settings are now Ctrl+F1/F2/F3/F4/F5/F6
- (V)ocals, (K)araoke mode and pitch (W)ave switch now use letters instead of function keys
- Other changes (some intentional, others not)
---
game/joystick.cc | 2 +-
game/main.cc | 16 ++-----
game/screen_sing.cc | 115 +++++++++++++++++++++++++++-----------------------
3 files changed, 68 insertions(+), 65 deletions(-)
diff --git a/game/joystick.cc b/game/joystick.cc
index 90f4c2e..207d6fa 100644
--- a/game/joystick.cc
+++ b/game/joystick.cc
@@ -80,7 +80,7 @@ input::NavButton input::getNav(SDL_Event const &e) {
else if (k == SDLK_LEFT) return input::LEFT;
else if (k == SDLK_RIGHT) return input::RIGHT;
else if (k == SDLK_RETURN) return input::START;
- else if (k == SDLK_ESCAPE || k == SDLK_q) return input::CANCEL;
+ else if (k == SDLK_ESCAPE) return input::CANCEL;
else if (k == SDLK_PAGEUP) return input::MOREUP;
else if (k == SDLK_PAGEDOWN) return input::MOREDOWN;
else if (k == SDLK_PAUSE || (k == SDLK_p && mod & KMOD_CTRL)) return input::PAUSE;
diff --git a/game/main.cc b/game/main.cc
index 30059bf..05b36cd 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -46,7 +46,6 @@ static void checkEvents_SDL(ScreenManager& sm, Window& window) {
std::cout << "Terminating, please wait... (or kill the process)" << std::endl;
throw QuitNow();
}
- static bool esc = false;
SDL_Event event;
while(SDL_PollEvent(&event) == 1) {
switch(event.type) {
@@ -56,23 +55,16 @@ static void checkEvents_SDL(ScreenManager& sm, Window& window) {
case SDL_VIDEORESIZE:
window.resize(event.resize.w, event.resize.h);
break;
- case SDL_KEYUP:
- if (event.key.keysym.sym == SDLK_ESCAPE) esc = false;
- break;
case SDL_KEYDOWN:
int keypressed = event.key.keysym.sym;
SDLMod modifier = event.key.keysym.mod;
- // Workaround for key repeat on escape
- if (keypressed == SDLK_ESCAPE) {
- if (esc) return;
- esc = true;
- }
if ((keypressed == SDLK_RETURN && modifier & KMOD_ALT) || keypressed == SDLK_F11) {
config["graphic/fullscreen"].b() = !config["graphic/fullscreen"].b();
continue; // Already handled here...
}
if (keypressed == SDLK_PRINT || keypressed == SDLK_F12) {
g_take_screenshot = true;
+ continue;
}
if (keypressed == SDLK_F4 && modifier & KMOD_ALT) {
sm.finished();
@@ -80,8 +72,10 @@ static void checkEvents_SDL(ScreenManager& sm, Window& window) {
}
break;
}
- // Forward to screen if the input system doesn't eat the event first
- if(!input::SDL::pushEvent(event)) sm.getCurrentScreen()->manageEvent(event);
+ // Forward to screen even if the input system takes it (ignoring pushEvent return value)
+ // This is needed to allow navigation (quiting the song) to function even then
+ input::SDL::pushEvent(event);
+ sm.getCurrentScreen()->manageEvent(event);
switch(glGetError()) {
case GL_INVALID_ENUM: std::cerr << "OpenGL error: invalid enum" << std::endl; break;
case GL_INVALID_VALUE: std::cerr << "OpenGL error: invalid value" << std::endl; break;
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index 36ebb0c..2a663d8 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -205,65 +205,74 @@ void ScreenSing::activateNextScreen()
}
void ScreenSing::manageEvent(SDL_Event event) {
- if (event.type == SDL_KEYDOWN) {
- double time = m_audio.getPosition();
- Song::Status status = m_song->status(time);
- m_quitTimer.setValue(QUIT_TIMEOUT);
- bool seekback = false;
- int key = event.key.keysym.sym;
- if (key == SDLK_ESCAPE || key == SDLK_q) {
- // In ScoreWindow ESC goes to Players, otherwise insta-quit to Songs
- if (m_score_window.get() && key == SDLK_ESCAPE) { activateNextScreen(); return; }
- ScreenManager* sm = ScreenManager::getSingletonPtr();
- sm->activateScreen("Songs");
+ double time = m_audio.getPosition();
+ Song::Status status = m_song->status(time);
+ input::NavButton nav(input::getNav(event));
+ int key = event.key.keysym.sym;
+ // A kludge to allow using space for navigation
+ if (event.type == SDL_KEYDOWN && key == SDLK_SPACE) nav = m_score_window.get() ? input::START : input::PAUSE;
+ if (nav != input::NONE) {
+ if (nav == input::CANCEL) {
+ // In ScoreWindow cancel goes to Players, otherwise insta-quit to Songs
+ if (m_score_window.get()) activateNextScreen();
+ else ScreenManager::getSingletonPtr()->activateScreen("Songs");
return;
}
- else if (key == SDLK_RETURN) {
- if (m_score_window.get()) { activateNextScreen(); return; } // Score window visible -> Enter quits
- else if (status == Song::FINISHED && m_song->track_map.empty()) {
- m_engine->kill(); // kill the engine thread (to avoid consuming memory)
+ if (nav == input::PAUSE) m_audio.togglePause();
+ if (m_score_window.get()) {
+ if (nav == input::START) activateNextScreen(); // Score window visible -> Start quits
+ return; // The rest are only available when score window is not displayed
+ }
+ // Start button has special functions for skipping things (only in singing for now)
+ if (nav == input::START && m_song->track_map.empty()) {
+ // Open score dialog early
+ if (status == Song::FINISHED) {
+ m_engine->kill(); // kill the engine thread
m_score_window.reset(new ScoreWindow(m_instruments, m_database, m_dancers)); // Song finished, but no score window -> show it
}
+ // Skip instrumental breaks (not supported with instruments yet)
+ else if (status == Song::INSTRUMENTAL_BREAK) {
+ double diff = m_layout_singer->lyrics_begin() - 3.0 - time;
+ if (diff > 0.0) m_audio.seek(diff);
+ }
}
- else if (key == SDLK_SPACE && m_score_window.get()) { activateNextScreen(); return; } // Score window visible -> Space quits
- else if (key == SDLK_SPACE || key == SDLK_PAUSE) m_audio.togglePause();
- if (m_score_window.get()) return;
- // The rest are only available when score window is not displayed and when there are no instruments
- if (key == SDLK_RETURN && status == Song::INSTRUMENTAL_BREAK && m_song->track_map.empty()) {
- double diff = m_layout_singer->lyrics_begin() - 3.0 - time;
- if (diff > 0.0) m_audio.seek(diff);
- }
- else if (key == SDLK_F4) m_audio.toggleSynth(m_song->notes);
- else if (key == SDLK_F5) --config["audio/video_delay"];
- else if (key == SDLK_F6) ++config["audio/video_delay"];
- else if (key == SDLK_F7) --config["audio/round-trip"];
- else if (key == SDLK_F8) ++config["audio/round-trip"];
- else if (key == SDLK_F9) ++config["game/karaoke_mode"];
- else if (key == SDLK_F10) ++config["game/pitch"];
- else if (key == SDLK_HOME) m_audio.seekPos(0.0);
- else if (key == SDLK_LEFT) { m_audio.seek(-5.0); seekback = true; }
- else if (key == SDLK_RIGHT) m_audio.seek(5.0);
- else if (key == SDLK_UP && !(event.key.keysym.mod & KMOD_CTRL)) m_audio.seek(30.0);
- else if (key == SDLK_DOWN && !(event.key.keysym.mod & KMOD_CTRL)) { m_audio.seek(-30.0); seekback = true; }
- else if (key == SDLK_UP && (event.key.keysym.mod & KMOD_CTRL)) ++config["audio/music_volume"];
- else if (key == SDLK_DOWN && (event.key.keysym.mod & KMOD_CTRL)) --config["audio/music_volume"];
- else if (key == SDLK_k && event.key.keysym.mod & KMOD_SHIFT) { m_audio.streamFade("vocals", 1.0); }
- else if (key == SDLK_k && !(event.key.keysym.mod & KMOD_SHIFT)) { m_audio.streamFade("vocals", 0.0); }
- else if (key == SDLK_r && event.key.keysym.mod & KMOD_CTRL) {
- exit(); m_song->reload(); enter();
- m_audio.seek(time);
- }
- // Some things must be reset after seeking backwards
- if (seekback) {
- m_layout_singer->reset();
+ // Volume control
+ if (nav == input::CTRL_UP) ++config["audio/music_volume"];
+ if (nav == input::CTRL_DOWN) --config["audio/music_volume"];
+ } else if (event.type == SDL_KEYDOWN) {
+ m_quitTimer.setValue(QUIT_TIMEOUT);
+ if (m_score_window.get()) return; // The rest are only available when score window is not displayed
+ // Control combinations
+ if (event.key.keysym.mod & KMOD_CTRL) {
+ // Latency settings
+ if (key == SDLK_F1) --config["audio/round-trip"];
+ if (key == SDLK_F2) ++config["audio/round-trip"];
+ if (key == SDLK_F3) --config["audio/video_delay"];
+ if (key == SDLK_F4) ++config["audio/video_delay"];
+ if (key == SDLK_F5) --config["audio/controller_delay"];
+ if (key == SDLK_F6) ++config["audio/controller_delay"];
+ // Reload current song
+ if (key == SDLK_r) {
+ exit(); m_song->reload(); enter();
+ // m_audio.seek(time); FIXME: enable after seeking is enabled
+ }
+ if (key == SDLK_s) m_audio.toggleSynth(m_song->notes);
+ } else {
+ // Toggle vocals (in songs with a separate vocals track)
+ if (key == SDLK_v) { m_audio.streamFade("vocals", event.key.keysym.mod & KMOD_SHIFT ? 1.0 : 0.0); }
+ if (key == SDLK_k) ++config["game/karaoke_mode"]; // Toggle karaoke mode
+ if (key == SDLK_w) ++config["game/pitch"]; // Toggle pitch wave
+ if (m_song->track_map.empty()) { // Seeking is currently only permitted for karaoke songs
+ bool seekback = false;
+ if (key == SDLK_HOME) m_audio.seekPos(0.0);
+ if (key == SDLK_LEFT) { m_audio.seek(-5.0); seekback = true; }
+ if (key == SDLK_RIGHT) m_audio.seek(5.0);
+ if (key == SDLK_UP) m_audio.seek(30.0);
+ if (key == SDLK_DOWN) { m_audio.seek(-30.0); seekback = true; }
+ // Some things must be reset after seeking backwards
+ if (seekback) m_layout_singer->reset();
+ }
}
- //} else if (event.type == SDL_JOYBUTTONDOWN) {
- //int button = event.jbutton.button;
- //if (button == 9 /* START */) m_audio.togglePause();
- //if (button == 8 /* SELECT */) {
- //ScreenManager::getSingletonPtr()->activateScreen("Songs");
- //return;
- //}
}
}
|