浏览代码

use video player for spellbook animation

Laserlicht 10 月之前
父节点
当前提交
8808c9538c

+ 0 - 4
client/media/CEmptyVideoPlayer.h

@@ -14,10 +14,6 @@
 class CEmptyVideoPlayer final : public IVideoPlayer
 {
 public:
-	void playSpellbookAnimation(const VideoPath & name, const Point & position) override
-	{
-	}
-
 	/// Load video from specified path
 	std::unique_ptr<IVideoInstance> open(const VideoPath & name, float scaleFactor) override
 	{

+ 0 - 62
client/media/CVideoHandler.cpp

@@ -637,68 +637,6 @@ std::pair<std::unique_ptr<ui8 []>, si64> CAudioInstance::extractAudio(const Vide
 	return dat;
 }
 
-bool CVideoPlayer::openAndPlayVideoImpl(const VideoPath & name, const Point & position, bool useOverlay, bool stopOnKey)
-{
-	CVideoInstance instance;
-
-	auto extractedAudio = getAudio(name);
-	int audioHandle = CCS->soundh->playSound(extractedAudio);
-
-	if (!instance.openInput(name))
-		return true;
-
-	instance.openVideo();
-	instance.prepareOutput(1, true);
-
-	auto lastTimePoint = boost::chrono::steady_clock::now();
-
-	while(instance.loadNextFrame())
-	{
-		if(stopOnKey)
-		{
-			GH.input().fetchEvents();
-			if(GH.input().ignoreEventsUntilInput())
-			{
-				CCS->soundh->stopSound(audioHandle);
-				return false;
-			}
-		}
-
-		SDL_Rect rect;
-		rect.x = position.x;
-		rect.y = position.y;
-		rect.w = instance.dimensions.x;
-		rect.h = instance.dimensions.y;
-
-		SDL_RenderFillRect(mainRenderer, &rect);
-
-		if(instance.textureYUV)
-			SDL_RenderCopy(mainRenderer, instance.textureYUV, nullptr, &rect);
-		else
-			SDL_RenderCopy(mainRenderer, instance.textureRGB, nullptr, &rect);
-
-		SDL_RenderPresent(mainRenderer);
-
-		// Framerate delay
-		double targetFrameTimeSeconds = instance.getCurrentFrameDuration();
-		auto targetFrameTime = boost::chrono::milliseconds(static_cast<int>(1000 * targetFrameTimeSeconds));
-
-		auto timePointAfterPresent = boost::chrono::steady_clock::now();
-		auto timeSpentBusy = boost::chrono::duration_cast<boost::chrono::milliseconds>(timePointAfterPresent - lastTimePoint);
-
-		if(targetFrameTime > timeSpentBusy)
-			boost::this_thread::sleep_for(targetFrameTime - timeSpentBusy);
-
-		lastTimePoint = boost::chrono::steady_clock::now();
-	}
-	return true;
-}
-
-void CVideoPlayer::playSpellbookAnimation(const VideoPath & name, const Point & position)
-{
-	openAndPlayVideoImpl(name, position * GH.screenHandler().getScalingFactor(), false, false);
-}
-
 std::unique_ptr<IVideoInstance> CVideoPlayer::open(const VideoPath & name, float scaleFactor)
 {
 	auto result = std::make_unique<CVideoInstance>();

+ 0 - 2
client/media/CVideoHandler.h

@@ -103,11 +103,9 @@ public:
 
 class CVideoPlayer final : public IVideoPlayer
 {
-	bool openAndPlayVideoImpl(const VideoPath & name, const Point & position, bool useOverlay, bool stopOnKey);
 	void openVideoFile(CVideoInstance & state, const VideoPath & fname);
 
 public:
-	void playSpellbookAnimation(const VideoPath & name, const Point & position) final;
 	std::unique_ptr<IVideoInstance> open(const VideoPath & name, float scaleFactor) final;
 	std::pair<std::unique_ptr<ui8[]>, si64> getAudio(const VideoPath & videoToOpen) final;
 };

+ 0 - 3
client/media/IVideoPlayer.h

@@ -45,9 +45,6 @@ public:
 class IVideoPlayer : boost::noncopyable
 {
 public:
-	/// Plays video on top of the screen, returns only after playback is over
-	virtual void playSpellbookAnimation(const VideoPath & name, const Point & position) = 0;
-
 	/// Load video from specified path. Returns nullptr on failure
 	virtual std::unique_ptr<IVideoInstance> open(const VideoPath & name, float scaleFactor) = 0;
 

+ 13 - 2
client/windows/CSpellWindow.cpp

@@ -30,6 +30,7 @@
 #include "../widgets/CTextInput.h"
 #include "../widgets/TextControls.h"
 #include "../widgets/Buttons.h"
+#include "../widgets/VideoWidget.h"
 #include "../adventureMap/AdventureMapInterface.h"
 #include "../render/AssetGenerator.h"
 
@@ -395,6 +396,8 @@ void CSpellWindow::fRcornerb()
 
 void CSpellWindow::show(Canvas & to)
 {
+	if(video)
+		video->show(to);
 	statusBar->show(to);
 }
 
@@ -493,14 +496,22 @@ void CSpellWindow::setCurrentPage(int value)
 
 void CSpellWindow::turnPageLeft()
 {
+	OBJECT_CONSTRUCTION;
 	if(settings["video"]["spellbookAnimation"].Bool() && !isBigSpellbook)
-		CCS->videoh->playSpellbookAnimation(VideoPath::builtin("PGTRNLFT.SMK"), pos.topLeft() + Point(13, 14));
+		video = std::make_shared<VideoWidgetOnce>(Point(13, 14), VideoPath::builtin("PGTRNLFT.SMK"), false, [this](){
+			video.reset();
+			redraw();
+		});
 }
 
 void CSpellWindow::turnPageRight()
 {
+	OBJECT_CONSTRUCTION;
 	if(settings["video"]["spellbookAnimation"].Bool() && !isBigSpellbook)
-		CCS->videoh->playSpellbookAnimation(VideoPath::builtin("PGTRNRGH.SMK"), pos.topLeft() + Point(13, 14));
+		video = std::make_shared<VideoWidgetOnce>(Point(13, 14), VideoPath::builtin("PGTRNRGH.SMK"), false, [this](){
+			video.reset();
+			redraw();
+		});
 }
 
 void CSpellWindow::keyPressed(EShortcut key)

+ 3 - 0
client/windows/CSpellWindow.h

@@ -28,6 +28,7 @@ class CSpellWindow;
 class CTextInput;
 class TransparentFilledRectangle;
 class CToggleButton;
+class VideoWidgetOnce;
 
 /// The spell window
 class CSpellWindow : public CWindowObject
@@ -86,6 +87,8 @@ class CSpellWindow : public CWindowObject
 	std::shared_ptr<CToggleButton> showAllSpells;
 	std::shared_ptr<CLabel> showAllSpellsDescription;
 
+	std::shared_ptr<VideoWidgetOnce> video;
+
 	bool isBigSpellbook;
 	int spellsPerPage;
 	int offL;