Skip to content

Commit

Permalink
Add fade outs in cutscenes
Browse files Browse the repository at this point in the history
  • Loading branch information
xavieran committed Jun 23, 2024
1 parent 5deacd8 commit 385af0d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 39 deletions.
37 changes: 14 additions & 23 deletions app/play_cutscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "gui/backgrounds.hpp"
#include "gui/cutscenePlayer.hpp"
#include "gui/core/mouseEvent.hpp"
#include "gui/guiManager.hpp"
#include "gui/window.hpp"

#include "imgui/imguiWrapper.hpp"
Expand Down Expand Up @@ -89,30 +90,27 @@ int main(int argc, char** argv)
width / guiScalar,
height / guiScalar};

Gui::AnimatorStore animatorStore{};

auto cutscenePlayer = Gui::CutscenePlayer{
spriteManager,
animatorStore,
font,
bookFont,
backgrounds,
[](){}
};
auto gameState = BAK::GameState{nullptr};
auto guiManager = Gui::GuiManager{
rootWidget.GetCursor(),
spriteManager,
gameState
};

auto chapter = BAK::Chapter{static_cast<unsigned>(std::atoi(argv[1]))};
auto startActions = BAK::CutsceneList::GetStartScene(chapter);
auto finishActions = BAK::CutsceneList::GetFinishScene(chapter);
std::vector<BAK::CutsceneAction> actions{};
for (const auto& action : startActions)
{
cutscenePlayer.QueueAction(action);
actions.emplace_back(action);
}
for (const auto& action : finishActions)
{
cutscenePlayer.QueueAction(action);
actions.emplace_back(action);
}

rootWidget.AddChildBack(&cutscenePlayer);
rootWidget.AddChildFront(&guiManager);

bool playing = false;

Expand All @@ -128,15 +126,6 @@ int main(int argc, char** argv)
{
rootWidget.OnMouseEvent(
Gui::LeftMousePress{guiScaleInv * click});
if (!playing)
{
cutscenePlayer.Play();
playing = true;
}
else
{
cutscenePlayer.Advance();
}
},
[&](const auto click)
{
Expand Down Expand Up @@ -180,12 +169,14 @@ int main(int argc, char** argv)

double currentTime = 0;
double lastTime = 0;

guiManager.PlayCutscene(actions, []{});
do
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

currentTime = glfwGetTime();
animatorStore.OnTimeDelta(currentTime - lastTime);
guiManager.OnTimeDelta(currentTime - lastTime);
lastTime = currentTime;

guiRenderer.RenderGui(&rootWidget);
Expand Down
3 changes: 3 additions & 0 deletions bak/character.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "bak/character.hpp"

#include "bak/itemNumbers.hpp"

#include "com/ostream.hpp"

#include <algorithm>
#include <ios>

namespace BAK {
Expand Down
3 changes: 0 additions & 3 deletions bak/character.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
#include "bak/IContainer.hpp"

#include "bak/condition.hpp"
#include "bak/itemNumbers.hpp"
#include "bak/skills.hpp"
#include "bak/spells.hpp"
#include "bak/types.hpp"
#include "bak/inventory.hpp"

#include <algorithm>
#include <cstdint>
#include <iterator>
#include <ostream>
#include <string>

Expand Down
18 changes: 13 additions & 5 deletions gui/cutscenePlayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "bak/cutscenes.hpp"

#include "gui/IGuiManager.hpp"
#include "gui/bookPlayer.hpp"
#include "gui/core/widget.hpp"
#include "gui/dynamicTTM.hpp"
Expand All @@ -17,6 +18,7 @@ class CutscenePlayer : public Widget
const Font& font,
const Font& bookFont,
const Backgrounds& background,
IGuiManager& guiManager,
std::function<void()>&& cutsceneFinished)
:
Widget(RectTag{}, glm::vec2{}, glm::vec2{320, 200}, glm::vec4{}, true),
Expand All @@ -32,6 +34,7 @@ class CutscenePlayer : public Widget
background,
[&](){ SceneFinished(); },
[&](auto book){ PlayBook(book); }),
mGuiManager{guiManager},
mCutsceneFinished{std::move(cutsceneFinished)}
{
}
Expand Down Expand Up @@ -100,20 +103,24 @@ class CutscenePlayer : public Widget
{
if (mTtmPlaying)
{
ClearChildren();
AddChildBack(mDynamicTTM.GetScene());
mDynamicTTM.AdvanceAction();
mGuiManager.DoFade(1.5, [&]{
ClearChildren();
AddChildBack(mDynamicTTM.GetScene());
mDynamicTTM.AdvanceAction();
});
}
else
{
Play();
mGuiManager.DoFade(1.5, [&]{ Play(); });
}
}

void SceneFinished()
{
mTtmPlaying = false;
Play();
mGuiManager.DoFade(1.5, [&]{
Play();
});
}

void PlayBook(unsigned book)
Expand All @@ -133,6 +140,7 @@ class CutscenePlayer : public Widget

BookPlayer mBookPlayer;
DynamicTTM mDynamicTTM;
IGuiManager& mGuiManager;

std::function<void()> mCutsceneFinished;
};
Expand Down
27 changes: 19 additions & 8 deletions gui/guiManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class GuiManager final : public Widget, public IGuiManager
mFontManager.GetGameFont(),
mFontManager.GetBookFont(),
mBackgrounds,
*this,
[this](){ CutsceneFinished(); }
},
mMainView{*this, mBackgrounds, mIcons, mFontManager.GetSpellFont()},
Expand Down Expand Up @@ -241,19 +242,18 @@ class GuiManager final : public Widget, public IGuiManager
mCutscenePlayer.QueueAction(action);
}
DoFade(1.5, [this]{
mPreviousScreen = mScreenStack.Top();
mScreenStack.PopScreen();
if (mScreenStack.HasChildren())
{
mPreviousScreen = mScreenStack.Top();
mScreenStack.PopScreen();
}
mScreenStack.PushScreen(&mCutscenePlayer);
mCutscenePlayer.Play();
});
}

void CutsceneFinished()
{
//DoFade(1.0, [this]{
// mScreenStack.PopScreen();
// mScreenStack.PushScreen(mPreviousScreen);
//});
mCutsceneFinished();
}

Expand Down Expand Up @@ -547,11 +547,22 @@ class GuiManager final : public Widget, public IGuiManager

void ShowGameStartMap() override
{
DoFade(1.0, [this]{
auto ShowMap = [&]{
mScreenStack.PopScreen();
mFullMap.DisplayGameStartMode(mGameState.GetChapter(), mGameState.GetMapLocation());
mScreenStack.PushScreen(&mFullMap);
});
};
// Dirty, but this is what happens if coming out of a cutscene
if (HaveChild(&mFadeScreen))
{
ShowMap();
}
else
{
DoFade(1.0, [showMap=ShowMap]{
showMap();
});
}
}

void ShowCureScreen(
Expand Down

0 comments on commit 385af0d

Please sign in to comment.