diff --git a/assets/Textures/GUI/HUD/LevelIndicatorBG.png b/assets/Textures/GUI/HUD/LevelIndicatorBG.png new file mode 100644 index 0000000..46cc1b3 Binary files /dev/null and b/assets/Textures/GUI/HUD/LevelIndicatorBG.png differ diff --git a/assets/Textures/GUI/HUD/ScoreIndicatorBG.png b/assets/Textures/GUI/HUD/ScoreIndicatorBG.png new file mode 100644 index 0000000..db97909 Binary files /dev/null and b/assets/Textures/GUI/HUD/ScoreIndicatorBG.png differ diff --git a/assets/Textures/GUI/Menu/Background.png b/assets/Textures/GUI/Menu/Background.png new file mode 100644 index 0000000..8b598c3 Binary files /dev/null and b/assets/Textures/GUI/Menu/Background.png differ diff --git a/assets/Textures/GUI/Menu/Left.png b/assets/Textures/GUI/Menu/Left.png new file mode 100644 index 0000000..e7813de Binary files /dev/null and b/assets/Textures/GUI/Menu/Left.png differ diff --git a/assets/Textures/GUI/Menu/MainOptions.png b/assets/Textures/GUI/Menu/MainOptions.png new file mode 100644 index 0000000..a38c916 Binary files /dev/null and b/assets/Textures/GUI/Menu/MainOptions.png differ diff --git a/assets/Textures/GUI/Menu/MainOptionsClick.png b/assets/Textures/GUI/Menu/MainOptionsClick.png new file mode 100644 index 0000000..5a69342 Binary files /dev/null and b/assets/Textures/GUI/Menu/MainOptionsClick.png differ diff --git a/assets/Textures/GUI/Menu/MainOptionsHover.png b/assets/Textures/GUI/Menu/MainOptionsHover.png new file mode 100644 index 0000000..c6e9c02 Binary files /dev/null and b/assets/Textures/GUI/Menu/MainOptionsHover.png differ diff --git a/assets/Textures/GUI/Menu/MainSquidout.png b/assets/Textures/GUI/Menu/MainSquidout.png new file mode 100644 index 0000000..85d8748 Binary files /dev/null and b/assets/Textures/GUI/Menu/MainSquidout.png differ diff --git a/assets/Textures/GUI/Menu/MainSquidoutClick.png b/assets/Textures/GUI/Menu/MainSquidoutClick.png new file mode 100644 index 0000000..f2206a3 Binary files /dev/null and b/assets/Textures/GUI/Menu/MainSquidoutClick.png differ diff --git a/assets/Textures/GUI/Menu/MainSquidoutHover.png b/assets/Textures/GUI/Menu/MainSquidoutHover.png new file mode 100644 index 0000000..8fe33fe Binary files /dev/null and b/assets/Textures/GUI/Menu/MainSquidoutHover.png differ diff --git a/assets/Textures/GUI/Menu/MainTimeAttack.png b/assets/Textures/GUI/Menu/MainTimeAttack.png new file mode 100644 index 0000000..42ff9f3 Binary files /dev/null and b/assets/Textures/GUI/Menu/MainTimeAttack.png differ diff --git a/assets/Textures/GUI/Menu/MainTimeAttackClick.png b/assets/Textures/GUI/Menu/MainTimeAttackClick.png new file mode 100644 index 0000000..3f37dc8 Binary files /dev/null and b/assets/Textures/GUI/Menu/MainTimeAttackClick.png differ diff --git a/assets/Textures/GUI/Menu/MainTimeAttackHover.png b/assets/Textures/GUI/Menu/MainTimeAttackHover.png new file mode 100644 index 0000000..33cfc2d Binary files /dev/null and b/assets/Textures/GUI/Menu/MainTimeAttackHover.png differ diff --git a/assets/Textures/GUI/Menu/MainTitle.png b/assets/Textures/GUI/Menu/MainTitle.png new file mode 100644 index 0000000..9f2d607 Binary files /dev/null and b/assets/Textures/GUI/Menu/MainTitle.png differ diff --git a/assets/Textures/GUI/Menu/OptionsBGMTitle.png b/assets/Textures/GUI/Menu/OptionsBGMTitle.png new file mode 100644 index 0000000..5e35cbb Binary files /dev/null and b/assets/Textures/GUI/Menu/OptionsBGMTitle.png differ diff --git a/assets/Textures/GUI/Menu/OptionsSFXTitle.png b/assets/Textures/GUI/Menu/OptionsSFXTitle.png new file mode 100644 index 0000000..2c7b9b9 Binary files /dev/null and b/assets/Textures/GUI/Menu/OptionsSFXTitle.png differ diff --git a/assets/Textures/GUI/Menu/OptionsTitle.png b/assets/Textures/GUI/Menu/OptionsTitle.png new file mode 100644 index 0000000..08aa3f5 Binary files /dev/null and b/assets/Textures/GUI/Menu/OptionsTitle.png differ diff --git a/assets/Textures/GUI/Menu/SliderBackground.png b/assets/Textures/GUI/Menu/SliderBackground.png new file mode 100644 index 0000000..427e2e3 Binary files /dev/null and b/assets/Textures/GUI/Menu/SliderBackground.png differ diff --git a/assets/Textures/GUI/Menu/SliderHandle.png b/assets/Textures/GUI/Menu/SliderHandle.png new file mode 100644 index 0000000..49004d4 Binary files /dev/null and b/assets/Textures/GUI/Menu/SliderHandle.png differ diff --git a/include/Core/Engine.h b/include/Core/Engine.h old mode 100755 new mode 100644 index b1e831c..9841ee0 --- a/include/Core/Engine.h +++ b/include/Core/Engine.h @@ -53,6 +53,13 @@ #include "Physics/ESetImpulse.h" #include "Physics/CWaterVolume.h" +#include "Game/EGameStart.h" +#include "Sound/EPlaySound.h" + +#include "GUI/Frame.h" +#include "GUI/Button.h" +#include "Game/MainMenu.h" +#include "Game/HUD.h" namespace dd { @@ -70,12 +77,16 @@ public: m_Renderer->SetResolution(Rectangle(0, 0, 675, 1080)); m_Renderer->Initialize(); + m_FrameStack = new GUI::Frame(m_EventBroker.get()); + m_FrameStack->Width = 675; + m_FrameStack->Height = 1080; + auto hud = new GUI::HUD(m_FrameStack, "HUD"); + auto menu = new GUI::MainMenu(m_FrameStack, "MainMenu"); + m_InputManager = std::make_shared(m_Renderer->Window(), m_EventBroker); m_World = std::make_shared(m_EventBroker); - - //TODO: Move this out of engine.h m_World->ComponentFactory.Register(); m_World->SystemFactory.Register( @@ -123,7 +134,7 @@ public: //OctoBall - { + { auto ent = m_World->CreateEntity(); std::shared_ptr transform = m_World->AddComponent(ent); transform->Position = glm::vec3(-0.f, 0.26f, -9.f); @@ -134,14 +145,14 @@ public: std::shared_ptr circleShape = m_World->AddComponent(ent); std::shared_ptr ball = m_World->AddComponent(ent); ball->Speed = 5.f; - std::shared_ptr physics = m_World->AddComponent(ent); - physics->Static = false; + std::shared_ptr physics = m_World->AddComponent(ent); + physics->Static = false; auto plight = m_World->AddComponent(ent); plight->Radius = 2.f; m_World->CommitEntity(ent); - } + } //PointLightTest { @@ -316,6 +327,11 @@ public: m_World->CommitEntity(ent); } + + //EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &Engine::OnGameStart); + m_EGameStart = decltype(m_EGameStart)(std::bind(&Engine::OnGameStart, this, std::placeholders::_1)); + m_EventBroker->Subscribe(m_EGameStart); + m_LastTime = glfwGetTime(); } @@ -327,27 +343,32 @@ public: double dt = currentTime - m_LastTime; m_LastTime = currentTime; - ResourceManager::Update(); - // Update input m_InputManager->Update(dt); + // Swap event queues to get fresh input data in the read queue + //m_EventBroker->Swap(); - m_World->Update(dt); - - - if (glfwGetKey(m_Renderer->Window(), GLFW_KEY_R)) { - ResourceManager::Reload("Shaders/Deferred/3/Fragment.glsl"); + ResourceManager::Update(); + if (m_GameIsRunning) { + m_World->Update(dt); } + m_EventBroker->Process(); + m_FrameStack->UpdateLayered(dt); + m_RendererQueue.Clear(); + m_FrameStack->DrawLayered(m_RendererQueue); //TODO Fill up the renderQueue with models (Temp fix) - TEMPAddToRenderQueue(); + if (m_GameIsRunning) { + TEMPAddToRenderQueue(); + } // Render scene //TODO send renderqueue to draw. m_Renderer->Draw(m_RendererQueue); + m_EventBroker->Process(); // Swap event queues - m_EventBroker->Clear(); + m_EventBroker->Swap(); glfwPollEvents(); } @@ -358,12 +379,9 @@ public: //TODO: Get this out of engine.h void TEMPAddToRenderQueue() { - if (!m_TransformSystem) m_TransformSystem = m_World->GetSystem(); - m_RendererQueue.Clear(); - for (auto &pair : *m_World->GetEntities()) { EntityID entity = pair.first; @@ -443,7 +461,6 @@ public: } } - m_RendererQueue.Sort(); } //TODO: Get this out of engine.h @@ -462,7 +479,6 @@ public: job.EndIndex = texGroup.EndIndex; job.ModelMatrix = modelMatrix; job.Color = color; - job.fileName = fileName; m_RendererQueue.Deferred.Add(job); } @@ -508,14 +524,34 @@ public: } private: - std::shared_ptr m_ResourceManager; std::shared_ptr m_EventBroker; + GUI::Frame* m_FrameStack = nullptr; std::shared_ptr m_Renderer; RenderQueueCollection m_RendererQueue; std::shared_ptr m_InputManager; std::shared_ptr m_World; - + //TODO: Redo + bool m_GameIsRunning = false; + dd::EventRelay m_EGameStart; + bool OnGameStart(const dd::Events::GameStart &event) + { + m_GameIsRunning = true; + //Todo: Move this + { + dd::Events::PlaySound e; + e.path = "Sounds/BGM/under-the-sea-instrumental.wav"; + e.isAmbient = true; + m_EventBroker->Publish(e); + } + { + dd::Events::PlaySound e; + e.path = "Sounds/BGM/water-flowing.wav"; + e.volume = 0.3f; + e.isAmbient = true; + m_EventBroker->Publish(e); + } + }; double m_LastTime; }; diff --git a/include/Core/EventBroker.h b/include/Core/EventBroker.h index f19309c..cb5e39c 100644 --- a/include/Core/EventBroker.h +++ b/include/Core/EventBroker.h @@ -119,7 +119,7 @@ public: template int Process(); int Process(std::string contextTypeName); - void Clear(); + void Swap(); void Unsubscribe(BaseEventRelay &relay); private: diff --git a/include/Core/PNG.h b/include/Core/PNG.h index fc99324..994a5bc 100644 --- a/include/Core/PNG.h +++ b/include/Core/PNG.h @@ -33,9 +33,6 @@ class PNG : public Image public: PNG(std::string path); ~PNG(); - -private: - }; } diff --git a/include/Core/RenderQueue.h b/include/Core/RenderQueue.h index a8d88e7..0319267 100755 --- a/include/Core/RenderQueue.h +++ b/include/Core/RenderQueue.h @@ -22,8 +22,9 @@ #include #include -#include "Texture.h" -#include "Model.h" +#include "Core/Util/Rectangle.h" +#include "Core/Texture.h" +#include "Core/Model.h" namespace dd { @@ -52,8 +53,8 @@ struct ModelJob : RenderJob unsigned int ShaderID; unsigned int TextureID; - std::string fileName; - + glm::mat4 ProjectionMatrix; + glm::mat4 ViewMatrix; glm::mat4 ModelMatrix; GLuint DiffuseTexture; GLuint NormalTexture; @@ -90,6 +91,8 @@ struct SpriteJob : RenderJob unsigned int ShaderID; unsigned int TextureID; + glm::mat4 ProjectionMatrix; + glm::mat4 ViewMatrix; glm::mat4 ModelMatrix; GLuint DiffuseTexture; GLuint NormalTexture; @@ -115,6 +118,18 @@ struct PointLightJob : RenderJob } }; +struct FrameJob : SpriteJob +{ + Rectangle Scissor; + Rectangle Viewport; + std::string Name; + + void CalculateHash() override + { + Hash = 0; + } +}; + struct WaterParticleJob : RenderJob { glm::vec3 Position; @@ -134,7 +149,7 @@ public: void Add(T &job) { job.CalculateHash(); - Jobs.push_front(std::shared_ptr(new T(job))); + Jobs.push_back(std::shared_ptr(new T(job))); m_Size++; } @@ -150,18 +165,17 @@ public: } int Size() const { return m_Size; } - - std::forward_list>::const_iterator begin() + std::list>::const_iterator begin() { return Jobs.begin(); } - std::forward_list>::const_iterator end() + std::list>::const_iterator end() { return Jobs.end(); } - std::forward_list> Jobs; + std::list> Jobs; private: int m_Size = 0; @@ -172,12 +186,14 @@ struct RenderQueueCollection RenderQueue Deferred; RenderQueue Forward; RenderQueue Lights; + RenderQueue GUI; void Clear() { Deferred.Clear(); Forward.Clear(); Lights.Clear(); + GUI.Clear(); } void Sort() @@ -185,6 +201,7 @@ struct RenderQueueCollection Deferred.Sort(); Forward.Sort(); Lights.Sort(); + GUI.Sort(); } }; diff --git a/include/Core/Renderer.h b/include/Core/Renderer.h index 94a3259..5a2b03f 100755 --- a/include/Core/Renderer.h +++ b/include/Core/Renderer.h @@ -117,6 +117,7 @@ private: void DrawScene(RenderQueue &objects, ShaderProgram &program); void DrawLightSpheres(RenderQueue &lights); void DrawWater(RenderQueue &objects); + void DrawGUI(RenderQueue& rq); void DebugKeys(); }; diff --git a/include/Core/Texture.h b/include/Core/Texture.h index 13bd113..f7cfd69 100644 --- a/include/Core/Texture.h +++ b/include/Core/Texture.h @@ -43,6 +43,9 @@ public: operator GLuint() const { return m_Texture; } + unsigned int Width = 0; + unsigned int Height = 0; + private: GLuint m_Texture = 0; }; diff --git a/include/Core/Util/Rectangle.h b/include/Core/Util/Rectangle.h index 6ce0695..c24501f 100644 --- a/include/Core/Util/Rectangle.h +++ b/include/Core/Util/Rectangle.h @@ -44,29 +44,30 @@ struct Rectangle int Height; virtual int Left() const { return X; } - void SetLeft(int left) + virtual void SetLeft(int left) { - Width += X - left; + //Width += X - left; X = left; } virtual int Right() const { return X + Width; } - void SetRight(int right) + virtual void SetRight(int right) { Width = right - X; } virtual int Top() const { return Y; } - void SetTop(int top) + virtual void SetTop(int top) { - Height += Y - top; + //Height += Y - top; Y = top; } virtual int Bottom() const { return Y + Height; } - int SetBottom(int bottom) + virtual void SetBottom(int bottom) { Height = bottom - Y; } - Rectangle& operator+=(const Rectangle &rhs) { + Rectangle& operator+=(const Rectangle &rhs) + { SetLeft(std::min(Left(), rhs.Left())); SetRight(std::max(Right(), rhs.Right())); SetTop(std::min(Top(), rhs.Top())); diff --git a/include/GUI/Button.h b/include/GUI/Button.h new file mode 100644 index 0000000..b2a665d --- /dev/null +++ b/include/GUI/Button.h @@ -0,0 +1,147 @@ +#ifndef GUI_BUTTON_H__ +#define GUI_BUTTON_H__ + +#include "GUI/TextureFrame.h" +#include "GUI/EButtonEnter.h" +#include "GUI/EButtonLeave.h" +#include "GUI/EButtonPress.h" +#include "GUI/EButtonRelease.h" +#include "Core/EMouseMove.h" +#include "Core/EMousePress.h" +#include "Core/EMouseRelease.h" + +namespace dd +{ +namespace GUI +{ + +class Button : public TextureFrame +{ +public: + Button(Frame* parent, std::string name) + : TextureFrame(parent, name) + { + EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &Button::OnMouseMove); + EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &Button::OnMousePress); + EVENT_SUBSCRIBE_MEMBER(m_EMouseRelease, &Button::OnMouseRelease); + } + + void SetTextureHover(std::string resourceName) + { + m_TextureHover = resourceName; + } + void SetTextureReleased(std::string resourceName) + { + m_TextureReleased = resourceName; + SetTexture(resourceName); + } + void SetTexturePressed(std::string resourceName) + { + m_TexturePressed = resourceName; + } + + void Draw(RenderQueueCollection& rq) override + { + if (m_Texture == nullptr && !m_TextureReleased.empty()) { + SetTexture(m_TextureReleased); + } + + TextureFrame::Draw(rq); + } + + virtual void OnEnter() { } + virtual void OnLeave() { } + virtual void OnPress() { } + virtual void OnRelease() { } + +protected: + bool m_MouseIsOver = false; + bool m_IsDown = false; + + virtual bool OnMouseMove(const Events::MouseMove& event) + { + bool isOver = Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1)); + if (isOver && !m_MouseIsOver) { // Enter + if (!m_IsDown) { + if (!m_TextureHover.empty()) { + SetTexture(m_TextureHover); + } + } + OnEnter(); + Events::ButtonEnter e; + e.FrameName = m_Name; + EventBroker->Publish(e); + } else if (!isOver && m_MouseIsOver) { // Leave + if (!m_IsDown) { + if (!m_TextureReleased.empty()) { + SetTexture(m_TextureReleased); + } + } + OnLeave(); + Events::ButtonLeave e; + e.FrameName = m_Name; + EventBroker->Publish(e); + } + m_MouseIsOver = isOver; + + return true; + } + virtual bool OnMousePress(const Events::MousePress& event) + { + if (!Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1))) { + return false; + } + + if (!m_TexturePressed.empty()) { + SetTexture(m_TexturePressed); + } + + m_IsDown = true; + OnPress(); + Events::ButtonPress e; + e.FrameName = m_Name; + e.Button = this; + EventBroker->Publish(e); + + return true; + } + virtual bool OnMouseRelease(const Events::MouseRelease& event) + { + bool isOver = Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1)); + if (!isOver && !m_IsDown) { + return false; + } + + if (m_MouseIsOver) { + if (!m_TextureHover.empty()) { + SetTexture(m_TextureHover); + } + } else { + if (!m_TextureReleased.empty()) { + SetTexture(m_TextureReleased); + } + } + + m_IsDown = false; + OnRelease(); + Events::ButtonRelease e; + e.FrameName = m_Name; + e.Button = this; + EventBroker->Publish(e); + + return true; + } + +private: + EventRelay m_EMouseMove; + EventRelay m_EMousePress; + EventRelay m_EMouseRelease; + + std::string m_TextureHover; + std::string m_TexturePressed; + std::string m_TextureReleased; +}; + +} +} +#endif diff --git a/include/GUI/EButtonEnter.h b/include/GUI/EButtonEnter.h new file mode 100644 index 0000000..b2fa352 --- /dev/null +++ b/include/GUI/EButtonEnter.h @@ -0,0 +1,40 @@ +/* + This file is part of Daydream Engine. + Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung + + Daydream Engine is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Daydream Engine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with Daydream Engine. If not, see . +*/ + +#ifndef Events_ButtonEnter_h__ +#define Events_ButtonEnter_h__ + +#include "Core/EventBroker.h" + +namespace dd +{ + +namespace Events +{ + +/** Thrown on GUI button hover. */ +struct ButtonEnter : Event +{ + std::string FrameName; +}; + +} + +} + +#endif // Events_ButtonEnter_h__ \ No newline at end of file diff --git a/include/GUI/EButtonLeave.h b/include/GUI/EButtonLeave.h new file mode 100644 index 0000000..c448190 --- /dev/null +++ b/include/GUI/EButtonLeave.h @@ -0,0 +1,40 @@ +/* + This file is part of Daydream Engine. + Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung + + Daydream Engine is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Daydream Engine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with Daydream Engine. If not, see . +*/ + +#ifndef Events_ButtonLeave_h__ +#define Events_ButtonLeave_h__ + +#include "Core/EventBroker.h" + +namespace dd +{ + +namespace Events +{ + +/** Thrown on GUI button hover. */ +struct ButtonLeave : Event +{ + std::string FrameName; +}; + +} + +} + +#endif // Events_ButtonLeave_h__ \ No newline at end of file diff --git a/include/GUI/EButtonPress.h b/include/GUI/EButtonPress.h new file mode 100644 index 0000000..9e18ece --- /dev/null +++ b/include/GUI/EButtonPress.h @@ -0,0 +1,43 @@ +/* + This file is part of Daydream Engine. + Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung + + Daydream Engine is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Daydream Engine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with Daydream Engine. If not, see . +*/ + +#ifndef Events_ButtonPress_h__ +#define Events_ButtonPress_h__ + +#include "Core/EventBroker.h" + +namespace dd +{ + +namespace GUI { class Button; } + +namespace Events +{ + +/** Thrown on GUI button press. */ +struct ButtonPress : Event +{ + std::string FrameName; + GUI::Button* Button; +}; + +} + +} + +#endif // Events_ButtonPress_h__ \ No newline at end of file diff --git a/include/GUI/EButtonRelease.h b/include/GUI/EButtonRelease.h new file mode 100644 index 0000000..a596c61 --- /dev/null +++ b/include/GUI/EButtonRelease.h @@ -0,0 +1,43 @@ +/* + This file is part of Daydream Engine. + Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung + + Daydream Engine is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Daydream Engine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with Daydream Engine. If not, see . +*/ + +#ifndef Events_ButtonRelease_h__ +#define Events_ButtonRelease_h__ + +#include "Core/EventBroker.h" + +namespace dd +{ + +namespace GUI { class Button; } + +namespace Events +{ + +/** Thrown on GUI button release. */ +struct ButtonRelease : Event +{ + std::string FrameName; + GUI::Button* Button; +}; + +} + +} + +#endif // Events_ButtonRelease_h__ \ No newline at end of file diff --git a/include/GUI/ESliderUpdate.h b/include/GUI/ESliderUpdate.h new file mode 100644 index 0000000..b2f3c9b --- /dev/null +++ b/include/GUI/ESliderUpdate.h @@ -0,0 +1,45 @@ +/* + This file is part of Daydream Engine. + Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung + + Daydream Engine is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Daydream Engine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with Daydream Engine. If not, see . +*/ + +#ifndef Events_SliderUpdate_h__ +#define Events_SliderUpdate_h__ + +#include "Core/EventBroker.h" + +namespace dd +{ + +namespace GUI { class Slider; } + +namespace Events +{ + +/** Thrown when GUI slider is moved. */ +struct SliderUpdate : Event +{ + std::string FrameName; + GUI::Slider* Slider; + float Percentage; + float DeltaPercentage; +}; + +} + +} + +#endif // Events_SliderUpdate_h__ \ No newline at end of file diff --git a/include/GUI/Frame.h b/include/GUI/Frame.h new file mode 100644 index 0000000..f7e302c --- /dev/null +++ b/include/GUI/Frame.h @@ -0,0 +1,264 @@ +#ifndef GUI_Frame_h__ +#define GUI_Frame_h__ + +#include +#include + +#include "Core/Util/Rectangle.h" +#include "Core/EventBroker.h" +#include "Core/EKeyDown.h" +#include "Core/EKeyUp.h" +#include "Core/ResourceManager.h" +#include "Core/Renderer.h" +#include "Core/RenderQueue.h" +#include "Core/Texture.h" +#include "Input/EInputCommand.h" + +namespace dd +{ +namespace GUI +{ + +class Frame : public Rectangle +{ +public: + enum class Anchor + { + Left, + Right, + Top, + Bottom + }; + + static const int BaseWidth = 1280; + static const int BaseHeight = 720; + + // Set up a base frame with an event broker + Frame(dd::EventBroker* eventBroker) + : EventBroker(eventBroker) + , BaseFrame(this) + , Rectangle() { } + + // Create a frame as a child + Frame(Frame* parent, std::string name) + : m_Name(name) + { + SetParent(parent); + EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Frame::OnKeyDown); + EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Frame::OnKeyUp); + EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &Frame::OnCommand); + } + + ~Frame() + { + /*for (auto layer : m_Children) + { + for (auto child : layer.second) + { + delete child.second; + } + } + + if (m_Parent) + { + m_Parent->RemoveChild(this); + }*/ + } + + Frame* Parent() const { return m_Parent; } + + void SetParent(Frame* parent) + { + if (parent == nullptr) { + LOG_ERROR("Failed to parent frame \"%s\": Invalid parent", m_Name.c_str()); + return; + } + + m_Layer = parent->Layer() + 1; + parent->AddChild(this); + m_Parent = parent; + EventBroker = parent->EventBroker; + BaseFrame = parent->BaseFrame; + } + + void AddChild(Frame* child) + { + m_Children[child->m_Layer].insert(std::make_pair(child->Name(), child)); + if (m_Parent) { + m_Parent->AddChild(child); + } + } + + void RemoveChild(Frame* child) + { + auto it = m_Children.find(child->m_Layer); + if (it != m_Children.end()) { + m_Children.erase(it); + } + + if (m_Parent) { + m_Parent->RemoveChild(child); + } + } + + std::string Name() const { return m_Name; } + void SetName(std::string val) { m_Name = val; } + + int Layer() const { return m_Layer; } + + bool Hidden() const + { + if (m_Parent) + return m_Parent->Hidden() || m_Hidden; + else + return m_Hidden; + } + bool Visible() const + { + return !Hidden(); + } + + virtual void Hide() { m_Hidden = true; } + virtual void Show() { m_Hidden = false; } + + int Left() const override + { + if (m_Parent) + return m_Parent->Left() + X; + else + return X; + } + void SetLeft(int absLeft) override + { + if (m_Parent) { + X = absLeft - m_Parent->Left(); + } else { + X = absLeft; + } + } + int Right() const override + { + return Left() + Width; + } + void SetRight(int absRight) override + { + if (m_Parent) { + X = absRight - Width - m_Parent->Left(); + } else { + X = absRight - Width; + } + } + int Top() const override + { + if (m_Parent) + return m_Parent->Top() + Y; + else + return Y; + } + void SetTop(int absTop) override + { + if (m_Parent) { + Y = absTop - m_Parent->Top(); + } else { + Y = absTop; + } + } + int Bottom() const override + { + return Top() + Height; + } + void SetBottom(int absBottom) override + { + if (m_Parent) { + Y = absBottom - Height - m_Parent->Top(); + } else { + Y = absBottom - Height; + } + } + + glm::vec2 Scale() + { + if (m_Parent) + return m_Parent->Scale(); + else + return glm::vec2(Width, Height) / glm::vec2(BaseWidth, BaseHeight); + } + + Rectangle AbsoluteRectangle() + { + int left = Left(); + if (m_Parent) + left = std::max(left, m_Parent->Left()); + int top = Top(); + if (m_Parent) + top = std::max(top, m_Parent->Top()); + int width = Right() - left; + int height = Bottom() - top; + return Rectangle(left, top, width, height); + } + + void UpdateLayered(double dt) + { + // Update ourselves + this->Update(dt); + + // Update children + for (auto& pairLayer : m_Children) { + auto children = pairLayer.second; + for (auto& pairChild : children) { + auto child = pairChild.second; + child->Update(dt); + } + } + } + + virtual void Update(double dt) { } + + void DrawLayered(RenderQueueCollection& rq) + { + if (this->Hidden()) + return; + + // Draw ourselves + this->Draw(rq); + + // Draw children + for (auto& pairLayer : m_Children) { + auto children = pairLayer.second; + for (auto& pairChild : children) { + auto child = pairChild.second; + if (child->Hidden()) + continue; + child->Draw(rq); + } + } + } + + virtual void Draw(RenderQueueCollection& rq) { } + +protected: + dd::EventBroker* EventBroker; + Frame* BaseFrame = nullptr; + + std::string m_Name = "UIParent"; + int m_Layer = 0; + bool m_Hidden = false; + + Frame* m_Parent = nullptr; + typedef std::multimap Children_t; // name -> frame + std::map m_Children; // layer -> Children_t + + virtual bool OnKeyDown(const Events::KeyDown& event) { return false; } + virtual bool OnKeyUp(const Events::KeyUp& event) { return false; } + virtual bool OnCommand(const Events::InputCommand& event) { return false; } + +private: + EventRelay m_EKeyDown; + EventRelay m_EKeyUp; + EventRelay m_EInputCommand; +}; + +} +} + +#endif // GUI_Frame_h__ diff --git a/include/GUI/Slider.h b/include/GUI/Slider.h new file mode 100644 index 0000000..de53245 --- /dev/null +++ b/include/GUI/Slider.h @@ -0,0 +1,124 @@ +#ifndef GUI_SLIDER_H__ +#define GUI_SLIDER_H__ + +#include "GUI/TextureFrame.h" +#include "GUI/Button.h" +#include "GUI/EButtonPress.h" +#include "GUI/EButtonRelease.h" +#include "GUI/ESliderUpdate.h" +#include "Core/EMouseMove.h" + +namespace dd +{ +namespace GUI +{ + +class Slider : public TextureFrame +{ +public: + Slider(Frame* parent, std::string name) + : TextureFrame(parent, name) + { + m_SliderButton = new GUI::Button(this, "SliderButton"); + m_SliderButton->DisableScissor(); + + EVENT_SUBSCRIBE_MEMBER(m_EButtonPress, &Slider::OnButtonPress); + EVENT_SUBSCRIBE_MEMBER(m_EButtonRelease, &Slider::OnButtonRelease); + EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &Slider::OnMouseMove); + } + + float Percentage() const { return m_Percentage; } + void SetPercentage(const float percentage) + { + m_Percentage = percentage; + m_SliderButton->X = percentage * (Width - m_SliderButton->Width); + } + + void SetTextureHover(std::string resourceName) + { + m_SliderButton->SetTextureHover(resourceName); + } + void SetTextureReleased(std::string resourceName) + { + m_SliderButton->SetTextureReleased(resourceName); + } + void SetTexturePressed(std::string resourceName) + { + m_SliderButton->SetTexturePressed(resourceName); + } + + void AlignVertically() + { + m_SliderButton->Y = (Height / 2) - (m_SliderButton->Height / 2); + } + + ~Slider() + { + if (m_SliderButton != nullptr) { + delete m_SliderButton; + m_SliderButton = nullptr; + } + } + + virtual void Update(double dt) override + { + + } + +private: + Button* m_SliderButton = nullptr; + bool m_IsGrabbed = false; + float m_Percentage = 0.f; + + EventRelay m_EButtonPress; + EventRelay m_EButtonRelease; + EventRelay m_EMouseMove; + + virtual bool OnButtonPress(const Events::ButtonPress& event) + { + if (event.Button == m_SliderButton) { + m_IsGrabbed = true; + } + + return true; + } + + virtual bool OnButtonRelease(const Events::ButtonRelease& event) + { + if (event.Button == m_SliderButton) { + m_IsGrabbed = false; + } + + return true; + } + + virtual bool OnMouseMove(const Events::MouseMove& event) + { + if (m_IsGrabbed) { + // Set horizontal position + m_SliderButton->X += event.DeltaX; + if (m_SliderButton->Left() < Left()) { + m_SliderButton->SetLeft(Left()); + } else if (m_SliderButton->Right() > Right()) { + m_SliderButton->SetRight(Right()); + } + + // Update percentage + float newPercentage = m_SliderButton->X / (float)(Width - m_SliderButton->Width); + Events::SliderUpdate e; + e.FrameName = Name(); + e.Slider = this; + e.Percentage = newPercentage; + e.DeltaPercentage = newPercentage - m_Percentage; + EventBroker->Publish(e); + m_Percentage = newPercentage; + } + + return true; + } +}; + +} +} +#endif + diff --git a/include/GUI/TextureFrame.h b/include/GUI/TextureFrame.h new file mode 100644 index 0000000..0b2bb98 --- /dev/null +++ b/include/GUI/TextureFrame.h @@ -0,0 +1,106 @@ +#ifndef GUI_TextureFrame_h__ +#define GUI_TextureFrame_h__ + +#include "GUI/Frame.h" +#include "Core/Texture.h" + +namespace dd +{ +namespace GUI +{ + +class TextureFrame : public Frame +{ +public: + TextureFrame(Frame* parent, std::string name) + : Frame(parent, name) { } + + void EnableScissor() { m_ScissorEnabled = true; } + void DisableScissor() { m_ScissorEnabled = false; } + + void Draw(RenderQueueCollection& rq) override + { + if (m_Texture == nullptr) + return; + + // Main texture + { + FrameJob job; + job.Scissor = (m_ScissorEnabled) ? m_Parent->AbsoluteRectangle() : Rectangle(); + job.Viewport = Rectangle(Left(), Top(), Width, Height); + job.TextureID = m_Texture->ResourceID; + job.DiffuseTexture = *m_Texture; + job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a * m_CurrentFade); + job.Name = Name(); + rq.GUI.Add(job); + } + + // Texture while fading + if (m_FadeTexture && m_CurrentFade < 1) { + FrameJob job; + job.Scissor = (m_ScissorEnabled) ? m_Parent->AbsoluteRectangle() : Rectangle(); + job.Viewport = Rectangle(Left(), Top(), Width, Height); + job.TextureID = m_FadeTexture->ResourceID; + job.DiffuseTexture = *m_FadeTexture; + job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a); + job.Name = Name(); + rq.GUI.Add(job); + } + } + + dd::Texture* Texture() const { return m_Texture; } + + void SetTexture(std::string resourceName) + { + m_Texture = ResourceManager::Load(resourceName); + if (m_Texture == nullptr) { + m_Texture = ResourceManager::Load("Textures/Core/ErrorTexture.png"); + } + SizeToTexture(); + } + + void SizeToTexture() + { + if (m_Texture != nullptr) { + this->Width = m_Texture->Width; + this->Height = m_Texture->Height; + } + } + + void FadeToTexture(std::string resourceName, double duration) + { + m_FadeTexture = m_Texture; + SetTexture(resourceName); + m_FadeDuration = duration; + m_CurrentFade = 0.f; + } + + void Update(double dt) override + { + if (m_CurrentFade < 1) { + m_CurrentFade += dt / m_FadeDuration; + if (m_CurrentFade > 1) { + m_FadeTexture = nullptr; + m_CurrentFade = 1; + m_FadeDuration = 0; + } + } + } + + glm::vec4 Color() const { return m_Color; } + void SetColor(glm::vec4 val) { m_Color = val; } + +protected: + bool m_ScissorEnabled = true; + dd::Texture* m_Texture = nullptr; + dd::Texture* m_FadeTexture = nullptr; + glm::vec4 m_Color = glm::vec4(1.f, 1.f, 1.f, 1.f); + float m_FadeDuration = 0.f; + float m_CurrentFade = 1.f; + +}; + +} +} + +#endif // GUI_TextureFrame_h__ diff --git a/include/Game/EGameStart.h b/include/Game/EGameStart.h new file mode 100644 index 0000000..bfee0fd --- /dev/null +++ b/include/Game/EGameStart.h @@ -0,0 +1,25 @@ +// +// Created by Adam on 2015-09-25. +// + +#ifndef EVENTS_EGAMESTART_H__ +#define EVENTS_EGAMESTART_H__ + +#include "Core/EventBroker.h" + +namespace dd +{ + +namespace Events +{ + +struct GameStart : public Event +{ + +}; + +} + +} + +#endif diff --git a/include/Game/HUD.h b/include/Game/HUD.h new file mode 100644 index 0000000..e660a9e --- /dev/null +++ b/include/Game/HUD.h @@ -0,0 +1,37 @@ +#ifndef GUI_HUD_H__ +#define GUI_HUD_H__ + +#include "GUI/Frame.h" +#include "GUI/TextureFrame.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_ScoreIndicator = new GUI::TextureFrame(this, "HUDScoreIndicator"); + m_ScoreIndicator->SetTexture("Textures/GUI/HUD/ScoreIndicatorBG.png"); + m_ScoreIndicator->SetRight(Right()); + } + +private: + TextureFrame* m_LevelIndicator = nullptr; + TextureFrame* m_ScoreIndicator = nullptr; +}; + +} +} +#endif + diff --git a/include/Game/LevelSystem.h.orig b/include/Game/LevelSystem.h.orig deleted file mode 100755 index 5e56ad3..0000000 --- a/include/Game/LevelSystem.h.orig +++ /dev/null @@ -1,149 +0,0 @@ -// -// Created by Adniklastrator on 2015-09-09. -// - -#ifndef DAYDREAM_LEVELSYSTEM_H -#define DAYDREAM_LEVELSYSTEM_H - -#include "Core/System.h" -#include "Core/CTransform.h" -#include "Core/EventBroker.h" -#include "Core/World.h" -#include "Rendering/CSprite.h" -#include "Rendering/CModel.h" -#include "Game/CBrick.h" -#include "Game/CBall.h" -#include "Game/CLife.h" -#include "Game/CPowerUp.h" -#include "Game/EStageCleared.h" -#include "Game/ELifeLost.h" -#include "Game/EResetBall.h" -#include "Game/EScoreEvent.h" -<<<<<<< HEAD -#include "Physics/CRectangleShape.h" -======= -#include "Game/EMultiBall.h" -#include "Game/EGameOver.h" -#include "Game/ECreatePowerUp.h" -#include "Game/EPowerUpTaken.h" -#include "Game/Bricks/CPowerUpBrick.h" -#include "Physics/CBoxShape.h" ->>>>>>> 72413dc0a93bd3a2f6ab9fa7e19bbc3b846232db -#include "Physics/CPhysics.h" -#include "Physics/CCircleShape.h" -#include "Physics/ESetImpulse.h" -#include "Physics/EContact.h" -#include "Sound/CCollisionSound.h" -#include "Game/PadSystem.h" -#include -#include -#include - -namespace dd -{ - -namespace Systems -{ - - // Me trying things out. -class Level -{ -public: - int levelRows; - int levelLines; - int levelSpaceBetweenBricks; - int levelSpaceToEdge; - int bricks[]; -}; - -class LevelSystem : public System -{ -public: - LevelSystem(World* world, std::shared_ptr eventBroker) - : System(world, eventBroker) - { } - - void Initialize() override; - - void CreateBasicLevel(int, int, glm::vec2, float); - void CreateLife(int); - void SaveLevel(int, int, glm::vec2, int); // Shouldn't be here, but I'm experimenting. - void LoadLevel(char[20]); - void CreateBrick(int, int, glm::vec2, float, int); - void ProcessCollision(); - - void OnEntityRemoved(EntityID entity); - - void EndLevel(); - - void Update(double dt) override; - void UpdateEntity(double dt, EntityID entity, EntityID parent) override; - - bool Restarting() const { return m_Restarting; } - void SetRestarting(const bool& restarting) { m_Restarting = restarting; } - bool Initialized() const { return m_Initialized; } - void SetInitialized(const bool& initialized) { m_Initialized = initialized; } - int& Lives() { return m_Lives; } - void SetLives(const int& lives) { m_Lives = lives; } - int& PastLives() { return m_PastLives; } - void SetPastLives(const int& pastLives) { m_PastLives = pastLives; } - int& MultiBalls() { return m_MultiBalls; } - void SetMultiBalls(const int& multiBalls) { m_MultiBalls = multiBalls; } - int& PowerUps() { return m_PowerUps; } - void SetPowerUps(const int& powerUps) { m_PowerUps = powerUps; } - int& Score() { return m_Score; } - void SetScore(const int& score) { m_Score = score; } - int& NumberOfBricks() { return m_NumberOfBricks; } - void SetNumberOfBricks(const int& numberOfBricks) { m_NumberOfBricks = numberOfBricks; } - int& Rows() { return m_Rows; } - void SetRows(const int& rows) { m_Rows = rows; } - int& Lines() { return m_Lines; } - void SetLines(const int& lines) { m_Lines = lines; } - float& SpaceToEdge() { return m_SpaceToEdge; } - void SetSpaceToEdge(const float& spaceToEdge) { m_SpaceToEdge = spaceToEdge; } - - glm::vec2& SpaceBetweenBricks() { return m_SpaceBetweenBricks; } - void SetSpaceBetweenBricks(const glm::vec2& spaceBetweenBricks) { m_SpaceBetweenBricks = spaceBetweenBricks; } - float& EdgeX() { return m_EdgeX; } - void SetEdgeX(const float& edgeX) { m_EdgeX = edgeX; } - float& EdgeY() { return m_EdgeY; } - void SetEdgeY(const float& edgeY) { m_EdgeY = edgeY; } - -private: - bool m_Restarting = false; - bool m_Initialized = false; - int m_Lives = 3; - int m_PastLives = 3; - int m_MultiBalls = 0; - int m_PowerUps = 0; - int m_Score = 0; - int m_NumberOfBricks; - int m_Rows = 6; - int m_Lines = 7; - float m_SpaceToEdge = 0.25f; - glm::vec2 m_SpaceBetweenBricks = glm::vec2(1, 0.4); - float m_EdgeX = 3.2f; - float m_EdgeY = 5.2f; - - dd::EventRelay m_EContact; - dd::EventRelay m_ELifeLost; - dd::EventRelay m_EScoreEvent; - dd::EventRelay m_EMultiBall; - dd::EventRelay m_ECreatePowerUp; - dd::EventRelay m_EPowerUpTaken; - dd::EventRelay m_EStageCleared; - - bool OnContact(const dd::Events::Contact &event); - bool OnLifeLost(const dd::Events::LifeLost &event); - bool OnScoreEvent(const dd::Events::ScoreEvent &event); - bool OnMultiBall(const dd::Events::MultiBall &event); - bool OnCreatePowerUp(const dd::Events::CreatePowerUp &event); - bool OnPowerUpTaken(const dd::Events::PowerUpTaken &event); - bool OnStageCleared(const dd::Events::StageCleared &event); -}; - -} - -} - -#endif //DAYDREAM_LEVELSYSTEM_H diff --git a/include/Game/MainMenu.h b/include/Game/MainMenu.h new file mode 100644 index 0000000..a9afe4c --- /dev/null +++ b/include/Game/MainMenu.h @@ -0,0 +1,59 @@ +#ifndef GUI_MAINMENU_H__ +#define GUI_MAINMENU_H__ + +#include "GUI/TextureFrame.h" +#include "Game/MainMenuMain.h" +#include "Game/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 m_EKeyUp; + bool OnKeyUp(const Events::KeyUp& event) + { + if (event.KeyCode == GLFW_KEY_ESCAPE) { + Show(); + } + + return true; + } +}; + +} +} +#endif + diff --git a/include/Game/MainMenuMain.h b/include/Game/MainMenuMain.h new file mode 100644 index 0000000..24296ed --- /dev/null +++ b/include/Game/MainMenuMain.h @@ -0,0 +1,70 @@ +#ifndef GUI_MAINMENUMAIN_H__ +#define GUI_MAINMENUMAIN_H__ + +#include "GUI/TextureFrame.h" +#include "GUI/Button.h" +#include "Game/EGameStart.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 m_EButtonRelease; + virtual bool OnButtonRelease(const Events::ButtonRelease& event) + { + if (event.Button == m_SquidoutButton) { + Events::GameStart e; + EventBroker->Publish(e); + m_Parent->Hide(); + } + + return true; + } +}; + +} +} +#endif diff --git a/include/Game/MainMenuOptions.h b/include/Game/MainMenuOptions.h new file mode 100644 index 0000000..476fa4a --- /dev/null +++ b/include/Game/MainMenuOptions.h @@ -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 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 diff --git a/src/game/CMakeLists.txt b/src/game/CMakeLists.txt index a63eb23..6834897 100755 --- a/src/game/CMakeLists.txt +++ b/src/game/CMakeLists.txt @@ -79,6 +79,12 @@ file(GLOB SOURCE_FILES_Sound ) source_group(Sound FILES ${SOURCE_FILES_Sound}) +file(GLOB SOURCE_FILES_GUI + "${INCLUDE_PATH}/GUI/*.h" + "GUI/*.cpp" +) +source_group(GUI FILES ${SOURCE_FILES_GUI}) + set(SOURCE_FILES ${SOURCE_FILES_Core} ${SOURCE_FILES_Core_Util} @@ -87,11 +93,14 @@ set(SOURCE_FILES ${SOURCE_FILES_Transform} ${SOURCE_FILES_Physics} ${SOURCE_FILES_Game} - ${SOURCE_FILES_Sound} ../../include/Game/EGameOver.h ../../include/Game/Bricks/CPowerUpBrick.h ../../include/Game/CPowerUp.h ../../include/Game/ECreatePowerUp.h ../../include/Game/EPowerUpTaken.h) + ${SOURCE_FILES_Sound} + ${SOURCE_FILES_GUI} +) if(CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") - set(STATIC_LIBRARY_FLAGS "${STATIC_LIBRARY_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w") + set(STATIC_LIBRARY_FLAGS "${STATIC_LIBRARY_FLAGS}") endif() add_library(game ${SOURCE_FILES}) diff --git a/src/game/CMakeLists.txt.game b/src/game/CMakeLists.txt.game deleted file mode 100644 index 5e236f1..0000000 --- a/src/game/CMakeLists.txt.game +++ /dev/null @@ -1,38 +0,0 @@ -project(game) - -find_package(OpenGL REQUIRED) -find_package(GLEW REQUIRED) -find_package(GLFW REQUIRED) -find_package(Boost REQUIRED) -find_package(assimp REQUIRED) -find_package(ZLIB REQUIRED) -find_package(PNG REQUIRED) - -include_directories( - ${CMAKE_SOURCE_DIR}/include/dd - ${OPENGL_INCLUDE_DIR} - ${GLEW_INCLUDE_DIRS} - ${GLFW_INCLUDE_DIRS} - ${Boost_INCLUDE_DIRS} - ${assimp_INCLUDE_DIRS} - ${PNG_INCLUDE_DIRS} -) - -set(SOURCE_FILES - main.cpp -) - -if(CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") -endif() - -add_executable(game ${SOURCE_FILES}) -target_link_libraries(game - daydream - ${OPENGL_LIBRARIES} - ${GLEW_LIBRARIES} - ${GLFW_LIBRARIES} - ${Boost_LIBRARIES} - ${assimp_LIBRARIES} - ${PNG_LIBRARIES} -) \ No newline at end of file diff --git a/src/game/Core/EventBroker.cpp b/src/game/Core/EventBroker.cpp index f24b073..2c68fd0 100644 --- a/src/game/Core/EventBroker.cpp +++ b/src/game/Core/EventBroker.cpp @@ -79,7 +79,7 @@ int dd::EventBroker::Process(std::string contextTypeName) return eventsProcessed; } -void dd::EventBroker::Clear() +void dd::EventBroker::Swap() { std::swap(m_EventQueueRead, m_EventQueueWrite); m_EventQueueWrite->clear(); diff --git a/src/game/Core/Renderer.cpp b/src/game/Core/Renderer.cpp index 8745136..2226ba2 100755 --- a/src/game/Core/Renderer.cpp +++ b/src/game/Core/Renderer.cpp @@ -288,6 +288,7 @@ void dd::Renderer::Draw(RenderQueueCollection& rq) rq.Forward.Jobs.sort(dd::Renderer::DepthSort); DrawDeferred(rq.Deferred, rq.Lights); DrawForward(rq.Forward, rq.Lights); + DrawGUI(rq.GUI); // Finally: Draw the deferred+forward combined texture to the screen glDisable(GL_CULL_FACE); @@ -672,3 +673,57 @@ void dd::Renderer::DebugKeys() m_CurrentScreenBuffer = t_m_BWater; } } + +void dd::Renderer::DrawGUI(dd::RenderQueue& rq) +{ + glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred3); + glDisable(GL_CULL_FACE); + glCullFace(GL_BACK); + glDisable(GL_DEPTH_TEST); + glEnable(GL_BLEND); + //glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD); + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); + + m_spScreen->Bind(); + + glm::mat4 MVP; + + for (auto &job : rq) { + auto frameJob = std::dynamic_pointer_cast(job); + if (frameJob) { + FrameJob jobCopy = *(frameJob.get()); + glm::mat4 viewMatrix = glm::mat4(1); //frameJob->ViewMatrix; + glm::mat4 PV = glm::mat4(1); //frameJob->ProjectionMatrix * viewMatrix; + glm::mat4 modelMatrix = glm::mat4(1); //frameJob->ModelMatrix; + MVP = PV * modelMatrix; + glUniformMatrix4fv(glGetUniformLocation(*m_spScreen, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); + glUniformMatrix4fv(glGetUniformLocation(*m_spScreen, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); + glUniformMatrix4fv(glGetUniformLocation(*m_spScreen, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix)); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, frameJob->DiffuseTexture); + //glActiveTexture(GL_TEXTURE1); + //glBindTexture(GL_TEXTURE_2D, frameJob->NormalTexture); + //glActiveTexture(GL_TEXTURE2); + //glBindTexture(GL_TEXTURE_2D, frameJob->SpecularTexture); + + Rectangle& vp = frameJob->Viewport; + glViewport(vp.X, m_Resolution.Height - vp.Y - vp.Height, vp.Width, vp.Height); + Rectangle& sc = frameJob->Scissor; + if (sc == Rectangle()) { + glDisable(GL_SCISSOR_TEST); + } else { + glEnable(GL_SCISSOR_TEST); + glScissor(sc.X, m_Resolution.Height - sc.Y - sc.Height, sc.Width, sc.Height); + } + + glBindVertexArray(m_ScreenQuad); + glDrawArrays(GL_TRIANGLES, 0, 6); + + continue; + } + } + + glDisable(GL_SCISSOR_TEST); + glViewport(0, 0, m_Resolution.Width, m_Resolution.Height); +} diff --git a/src/game/Core/Texture.cpp b/src/game/Core/Texture.cpp index f9ba46e..8fb8b33 100755 --- a/src/game/Core/Texture.cpp +++ b/src/game/Core/Texture.cpp @@ -31,6 +31,9 @@ dd::Texture::Texture(std::string path) } } + this->Width = image->Width; + this->Height = image->Height; + GLint format; switch (image->Format) { case Image::ImageFormat::RGB: diff --git a/src/game/Sound/SoundSystem.cpp b/src/game/Sound/SoundSystem.cpp index 8594d92..90939a1 100644 --- a/src/game/Sound/SoundSystem.cpp +++ b/src/game/Sound/SoundSystem.cpp @@ -36,26 +36,7 @@ void dd::Systems::SoundSystem::Initialize() EVENT_SUBSCRIBE_MEMBER(m_EMasterVolume, &SoundSystem::OnMasterVolume); - //Todo: Move this - { - dd::Events::PlaySound e; - e.path = "Sounds/BGM/under-the-sea-instrumental.wav"; - e.isAmbient = true; - EventBroker->Publish(e); - } - { - dd::Events::PlaySound e; - e.path = "Sounds/BGM/water-flowing.wav"; - e.volume = 0.3f; - e.isAmbient = true; - EventBroker->Publish(e); - } - { - dd::Events::MasterVolume e; - e.isAmbient = true; - e.gain = 1.f; - EventBroker->Publish(e); - } + } void dd::Systems::SoundSystem::Update(double dt) @@ -182,12 +163,6 @@ bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event) } } - { - dd::Events::StopSound e; - e.path = "Sounds/BGM/water-flowing.wav"; - EventBroker->Publish(e); - } - //Send play-sound event dd::Events::PlaySound e; e.path = collisionSound->filePath;