From 1bf05d43a1da5bd31d864f5328128871ee5d8f2a Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Thu, 16 Nov 2023 22:39:50 +0100 Subject: [PATCH] fix video implementation error; implement paging; video loading --- Mods/vcmi/mod.json | 4 +++ client/CVideoHandler.cpp | 10 +++++-- client/windows/CTutorialWindow.cpp | 44 ++++++++++++++++++++---------- client/windows/CTutorialWindow.h | 4 +++ 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/Mods/vcmi/mod.json b/Mods/vcmi/mod.json index e1eeccc8a..cedf5bf5b 100644 --- a/Mods/vcmi/mod.json +++ b/Mods/vcmi/mod.json @@ -214,6 +214,10 @@ "SOUNDS/": [ {"type" : "dir", "path" : "/Sounds"} + ], + "VIDEO/": + [ + {"type" : "dir", "path" : "/Video"} ] } } diff --git a/client/CVideoHandler.cpp b/client/CVideoHandler.cpp index 38cecc84b..afdd19cc7 100644 --- a/client/CVideoHandler.cpp +++ b/client/CVideoHandler.cpp @@ -41,8 +41,11 @@ extern "C" { static int lodRead(void* opaque, uint8_t* buf, int size) { auto video = reinterpret_cast(opaque); + int bytes = static_cast(video->data->read(buf, size)); + if(bytes == 0) + return AVERROR_EOF; - return static_cast(video->data->read(buf, size)); + return bytes; } static si64 lodSeek(void * opaque, si64 pos, int whence) @@ -59,8 +62,11 @@ static si64 lodSeek(void * opaque, si64 pos, int whence) static int lodReadAudio(void* opaque, uint8_t* buf, int size) { auto video = reinterpret_cast(opaque); + int bytes = static_cast(video->dataAudio->read(buf, size)); + if(bytes == 0) + return AVERROR_EOF; - return static_cast(video->dataAudio->read(buf, size)); + return bytes; } static si64 lodSeekAudio(void * opaque, si64 pos, int whence) diff --git a/client/windows/CTutorialWindow.cpp b/client/windows/CTutorialWindow.cpp index 53f4ad9ff..48afe2e4a 100644 --- a/client/windows/CTutorialWindow.cpp +++ b/client/windows/CTutorialWindow.cpp @@ -26,11 +26,11 @@ #include "../render/Canvas.h" CTutorialWindow::CTutorialWindow(const TutorialMode & m) - : CWindowObject(BORDERED, ImagePath::builtin("DIBOXBCK")), mode { m } + : CWindowObject(BORDERED, ImagePath::builtin("DIBOXBCK")), mode { m }, page { 0 } { OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; - pos = Rect(pos.x, pos.y, 540, 400); //video: 480x320 + pos = Rect(pos.x, pos.y, 380, 400); //video: 320x240 background = std::make_shared(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, pos.w, pos.h)); updateShadow(); @@ -39,14 +39,25 @@ CTutorialWindow::CTutorialWindow(const TutorialMode & m) addUsedEvents(LCLICK); - buttonOk = std::make_shared(Point(239, 367), AnimationPath::builtin("IOKAY"), CButton::tooltip(), std::bind(&CTutorialWindow::close, this), EShortcut::GLOBAL_ACCEPT); //62x28 - buttonLeft = std::make_shared(Point(5, 177), AnimationPath::builtin("HSBTNS3"), CButton::tooltip(), std::bind(&CTutorialWindow::previous, this), EShortcut::MOVE_LEFT); //22x46 - buttonRight = std::make_shared(Point(513, 177), AnimationPath::builtin("HSBTNS5"), CButton::tooltip(), std::bind(&CTutorialWindow::next, this), EShortcut::MOVE_RIGHT); //22x46 + if(mode == TutorialMode::TOUCH_ADVENTUREMAP) videos = { "RightClick", "MapPanning", "MapZooming" }; + else if(mode == TutorialMode::TOUCH_BATTLE) videos = { "BattleDirection", "BattleDirectionAbort", "AbortSpell" }; - buttonLeft->block(true); + labelTitle = std::make_shared(190, 15, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, "Touchscreen Intro"); + buttonOk = std::make_shared(Point(159, 367), AnimationPath::builtin("IOKAY"), CButton::tooltip(), std::bind(&CTutorialWindow::close, this), EShortcut::GLOBAL_ACCEPT); //62x28 + buttonLeft = std::make_shared(Point(5, 217), AnimationPath::builtin("HSBTNS3"), CButton::tooltip(), std::bind(&CTutorialWindow::previous, this), EShortcut::MOVE_LEFT); //22x46 + buttonRight = std::make_shared(Point(352, 217), AnimationPath::builtin("HSBTNS5"), CButton::tooltip(), std::bind(&CTutorialWindow::next, this), EShortcut::MOVE_RIGHT); //22x46 - labelTitle = std::make_shared(270, 15, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, "Touchscreen Intro"); - labelInformation = std::make_shared(Rect(5, 50, 530, 60), EFonts::FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."); + setContent(); +} + +void CTutorialWindow::setContent() +{ + video = "tutorial/" + videos[page]; + + buttonLeft->block(page<1); + buttonRight->block(page>videos.size() - 2); + + labelInformation = std::make_shared(Rect(5, 40, 370, 60), EFonts::FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."); } void CTutorialWindow::openWindowFirstTime(const TutorialMode & m) @@ -72,31 +83,34 @@ void CTutorialWindow::close() void CTutorialWindow::next() { - + page++; + setContent(); + deactivate(); + activate(); } void CTutorialWindow::previous() { - + page--; + setContent(); + deactivate(); + activate(); } void CTutorialWindow::show(Canvas & to) { - CCS->videoh->update(pos.x + 200, pos.y + 200, to.getInternalSurface(), true, false, + CCS->videoh->update(pos.x + 30, pos.y + 120, to.getInternalSurface(), true, false, [&]() { CCS->videoh->close(); CCS->videoh->open(VideoPath::builtin(video)); }); - redraw(); CIntObject::show(to); } void CTutorialWindow::activate() { - video = "tutorial/BattleDirection"; - CCS->videoh->open(VideoPath::builtin(video)); CIntObject::activate(); } @@ -104,4 +118,4 @@ void CTutorialWindow::activate() void CTutorialWindow::deactivate() { CCS->videoh->close(); -} \ No newline at end of file +} diff --git a/client/windows/CTutorialWindow.h b/client/windows/CTutorialWindow.h index 4b6e165ec..17c73bc50 100644 --- a/client/windows/CTutorialWindow.h +++ b/client/windows/CTutorialWindow.h @@ -35,10 +35,14 @@ class CTutorialWindow : public CWindowObject std::shared_ptr labelInformation; std::string video; + std::vector videos; + + int page; void close(); void next(); void previous(); + void setContent(); public: CTutorialWindow(const TutorialMode & m);