Browse Source

Video in Tavern Window. Minor improvements.

Michał W. Urbańczyk 16 years ago
parent
commit
f0dea8d708
5 changed files with 68 additions and 18 deletions
  1. 1 1
      client/CPlayerInterface.cpp
  2. 2 1
      client/CPreGame.cpp
  3. 11 0
      client/GUIClasses.cpp
  4. 48 15
      hch/CVideoHandler.cpp
  5. 6 1
      hch/CVideoHandler.h

+ 1 - 1
client/CPlayerInterface.cpp

@@ -892,7 +892,7 @@ void CPlayerInterface::handleMouseMotion(SDL_Event *sEvent)
 	}
 
 	//adventure map scrolling with mouse
-	if(!SDL_GetKeyState(NULL)[SDLK_LCTRL])
+	if(!SDL_GetKeyState(NULL)[SDLK_LCTRL]  &&  adventureInt->active)
 	{
 		if(sEvent->motion.x<15)
 		{

+ 2 - 1
client/CPreGame.cpp

@@ -2055,7 +2055,6 @@ StartInfo CPreGame::runLoop()
 
 #ifdef _WIN32
 	CGI->videoh->open("ACREDIT.SMK");
-	CGI->videoh->show(8, 105, screen, false);
 #endif
 
 	while(run)
@@ -2336,7 +2335,9 @@ StartInfo CPreGame::runLoop()
 		SDL_Delay(20); //give time for other apps
 	}
 	ret.mode = (fromMenu==newGame) ? 0 : 1;
+#ifdef _WIN32
 	CGI->videoh->close();
+#endif
 
 	return ret;
 }

+ 11 - 0
client/GUIClasses.cpp

@@ -39,6 +39,7 @@
 #include "../lib/NetPacks.h"
 #include "CSpellWindow.h"
 #include "CHeroWindow.h"
+#include "../hch/CVideoHandler.h"
 
 /*
  * GUIClasses.cpp, part of VCMI engine
@@ -2788,6 +2789,10 @@ CTavernWindow::CTavernWindow(const CGHeroInstance *H1, const CGHeroInstance *H2,
 		if(!H1)
 			recruit->block(1);
 	}
+
+#ifdef _WIN32
+	CGI->videoh->open("TAVERN.BIK");
+#endif
 }
 
 void CTavernWindow::recruitb()
@@ -2799,6 +2804,9 @@ void CTavernWindow::recruitb()
 
 CTavernWindow::~CTavernWindow()
 {
+#ifdef _WIN32
+	CGI->videoh->close();
+#endif
 	SDL_FreeSurface(bg);
 	delete cancel;
 	delete thiefGuild;
@@ -2837,6 +2845,9 @@ void CTavernWindow::close()
 void CTavernWindow::show(SDL_Surface * to)
 {
 	blitAt(bg,pos.x,pos.y,to);
+#ifdef _WIN32
+	CGI->videoh->update(pos.x+70, pos.y+56, to, true, false);
+#endif
 	if(h1.h)
 		h1.show(to);
 	if(h2.h)

+ 48 - 15
hch/CVideoHandler.cpp

@@ -181,6 +181,14 @@ int CBIKHandler::frameCount() const
 	return hBink->frameCount;
 }
 
+void CBIKHandler::redraw( int x, int y, SDL_Surface *dst, bool update )
+{
+	int w = hBink->width, h = hBink->height;
+	blitBuffer(buffer, x, y, w, h, dst);
+	if(update)
+		SDL_UpdateRect(dst, x, y, w, h);
+}
+
 void CSmackPlayer::nextFrame()
 {
 	ptrSmackNextFrame(data);
@@ -241,8 +249,22 @@ void CSmackPlayer::show( int x, int y, SDL_Surface *dst, bool update)
 	//put frame to the buffer
 	ptrSmackToBuffer(data, 0, 0, stripe, w, buf, 0x80000000);
 	ptrSmackDoFrame(data);
+	redraw(x, y, dst, update);
+}
 
+int CSmackPlayer::curFrame() const
+{
+	return data->currentFrame;
+}
+
+int CSmackPlayer::frameCount() const
+{
+	return data->frameCount;
+}
 
+void CSmackPlayer::redraw( int x, int y, SDL_Surface *dst, bool update )
+{
+	int w = data->width, h = data->height;
 	/* Lock the screen for direct access to the pixels */
 	if ( SDL_MUSTLOCK(dst) ) 
 	{
@@ -279,16 +301,6 @@ void CSmackPlayer::show( int x, int y, SDL_Surface *dst, bool update)
 		SDL_UpdateRect(dst, x, y, w, h);
 }
 
-int CSmackPlayer::curFrame() const
-{
-	return data->currentFrame;
-}
-
-int CSmackPlayer::frameCount() const
-{
-	return data->frameCount;
-}
-
 CVideoPlayer::CVideoPlayer()
 {
 	vidh = new CVidHandler(std::string(DATA_DIR "Data" PATHSEPARATOR "VIDEO.VID"));
@@ -308,6 +320,7 @@ void CVideoPlayer::open(std::string name)
 		current = &smkPlayer;
 
 	fname = name;
+	first = true;
 
 	//extract video from video.vid so we can play it
 	vidh->extract(name, name);
@@ -365,15 +378,35 @@ bool CVideoPlayer::openAndPlayVideo(std::string name, int x, int y, SDL_Surface
 	return ret;
 }
 
-void CVideoPlayer::update( int x, int y, SDL_Surface *dst, bool redraw, bool update )
+void CVideoPlayer::update( int x, int y, SDL_Surface *dst, bool forceRedraw, bool update )
 {
-	bool w = wait(); //check if should keep current frame
+	bool w = false;
+	if(!first)
+	{
+		w = wait(); //check if should keep current frame
+		if(!w)
+			nextFrame();
+	}
+	else
+	{
+		first = false;
+	}
+
 
-	if(!w)
-		nextFrame();
 
-	if(!w || redraw) //redraw if changed frame or we was told to
+	if(!w) 
+	{
 		show(x,y,dst,update);
+	}
+	else if (forceRedraw)
+	{
+		redraw(x, y, dst, update);
+	}
+}
+
+void CVideoPlayer::redraw( int x, int y, SDL_Surface *dst, bool update )
+{
+	current->redraw(x, y, dst, update);
 }
 
 //reads events and throws on key down

+ 6 - 1
hch/CVideoHandler.h

@@ -65,6 +65,7 @@ public:
 	virtual void close()=0;
 	virtual void nextFrame()=0;
 	virtual void show(int x, int y, SDL_Surface *dst, bool update = true)=0;
+	virtual void redraw(int x, int y, SDL_Surface *dst, bool update = true)=0; //reblits buffer
 	virtual bool wait()=0;
 	virtual int curFrame() const =0;
 	virtual int frameCount() const =0;
@@ -90,6 +91,7 @@ public:
 	void close();
 	void nextFrame();
 	void show(int x, int y, SDL_Surface *dst, bool update = true);
+	void redraw(int x, int y, SDL_Surface *dst, bool update = true); //reblits buffer
 	bool wait();
 	int curFrame() const;
 	int frameCount() const;
@@ -143,6 +145,7 @@ public:
 	void close();
 	void nextFrame();
 	void show(int x, int y, SDL_Surface *dst, bool update = true);
+	void redraw(int x, int y, SDL_Surface *dst, bool update = true); //reblits buffer
 	bool wait();
 	int curFrame() const;
 	int frameCount() const;
@@ -160,6 +163,7 @@ private:
 	IVideoPlayer *current; //points to bik or smk player, appropriate to type of currently played video
 
 	std::string fname; //name of current video file (empty if idle)
+	bool first; //are we about to display the first frame (blocks update)
 public:
 	CVideoPlayer(); //c-tor
 	~CVideoPlayer(); //d-tor
@@ -169,7 +173,8 @@ public:
 	void close();
 	void nextFrame(); //move animation to the next frame
 	void show(int x, int y, SDL_Surface *dst, bool update = true); //blit current frame
-	void update(int x, int y, SDL_Surface *dst, bool redraw, bool update = true); //moves to next frame if appropriate, and blits it or blits only if redraw paremeter is set true
+	void redraw(int x, int y, SDL_Surface *dst, bool update = true); //reblits buffer
+	void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true); //moves to next frame if appropriate, and blits it or blits only if redraw paremeter is set true
 	bool wait(); //true if we should wait before displaying next frame (for keeping FPS)
 	int curFrame() const; //current frame number <1, framecount>
 	int frameCount() const;