Add Text rendering and Hull / Fuel Meters

This commit is contained in:
Bram Verhulst
2024-05-16 02:04:36 +02:00
parent 600050c198
commit 8866f33c09
18 changed files with 286 additions and 118 deletions

26
Game/Gui/GuiText.cpp Normal file
View File

@@ -0,0 +1,26 @@
#include "pch.h"
#include "GuiText.h"
#include "colors.h"
GuiText::GuiText(const Vector2f& position, const std::string& text, const std::string& fontPath, int size, const Color4f& color): m_Position(position), m_Text(new Text(text, fontPath, size, color)) {
}
GuiText::GuiText(): m_Position(100,100), m_Text(new Text("Undefined", "fonts/verdana.ttf", 10, Colors::WHITE)) {
}
void GuiText::Draw() const {
m_Text->Draw(m_Position);
}
void GuiText::Update(float elapsedSec) {
}
void GuiText::ChangeText(const std::string& text) const {
m_Text->ChangeText(text);
}
GuiText::~GuiText() {
delete m_Text;
}

20
Game/Gui/GuiText.h Normal file
View File

@@ -0,0 +1,20 @@
#pragma once
#include "GuiElement.h"
#include "Text.h"
#include "Texture.h"
class GuiText : public GuiElement {
public:
GuiText(const Vector2f& position, const std::string& text, const std::string& fontPath, int size, const Color4f& color);
GuiText();
void Draw() const override;
void Update(float elapsedSec) override;
void ChangeText(const std::string& text) const;
~GuiText() override;
private:
Vector2f m_Position;
Text* m_Text;
};

View File

@@ -1,8 +1,23 @@
#include "pch.h"
#include "MainScreen.h"
#include "colors.h"
#include "utils.h"
#include "Gui/GuiText.h"
MainScreen::MainScreen(TextureManager* manager) : Screen("", Vector2f{0, 0}, Vector2f{900.f, 500.f}, manager) {
m_FuelMeter = new GuiMeter("gui/main/fuel/fuel.png", Vector2f{20, 500.f - 146 / 1.5 - 20}, Vector2f{336, 146},Vector2f{336 / 2, 146 / 1.5}, 21, manager);
Vector2f ScreenSize = utils::GetViewport();
Vector2f FuelFrameSize{ 336, 77 };
Vector2f HullFrameSize{ 61, 76 };
m_FuelMeter = new GuiMeter("gui/main/fuel/fuel.png", Vector2f{HullFrameSize.x + 10, ScreenSize.y - FuelFrameSize.y }, FuelFrameSize,FuelFrameSize / 1.3, 21, manager);
this->AddElement(m_FuelMeter);
m_HullMeter = new GuiMeter("gui/main/hull/hull.png", Vector2f{5, ScreenSize.y - HullFrameSize.y - 10 }, HullFrameSize, HullFrameSize, 50, manager);
this->AddElement(m_HullMeter);
Vector2f DepthMeterPosition{10, ScreenSize.y - 120};
m_DepthText = new GuiText(DepthMeterPosition, "Depth: 20", "fonts/Arial.ttf", 20, Colors::YELLOW);
this->AddElement(m_DepthText);
}
MainScreen::~MainScreen() = default;
void MainScreen::Draw() const {
@@ -14,3 +29,10 @@ void MainScreen::Update(float elapsedSecs) {
void MainScreen::SetFuelMeterValue(float value) const {
m_FuelMeter->SetValue(value);
}
void MainScreen::SetHullMeterValue(float value) const {
m_HullMeter->SetValue(value);
}
void MainScreen::SetDepth(const std::string& text) const {
m_DepthText->ChangeText(text);
}

View File

@@ -1,5 +1,6 @@
#pragma once
#include "Gui/GuiMeter.h"
#include "Gui/GuiText.h"
#include "Gui/Screen.h"
class MainScreen: public Screen {
@@ -11,8 +12,14 @@ public:
virtual void Update(float elapsedSecs) override;
void SetFuelMeterValue(float value) const;
void SetHullMeterValue(float value) const;
void SetDepth(const std::string& text) const;
private:
GuiMeter* m_FuelMeter;
GuiMeter* m_HullMeter;
GuiText* m_DepthText;
};