Working NumberFrame and score indicator
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
@@ -0,0 +1,108 @@
|
|||||||
|
#ifndef GUI_NUMBERFRAME_H__
|
||||||
|
#define GUI_NUMBERFRAME_H__
|
||||||
|
|
||||||
|
#include "GUI/TextureFrame.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
namespace GUI
|
||||||
|
{
|
||||||
|
|
||||||
|
class NumberFrame : public Frame
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NumberFrame(Frame* parent, std::string name)
|
||||||
|
: Frame(parent, name)
|
||||||
|
{
|
||||||
|
m_NumberTextures[0] = "Textures/GUI/Numbers/N0.png";
|
||||||
|
m_NumberTextures[1] = "Textures/GUI/Numbers/N1.png";
|
||||||
|
m_NumberTextures[2] = "Textures/GUI/Numbers/N2.png";
|
||||||
|
m_NumberTextures[3] = "Textures/GUI/Numbers/N3.png";
|
||||||
|
m_NumberTextures[4] = "Textures/GUI/Numbers/N4.png";
|
||||||
|
m_NumberTextures[5] = "Textures/GUI/Numbers/N5.png";
|
||||||
|
m_NumberTextures[6] = "Textures/GUI/Numbers/N6.png";
|
||||||
|
m_NumberTextures[7] = "Textures/GUI/Numbers/N7.png";
|
||||||
|
m_NumberTextures[8] = "Textures/GUI/Numbers/N8.png";
|
||||||
|
m_NumberTextures[9] = "Textures/GUI/Numbers/N9.png";
|
||||||
|
SetNumber(0);
|
||||||
|
|
||||||
|
// Create number frame if missing
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
auto frame = new GUI::TextureFrame(this, "NumberFrameDigit");
|
||||||
|
frame->SetTexture(m_NumberTextures[0]);
|
||||||
|
frame->DisableScissor();
|
||||||
|
// Position frame based on alignment
|
||||||
|
if (i > 0) {
|
||||||
|
frame->X = i * 20;
|
||||||
|
}
|
||||||
|
Width += frame->Width;
|
||||||
|
if (Height < frame->Height) {
|
||||||
|
Height = frame->Height;
|
||||||
|
}
|
||||||
|
m_NumberFrames.push_front(frame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int Number() const { return m_Number; }
|
||||||
|
void SetNumber(int number)
|
||||||
|
{
|
||||||
|
m_Number = number;
|
||||||
|
|
||||||
|
// Clear number textures
|
||||||
|
//for (auto& frame : m_NumberFrames) {
|
||||||
|
// frame->SetTexture("");
|
||||||
|
//}
|
||||||
|
|
||||||
|
//Width = 0;
|
||||||
|
//Height = 0;
|
||||||
|
|
||||||
|
int n = 0;
|
||||||
|
do {
|
||||||
|
// // Create number frame if missing
|
||||||
|
// if (m_NumberFrames.size() <= n) {
|
||||||
|
// auto frame = new GUI::TextureFrame(this, "NumberFrameDigit");
|
||||||
|
// frame->DisableScissor();
|
||||||
|
// m_NumberFrames.push_front(frame);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Update value
|
||||||
|
int digit = number % 10;
|
||||||
|
m_NumberFrames[n]->SetTexture(m_NumberTextures[digit]);
|
||||||
|
//Width += m_NumberFrames[n]->Width;
|
||||||
|
//if (Height < m_NumberFrames[n]->Height) {
|
||||||
|
// Height = m_NumberFrames[n]->Height;
|
||||||
|
//}
|
||||||
|
// // Position frame based on alignment
|
||||||
|
// if (n > 0) {
|
||||||
|
// if (!m_LeftAligned) {
|
||||||
|
// m_NumberFrames[n]->SetLeft(m_NumberFrames[n - 1]->Right());
|
||||||
|
// } else {
|
||||||
|
// m_NumberFrames[n]->SetRight(m_NumberFrames[n - 1]->Left());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
number /= 10;
|
||||||
|
n++;
|
||||||
|
} while (number > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetLeftAlign() { m_LeftAligned = true; }
|
||||||
|
void SetRightAlign() { m_LeftAligned = false; }
|
||||||
|
|
||||||
|
virtual void Update(double dt) override
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_Number = 0;
|
||||||
|
bool m_LeftAligned = true;
|
||||||
|
|
||||||
|
std::string m_NumberTextures[10];
|
||||||
|
std::deque<TextureFrame*> m_NumberFrames;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -52,6 +52,11 @@ public:
|
|||||||
|
|
||||||
void SetTexture(std::string resourceName)
|
void SetTexture(std::string resourceName)
|
||||||
{
|
{
|
||||||
|
if (resourceName.empty()) {
|
||||||
|
m_Texture = nullptr;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_Texture = ResourceManager::Load<dd::Texture>(resourceName);
|
m_Texture = ResourceManager::Load<dd::Texture>(resourceName);
|
||||||
if (m_Texture == nullptr) {
|
if (m_Texture == nullptr) {
|
||||||
m_Texture = ResourceManager::Load<dd::Texture>("Textures/Core/ErrorTexture.png");
|
m_Texture = ResourceManager::Load<dd::Texture>("Textures/Core/ErrorTexture.png");
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
#include "GUI/Frame.h"
|
#include "GUI/Frame.h"
|
||||||
#include "GUI/TextureFrame.h"
|
#include "GUI/TextureFrame.h"
|
||||||
|
#include "GUI/NumberFrame.h"
|
||||||
|
#include "Core/EKeyUp.h"
|
||||||
|
#include "Game/EScoreEvent.h"
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
{
|
{
|
||||||
@@ -24,11 +27,24 @@ public:
|
|||||||
m_ScoreIndicator = new GUI::TextureFrame(this, "HUDScoreIndicator");
|
m_ScoreIndicator = new GUI::TextureFrame(this, "HUDScoreIndicator");
|
||||||
m_ScoreIndicator->SetTexture("Textures/GUI/HUD/ScoreIndicatorBG.png");
|
m_ScoreIndicator->SetTexture("Textures/GUI/HUD/ScoreIndicatorBG.png");
|
||||||
m_ScoreIndicator->SetRight(Right());
|
m_ScoreIndicator->SetRight(Right());
|
||||||
|
m_ScoreNumberFrame = new GUI::NumberFrame(m_ScoreIndicator, "HUDScoreNumberFrame");
|
||||||
|
m_ScoreNumberFrame->X = 15;
|
||||||
|
m_ScoreNumberFrame->Y = 21;
|
||||||
|
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EScore, &HUD::OnScore);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TextureFrame* m_LevelIndicator = nullptr;
|
TextureFrame* m_LevelIndicator = nullptr;
|
||||||
TextureFrame* m_ScoreIndicator = nullptr;
|
TextureFrame* m_ScoreIndicator = nullptr;
|
||||||
|
NumberFrame* m_ScoreNumberFrame = nullptr;
|
||||||
|
|
||||||
|
EventRelay<Frame, Events::ScoreEvent> m_EScore;
|
||||||
|
|
||||||
|
bool OnScore(const Events::ScoreEvent& event)
|
||||||
|
{
|
||||||
|
m_ScoreNumberFrame->SetNumber(event.Score);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public:
|
|||||||
m_MainMenuOptions->SetLeft(m_LeftBanner->Right());
|
m_MainMenuOptions->SetLeft(m_LeftBanner->Right());
|
||||||
m_MainMenuOptions->SetTop(m_MainMenuMain->Bottom());
|
m_MainMenuOptions->SetTop(m_MainMenuMain->Bottom());
|
||||||
|
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &MainMenu::OnKeyUp);
|
//EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &MainMenu::OnKeyUp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -42,7 +42,7 @@ private:
|
|||||||
MainMenuMain* m_MainMenuMain;
|
MainMenuMain* m_MainMenuMain;
|
||||||
MainMenuOptions* m_MainMenuOptions;
|
MainMenuOptions* m_MainMenuOptions;
|
||||||
|
|
||||||
EventRelay<Frame, Events::KeyUp> m_EKeyUp;
|
//EventRelay<Frame, Events::KeyUp> m_EKeyUp;
|
||||||
bool OnKeyUp(const Events::KeyUp& event)
|
bool OnKeyUp(const Events::KeyUp& event)
|
||||||
{
|
{
|
||||||
if (event.KeyCode == GLFW_KEY_ESCAPE) {
|
if (event.KeyCode == GLFW_KEY_ESCAPE) {
|
||||||
|
|||||||