Added first stage story

This commit is contained in:
2015-10-08 23:41:27 +02:00
parent 18e2891621
commit 7ee0bbc32b
31 changed files with 117 additions and 36 deletions
+2 -5
View File
@@ -3,8 +3,7 @@
#include "GUI/TextureFrame.h"
#include "GUI/Button.h"
#include "Game/EGameStart.h"
#include "Game/GUI/HUD.h"
#include "Game/GUI/Story1.h"
namespace dd
{
@@ -57,10 +56,8 @@ private:
virtual bool OnButtonRelease(const Events::ButtonRelease& event)
{
if (event.Button == m_SquidoutButton) {
Events::GameStart e;
EventBroker->Publish(e);
m_Parent->Hide();
auto hud = new GUI::HUD(BaseFrame, "HUD");
auto story = new GUI::Story1(BaseFrame, "Story1");
}
return true;
+68
View File
@@ -5,6 +5,9 @@
#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
{
@@ -18,6 +21,41 @@ public:
: 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;
@@ -157,12 +195,42 @@ public:
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 (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;
+47 -31
View File
@@ -22,7 +22,9 @@ public:
StoryboardFrame(Frame* parent, std::string name)
: TextureFrame(parent, name)
{
m_TextureFrame = new TextureFrame(this, "StoryboardFrameHelper");
//m_TextureFrame->DisableScissor();
}
@@ -33,44 +35,55 @@ public:
void Play()
{
m_Playing = 1;
m_Playing = true;
}
void Skip()
{
m_Playing = false;
OnComplete();
}
void Update(double dt)
{
if (!m_Playing) {
if (Hidden()) {
return;
}
m_Time += (double)m_Playing * dt;
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);
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();
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;
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++;
}
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();
}
}
@@ -82,8 +95,13 @@ public:
m_TextureFrame->Height = (int)easeSine(progress, m_StartRect.Height, (m_TargetRect.Height - m_StartRect.Height), 1.0);
}
public:
int m_Playing = 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;
@@ -91,8 +109,6 @@ public:
Rectangle m_StartRect;
Rectangle m_TargetRect;
TextureFrame* m_TextureFrame = nullptr;
double easeSine(double t, double b, double c, double d)
{
return -c / 2 * (glm::cos(glm::pi<double>()*t / d) - 1) + b;