commit d21782d4
The scores display can now be controlled with a keypad
Changed files
| M | source/code/MenuSystem.cpp before |
| M | source/code/MenuSystem.h before |
| M | source/code/ScoresDisplay.cpp before |
diff --git a/source/code/MenuSystem.cpp b/source/code/MenuSystem.cpp
index 1d12112..479e1ca 100644
--- a/source/code/MenuSystem.cpp
+++ b/source/code/MenuSystem.cpp
@@ -186,7 +186,7 @@ bool isUpEvent(const SDL_Event& event) {
}
}
if (event.type == SDL_CONTROLLERBUTTONDOWN) {
- if (event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_UP || event.cbutton.button == SDL_CONTROLLERBUTTONUP ) {
+ if (event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_UP ) {
return true;
}
}
@@ -200,7 +200,35 @@ bool isDownEvent(const SDL_Event& event) {
}
}
if (event.type == SDL_CONTROLLERBUTTONDOWN) {
- if (event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN || event.cbutton.button == SDL_CONTROLLERBUTTONDOWN ) {
+ if (event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN ) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool isLeftEvent(const SDL_Event& event) {
+ if ( event.type == SDL_KEYDOWN ) {
+ if (event.key.keysym.sym == SDLK_LEFT) {
+ return true;
+ }
+ }
+ if (event.type == SDL_CONTROLLERBUTTONDOWN) {
+ if (event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT ) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool isRightEvent(const SDL_Event& event) {
+ if ( event.type == SDL_KEYDOWN ) {
+ if (event.key.keysym.sym == SDLK_DOWN) {
+ return true;
+ }
+ }
+ if (event.type == SDL_CONTROLLERBUTTONDOWN) {
+ if (event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT ) {
return true;
}
}
@@ -268,7 +296,7 @@ void Menu::run() {
}
}
- if (isEscapeEvent(event)) {
+ if (isEscapeEvent(event) && isSubmenu) {
running = false;
}
diff --git a/source/code/MenuSystem.h b/source/code/MenuSystem.h
index f880fda..a33378c 100644
--- a/source/code/MenuSystem.h
+++ b/source/code/MenuSystem.h
@@ -133,5 +133,17 @@ public:
std::string getFile(SDL_Surface **screen);
};
+bool isUpEvent(const SDL_Event& event);
+
+bool isDownEvent(const SDL_Event& event);
+
+bool isLeftEvent(const SDL_Event& event);
+
+bool isRightEvent(const SDL_Event& event);
+
+bool isEscapeEvent(const SDL_Event& event);
+
+bool isConfirmEvent(const SDL_Event& event);
+
#endif /* _MENUSYSTEM_H */
diff --git a/source/code/ScoresDisplay.cpp b/source/code/ScoresDisplay.cpp
index fca0adc..45cb2b4 100644
--- a/source/code/ScoresDisplay.cpp
+++ b/source/code/ScoresDisplay.cpp
@@ -25,6 +25,7 @@ http://www.blockattack.net
#include "global.hpp"
#include "common.h"
#include "stats.h"
+#include "MenuSystem.h"
using namespace std;
@@ -159,27 +160,24 @@ void ScoresDisplay::Draw(SDL_Renderer* target) {
}
void ScoresDisplay::ProcessInput(const SDL_Event& event, bool& processed) {
- if ( event.type == SDL_KEYDOWN ) {
- if ( (event.key.keysym.sym == SDLK_RIGHT)) {
- page++;
- if (page>=numberOfPages) {
- page = 0;
- }
+
+ if (isLeftEvent(event)) {
+ page++;
+ if (page>=numberOfPages) {
+ page = 0;
}
- else if ( (event.key.keysym.sym == SDLK_LEFT)) {
- page--;
- if (page<0) {
- page = numberOfPages-1;
- }
- }
-
- if ( (event.key.keysym.sym == SDLK_RETURN)||(event.key.keysym.sym == SDLK_KP_ENTER) ) {
- isActive = false;
- }
- else if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
- isActive = false;
+ }
+
+ if (isRightEvent(event)) {
+ page--;
+ if (page<0) {
+ page = numberOfPages-1;
}
}
+
+ if (isConfirmEvent(event) || isEscapeEvent(event)) {
+ isActive = false;
+ }
}
void ScoresDisplay::Update() {