Explorar o código

Sporo zmian:
- troche zreorganizowana "obsluga" "defow/lodow". Dodanie lodhandlera.
- poprawki w specyfikacji
- dodanie klasy CPreGame i wyswietlanie menu glownego.
Uwaga - ledwo to zaczalem, jest bardzo niedokończone. Dokończę w ciągu najbliższych dni, więc proszę nie grzeb mi w tym zanadto :)
- pewnie trochu innych zmian, nie miałe otwartego notatnika ;)

Michał W. Urbańczyk %!s(int64=18) %!d(string=hai) anos
pai
achega
93e2667e9e
Modificáronse 9 ficheiros con 96 adicións e 14 borrados
  1. 2 2
      CAmbarCendamo.cpp
  2. 5 5
      CMT.cpp
  3. 28 0
      CPreGame.cpp
  4. 33 0
      CPreGame.h
  5. 6 5
      CSemiDefHandler.cpp
  6. 2 2
      CSemiDefHandler.h
  7. 12 0
      CSemiLodHandler.cpp
  8. 8 0
      CSemiLodHandler.h
  9. BIN=BIN
      h3m.txt

+ 2 - 2
CAmbarCendamo.cpp

@@ -425,14 +425,14 @@ void CAmbarCendamo::loadDefs()
 			if (loadedTypes.find(map.terrain[i][j].tertype)==loadedTypes.end())
 			{
 				CSemiDefHandler  *sdh = new CSemiDefHandler();
-				sdh->openDef(("H3sprite.lod\\"+sdh->nameFromType(map.terrain[i][j].tertype)).c_str());
+				sdh->openDef((sdh->nameFromType(map.terrain[i][j].tertype)).c_str(),"H3sprite.lod");
 				loadedTypes.insert(map.terrain[i][j].tertype);
 				defs.push_back(sdh);
 			}
 			if (loadedTypes.find(map.undergroungTerrain[i][j].tertype)==loadedTypes.end())
 			{
 				CSemiDefHandler  *sdh = new CSemiDefHandler();
-				sdh->openDef(("H3sprite.lod\\"+sdh->nameFromType(map.undergroungTerrain[i][j].tertype)).c_str());
+				sdh->openDef((sdh->nameFromType(map.undergroungTerrain[i][j].tertype)).c_str(),"H3sprite.lod");
 				loadedTypes.insert(map.undergroungTerrain[i][j].tertype);
 				defs.push_back(sdh);
 			}

+ 5 - 5
CMT.cpp

@@ -16,7 +16,6 @@
 #include "CAbilityHandler.h"
 #include "CSpellHandler.h"
 #include "CGameInfo.h"
-
 #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
 #  include <fcntl.h>
 #  include <io.h>
@@ -26,12 +25,11 @@
 #endif
 #define CHUNK 16384
 #define pi 3.14159
-const char * NAME = "VCMI 0.1";
-
-
+const char * NAME = "VCMI 0.2";
 #include "CAmbarCendamo.h"
 #include "mapHandler.h"
 #include "global.h"
+#include "CPreGame.h"
 /* Compress from file source to file dest until EOF on source.
    def() returns Z_OK on success, Z_MEM_ERROR if memory could not be
    allocated for processing, Z_STREAM_ERROR if an invalid compression
@@ -208,7 +206,7 @@ int _tmain(int argc, _TCHAR* argv[])
 	if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER/*|SDL_INIT_EVENTTHREAD*/)==0)
 	{
 		
-		screen = SDL_SetVideoMode(1024,768,24,SDL_HWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/);
+		screen = SDL_SetVideoMode(800,600,24,SDL_HWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/);
 		ekran = screen;
 		//FILE * zr = fopen("mal.txt","r");
 		//FILE * ko = fopen("wyn.txt","w");
@@ -227,6 +225,8 @@ int _tmain(int argc, _TCHAR* argv[])
 		//	fclose(ko);fclose(zr);
 		//}
 		SDL_WM_SetCaption(NAME,"");
+		CPreGame * cpg = new CPreGame();
+		//cpg->runLoop();
 		THC timeHandler tmh;
 		CGameInfo * cgi = new CGameInfo;
 		CGameInfo::mainObj = cgi;

+ 28 - 0
CPreGame.cpp

@@ -0,0 +1,28 @@
+#include "stdafx.h"
+#include "CPreGame.h"
+#include "SDL.h";
+extern SDL_Surface * ekran;
+CPreGame::CPreGame()
+{
+	initMainMenu();
+	showMainMenu();
+}
+void CPreGame::initMainMenu()
+{
+	ourMainMenu = new menuItems();
+	ourMainMenu->background = SDL_LoadBMP("h3bitmap.lod\\ZPIC1005.bmp");
+	CSemiLodHandler * slh = new CSemiLodHandler();
+	slh->openLod("H3sprite.lod");
+	ourMainMenu->newGame = slh->giveDef("ZMENUNG.DEF");
+	handledLods.push_back(slh);
+	delete slh;
+}
+void CPreGame::showMainMenu()
+{
+	SDL_BlitSurface(ourMainMenu->background,NULL,ekran,NULL);
+	SDL_Flip(ekran);
+	SDL_BlitSurface(ourMainMenu->newGame->ourImages[0].bitmap,NULL,ekran,NULL);
+	SDL_Flip(ekran);
+}
+void CPreGame::runLoop()
+{}

+ 33 - 0
CPreGame.h

@@ -0,0 +1,33 @@
+#include "SDL.h"
+#include "CSemiDefHandler.h"
+#include "CSemiLodHandler.h"
+struct AnimatedPic
+{
+	std::vector<SDL_Surface*> frames;
+	~AnimatedPic()
+	{
+		for (int i=0;i<frames.size();i++) 
+		{
+			SDL_FreeSurface(frames[i]);
+			delete frames[i];
+		}
+	}
+};
+class CPreGame
+{
+public:
+	enum EState { //where are we?
+		mainMenu, ScenarioList
+	} state;
+	struct menuItems { 
+		SDL_Surface * background;
+		CSemiDefHandler *newGame, *loadGame, *highScores,*credits, *quit;
+		SDL_Rect lNewGame, lLoadGame, lHighScores, lCredits, lQuit;
+	} * ourMainMenu;
+	std::string map; //selected map
+	std::vector<CSemiLodHandler *> handledLods; 
+	CPreGame(); //c-tor
+	void showMainMenu();  
+	void runLoop(); // runs mainloop of PreGame
+	void initMainMenu(); //loads components for main menu
+};

+ 6 - 5
CSemiDefHandler.cpp

@@ -58,10 +58,10 @@ std::string CSemiDefHandler::nameFromType (EterrainType typ)
 		}
 	}
 }
-void CSemiDefHandler::openDef(const char *name)
+void CSemiDefHandler::openDef(std::string name, std::string lodName)
 {
 	std::ifstream * is = new std::ifstream();
-	is -> open(name,std::ios::binary);
+	is -> open((lodName+"\\"+name).c_str(),std::ios::binary);
 	is->seekg(0,std::ios::end); // na koniec
 	int andame = is->tellg();  // read length
 	is->seekg(0,std::ios::beg); // wracamy na poczatek
@@ -73,7 +73,7 @@ void CSemiDefHandler::openDef(const char *name)
 	delete is;
 
 	readFileList();
-	loadImages();
+	loadImages(lodName);
 
 }
 void CSemiDefHandler::readFileList()
@@ -96,11 +96,11 @@ void CSemiDefHandler::readFileList()
 		else pom--;
 	}
 }
-void CSemiDefHandler::loadImages()
+void CSemiDefHandler::loadImages(std::string path)
 {
 	for (int i=0; i<namesOfImgs.size(); i++)
 	{
-		openImg(("H3sprite.lod\\_"+defName+"\\"+namesOfImgs[i]).c_str());
+		openImg((path+"\\_"+defName+"\\"+namesOfImgs[i]).c_str());
 	}
 }
  void SDL_DisplayBitmap(const char *file, SDL_Surface *ekran, int x, int y)
@@ -133,6 +133,7 @@ void CSemiDefHandler::openImg(const char *name)
 	}
 	Cimage vinya;
 	vinya.bitmap = image;
+	SDL_SetColorKey(vinya.bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(vinya.bitmap->format,0,255,255));
 	vinya.imName = name;
 	ourImages.push_back(vinya);
 }

+ 2 - 2
CSemiDefHandler.h

@@ -21,8 +21,8 @@ public:
 
 	static std::string nameFromType(EterrainType typ);
 	void openImg(const char *name);
-	void openDef(const char *name);
+	void openDef(std::string name, std::string lodName);
 	void readFileList();
-	void loadImages();
+	void loadImages(std::string path);
 };
 #endif // SEMIDEF_H

+ 12 - 0
CSemiLodHandler.cpp

@@ -0,0 +1,12 @@
+#include "stdafx.h"
+#include "CSemiLodHandler.h"
+void CSemiLodHandler::openLod(std::string path)
+{
+	ourName = path;
+};
+CSemiDefHandler * CSemiLodHandler::giveDef(std::string name)
+{
+	CSemiDefHandler * ret = new CSemiDefHandler();
+	ret->openDef(name, ourName);
+	return ret;
+};

+ 8 - 0
CSemiLodHandler.h

@@ -0,0 +1,8 @@
+#include "CSemiDefHandler.h"
+class CSemiLodHandler
+{
+public:
+	std::string ourName; // name of our lod
+	void openLod(std::string path);
+	CSemiDefHandler * giveDef(std::string name); //loads def from our lod
+};

BIN=BIN
h3m.txt