git repos / blockattack-game

commit 95bc02ff

sago007 · 2009-03-15 02:46
95bc02ffdadf706d9cdfff5ce9e1b2532b947aea patch · browse files
parent cad041e3cf15bab02cf7d86c3050367315e92fdf

Starting to create temp keyboard/joypad menu browsing


git-svn-id: https://blockattack.svn.sourceforge.net/svnroot/blockattack/trunk@71 9d7177f8-192b-0410-8f35-a16a89829b06

Changed files

M source/code/main.cpp before
M source/code/mainVars.hpp before
diff --git a/source/code/main.cpp b/source/code/main.cpp index cd4d8fc..8ae1eec 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -75,6 +75,7 @@ Copyright (C) 2008 Poul Sander
//#include "ttfont.h" //To use True Type Fonts in SDL
//#include "config.h"
#include <vector>
+#include <SDL/SDL_timer.h>
//#include "MenuSystem.h"
//if SHAREDIR is not used we look in current directory
@@ -3437,7 +3438,7 @@ int main(int argc, char *argv[])
PHYSFS_addToSearchPath("blockattack.data", 1);
#endif
-
+
//Init SDL
if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
{
@@ -3485,6 +3486,12 @@ int main(int argc, char *argv[])
#endif
cout << "-------------------------------------------" << endl;
+ //The menu cannot be activated the first second to prevent unexpected events
+ keymenu.canBeActivatedTime = SDL_GetTicks()+1000;
+ keymenu.activated = false;
+ for(int i=0;i<KEYMENU_MAXWITH;i++)
+ keymenu.menumap[i][0] = true;
+
keySettings[0].up= SDLK_UP;
keySettings[0].down = SDLK_DOWN;
keySettings[0].left = SDLK_LEFT;
@@ -3928,6 +3935,12 @@ int main(int argc, char *argv[])
}
if ( event.key.keysym.sym == SDLK_F8 )
{
+ if(!keymenu.activated && keymenu.canBeActivatedTime > SDL_GetTicks())
+ {
+ keymenu.activated = true;
+ keymenu.x = 0;
+ keymenu.y = 0;
+ }
}
if ( event.key.keysym.sym == SDLK_F9 ) {
writeScreenShot();
diff --git a/source/code/mainVars.hpp b/source/code/mainVars.hpp index 3418e00..6ebdee3 100644 --- a/source/code/mainVars.hpp +++ b/source/code/mainVars.hpp
@@ -319,6 +319,23 @@ struct control
control keySettings[3]; //array to hold the controls (default and two custom)
+#define KEYMENU_MAXWITH 4
+#define KEYMENU_MAXDEPTH 7
+
+//The following struct holds variables relevant to selecting menu items with
+//keyboard/joypad.
+struct KeyMenu_t
+{
+ unsigned long canBeActivatedTime; //Time that the KeyMenu can be activated by pressing a button
+ bool activated; //The keymenu is activated
+ //Here comes the coordinates to the key we are howering.
+ int x;
+ int y;
+ bool menumap[KEYMENU_MAXWITH][KEYMENU_MAXDEPTH];
+};
+
+KeyMenu_t keymenu;
+
enum stageButton {SBdontShow, SBstageClear, SBpuzzleMode};
stageButton stageButtonStatus = SBdontShow;