瀏覽代碼

video & audio correction; win/lose

Laserlicht 2 年之前
父節點
當前提交
30c6cf3b98

+ 1 - 2
client/CPlayerInterface.cpp

@@ -1696,8 +1696,7 @@ void CPlayerInterface::requestReturningToMainMenu(bool won)
 				CSH->endGameplay();
 				GH.defActionsDef = 63;
 				CMM->menu->switchToTab("main");
-				if(won)
-					GH.windows().createAndPushWindow<CHighScoreInputScreen>();
+				GH.windows().createAndPushWindow<CHighScoreInputScreen>(won);
 			}
 		);
 	}

+ 1 - 1
client/CServerHandler.cpp

@@ -698,7 +698,7 @@ void CServerHandler::startCampaignScenario(std::shared_ptr<CampaignState> cs)
 			else
 			{
 				CMM->openCampaignScreen(ourCampaign->campaignSet);
-				GH.windows().createAndPushWindow<CHighScoreInputScreen>();
+				GH.windows().createAndPushWindow<CHighScoreInputScreen>(true);
 			}
 		};
 		if(epilogue.hasPrologEpilog)

+ 3 - 1
client/CVideoHandler.cpp

@@ -349,7 +349,7 @@ void CVideoPlayer::redraw( int x, int y, SDL_Surface *dst, bool update )
 	show(x, y, dst, update);
 }
 
-void CVideoPlayer::update( int x, int y, SDL_Surface *dst, bool forceRedraw, bool update )
+void CVideoPlayer::update( int x, int y, SDL_Surface *dst, bool forceRedraw, bool update, std::function<void()> restart)
 {
 	if (sws == nullptr)
 		return;
@@ -368,6 +368,8 @@ void CVideoPlayer::update( int x, int y, SDL_Surface *dst, bool forceRedraw, boo
 			show(x,y,dst,update);
 		else
 		{
+			if(restart)
+				restart();
 			VideoPath filenameToReopen = fname; // create copy to backup this->fname
 			open(filenameToReopen);
 			nextFrame();

+ 2 - 2
client/CVideoHandler.h

@@ -31,7 +31,7 @@ public:
 class IMainVideoPlayer : public IVideoPlayer
 {
 public:
-	virtual void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true){}
+	virtual void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true, std::function<void()> restart = 0){}
 	virtual bool openAndPlayVideo(const VideoPath & name, int x, int y, bool stopOnKey = false, bool scale = false)
 	{
 		return false;
@@ -101,7 +101,7 @@ public:
 
 	void show(int x, int y, SDL_Surface *dst, bool update = true) override; //blit current frame
 	void redraw(int x, int y, SDL_Surface *dst, bool update = true) override; //reblits buffer
-	void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true) override; //moves to next frame if appropriate, and blits it or blits only if redraw parameter is set true
+	void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true, std::function<void()> restart = 0) override; //moves to next frame if appropriate, and blits it or blits only if redraw parameter is set true
 
 	// Opens video, calls playVideo, closes video; returns playVideo result (if whole video has been played)
 	bool openAndPlayVideo(const VideoPath & name, int x, int y, bool stopOnKey = false, bool scale = false) override;

+ 40 - 10
client/mainmenu/CHighScoreScreen.cpp

@@ -22,6 +22,7 @@
 
 #include "../CGameInfo.h"
 #include "../CVideoHandler.h"
+#include "../CMusicHandler.h"
 #include "../../lib/CGeneralTextHandler.h"
 #include "../../lib/CConfigHandler.h"
 #include "../../lib/CCreatureHandler.h"
@@ -167,8 +168,8 @@ void CHighScoreScreen::buttonExitClick()
     close();
 }
 
-CHighScoreInputScreen::CHighScoreInputScreen()
-	: CWindowObject(BORDERED)
+CHighScoreInputScreen::CHighScoreInputScreen(bool won)
+	: CWindowObject(BORDERED), won(won)
 {
     addUsedEvents(LCLICK);
 
@@ -176,11 +177,20 @@ CHighScoreInputScreen::CHighScoreInputScreen()
 	pos = center(Rect(0, 0, 800, 600));
 	updateShadow();
 
-    int border = 100;
-    int textareaW = ((pos.w - 2 * border) / 4);
-    std::vector<std::string> t = { "438", "439", "440", "441", "676" };
-    for (int i = 0; i < 5; i++)
-        texts.push_back(std::make_shared<CMultiLineLabel>(Rect(textareaW * i + border - (textareaW / 2), 450, textareaW, 100), FONT_HIGH_SCORE, ETextAlignment::TOPCENTER, Colors::WHITE, CGI->generaltexth->translate("core.genrltxt." + t[i])));
+    if(won)
+    {
+        int border = 100;
+        int textareaW = ((pos.w - 2 * border) / 4);
+        std::vector<std::string> t = { "438", "439", "440", "441", "676" };
+        for (int i = 0; i < 5; i++)
+            texts.push_back(std::make_shared<CMultiLineLabel>(Rect(textareaW * i + border - (textareaW / 2), 450, textareaW, 100), FONT_HIGH_SCORE, ETextAlignment::TOPCENTER, Colors::WHITE, CGI->generaltexth->translate("core.genrltxt." + t[i])));
+ 
+        CCS->musich->playMusic(AudioPath::builtin("music/Win Scenario"), true, true);
+    }
+    else
+        CCS->musich->playMusic(AudioPath::builtin("music/UltimateLose"), false, true);
+
+    video = won ? "HSANIM.SMK" : "LOSEGAME.SMK";
 }
 
 void CHighScoreInputScreen::addEntry(std::string text) {
@@ -189,7 +199,18 @@ void CHighScoreInputScreen::addEntry(std::string text) {
 
 void CHighScoreInputScreen::show(Canvas & to)
 {
-	CCS->videoh->update(pos.x, pos.y, to.getInternalSurface(), true, false);
+	CCS->videoh->update(pos.x, pos.y, to.getInternalSurface(), true, false,
+    [&]()
+    {
+        if(won)
+        {
+            CCS->videoh->close();
+            video = "HSLOOP.SMK";
+            CCS->videoh->open(VideoPath::builtin(video));
+        }
+        else
+            close();
+    });
     redraw();
 
 	CIntObject::show(to);
@@ -197,7 +218,7 @@ void CHighScoreInputScreen::show(Canvas & to)
 
 void CHighScoreInputScreen::activate()
 {
-    CCS->videoh->open(VideoPath::builtin("HSLOOP.SMK"));
+    CCS->videoh->open(VideoPath::builtin(video));
 	CIntObject::activate();
 }
 
@@ -211,6 +232,12 @@ void CHighScoreInputScreen::clickPressed(const Point & cursorPosition)
 {
     OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
 
+    if(!won)
+    {
+        close();
+        return;
+    }
+
     if(!input)
     {
         input = std::make_shared<CHighScoreInput>(
@@ -219,8 +246,11 @@ void CHighScoreInputScreen::clickPressed(const Point & cursorPosition)
             if(!text.empty())
             {
                 addEntry(text);
+                close();
+                GH.windows().createAndPushWindow<CHighScoreScreen>();
             }
-            close();
+            else
+                close();
         });
     }
 }

+ 4 - 1
client/mainmenu/CHighScoreScreen.h

@@ -59,8 +59,11 @@ class CHighScoreInputScreen : public CWindowObject
 {
     std::vector<std::shared_ptr<CMultiLineLabel>> texts;
     std::shared_ptr<CHighScoreInput> input;
+
+    std::string video;
+    bool won;
 public:
-	CHighScoreInputScreen();
+	CHighScoreInputScreen(bool won);
 
     void addEntry(std::string text);