mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-16 22:41:48 +01:00
Fix digging
This commit is contained in:
@@ -1,28 +1,28 @@
|
||||
#include "pch.h"
|
||||
#include "Button.h"
|
||||
#include "GuiButton.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "colors.h"
|
||||
#include "utils.h"
|
||||
Button::Button(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): m_Position(pos), m_Size(size) {
|
||||
GuiButton::GuiButton(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): m_Position(pos), m_Size(size) {
|
||||
m_Texture = manager->GetTexture(filePath);
|
||||
if(size.x == 0 && size.y == 0) {
|
||||
m_Size = Vector2f{float(m_Texture->GetWidth()), float(m_Texture->GetHeight())};
|
||||
}
|
||||
std::cout << "Button created" << '\n';
|
||||
}
|
||||
Button::~Button() {
|
||||
GuiButton::~GuiButton() {
|
||||
std::cout << "Button destroyed" << '\n';
|
||||
}
|
||||
void Button::Draw() const {
|
||||
void GuiButton::Draw() const {
|
||||
Rectf dest = Rectf(m_Position, m_Size);
|
||||
Rectf src = Rectf(0, 0, m_Texture->GetWidth(), m_Texture->GetHeight());
|
||||
if(m_IsHovered) {
|
||||
m_Texture->Draw(dest, src, false);
|
||||
}
|
||||
}
|
||||
void Button::Update(float elapsedSec) {
|
||||
void GuiButton::Update(float elapsedSec) {
|
||||
Vector2f mousePos = utils::GetMousePos();
|
||||
Rectf buttonRect = Rectf(m_Position, m_Size);
|
||||
|
||||
@@ -2,17 +2,18 @@
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
|
||||
#include "GuiElement.h"
|
||||
#include "Texture.h"
|
||||
#include "../TextureManager.h"
|
||||
|
||||
class Button
|
||||
class GuiButton : public GuiElement
|
||||
{
|
||||
public:
|
||||
Button() = default;
|
||||
Button(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager);
|
||||
~Button();
|
||||
void Draw() const;
|
||||
void Update(float elapsedSec);
|
||||
GuiButton() = default;
|
||||
GuiButton(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager);
|
||||
~GuiButton() override;
|
||||
virtual void Draw() const override;
|
||||
virtual void Update(float elapsedSec) override;
|
||||
|
||||
void SetOnClick(std::function<void(void)> onClick) {
|
||||
m_OnClick = onClick;
|
||||
2
Game/Gui/GuiElement.cpp
Normal file
2
Game/Gui/GuiElement.cpp
Normal file
@@ -0,0 +1,2 @@
|
||||
#include "pch.h"
|
||||
#include "GuiElement.h"
|
||||
14
Game/Gui/GuiElement.h
Normal file
14
Game/Gui/GuiElement.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
class GuiElement
|
||||
{
|
||||
public:
|
||||
GuiElement() = default;
|
||||
virtual ~GuiElement() = default;
|
||||
|
||||
virtual void Draw() const = 0;
|
||||
virtual void Update(float elapsedSec) = 0;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
18
Game/Gui/GuiMeter.cpp
Normal file
18
Game/Gui/GuiMeter.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "pch.h"
|
||||
#include "GuiMeter.h"
|
||||
|
||||
#include "TextureManager.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() {
|
||||
delete m_Animation;
|
||||
}
|
||||
void GuiMeter::Draw() const {
|
||||
m_Animation->Draw(m_Position);
|
||||
}
|
||||
void GuiMeter::Update(float elapsedSec) {
|
||||
|
||||
|
||||
}
|
||||
25
Game/Gui/GuiMeter.h
Normal file
25
Game/Gui/GuiMeter.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include "GuiElement.h"
|
||||
#include "Texture.h"
|
||||
#include "Animations/Animation.h"
|
||||
|
||||
class TextureManager;
|
||||
|
||||
class GuiMeter : public GuiElement
|
||||
{
|
||||
public:
|
||||
GuiMeter() = default;
|
||||
GuiMeter(const std::string& filePath, Vector2f pos, Vector2f frameSize, int frameCount, TextureManager* manager);
|
||||
virtual ~GuiMeter();
|
||||
|
||||
virtual void Draw() const override;
|
||||
virtual void Update(float elapsedSec) override;
|
||||
|
||||
private:
|
||||
Animation* m_Animation{ nullptr };
|
||||
Vector2f m_Position;
|
||||
|
||||
float m_Value{ 0.0f };
|
||||
|
||||
int m_FrameCount;
|
||||
};
|
||||
@@ -5,12 +5,12 @@ Screen::Screen(const std::string& filePath, Vector2f pos, Vector2f size, Texture
|
||||
m_Background = manager->GetTexture(filePath);
|
||||
}
|
||||
Screen::~Screen() {
|
||||
for (Button* b : m_Buttons) {
|
||||
for (GuiElement* b : m_Elements) {
|
||||
delete b;
|
||||
}
|
||||
}
|
||||
void Screen::Update(float elapsedSecs) {
|
||||
for (Button* b : m_Buttons) {
|
||||
for (GuiElement* b : m_Elements) {
|
||||
b->Update(elapsedSecs);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ void Screen::Draw() const {
|
||||
Rectf src = Rectf(0, 0, m_Background->GetWidth(), m_Background->GetHeight());
|
||||
m_Background->Draw(dest, src, false);
|
||||
|
||||
for (Button* b : m_Buttons) {
|
||||
for (GuiElement* b : m_Elements) {
|
||||
b->Draw();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
|
||||
#include "Button.h"
|
||||
#include "GuiButton.h"
|
||||
#include "structs.h"
|
||||
#include "Texture.h"
|
||||
#include "../TextureManager.h"
|
||||
@@ -14,7 +14,7 @@ public:
|
||||
|
||||
virtual ~Screen();
|
||||
|
||||
void AddButton(Button* button) { m_Buttons.push_back(button); }
|
||||
void AddElement(GuiElement* element) { m_Elements.push_back(element); }
|
||||
|
||||
virtual void Update(float elapsedSecs);
|
||||
virtual void Draw() const;
|
||||
@@ -24,5 +24,5 @@ private:
|
||||
|
||||
Texture* m_Background{ nullptr };
|
||||
|
||||
std::vector<Button*> m_Buttons;
|
||||
std::vector<GuiElement*> m_Elements;
|
||||
};
|
||||
|
||||
@@ -15,29 +15,29 @@ FuelScreen::FuelScreen(const std::string& filePath, Vector2f pos, Vector2f size,
|
||||
const Vector2f closeButtonOffset = Vector2f { 460, 396 - 14 };
|
||||
Vector2f closeButtonPos = fuelScreenCenter + closeButtonOffset;
|
||||
closeButtonPos.y -= 18;
|
||||
Button* closeFuelButton = new Button { "gui/close.png", closeButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
GuiButton* closeFuelButton = new GuiButton { "gui/close.png", closeButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
closeFuelButton->SetOnClick([this]() { ScreenManager::GetInstance()->CloseScreen(); });
|
||||
this->AddButton(closeFuelButton);
|
||||
this->AddElement(closeFuelButton);
|
||||
|
||||
const Vector2f oneDollarButtonPos = Vector2f { 451, 287 };
|
||||
Button* fiveDollarButton = new Button { "gui/fuel/5dollars.png", oneDollarButtonPos , Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddButton(fiveDollarButton);
|
||||
GuiButton* fiveDollarButton = new GuiButton { "gui/fuel/5dollars.png", oneDollarButtonPos , Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddElement(fiveDollarButton);
|
||||
|
||||
const Vector2f tenDollarButtonPos = oneDollarButtonPos + Vector2f { 113, -1 };
|
||||
Button* tenDollarButton = new Button { "gui/fuel/10dollars.png", tenDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddButton(tenDollarButton);
|
||||
GuiButton* tenDollarButton = new GuiButton { "gui/fuel/10dollars.png", tenDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddElement(tenDollarButton);
|
||||
|
||||
const Vector2f twentyFiveDollarButtonPos = oneDollarButtonPos + Vector2f { 0, -89 };
|
||||
Button* twentyFiveDollarButton = new Button { "gui/fuel/25dollars.png", twentyFiveDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddButton(twentyFiveDollarButton);
|
||||
GuiButton* twentyFiveDollarButton = new GuiButton { "gui/fuel/25dollars.png", twentyFiveDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddElement(twentyFiveDollarButton);
|
||||
|
||||
const Vector2f fiftyDollarButtonPos = twentyFiveDollarButtonPos + Vector2f { 114, 0 };
|
||||
Button* fiftyDollarButton = new Button { "gui/fuel/50dollars.png", fiftyDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddButton(fiftyDollarButton);
|
||||
GuiButton* fiftyDollarButton = new GuiButton { "gui/fuel/50dollars.png", fiftyDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddElement(fiftyDollarButton);
|
||||
|
||||
const Vector2f fillTankButtonPos = Vector2f { 450, 108 };
|
||||
Button* fillTankButton = new Button { "gui/fuel/fillTank.png", fillTankButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddButton(fillTankButton);
|
||||
GuiButton* fillTankButton = new GuiButton { "gui/fuel/fillTank.png", fillTankButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddElement(fillTankButton);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user