Moved game GUI to its own subfolder

This commit is contained in:
2015-10-08 10:46:28 +02:00
parent bfa8545483
commit 7bf1d7cf24
6 changed files with 11 additions and 4 deletions
+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
+69
View File
@@ -0,0 +1,69 @@
#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/FPSCounter.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");
EVENT_SUBSCRIBE_MEMBER(m_EScore, &HUD::OnScore);
}
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;
EventRelay<Frame, Events::ScoreEvent> m_EScore;
bool OnScore(const Events::ScoreEvent& event)
{
m_ScoreNumberFrame->SetNumber(m_ScoreNumberFrame->Number() + event.Score);
return true;
}
};
}
}
#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
+72
View File
@@ -0,0 +1,72 @@
#ifndef GUI_MAINMENUMAIN_H__
#define GUI_MAINMENUMAIN_H__
#include "GUI/TextureFrame.h"
#include "GUI/Button.h"
#include "Game/EGameStart.h"
#include "Game/GUI/HUD.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) {
Events::GameStart e;
EventBroker->Publish(e);
m_Parent->Hide();
auto hud = new GUI::HUD(BaseFrame, "HUD");
}
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