Merge remote-tracking branch 'origin/master' into Physics

Conflicts:
	src/game/Game/LevelSystem.cpp
This commit is contained in:
viktorljung
2015-10-09 00:22:32 +02:00
48 changed files with 606 additions and 89 deletions
+23
View File
@@ -0,0 +1,23 @@
#ifndef GAME_GUI_ELOADINGFRAMECOMPLETE_H__
#define GAME_GUI_ELOADINGFRAMECOMPLETE_H__
#include "Core/EventBroker.h"
namespace dd
{
namespace GUI { class LoadingFrame; }
namespace Events
{
struct LoadingFrameComplete : Event
{
std::string FrameName;
GUI::LoadingFrame* Frame = nullptr;
};
}
}
#endif
+45
View File
@@ -0,0 +1,45 @@
#ifndef GUI_FPSCOUNTER_H__
#define GUI_FPSCOUNTER_H__
#include <numeric>
#include "GUI/Frame.h"
#include "GUI/NumberFrame.h"
namespace dd
{
namespace GUI
{
class FPSCounter : public Frame
{
public:
FPSCounter(Frame* parent, std::string name)
: Frame(parent, name)
{
m_FrameTimes.resize(m_MaxSamples);
m_Numbers = new GUI::NumberFrame(this, "FPSCounterNumberFrame");
}
virtual void Update(double dt)
{
m_FrameTimes[m_CurrentFrame % m_MaxSamples] = dt;
double sum = std::accumulate(m_FrameTimes.begin(), m_FrameTimes.end(), 0.0);
sum /= std::min(m_CurrentFrame, m_MaxSamples);
m_Numbers->SetNumber(std::round(1.0 / sum));
m_CurrentFrame++;
}
private:
NumberFrame* m_Numbers = nullptr;
int m_MaxSamples = 100;
int m_CurrentFrame = 0;
std::vector<double> m_FrameTimes;
};
}
}
#endif
+116
View File
@@ -0,0 +1,116 @@
#ifndef GUI_HUD_H__
#define GUI_HUD_H__
#include "GUI/Frame.h"
#include "GUI/TextureFrame.h"
#include "GUI/NumberFrame.h"
#include "Core/EKeyUp.h"
#include "Game/EScoreEvent.h"
#include "Game/GUI/FPSCounter.h"
#include "Game/EGameOver.h"
#include "Game/EClusterClear.h"
#include "Game/EKrakenAttack.h"
#include "GUI/Slider.h"
namespace dd
{
namespace GUI
{
class HUD : public Frame
{
public:
HUD(Frame* parent, std::string name)
: Frame(parent, name)
{
Width = parent->Width;
Height = parent->Height;
m_LevelIndicator = new GUI::TextureFrame(this, "HUDLevelIndicator");
m_LevelIndicator->SetTexture("Textures/GUI/HUD/LevelIndicatorBG.png");
m_AreaNumberFrame = new GUI::NumberFrame(m_LevelIndicator, "HUDScoreNumberFrameawdawdwa");
m_AreaNumberFrame->X = 132;
m_AreaNumberFrame->Y = 19;
m_AreaNumberFrame->SetNumber(6);
m_StageNumberFrame = new GUI::NumberFrame(m_LevelIndicator, "HUDScoreNumberFrameawdawdwa");
m_StageNumberFrame->X = 165;
m_StageNumberFrame->Y = 19;
m_StageNumberFrame->SetNumber(5);
m_ScoreIndicator = new GUI::TextureFrame(this, "HUDScoreIndicator");
m_ScoreIndicator->SetTexture("Textures/GUI/HUD/ScoreIndicatorBG.png");
m_ScoreIndicator->SetRight(Right());
m_ScoreNumberFrame = new GUI::NumberFrame(m_ScoreIndicator, "HUDScoreNumberFrame");
m_ScoreNumberFrame->X = 15;
m_ScoreNumberFrame->Y = 21;
m_FPSCounter = new GUI::FPSCounter(this, "FPSCounter");
m_KrakenAttackSlider = new Slider(this, "KrakenSlider");
m_KrakenAttackSlider->SetTexture("Textures/GUI/Menu/SliderBackground.png");
m_KrakenAttackSlider->SetTextureReleased("Textures/GUI/Menu/SliderHandle.png");
m_KrakenAttackSlider->SetLeft(Width / 2 - m_KrakenAttackSlider->Width / 2);
m_KrakenAttackSlider->Y = 800;
m_KrakenAttackSlider->Hide();
EVENT_SUBSCRIBE_MEMBER(m_EScore, &HUD::OnScore);
EVENT_SUBSCRIBE_MEMBER(m_EGameOver, &HUD::OnGameOver);
EVENT_SUBSCRIBE_MEMBER(m_ClusterClear, &HUD::OnClusterClear);
EVENT_SUBSCRIBE_MEMBER(m_KrakenAttack, &HUD::OnKrakenAttack);
}
private:
TextureFrame* m_LevelIndicator = nullptr;
TextureFrame* m_ScoreIndicator = nullptr;
NumberFrame* m_AreaNumberFrame = nullptr;
NumberFrame* m_StageNumberFrame = nullptr;
NumberFrame* m_ScoreNumberFrame = nullptr;
FPSCounter* m_FPSCounter = nullptr;
TextureFrame* m_GameOverFrame = nullptr;
TextureFrame* m_ClusterClearFrame = nullptr;
Slider* m_KrakenAttackSlider = nullptr;
EventRelay<Frame, Events::ScoreEvent> m_EScore;
EventRelay<Frame, Events::GameOver> m_EGameOver;
EventRelay<Frame, Events::ClusterClear> m_ClusterClear;
EventRelay<Frame, Events::KrakenAttack> m_KrakenAttack;
bool OnScore(const Events::ScoreEvent& event)
{
m_ScoreNumberFrame->SetNumber(m_ScoreNumberFrame->Number() + event.Score);
return true;
}
bool OnGameOver(const Events::GameOver& event)
{
m_GameOverFrame = new GUI::TextureFrame(this, "HUDGameOverFrame");
m_GameOverFrame->SetTexture("Textures/GUI/HUD/GameOverScreen.png");
return true;
}
bool OnClusterClear(const Events::ClusterClear& event)
{
m_ClusterClearFrame = new GUI::TextureFrame(this, "HUDGameOverFrame");
m_ClusterClearFrame->SetTexture("Textures/GUI/HUD/WinScreen.png");
return true;
}
bool OnKrakenAttack(const Events::KrakenAttack& event)
{
if (event.ChargeUpdate >= 1.f) {
m_KrakenAttackSlider->Hide();
} else {
m_KrakenAttackSlider->Show();
m_KrakenAttackSlider->SetPercentage(event.ChargeUpdate);
}
return true;
}
};
}
}
#endif
+73
View File
@@ -0,0 +1,73 @@
#ifndef GAME_GUI_LOADINGFRAME_H__
#define GAME_GUI_LOADINGFRAME_H__
#include "GUI/TextureFrame.h"
#include "GUI/Slider.h"
#include "Core/ResourceManager.h"
#include "Game/GUI/ELoadingFrameComplete.h"
namespace dd
{
namespace GUI
{
class LoadingFrame : public TextureFrame
{
public:
LoadingFrame(Frame* parent, std::string name)
: TextureFrame(parent, name)
{
m_Slider = new GUI::Slider(this, "LoadingFrameSlider");
//m_SFXSlider->X = 0;
m_Slider->Y = 453;
//m_SFXSlider->SetTop(m_TitleSFX->Bottom() + 10);
m_Slider->SetTexture("Textures/GUI/Menu/SliderBackground.png");
m_Slider->SetTextureReleased("Textures/GUI/Menu/SliderHandle.png");
m_Slider->AlignVertically();
m_Slider->SetPercentage(1.f);
m_Slider->X = Width / 2.f - m_Slider->Width / 2.f;
}
void AddTexturePreload(std::string resourceName)
{
m_Items.push_back(resourceName);
}
void Preload()
{
m_Preloading = true;
}
void CancelPreload()
{
m_Preloading = false;
m_CurrentItem = 0;
}
void Update(double dt) override
{
if (m_Preloading) {
ResourceManager::Preload<dd::Texture>(m_Items[m_CurrentItem]);
m_Slider->SetPercentage((m_CurrentItem + 1) / (float)m_Items.size());
m_CurrentItem++;
if (m_CurrentItem >= m_Items.size()) {
m_Preloading = false;
dd::Events::LoadingFrameComplete e;
e.FrameName = Name();
e.Frame = this;
EventBroker->Publish(e);
}
}
}
private:
bool m_Preloading = false;
int m_CurrentItem = 0;
std::vector<std::string> m_Items;
GUI::Slider* m_Slider = nullptr;
};
}
}
#endif
+59
View File
@@ -0,0 +1,59 @@
#ifndef GUI_MAINMENU_H__
#define GUI_MAINMENU_H__
#include "GUI/TextureFrame.h"
#include "Game/GUI/MainMenuMain.h"
#include "Game/GUI/MainMenuOptions.h"
#include "Core/EKeyUp.h"
namespace dd
{
namespace GUI
{
class MainMenu : public TextureFrame
{
public:
MainMenu(Frame* parent, std::string name)
: TextureFrame(parent, name)
{
SetTexture("Textures/GUI/Menu/Background.png");
Width = 675;
Height = 1080;
m_LeftBanner = new GUI::TextureFrame(this, "MainMenuLeftBanner");
m_LeftBanner->SetTexture("Textures/GUI/Menu/Left.png");
m_LeftBanner->Width = 231;
m_LeftBanner->Height = 1080;
m_MainMenuMain = new GUI::MainMenuMain(this, "MainMenuMain");
m_MainMenuMain->SetLeft(m_LeftBanner->Right());
m_MainMenuMain->SetTop(60);
m_MainMenuOptions = new GUI::MainMenuOptions(this, "MainMenuOptions");
m_MainMenuOptions->SetLeft(m_LeftBanner->Right());
m_MainMenuOptions->SetTop(m_MainMenuMain->Bottom());
//EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &MainMenu::OnKeyUp);
}
private:
TextureFrame* m_LeftBanner;
MainMenuMain* m_MainMenuMain;
MainMenuOptions* m_MainMenuOptions;
//EventRelay<Frame, Events::KeyUp> m_EKeyUp;
bool OnKeyUp(const Events::KeyUp& event)
{
if (event.KeyCode == GLFW_KEY_ESCAPE) {
Show();
}
return true;
}
};
}
}
#endif
+69
View File
@@ -0,0 +1,69 @@
#ifndef GUI_MAINMENUMAIN_H__
#define GUI_MAINMENUMAIN_H__
#include "GUI/TextureFrame.h"
#include "GUI/Button.h"
#include "Game/GUI/Story1.h"
namespace dd
{
namespace GUI
{
class MainMenuMain : public TextureFrame
{
public:
MainMenuMain(Frame* parent, std::string name)
: TextureFrame(parent, name)
{
Width = 409;
Height = 543;
m_Title = new GUI::TextureFrame(this, "MainMenuMainTitle");
m_Title->SetTexture("Textures/GUI/Menu/MainTitle.png");
m_SquidoutButton = new GUI::Button(this, "MainMenuMainSquidoutButton");
m_SquidoutButton->SetTop(m_Title->Bottom());
m_SquidoutButton->SetTextureReleased("Textures/GUI/Menu/MainSquidout.png");
m_SquidoutButton->SetTextureHover("Textures/GUI/Menu/MainSquidoutHover.png");
m_SquidoutButton->SetTexturePressed("Textures/GUI/Menu/MainSquidoutClick.png");
m_SquidoutButton->SizeToTexture();
m_TimeAttackButton = new GUI::Button(this, "MainMenuMainTimeAttackButton");
m_TimeAttackButton->SetTop(m_SquidoutButton->Bottom());
m_TimeAttackButton->SetTextureReleased("Textures/GUI/Menu/MainTimeAttack.png");
m_TimeAttackButton->SetTextureHover("Textures/GUI/Menu/MainTimeAttackHover.png");
m_TimeAttackButton->SetTexturePressed("Textures/GUI/Menu/MainTimeAttackClick.png");
m_TimeAttackButton->SizeToTexture();
m_OptionsButton = new GUI::Button(this, "MainMenuMainOptionsButton");
m_OptionsButton->SetTop(m_TimeAttackButton->Bottom());
m_OptionsButton->SetTextureReleased("Textures/GUI/Menu/MainOptions.png");
m_OptionsButton->SetTextureHover("Textures/GUI/Menu/MainOptionsHover.png");
m_OptionsButton->SetTexturePressed("Textures/GUI/Menu/MainOptionsClick.png");
m_OptionsButton->SizeToTexture();
EVENT_SUBSCRIBE_MEMBER(m_EButtonRelease, &MainMenuMain::OnButtonRelease);
}
private:
TextureFrame* m_Title;
Button* m_SquidoutButton;
Button* m_TimeAttackButton;
Button* m_OptionsButton;
EventRelay<Frame, Events::ButtonRelease> m_EButtonRelease;
virtual bool OnButtonRelease(const Events::ButtonRelease& event)
{
if (event.Button == m_SquidoutButton) {
m_Parent->Hide();
auto story = new GUI::Story1(BaseFrame, "Story1");
}
return true;
}
};
}
}
#endif
+82
View File
@@ -0,0 +1,82 @@
#ifndef GUI_MAINMENUOPTIONS_H__
#define GUI_MAINMENUOPTIONS_H__
#include "GUI/TextureFrame.h"
#include "GUI/Button.h"
#include "GUI/Slider.h"
#include "GUI/ESliderUpdate.h"
#include "Sound/EMasterVolume.h"
namespace dd
{
namespace GUI
{
class MainMenuOptions : public TextureFrame
{
public:
MainMenuOptions(Frame* parent, std::string name)
: TextureFrame(parent, name)
{
Width = 409;
Height = 1080;
m_Title = new GUI::TextureFrame(this, "MainMenuOptionsTitle");
m_Title->SetTexture("Textures/GUI/Menu/OptionsTitle.png");
m_TitleSFX = new GUI::TextureFrame(this, "MainMenuOptionsSFXTitle");
m_TitleSFX->SetTop(m_Title->Bottom() + 20);
m_TitleSFX->SetTexture("Textures/GUI/Menu/OptionsSFXTitle.png");
m_SFXSlider = new GUI::Slider(this, "MainMenuOptionsSFXSlider");
m_SFXSlider->X = 66;
m_SFXSlider->SetTop(m_TitleSFX->Bottom() + 10);
m_SFXSlider->SetTexture("Textures/GUI/Menu/SliderBackground.png");
m_SFXSlider->SetTextureReleased("Textures/GUI/Menu/SliderHandle.png");
m_SFXSlider->AlignVertically();
m_SFXSlider->SetPercentage(1.f);
m_TitleBGM = new GUI::TextureFrame(this, "MainMenuOptionsBGMTitle");
m_TitleBGM->SetTop(m_SFXSlider->Bottom() + 20);
m_TitleBGM->SetTexture("Textures/GUI/Menu/OptionsBGMTitle.png");
m_BGMSlider = new GUI::Slider(this, "MainMenuOptionsBGMSlider");
m_BGMSlider->X = 66;
m_BGMSlider->SetTop(m_TitleBGM->Bottom() + 10);
m_BGMSlider->SetTexture("Textures/GUI/Menu/SliderBackground.png");
m_BGMSlider->SetTextureReleased("Textures/GUI/Menu/SliderHandle.png");
m_BGMSlider->AlignVertically();
m_BGMSlider->SetPercentage(1.f);
EVENT_SUBSCRIBE_MEMBER(m_ESliderUpdate, &MainMenuOptions::OnSliderUpdate);
}
private:
TextureFrame* m_Title = nullptr;
TextureFrame* m_TitleSFX = nullptr;
Slider* m_SFXSlider = nullptr;
Slider* m_BGMSlider = nullptr;
TextureFrame* m_TitleBGM = nullptr;
EventRelay<Frame, Events::SliderUpdate> m_ESliderUpdate;
bool OnSliderUpdate(const Events::SliderUpdate& event)
{
if (event.Slider == m_SFXSlider) {
Events::MasterVolume e;
e.IsAmbient = false;
e.Gain = event.Percentage;
EventBroker->Publish(e);
}
if (event.Slider == m_BGMSlider) {
Events::MasterVolume e;
e.IsAmbient = true;
e.Gain = event.Percentage;
EventBroker->Publish(e);
}
return true;
}
};
}
}
#endif
+247
View File
@@ -0,0 +1,247 @@
#ifndef GAME_GUI_STORY1_H__
#define GAME_GUI_STORY1_H__
#include "Core/ResourceManager.h"
#include "Game/GUI/StoryboardFrame.h"
#include "Game/GUI/ELoadingFrameComplete.h"
#include "Game/GUI/LoadingFrame.h"
#include "Game/EGameStart.h"
#include "Core/EKeyDown.h"
#include "Game/GUI/HUD.h"
namespace dd
{
namespace GUI
{
class Story1 : public StoryboardFrame
{
public:
Story1(Frame* parent, std::string name)
: StoryboardFrame(parent, name)
{
EVENT_SUBSCRIBE_MEMBER(m_ELoadingFrameComplete, &Story1::OnLoadingFrameComplete);
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Story1::OnKeyDown);
m_LoadingFrame = new GUI::LoadingFrame(this, "Story1LoadingFrame");
m_LoadingFrame->SetTexture("Textures/GUI/Loading.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/Brunn1.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/Brunn2.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/Brunn3.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/Brunn4.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/Brunn5.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene1.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene2.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene3.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene4.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene5.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene6.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene7.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene8.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene9.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene10.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene11.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene12.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene13.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene14.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene15.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene16.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene17.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene18.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene19.png");
m_LoadingFrame->Preload();
m_Spacebar = new TextureFrame(this, "ZZZSpacebar");
m_Spacebar->SetTexture("Textures/GUI/SpacebarSkip.png");
m_Spacebar->SetRight(Right() - 10);
m_Spacebar->SetBottom(Bottom() - 10);
m_Spacebar->DisableScissor();
Transition t;
/*
Sid in the well scene
*/
t.Time = t.Time + 0;
t.Duration = 0;
t.Texture = "Textures/Story/Brunn1.png";
t.Viewport = Rectangle(3108, 11276, 1376, 2203);
AddTransition(t);
t.Time = t.Time + 2;
t.Duration = 0.5;
t.Texture = "Textures/Story/Brunn2.png";
AddTransition(t);
t.Time = t.Time + 3;
t.Duration = 0.5;
t.Texture = "Textures/Story/Brunn3.png";
AddTransition(t);
t.Time = t.Time + 3;
t.Duration = 4;
t.Texture = "Textures/Story/Brunn4.png";
t.Viewport = Rectangle(2232, 0, 2952, 4725);
AddTransition(t);
t.Time = t.Time + 5;
t.Duration = 0;
t.Texture = "Textures/Story/Brunn5.png";
AddTransition(t);
/*
Submarine scene
*/
t.Time = t.Time + 4;
t.Duration = 2.5;
t.Texture = "Textures/Story/SubScene1.png";
t.Viewport = Rectangle(976, 0, 1615, 2586);
AddTransition(t);
// I'm Tom and stuff!
t.Time = t.Time + 1;
t.Duration = 0.5;
t.Texture = "Textures/Story/SubScene2.png";
AddTransition(t);
// Pan to the right here
t.Time = t.Time + 3.5;
t.Duration = 2;
t.Texture = "Textures/Story/SubScene3.png";
t.Viewport = Rectangle(1574, 0, 1615, 2586);
AddTransition(t);
// ZAP!
t.Time = t.Time + 2.5;
t.Duration = 0.5;
t.Texture = "Textures/Story/SubScene4.png";
AddTransition(t);
t.Time = t.Time + 0.5;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene5.png";
AddTransition(t);
t.Time = t.Time + 0.1;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene6.png";
AddTransition(t);
t.Time = t.Time + 0.5;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene7.png";
AddTransition(t);
// BZZT!
t.Time = t.Time + 1;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene8.png";
AddTransition(t);
t.Time = t.Time + 0.5;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene9.png";
AddTransition(t);
t.Time = t.Time + 0.1;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene10.png";
AddTransition(t);
t.Time = t.Time + 0.5;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene11.png";
AddTransition(t);
t.Time = t.Time + 1;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene12.png";
AddTransition(t);
t.Time = t.Time + 0.5;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene13.png";
AddTransition(t);
t.Time = t.Time + 0.2;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene14.png";
AddTransition(t);
t.Time = t.Time + 0.5;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene15.png";
AddTransition(t);
t.Time = t.Time + 1;
t.Duration = 0.5;
t.Texture = "Textures/Story/SubScene16.png";
AddTransition(t);
t.Time = t.Time + 3.5;
t.Duration = 0.5;
t.Texture = "Textures/Story/SubScene17.png";
AddTransition(t);
t.Time = t.Time + 3;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene18.png";
AddTransition(t);
t.Time = t.Time + 2;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene19.png";
AddTransition(t);
}
void Update(double dt) override
{
StoryboardFrame::Update(dt);
if (m_Spacebar == nullptr) {
}
}
void OnComplete() override
{
m_Spacebar->Show();
}
private:
GUI::LoadingFrame* m_LoadingFrame = nullptr;
TextureFrame* m_Spacebar = nullptr;
EventRelay<Frame, Events::KeyDown> m_EKeyDown;
bool OnKeyDown(const Events::KeyDown& event)
{
if (Hidden()) {
return false;
}
if (event.KeyCode == GLFW_KEY_SPACE) {
m_LoadingFrame->CancelPreload();
Events::GameStart e;
EventBroker->Publish(e);
Hide();
auto hud = new GUI::HUD(BaseFrame, "HUD");
}
return true;
}
EventRelay<Frame, Events::LoadingFrameComplete> m_ELoadingFrameComplete;
bool OnLoadingFrameComplete(const Events::LoadingFrameComplete& event)
{
if (event.FrameName == "Story1LoadingFrame") {
event.Frame->Hide();
m_Spacebar->Hide();
Play();
}
return true;
}
};
}
}
#endif
+128
View File
@@ -0,0 +1,128 @@
#ifndef GAME_GUI_STORYBOARDFRAME_H__
#define GAME_GUI_STORYBOARDFRAME_H__
#include "GUI/TextureFrame.h"
namespace dd
{
namespace GUI
{
class StoryboardFrame : public TextureFrame
{
public:
struct Transition
{
double Time = 0.0;
double Duration = 0.0;
Rectangle Viewport;
std::string Texture;
};
StoryboardFrame(Frame* parent, std::string name)
: TextureFrame(parent, name)
{
m_TextureFrame = new TextureFrame(this, "StoryboardFrameHelper");
//m_TextureFrame->DisableScissor();
}
void AddTransition(Transition& transition)
{
m_Timeline.push_back(transition);
}
void Play()
{
m_Playing = true;
}
void Skip()
{
m_Playing = false;
OnComplete();
}
void Update(double dt)
{
if (Hidden()) {
return;
}
if (m_Playing) {
m_Time += dt;
if (m_NextIndex < m_Timeline.size()) {
if (m_Time >= m_Timeline.at(m_NextIndex).Time) {
m_CurrentIndex = m_NextIndex;
Transition& t = m_Timeline.at(m_CurrentIndex);
m_TextureFrame->FadeToTexture(t.Texture, t.Duration);
//m_TextureFrame->SetTexture(t.Texture);
m_TextureFrame->SizeToTexture();
if (m_StartRect == Rectangle()) {
m_StartRect = Rectangle(0, 0, m_TextureFrame->Width, m_TextureFrame->Height);
}
else {
m_StartRect = m_TargetRect;
}
double wScaleParent = Width / (double)m_TextureFrame->Width;
double wScale = m_TextureFrame->Width / (double)t.Viewport.Width;
LOG_DEBUG("wScale: %f", wScale);
double hScaleParent = Height / (double)m_TextureFrame->Height;
double hScale = m_TextureFrame->Height / (double)t.Viewport.Height;
LOG_DEBUG("hScale: %f", hScale);
m_TargetRect.X = -t.Viewport.X * wScale * wScaleParent;
m_TargetRect.Y = -t.Viewport.Y * hScale * hScaleParent;
m_TargetRect.Width = m_TextureFrame->Width * wScale * wScaleParent;
m_TargetRect.Height = m_TextureFrame->Height * hScale * hScaleParent;
m_NextIndex++;
}
} else {
OnComplete();
}
}
Transition& t = m_Timeline.at(m_CurrentIndex);
double progress = glm::min((m_Time - t.Time)/t.Duration, 1.0);
m_TextureFrame->X = (int)easeSine(progress, m_StartRect.X, (m_TargetRect.X - m_StartRect.X), 1.0);
m_TextureFrame->Y = (int)easeSine(progress, m_StartRect.Y, (m_TargetRect.Y - m_StartRect.Y), 1.0);
m_TextureFrame->Width = (int)easeSine(progress, m_StartRect.Width, (m_TargetRect.Width - m_StartRect.Width), 1.0);
m_TextureFrame->Height = (int)easeSine(progress, m_StartRect.Height, (m_TargetRect.Height - m_StartRect.Height), 1.0);
}
virtual void OnComplete() { }
protected:
TextureFrame* m_TextureFrame = nullptr;
private:
bool m_Playing = false;
double m_Time = 0;
int m_CurrentIndex = 0;
int m_NextIndex = 0;
std::vector<Transition> m_Timeline;
Rectangle m_StartRect;
Rectangle m_TargetRect;
double easeSine(double t, double b, double c, double d)
{
return -c / 2 * (glm::cos(glm::pi<double>()*t / d) - 1) + b;
}
float easeExpo(float t,float b , float c, float d) {
if (t == 0) return b;
if (t == d) return b + c;
if ((t /= d / 2) < 1) return c / 2 * pow(2, 10 * (t - 1)) + b;
return c / 2 * (-pow(2, -10 * --t) + 2) + b;
}
};
}
}
#endif