mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-16 22:41:48 +01:00
Add Main UI, Fuel meter. Add particles to player digging
This commit is contained in:
@@ -3,17 +3,25 @@
|
||||
|
||||
#include "TextureManager.h"
|
||||
#include "utils.h"
|
||||
GuiMeter::GuiMeter(const std::string& filePath, Vector2f pos, Vector2f frameSize, int frameCount, TextureManager* manager): m_Position(pos), m_FrameCount(frameCount) {
|
||||
m_Animation = new Animation(manager->GetTexture(filePath),frameCount, 0.0f, Rectf{0, 0, frameSize.x, frameSize.y}, false);
|
||||
|
||||
GuiMeter::GuiMeter(const std::string& filePath, Vector2f pos, Vector2f frameSize, int frameCount, TextureManager* manager): GuiMeter(
|
||||
filePath, pos, frameSize, frameSize, frameCount, manager) {
|
||||
}
|
||||
GuiMeter::GuiMeter(const std::string& filePath, Vector2f pos, Vector2f frameSize, Vector2f drawSize, int frameCount, TextureManager* manager): m_Position(pos),
|
||||
m_DrawSize(drawSize), m_FrameCount(frameCount) {
|
||||
m_Animation = new Animation(manager->GetTexture(filePath), frameCount, 0.0f, Rectf { 0, 0, frameSize.x, frameSize.y }, false);
|
||||
}
|
||||
GuiMeter::~GuiMeter() {
|
||||
delete m_Animation;
|
||||
}
|
||||
void GuiMeter::Draw() const {
|
||||
m_Animation->Draw(m_Position);
|
||||
m_Animation->Draw(m_Position, Rectf{m_Position, m_DrawSize});
|
||||
utils::DrawRect(Rectf { m_Position, m_DrawSize});
|
||||
}
|
||||
void GuiMeter::Update(float elapsedSec) {
|
||||
m_Value += 1;
|
||||
const int frame = static_cast<int>(utils::map(m_Value, 0.0f, m_MaxValue, 0, (float)m_Animation->GetFrameCount()));
|
||||
m_Animation->SetFrame(frame);
|
||||
}
|
||||
}
|
||||
void GuiMeter::SetValue(float value) {
|
||||
m_Value = value;
|
||||
}
|
||||
|
||||
@@ -5,23 +5,26 @@
|
||||
|
||||
class TextureManager;
|
||||
|
||||
class GuiMeter : public GuiElement
|
||||
class GuiMeter final : public GuiElement
|
||||
{
|
||||
public:
|
||||
GuiMeter() = default;
|
||||
GuiMeter(const std::string& filePath, Vector2f pos, Vector2f frameSize, int frameCount, TextureManager* manager);
|
||||
virtual ~GuiMeter();
|
||||
GuiMeter(const std::string& filePath, Vector2f pos, Vector2f frameSize, Vector2f drawSize, int frameCount, TextureManager* manager);
|
||||
GuiMeter(GuiMeter& other) = delete;
|
||||
GuiMeter& operator=(const GuiMeter& other) = delete;
|
||||
GuiMeter(GuiMeter&& other) = delete;
|
||||
GuiMeter& operator=(GuiMeter&& other) = delete;
|
||||
virtual ~GuiMeter() override;
|
||||
|
||||
virtual void Draw() const override;
|
||||
virtual void Update(float elapsedSec) override;
|
||||
|
||||
void SetValue(float value) {
|
||||
m_Value = value;
|
||||
}
|
||||
void SetValue(float value);
|
||||
|
||||
private:
|
||||
Animation* m_Animation{ nullptr };
|
||||
Animation* m_Animation{ nullptr };
|
||||
Vector2f m_Position;
|
||||
Vector2f m_DrawSize;
|
||||
|
||||
float m_Value{ 0.0f };
|
||||
const float m_MaxValue{ 100.0f };
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
#include "Screen.h"
|
||||
|
||||
Screen::Screen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): m_Position(pos), m_Size(size) {
|
||||
m_Background = manager->GetTexture(filePath);
|
||||
if(!filePath.empty()) {
|
||||
m_Background = manager->GetTexture(filePath);
|
||||
} else {
|
||||
m_Background = nullptr;
|
||||
}
|
||||
}
|
||||
Screen::~Screen() {
|
||||
for (GuiElement* b : m_Elements) {
|
||||
@@ -15,11 +19,13 @@ void Screen::Update(float elapsedSecs) {
|
||||
}
|
||||
}
|
||||
void Screen::Draw() const {
|
||||
Rectf dest = Rectf(m_Position, m_Size);
|
||||
Rectf src = Rectf(0, 0, m_Background->GetWidth(), m_Background->GetHeight());
|
||||
m_Background->Draw(dest, src, false);
|
||||
if(m_Background != nullptr) { //Incase there is no background
|
||||
Rectf dest = Rectf(m_Position, m_Size);
|
||||
Rectf src = Rectf(0, 0, m_Background->GetWidth(), m_Background->GetHeight());
|
||||
m_Background->Draw(dest, src, false);
|
||||
}
|
||||
|
||||
for (GuiElement* b : m_Elements) {
|
||||
b->Draw();
|
||||
for (GuiElement* GuiElement : m_Elements) {
|
||||
GuiElement->Draw();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,8 +41,7 @@ FuelScreen::FuelScreen(const std::string& filePath, Vector2f pos, Vector2f size,
|
||||
|
||||
}
|
||||
|
||||
FuelScreen::~FuelScreen() {
|
||||
}
|
||||
FuelScreen::~FuelScreen() = default;
|
||||
|
||||
void FuelScreen::Draw() const {
|
||||
Screen::Draw();
|
||||
|
||||
16
Game/Gui/Screens/MainScreen.cpp
Normal file
16
Game/Gui/Screens/MainScreen.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "pch.h"
|
||||
#include "MainScreen.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);
|
||||
this->AddElement(m_FuelMeter);
|
||||
}
|
||||
MainScreen::~MainScreen() = default;
|
||||
void MainScreen::Draw() const {
|
||||
Screen::Draw();
|
||||
}
|
||||
void MainScreen::Update(float elapsedSecs) {
|
||||
Screen::Update(elapsedSecs);
|
||||
}
|
||||
void MainScreen::SetFuelMeterValue(float value) const {
|
||||
m_FuelMeter->SetValue(value);
|
||||
}
|
||||
18
Game/Gui/Screens/MainScreen.h
Normal file
18
Game/Gui/Screens/MainScreen.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include "Gui/GuiMeter.h"
|
||||
#include "Gui/Screen.h"
|
||||
|
||||
class MainScreen: public Screen {
|
||||
public:
|
||||
explicit MainScreen(TextureManager* manager);
|
||||
virtual ~MainScreen() override;
|
||||
|
||||
virtual void Draw() const override;
|
||||
virtual void Update(float elapsedSecs) override;
|
||||
|
||||
void SetFuelMeterValue(float value) const;
|
||||
|
||||
private:
|
||||
GuiMeter* m_FuelMeter;
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user