commit 2e57d791
Theme selection is now saved. Themes can now also be set on the command line.
git-svn-id: https://blockattack.svn.sourceforge.net/svnroot/blockattack/trunk@90 9d7177f8-192b-0410-8f35-a16a89829b06
Changed files
| M | source/code/BlockGame.hpp before |
| M | source/code/listFiles.cpp before |
| M | source/code/main.cpp before |
diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp
index da9ac47..2db7828 100644
--- a/source/code/BlockGame.hpp
+++ b/source/code/BlockGame.hpp
@@ -79,7 +79,9 @@ public:
Uint32 gameStartedAt;
Uint32 gameEndedAfter; //How long did the game last?
int linesCleared;
+ #if WITH_SDL
SDL_Surface* sBoard;
+ #endif
int TowerHeight;
BlockGame *garbageTarget;
Sint32 board[7][30];
@@ -107,9 +109,11 @@ public:
//Constructor
BlockGame(int tx, int ty) {
+ #if WITH_SDL
tmp = IMG_Load2((char*)"gfx/BackBoard.png");
sBoard = SDL_DisplayFormat(tmp);
SDL_FreeSurface(tmp);
+ #endif
srand((int)time(NULL));
nrFellDown = 0;
nrPushedPixel = 0;
@@ -164,7 +168,9 @@ public:
//Deconstructor, never really used... game used to crash when called, cause of the way sBoard was created
//It should work now and can be used if we want to assign more players in network games that we need to free later
~BlockGame() {
+ #if WITH_SDL
SDL_FreeSurface(sBoard);
+ #endif
}
void setGameSpeed(Uint8 globalSpeedLevel) {
@@ -237,13 +243,13 @@ public:
#endif
+ #if WITH_SDL
//Loads BackBoard again if surface format has changed
void convertSurface() {
SDL_FreeSurface(sBoard);
- cout << "2.1" << endl;
sBoard = SDL_DisplayFormat(backBoard);
- cout << "2.2" << endl;
}
+ #endif
//Instead of creating new object new game is called, to prevent memory leaks
void NewGame(int tx, int ty) {
@@ -1814,6 +1820,7 @@ public:
///////////////////////////// AI ends here! //////////////////////////////
//////////////////////////////////////////////////////////////////////////
+#if WITH_SDL
//Draws all the bricks to the board (including garbage)
void PaintBricks() {
for (int i=0;((i<13)&&(i<30));i++)
@@ -2160,6 +2167,8 @@ public:
DrawIMG(iGameOver, sBoard, 0, 5*bsize);
}
+ #endif
+
//Updates evrything, if not called nothing happends
void Update() {
Uint32 tempUInt32;
diff --git a/source/code/listFiles.cpp b/source/code/listFiles.cpp
index b007450..ca3cb4e 100644
--- a/source/code/listFiles.cpp
+++ b/source/code/listFiles.cpp
@@ -57,7 +57,7 @@ void ListFiles::setDirectory(string directory)
nrOfFiles=0;
filenames[nrOfFiles] = FindFileData.cFileName;
cout << "File: " << FindFileData.cFileName << endl;
- while ((FindNextFile(hFind, &FindFileData) != 0)&&(nrOfFiles<MAX_NR_OF_FILES-1))
+ while ((FindNextFile(hFind, &FindFileData) != 0) && FindFileData.cFileName.name[0]!='.' && (nrOfFiles<MAX_NR_OF_FILES-1))
{
nrOfFiles++;
filenames[nrOfFiles] = FindFileData.cFileName;
@@ -82,7 +82,7 @@ void ListFiles::setDirectory(string directory)
while ((dp=readdir(DirectoryPointer))&&(nrOfFiles<MAX_NR_OF_FILES-1))
{
string name = (string)(char*)dp->d_name;
- if (!isInList(name) && name != "." && name != "..")
+ if (!isInList(name) && name[0]!='.' )
{
nrOfFiles++;
filenames[nrOfFiles] = name;
diff --git a/source/code/main.cpp b/source/code/main.cpp
index 180ff8e..0354f87 100644
--- a/source/code/main.cpp
+++ b/source/code/main.cpp
@@ -52,6 +52,8 @@ Copyright (C) 2008 Poul Sander
#define LEVELEDITOR 0
#endif
+#define WITH_SDL 1
+
//Macros to convert surfaces (ffor faster drawing)
#define CONVERT(n) tmp = SDL_DisplayFormat(n); SDL_FreeSurface(n); n = tmp
#define CONVERTA(n) tmp = SDL_DisplayFormatAlpha(n); SDL_FreeSurface(n); n = tmp
@@ -193,6 +195,11 @@ void loadTheme(string themeName)
#if defined(__unix__) || defined(_WIN32)
PHYSFS_addToSearchPath(home.c_str(), 1);
#endif
+ if(themeName.compare(Config::getInstance()->getString("themename"))!=0)
+ {
+ //If this is a theme different from the saved one. Remember it!
+ Config::getInstance()->setString("themename",themeName);
+ }
if(themeName.compare("default")==0 || (themeName.compare("start")==0))
{
InitImages();
@@ -3182,6 +3189,8 @@ int main(int argc, char *argv[])
#endif
highPriority = false; //if true the game will take most resources, but increase framerate.
bFullscreen = false;
+ //Set default Config variables:
+ Config::getInstance()->setDefault("themename","default");
if (argc > 1)
{
int argumentNr = 1;
@@ -3195,13 +3204,15 @@ int main(int argc, char *argv[])
char singlePuzzleString[] = "-SP";
char noSoundAtAll[] = "-nosound";
char IntegratedEditor[] = "-editor";
+ char selectTheme[] = "-theme";
if (!(strncmp(argv[argumentNr],helpString,6)))
{
cout << "Block Attack Help" << endl << "--help Display this message" <<
endl << "-priority Starts game in high priority" << endl <<
"-forceredraw Redraw the whole screen every frame, prevents garbage" << endl <<
"-forcepartdraw Only draw what is changed, sometimes cause garbage" << endl <<
- "-nosound No sound will be played at all, and sound hardware want be loaded (use this if game crashes because of sound)" << endl <<
+ "-nosound No sound will be played at all, and sound hardware will not be loaded (use this if game crashes because of sound)" << endl <<
+ "-theme <THEMENAME> Changes to the theme <THEMENAME> on startup" << endl <<
"-editor Starts the build-in editor (not yet integrated)" << endl;
#ifdef WIN32
system("Pause");
@@ -3243,8 +3254,15 @@ int main(int argc, char *argv[])
cout << "Integrated Puzzle Editor Activated" << endl;
#else
cout << "Integrated Puzzle Editor was disabled at compile time" << endl;
+ return -1;
#endif
}
+ if(!(strncmp(argv[argumentNr],selectTheme,6)))
+ {
+ argumentNr++; //Go to themename (the next argument)
+ cout << "Theme set to \"" << argv[argumentNr] << '"' << endl;
+ Config::getInstance()->setString("themename",argv[argumentNr]);
+ }
argumentNr++;
} //while
} //if
@@ -3509,7 +3527,7 @@ int main(int argc, char *argv[])
//Init the file system abstraction layer
PHYSFS_init(argv[0]);
//Load default theme
- loadTheme("start");
+ loadTheme(Config::getInstance()->getString("themename"));
//Now sets the icon:
SDL_Surface *icon = IMG_Load2((char*)"gfx/icon.png");
SDL_WM_SetIcon(icon,NULL);