commit 593aeae4
Changes to menu system and correction of some headers
git-svn-id: https://blockattack.svn.sourceforge.net/svnroot/blockattack/trunk@124 9d7177f8-192b-0410-8f35-a16a89829b06
Changed files
diff --git a/source/code/CppSdl/CppSdlException.hpp b/source/code/CppSdl/CppSdlException.hpp
index 8460466..acc7715 100644
--- a/source/code/CppSdl/CppSdlException.hpp
+++ b/source/code/CppSdl/CppSdlException.hpp
@@ -22,6 +22,12 @@ namespace CppSdl {
class CppSdlException : std::exception{
public:
//CppSdlException();
+ /**
+ * Constructor for making a fully CppSdl compliant expection
+ * @param subsystem Can be: OTHER,IMAGE,TILE,SPRITE,LAYER,SCREEN
+ * @param errorNumber 1=Data error, 2=Invalid, 3=Missingfile, 4=null pointer
+ * @param msg Human readable error message.
+ */
CppSdlException(Subsystem subsystem, long errorNumber, std::string msg);
CppSdlException(const CppSdlException& orig);
virtual ~CppSdlException() throw();
diff --git a/source/code/MenuSystem.cc b/source/code/MenuSystem.cc
index b3a182a..9173577 100644
--- a/source/code/MenuSystem.cc
+++ b/source/code/MenuSystem.cc
@@ -16,12 +16,6 @@ Copyright (C) 2008 Poul Sander
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- Poul Sander
- R�vehjvej 36, V. 1111
- 2800 Kgs. Lyngby
- DENMARK
- blockattack@poulsander.com
- http://blockattack.sf.net
*/
#include <SDL/SDL_events.h>
diff --git a/source/code/MenuSystem.h b/source/code/MenuSystem.h
index 1af0fd0..7b922e8 100644
--- a/source/code/MenuSystem.h
+++ b/source/code/MenuSystem.h
@@ -16,20 +16,10 @@ Copyright (C) 2008 Poul Sander
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- Poul Sander
- R�vehjvej 36, V. 1111
- 2800 Kgs. Lyngby
- DENMARK
blockattack@poulsander.com
http://blockattack.sf.net
*/
-//
-// File: MenuSystem.h
-// Author: poul
-//
-// Created on 28. september 2008, 17:06
-//
#ifndef _MENUSYSTEM_H
#define _MENUSYSTEM_H
diff --git a/source/code/main.cpp b/source/code/main.cpp
index 43659fd..8e6345a 100644
--- a/source/code/main.cpp
+++ b/source/code/main.cpp
@@ -16,12 +16,6 @@ Copyright (C) 2008 Poul Sander
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- Poul Sander
- R�vehjvej 36, V. 1111
- 2800 Kgs. Lyngby
- DENMARK
- blockattack@poulsander.com
- http://blockattack.sf.net
*/
#include "common.h"
@@ -275,7 +269,7 @@ long NFont_OpenFont(NFont *target, string path,int ptsize, SDL_Color color, int
m_data = 0;
PHYSFS_close(myfile);
cout << "Error. Curropt data file!" << endl;
- return NULL;
+ return -3;
}
PHYSFS_close(myfile);
@@ -1638,7 +1632,7 @@ void writeScreenShot()
}
//Function to return the name of a key, to be displayed...
-string getKeyName(SDLKey key)
+static string getKeyName(SDLKey key)
{
string keyname(SDL_GetKeyName(key));
return keyname;
diff --git a/source/code/mainVars.hpp b/source/code/mainVars.hpp
index d5da3c8..38b22ce 100644
--- a/source/code/mainVars.hpp
+++ b/source/code/mainVars.hpp
@@ -16,11 +16,6 @@ Copyright (C) 2007 Poul Sander
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- Poul Sander
- R�veh�jvej 36, V. 1111
- 2800 Kgs. Lyngby
- DENMARK
- blockattack@poulsander.com
*/
//Make sure it is only included once
@@ -303,7 +298,7 @@ struct control
SDLKey push;
};
-static control keySettings[3]; //array to hold the controls (default and two custom)
+control keySettings[3]; //array to hold the controls (default and two custom)
#define KEYMENU_MAXWITH 4
#define KEYMENU_MAXDEPTH 7
diff --git a/source/code/menudef.cpp b/source/code/menudef.cpp
index a0faf2b..899df85 100644
--- a/source/code/menudef.cpp
+++ b/source/code/menudef.cpp
@@ -1,3 +1,25 @@
+/*
+menudef.cpp
+Copyright (C) 2011 Poul Sander
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ Poul Sander
+ blockattack@poulsander.com
+*/
+
#include "global.hpp"
#include <iostream>
#include <stdlib.h>
@@ -12,8 +34,47 @@ void PrintHi()
cout << "Hi" <<endl;
}
+//Stores the controls
+struct control
+{
+ SDLKey up;
+ SDLKey down;
+ SDLKey left;
+ SDLKey right;
+ SDLKey change;
+ SDLKey push;
+};
+
bool OpenDialogbox(int x, int y, char *name);
void OpenScoresDisplay();
+extern control keySettings[3];
+
+//Function to return the name of a key, to be displayed...
+static string getKeyName(SDLKey key)
+{
+ string keyname(SDL_GetKeyName(key));
+ cout << key << " translated to " << keyname << endl;
+ return keyname;
+}
+
+class Button_changekey : public Button {
+private:
+ SDLKey *m_key2change;
+ string m_keyname;
+public:
+ Button_changekey(SDLKey *key, string keyname);
+ void doAction();
+};
+
+Button_changekey::Button_changekey(SDLKey* key, string keyname) {
+ m_key2change = key;
+ m_keyname = keyname;
+ setLabel(m_keyname+" : "+getKeyName(*m_key2change));
+}
+
+void Button_changekey::doAction() {
+ setLabel(m_keyname+" : "+getKeyName(*m_key2change));
+}
void InitMenues()
{
@@ -69,69 +130,35 @@ void buttonActionHighscores(Button *b) {
OpenScoresDisplay();
}
-class ChangeKeysMenu {
-public:
- static long player;
- static void CreateKeysMenu(long playernumber);
- static void ChangeLeftKey(Button *b);
- static void ChangeRightKey(Button *b);
- static void ChangeUpKey(Button *b);
- static void ChangeDownKey(Button *b);
- static void ChangePushKey(Button *b);
- static void ChangeSwitchKey(Button *b);
- static void ChangeJoypadStatus(Button *b);
- static void ChangeMouseStatus(Button *b);
-};
-
-long ChangeKeysMenu::player;
-
-void ChangeKeysMenu::ChangeDownKey(Button* b) {
-
-}
-
-void ChangeKeysMenu::ChangeLeftKey(Button* b) {
-
-}
-
-void ChangeKeysMenu::ChangePushKey(Button* b) {
-
-}
-
-void ChangeKeysMenu::ChangeRightKey(Button* b) {
-
-}
-
-void ChangeKeysMenu::ChangeSwitchKey(Button* b) {
-
-}
-
-void ChangeKeysMenu::ChangeUpKey(Button* b) {
-
-}
-
static void ChangeKeysMenu(long playernumber) {
- ChangeKeysMenu::player = playernumber;
Menu km(&screen,false);
- Button bLeft, bRight, bUp, bDown, bPush, bSwitch, bJoypad, bMouse;
- bLeft.setLabel("Left : ");
- bLeft.setAction(ChangeKeysMenu::ChangeLeftKey);
- bRight.setLabel("Right : ");
- bRight.setAction(ChangeKeysMenu::ChangeRightKey);
- bUp.setLabel("Up : ");
- bUp.setAction(ChangeKeysMenu::ChangeUpKey);
- bDown.setLabel("Down : ");
- bDown.setAction(ChangeKeysMenu::ChangeDownKey);
+ Button_changekey bLeft(&keySettings[playernumber].left,"Left");
+ Button_changekey bRight(&keySettings[playernumber].right,"Right");
+ Button_changekey bUp(&keySettings[playernumber].up,"Up");
+ Button_changekey bDown(&keySettings[playernumber].down,"Down");
+ Button_changekey bPush(&keySettings[playernumber].push,"Push");
+ Button_changekey bSwitch(&keySettings[playernumber].change,"Change");
km.addButton(&bLeft);
km.addButton(&bRight);
km.addButton(&bUp);
km.addButton(&bDown);
+ km.addButton(&bPush);
+ km.addButton(&bSwitch);
km.run();
}
+static void ChangeKeysMenu1(Button *b) {
+ ChangeKeysMenu(0);
+}
+
+static void ChangeKeysMenu2(Button *b) {
+ ChangeKeysMenu(2);
+}
void ConfigureMenu(Button *b) {
Menu cm(&screen,false);
Button bMusic,bSound,buttonFullscreen,bPlayer1Name,bPlayer2Name;
+ Button bPlayer1Keys, bPlayer2Keys;
bMusic.setLabel(MusicEnabled? "Music: On" : "Music: Off");
bMusic.setAction(buttonActionMusic);
bSound.setLabel(SoundEnabled? "Music: On" : "Music: Off");
@@ -142,11 +169,17 @@ void ConfigureMenu(Button *b) {
bPlayer1Name.setLabel("Change player 1's name");
bPlayer2Name.setAction(buttonActionPlayer2Name);
bPlayer2Name.setLabel("Change player 2's name");
+ bPlayer1Keys.setAction(ChangeKeysMenu1);
+ bPlayer1Keys.setLabel("Change player 1's keys");
+ bPlayer2Keys.setAction(ChangeKeysMenu2);
+ bPlayer2Keys.setLabel("Change player 2's keys");
cm.addButton(&bMusic);
cm.addButton(&bSound);
cm.addButton(&buttonFullscreen);
cm.addButton(&bPlayer1Name);
cm.addButton(&bPlayer2Name);
+ cm.addButton(&bPlayer1Keys);
+ cm.addButton(&bPlayer2Keys);
cm.run();
}
@@ -174,4 +207,4 @@ void MainMenu()
m.addButton(&bConfigure);
m.addButton(&bHighscore);
m.run();
-}
\ No newline at end of file
+}