Add Alot
This commit is contained in:
@@ -1,72 +0,0 @@
|
||||
#include "pch.h"
|
||||
#include "FuelScreen.h"
|
||||
|
||||
#include "colors.h"
|
||||
#include "GameManager.h"
|
||||
#include "ScreenManager.h"
|
||||
#include "utils.h"
|
||||
FuelScreen::FuelScreen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): Screen(filePath, pos, size, manager)
|
||||
{
|
||||
const Vector2f fuelScreenSize = Vector2f { 492, 396 };
|
||||
// Vector2f fuelScreenCenter = Vector2f { utils::GetViewport().x / 2 - fuelScreenSize.x / 2, utils::GetViewport().y / 2 - fuelScreenSize.y / 2 };
|
||||
const Vector2f ScreenCenter = Vector2f { utils::GetViewport().x / 2, utils::GetViewport().y / 2 };
|
||||
|
||||
const Vector2f fuelScreenCenter = ScreenCenter - fuelScreenSize / 2;
|
||||
|
||||
|
||||
const Vector2f closeButtonOffset = Vector2f { 460, 396 - 14 };
|
||||
Vector2f closeButtonPos = fuelScreenCenter + closeButtonOffset;
|
||||
closeButtonPos.y -= 18;
|
||||
GuiButton* closeFuelButton = new GuiButton { "gui/close.png", closeButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
closeFuelButton->SetOnClick([this]() { ScreenManager::GetInstance()->CloseScreen(); });
|
||||
this->AddElement(closeFuelButton);
|
||||
|
||||
const Vector2f oneDollarButtonPos = Vector2f { 451, 287 };
|
||||
GuiButton* fiveDollarButton = new GuiButton { "gui/fuel/5dollars.png", oneDollarButtonPos , Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddElement(fiveDollarButton);
|
||||
|
||||
const Vector2f tenDollarButtonPos = oneDollarButtonPos + Vector2f { 113, -1 };
|
||||
GuiButton* tenDollarButton = new GuiButton { "gui/fuel/10dollars.png", tenDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddElement(tenDollarButton);
|
||||
|
||||
const Vector2f twentyFiveDollarButtonPos = oneDollarButtonPos + Vector2f { 0, -89 };
|
||||
GuiButton* twentyFiveDollarButton = new GuiButton { "gui/fuel/25dollars.png", twentyFiveDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddElement(twentyFiveDollarButton);
|
||||
|
||||
const Vector2f fiftyDollarButtonPos = twentyFiveDollarButtonPos + Vector2f { 114, 0 };
|
||||
GuiButton* fiftyDollarButton = new GuiButton { "gui/fuel/50dollars.png", fiftyDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddElement(fiftyDollarButton);
|
||||
|
||||
const Vector2f fillTankButtonPos = Vector2f { 450, 108 };
|
||||
GuiButton* fillTankButton = new GuiButton { "gui/fuel/fillTank.png", fillTankButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
|
||||
this->AddElement(fillTankButton);
|
||||
|
||||
|
||||
Vector2f offset{ 50, 320};
|
||||
m_MoneyText = new GuiText {fuelScreenCenter + offset, "$ 20", "fonts/Arial.ttf", 20, Colors::YELLOW };
|
||||
|
||||
}
|
||||
|
||||
FuelScreen::~FuelScreen() {
|
||||
delete m_MoneyText;
|
||||
};
|
||||
|
||||
void FuelScreen::Draw() const {
|
||||
|
||||
int currentFuel = GameManager::GetInstance().GetFuel();
|
||||
int maxFuel = GameManager::GetInstance().GetMaxFuel();
|
||||
|
||||
utils::SetColor(Colors::ORANGE);
|
||||
Vector2f fuelBarPos = Vector2f { 275, 135 };
|
||||
const int MAX_HEIGHT = 210;
|
||||
Vector2f fuelBarSize = Vector2f { 40, utils::map(currentFuel, 0, maxFuel, 0, MAX_HEIGHT) };
|
||||
utils::FillRect(Rectf{fuelBarPos, fuelBarSize});
|
||||
|
||||
Screen::Draw();
|
||||
m_MoneyText->Draw();
|
||||
|
||||
}
|
||||
void FuelScreen::Update(float elapsedSecs) {
|
||||
Screen::Update(elapsedSecs);
|
||||
m_MoneyText->ChangeText("$ " + std::to_string(GameManager::GetInstance().GetMoney()));
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
#include "../Screen.h"
|
||||
#include "Gui/GuiText.h"
|
||||
|
||||
class FuelScreen : public Screen
|
||||
{
|
||||
public:
|
||||
|
||||
FuelScreen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager);
|
||||
virtual ~FuelScreen() override;
|
||||
|
||||
virtual void Draw() const override;
|
||||
virtual void Update(float elapsedSecs) override;
|
||||
|
||||
private:
|
||||
GuiText* m_MoneyText;
|
||||
|
||||
};
|
||||
137
Game/Gui/Screens/FuelScreen/FuelScreen.cpp
Normal file
137
Game/Gui/Screens/FuelScreen/FuelScreen.cpp
Normal file
@@ -0,0 +1,137 @@
|
||||
#include "pch.h"
|
||||
#include "FuelScreen.h"
|
||||
|
||||
#include "colors.h"
|
||||
#include "GameManager.h"
|
||||
#include "../ScreenManager.h"
|
||||
#include "utils.h"
|
||||
FuelScreen::FuelScreen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): Screen(filePath, pos, size, manager) {
|
||||
const Vector2f fuelScreenSize { 492, 396 };
|
||||
const Vector2f ScreenCenter { utils::GetViewport().x / 2, utils::GetViewport().y / 2 };
|
||||
|
||||
const Vector2f fuelScreenCenter { ScreenCenter - fuelScreenSize / 2 };
|
||||
|
||||
m_BuySound = new SoundEffect { "sound/buy.wav" };
|
||||
|
||||
const Vector2f closeButtonOffset = Vector2f { 460, 396 - 14 };
|
||||
Vector2f closeButtonPos = fuelScreenCenter + closeButtonOffset;
|
||||
closeButtonPos.y -= 18;
|
||||
GuiButton* closeFuelButton = new GuiButton { "gui/close.png", closeButtonPos, Vector2f { 0, 0 }, true, TextureManager::GetInstance() };
|
||||
closeFuelButton->SetOnClick([this]()
|
||||
{
|
||||
ScreenManager::GetInstance()->CloseScreen();
|
||||
});
|
||||
this->AddElement(closeFuelButton);
|
||||
|
||||
const Vector2f oneDollarButtonPos = Vector2f { 451, 287 };
|
||||
GuiButton* fiveDollarButton = new GuiButton { "gui/fuel/5dollars.png", oneDollarButtonPos, Vector2f { 0, 0 }, true, TextureManager::GetInstance() };
|
||||
fiveDollarButton->SetOnClick([this]()
|
||||
{
|
||||
if (GameManager::GetInstance().GetMoney() > 5) {
|
||||
GameManager::GetInstance().AddFuel(5);
|
||||
GameManager::GetInstance().IncreaseMoney(-5);
|
||||
m_BuySound->Play(0);
|
||||
}
|
||||
else {
|
||||
std::cout << "Not enough money" << std::endl;
|
||||
}
|
||||
});
|
||||
this->AddElement(fiveDollarButton);
|
||||
|
||||
const Vector2f tenDollarButtonPos = oneDollarButtonPos + Vector2f { 113, -1 };
|
||||
GuiButton* tenDollarButton = new GuiButton { "gui/fuel/10dollars.png", tenDollarButtonPos, Vector2f { 0, 0 }, true, TextureManager::GetInstance() };
|
||||
tenDollarButton->SetOnClick([this]()
|
||||
{
|
||||
if (GameManager::GetInstance().GetMoney() > 10) {
|
||||
GameManager::GetInstance().AddFuel(10);
|
||||
GameManager::GetInstance().IncreaseMoney(-10);
|
||||
m_BuySound->Play(0);
|
||||
}
|
||||
else {
|
||||
std::cout << "Not enough money" << std::endl;
|
||||
}
|
||||
});
|
||||
this->AddElement(tenDollarButton);
|
||||
|
||||
const Vector2f twentyFiveDollarButtonPos = oneDollarButtonPos + Vector2f { 0, -89 };
|
||||
GuiButton* twentyFiveDollarButton = new GuiButton { "gui/fuel/25dollars.png", twentyFiveDollarButtonPos, Vector2f { 0, 0 }, true, TextureManager::GetInstance() };
|
||||
twentyFiveDollarButton->SetOnClick([this]()
|
||||
{
|
||||
if (GameManager::GetInstance().GetMoney() > 25) {
|
||||
GameManager::GetInstance().AddFuel(25);
|
||||
GameManager::GetInstance().IncreaseMoney(-25);
|
||||
m_BuySound->Play(0);
|
||||
}
|
||||
else {
|
||||
std::cout << "Not enough money" << std::endl;
|
||||
}
|
||||
});
|
||||
this->AddElement(twentyFiveDollarButton);
|
||||
|
||||
const Vector2f fiftyDollarButtonPos = twentyFiveDollarButtonPos + Vector2f { 114, 0 };
|
||||
GuiButton* fiftyDollarButton = new GuiButton { "gui/fuel/50dollars.png", fiftyDollarButtonPos, Vector2f { 0, 0 }, true, TextureManager::GetInstance() };
|
||||
fiftyDollarButton->SetOnClick([this]()
|
||||
{
|
||||
if (GameManager::GetInstance().GetMoney() > 50) {
|
||||
GameManager::GetInstance().AddFuel(50);
|
||||
GameManager::GetInstance().IncreaseMoney(-50);
|
||||
m_BuySound->Play(0);
|
||||
|
||||
}
|
||||
else {
|
||||
std::cout << "Not enough money" << std::endl;
|
||||
}
|
||||
});
|
||||
this->AddElement(fiftyDollarButton);
|
||||
|
||||
const Vector2f fillTankButtonPos = Vector2f { 450, 108 };
|
||||
GuiButton* fillTankButton = new GuiButton { "gui/fuel/fillTank.png", fillTankButtonPos, Vector2f { 0, 0 }, true, TextureManager::GetInstance() };
|
||||
fillTankButton->SetOnClick([this]()
|
||||
{
|
||||
if (GameManager::GetInstance().GetFuel() < GameManager::GetInstance().GetMaxFuel() - 2) {
|
||||
int fuelNeeded = static_cast<int>(GameManager::GetInstance().GetMaxFuel() - GameManager::GetInstance().GetFuel());
|
||||
if (fuelNeeded <= GameManager::GetInstance().GetMoney()) {
|
||||
GameManager::GetInstance().AddFuel(fuelNeeded);
|
||||
GameManager::GetInstance().IncreaseMoney(-fuelNeeded);
|
||||
m_BuySound->Play(0);
|
||||
}
|
||||
else {
|
||||
std::cout << "Not enough money" << std::endl;
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::cout << "Don't need fuel" << std::endl;
|
||||
}
|
||||
});
|
||||
this->AddElement(fillTankButton);
|
||||
|
||||
|
||||
Vector2f offset { 50, 320 };
|
||||
m_MoneyText = new GuiText { fuelScreenCenter + offset, "$ 20", "fonts/Arial.ttf", 20, Colors::YELLOW };
|
||||
|
||||
}
|
||||
|
||||
FuelScreen::~FuelScreen() {
|
||||
delete m_MoneyText;
|
||||
delete m_BuySound;
|
||||
};
|
||||
|
||||
void FuelScreen::Draw() const {
|
||||
|
||||
int currentFuel = GameManager::GetInstance().GetFuel();
|
||||
int maxFuel = GameManager::GetInstance().GetMaxFuel();
|
||||
|
||||
utils::SetColor(Color4f { 99.f / 255.f, 82.f / 255.f, 36.f / 255.f, 1.f });
|
||||
Vector2f fuelBarPos = Vector2f { 275, 135 };
|
||||
const int MAX_HEIGHT = 210;
|
||||
Vector2f fuelBarSize = Vector2f { 40, utils::map(currentFuel, 0, maxFuel, 0, MAX_HEIGHT) };
|
||||
utils::FillRect(Rectf { fuelBarPos, fuelBarSize });
|
||||
|
||||
Screen::Draw();
|
||||
m_MoneyText->Draw();
|
||||
|
||||
}
|
||||
void FuelScreen::Update(float elapsedSecs) {
|
||||
Screen::Update(elapsedSecs);
|
||||
m_MoneyText->ChangeText("$ " + std::to_string(GameManager::GetInstance().GetMoney())); //Not the best but will work
|
||||
}
|
||||
25
Game/Gui/Screens/FuelScreen/FuelScreen.h
Normal file
25
Game/Gui/Screens/FuelScreen/FuelScreen.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include "SoundEffect.h"
|
||||
#include "../../Screen.h"
|
||||
#include "Gui/GuiText.h"
|
||||
|
||||
class FuelScreen final : public Screen {
|
||||
public:
|
||||
FuelScreen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager);
|
||||
virtual ~FuelScreen() override;
|
||||
|
||||
FuelScreen(const FuelScreen& other) = delete;
|
||||
FuelScreen(FuelScreen&& other) = delete;
|
||||
FuelScreen& operator=(const FuelScreen& other) = delete;
|
||||
FuelScreen& operator=(FuelScreen&& other) = delete;
|
||||
|
||||
|
||||
virtual void Draw() const override;
|
||||
virtual void Update(float elapsedSecs) override;
|
||||
|
||||
private:
|
||||
GuiText* m_MoneyText;
|
||||
|
||||
SoundEffect* m_BuySound { nullptr };
|
||||
|
||||
};
|
||||
@@ -5,24 +5,55 @@
|
||||
#include "GameManager.h"
|
||||
#include "utils.h"
|
||||
#include "Gui/GuiText.h"
|
||||
MainScreen::MainScreen(TextureManager* manager) : Screen("", Vector2f{0, 0}, Vector2f{900.f, 500.f}, manager) {
|
||||
MainScreen::MainScreen(TextureManager* manager) : Screen("", Vector2f { 0, 0 }, Vector2f { 900.f, 500.f }, 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);
|
||||
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);
|
||||
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};
|
||||
Vector2f DepthMeterPosition { 10, ScreenSize.y - 120 };
|
||||
m_DepthText = new GuiText(DepthMeterPosition, "Depth: 20", "fonts/Arial.ttf", 20, Colors::YELLOW);
|
||||
this->AddElement(m_DepthText);
|
||||
|
||||
Vector2f ScoreMeterPosition{10, ScreenSize.y - 150};
|
||||
m_ScoreText = new GuiText(ScoreMeterPosition, "Score: 0", "fonts/Arial.ttf", 20, Colors::YELLOW);
|
||||
Vector2f ScoreMeterPosition { 150, ScreenSize.y - 50 };
|
||||
m_ScoreText = new GuiText(ScoreMeterPosition, "0", "fonts/Arial.ttf", 20, Colors::YELLOW);
|
||||
this->AddElement(m_ScoreText);
|
||||
|
||||
|
||||
Vector2f InvButtonPosition { ScreenSize.x - 150, ScreenSize.y - 60 };
|
||||
float InvButtonScale = 1.2f;
|
||||
m_InvButton = new GuiButton("gui/main/inv.png", InvButtonPosition, Vector2f { 58 * InvButtonScale, 55 * InvButtonScale }, false, manager);
|
||||
m_InvButton->SetOnClick([]()
|
||||
{
|
||||
// GameManager::GetInstance().ToggleInventory();
|
||||
std::cout << "Inventory button clicked" << std::endl;
|
||||
});
|
||||
this->AddElement(m_InvButton);
|
||||
|
||||
Vector2f OptionsButtonPosition { ScreenSize.x - 85, ScreenSize.y - 85 };
|
||||
m_OptionsButton = new GuiButton("gui/main/options.png", OptionsButtonPosition, Vector2f { 74, 56 }, false, manager);
|
||||
m_OptionsButton->SetOnClick([]()
|
||||
{
|
||||
// GameManager::GetInstance().ToggleOptions();
|
||||
std::cout << "Options button clicked" << std::endl;
|
||||
});
|
||||
this->AddElement(m_OptionsButton);
|
||||
|
||||
m_HelpButton = new GuiButton("gui/main/help.png", Vector2f { ScreenSize.x - 50, ScreenSize.y - 50 }, Vector2f { 50, 50 }, false, manager);
|
||||
m_HelpButton->SetOnClick([]()
|
||||
{
|
||||
// GameManager::GetInstance().ToggleHelp();
|
||||
std::cout << "Help button clicked" << std::endl;
|
||||
});
|
||||
this->AddElement(m_HelpButton);
|
||||
|
||||
m_MoneyText = new GuiText(Vector2f { ScreenSize.x - 450, ScreenSize.y - 35 }, "Filler Text", "fonts/Arial.ttf", 25, Colors::YELLOW);
|
||||
this->AddElement(m_MoneyText);
|
||||
}
|
||||
MainScreen::~MainScreen() = default;
|
||||
void MainScreen::Draw() const {
|
||||
@@ -43,4 +74,6 @@ void MainScreen::SetDepth(const std::string& text) const {
|
||||
void MainScreen::SetScore(const std::string& text) const {
|
||||
m_ScoreText->ChangeText(text);
|
||||
}
|
||||
|
||||
void MainScreen::SetMoney(const std::string& text) const {
|
||||
m_MoneyText->ChangeText(text);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "Gui/GuiText.h"
|
||||
#include "Gui/Screen.h"
|
||||
|
||||
class MainScreen: public Screen {
|
||||
class MainScreen final : public Screen {
|
||||
public:
|
||||
explicit MainScreen(TextureManager* manager);
|
||||
virtual ~MainScreen() override;
|
||||
@@ -16,6 +16,7 @@ public:
|
||||
|
||||
void SetDepth(const std::string& text) const;
|
||||
void SetScore(const std::string& text) const;
|
||||
void SetMoney(const std::string& text) const;
|
||||
|
||||
private:
|
||||
GuiMeter* m_FuelMeter;
|
||||
@@ -23,5 +24,10 @@ private:
|
||||
|
||||
GuiText* m_DepthText;
|
||||
GuiText* m_ScoreText;
|
||||
|
||||
GuiText* m_MoneyText;
|
||||
|
||||
GuiButton* m_InvButton;
|
||||
GuiButton* m_OptionsButton;
|
||||
GuiButton* m_HelpButton;
|
||||
|
||||
};
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
#include "pch.h"
|
||||
#include "ScreenManager.h"
|
||||
|
||||
#include "FuelScreen.h"
|
||||
#include "FuelScreen/FuelScreen.h"
|
||||
#include "SellScreen/SellScreen.h"
|
||||
#include "utils.h"
|
||||
ScreenManager* ScreenManager::m_pInstance = nullptr;
|
||||
|
||||
Screen* ScreenManager::m_FuelScreen{ nullptr };
|
||||
Screen* ScreenManager::m_SellScreen{ nullptr };
|
||||
Screen* ScreenManager::m_FuelScreen { nullptr };
|
||||
Screen* ScreenManager::m_SellScreen { nullptr };
|
||||
|
||||
ScreenManager* ScreenManager::GetInstance() {
|
||||
ScreenManager * ScreenManager::GetInstance() {
|
||||
|
||||
if(m_pInstance == nullptr) {
|
||||
if (m_pInstance == nullptr) {
|
||||
m_pInstance = new ScreenManager();
|
||||
}
|
||||
if(!m_pInstance->m_AreScreensInitialized) {
|
||||
m_pInstance->InitializeScreens(); //TODO: Ask if this a hack
|
||||
if (!m_pInstance->m_AreScreensInitialized) {
|
||||
m_pInstance->InitializeScreens();
|
||||
m_pInstance->m_AreScreensInitialized = true;
|
||||
}
|
||||
return m_pInstance;
|
||||
@@ -25,19 +26,19 @@ void ScreenManager::DestroyInstance() {
|
||||
}
|
||||
|
||||
void ScreenManager::OpenScreen(Screen* screen) {
|
||||
if(m_IsScreenOpen == false) {
|
||||
if (m_IsScreenOpen == false) {
|
||||
m_currentScreen = screen;
|
||||
m_IsScreenOpen = true;
|
||||
}
|
||||
}
|
||||
void ScreenManager::CloseScreen() {
|
||||
if(m_IsScreenOpen == true) {
|
||||
if (m_IsScreenOpen == true) {
|
||||
m_IsScreenOpen = false;
|
||||
m_currentScreen = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
bool ScreenManager::IsScreenOpen() {
|
||||
bool ScreenManager::IsScreenOpen() const {
|
||||
return m_IsScreenOpen;
|
||||
}
|
||||
ScreenManager::~ScreenManager() {
|
||||
@@ -51,8 +52,7 @@ void ScreenManager::InitializeScreens() {
|
||||
|
||||
Vector2f sellScreenSize = Vector2f { 533, 398 };
|
||||
Vector2f sellScreenCenter = Vector2f { utils::GetViewport().x / 2 - sellScreenSize.x / 2, utils::GetViewport().y / 2 - sellScreenSize.y / 2 };
|
||||
m_SellScreen = new Screen { "gui/sell/background.png", sellScreenCenter, sellScreenSize, TextureManager::GetInstance() };
|
||||
|
||||
m_SellScreen = new SellScreen { "gui/sell/background.png", sellScreenCenter, sellScreenSize, TextureManager::GetInstance() };
|
||||
|
||||
//m_Button = Button { "gui/close.png", closeButtonPos, closeButtonSize, TextureManager::GetInstance() };
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
|
||||
|
||||
|
||||
class ScreenManager
|
||||
{
|
||||
class ScreenManager {
|
||||
public:
|
||||
static ScreenManager* GetInstance();
|
||||
static void DestroyInstance();
|
||||
@@ -12,23 +11,26 @@ public:
|
||||
void OpenScreen(Screen* screen);
|
||||
void CloseScreen();
|
||||
|
||||
Screen* GetCurrentScreen() const { return m_currentScreen; }
|
||||
bool IsScreenOpen();
|
||||
Screen * GetCurrentScreen() const {
|
||||
return m_currentScreen;
|
||||
}
|
||||
bool IsScreenOpen() const;
|
||||
|
||||
static ScreenManager* m_pInstance;
|
||||
|
||||
|
||||
static Screen* m_FuelScreen;
|
||||
static Screen* m_SellScreen;
|
||||
|
||||
private:
|
||||
ScreenManager() = default;
|
||||
~ScreenManager();
|
||||
|
||||
void InitializeScreens();
|
||||
|
||||
bool m_IsScreenOpen{ false };
|
||||
|
||||
bool m_IsScreenOpen { false };
|
||||
Screen* m_currentScreen;
|
||||
|
||||
bool m_AreScreensInitialized{ false };
|
||||
|
||||
};
|
||||
bool m_AreScreensInitialized { false };
|
||||
|
||||
};
|
||||
|
||||
116
Game/Gui/Screens/SellScreen/SellScreen.cpp
Normal file
116
Game/Gui/Screens/SellScreen/SellScreen.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
#include "pch.h"
|
||||
#include "SellScreen.h"
|
||||
|
||||
#include "colors.h"
|
||||
#include "GameManager.h"
|
||||
#include "SellSreenRow.h"
|
||||
#include "../ScreenManager.h"
|
||||
#include "utils.h"
|
||||
SellScreen::SellScreen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): Screen(filePath, pos, size, manager) {
|
||||
const Vector2f sellScreenSize { 492, 396 };
|
||||
// Vector2f fuelScreenCenter = Vector2f { utils::GetViewport().x / 2 - fuelScreenSize.x / 2, utils::GetViewport().y / 2 - fuelScreenSize.y / 2 };
|
||||
const Vector2f ScreenCenter = Vector2f { utils::GetViewport().x / 2, utils::GetViewport().y / 2 };
|
||||
|
||||
const Vector2f sellScreenCenter = ScreenCenter - sellScreenSize / 2;
|
||||
|
||||
const Vector2f closeButtonOffset = Vector2f { 460, 396 - 14 };
|
||||
Vector2f closeButtonPos = sellScreenCenter + closeButtonOffset;
|
||||
closeButtonPos.y -= 18;
|
||||
GuiButton* closeFuelButton = new GuiButton { "gui/close.png", closeButtonPos, Vector2f { 0, 0 }, true, TextureManager::GetInstance() };
|
||||
closeFuelButton->SetOnClick([this]()
|
||||
{
|
||||
ScreenManager::GetInstance()->CloseScreen();
|
||||
});
|
||||
this->AddElement(closeFuelButton);
|
||||
|
||||
std::string HeaderText = "Cargo Bay Qty. Value Total Value"; //Dont ask
|
||||
Vector2f headerTextPos = Vector2f { 285, 400 };
|
||||
GuiText* m_HeaderText = new GuiText { headerTextPos, HeaderText, "fonts/Arial.ttf", 14, Colors::LIGHTGRAY };
|
||||
this->AddElement(m_HeaderText);
|
||||
|
||||
|
||||
std::string sellAllPath = "gui/sell/sellall.png";
|
||||
Vector2f sellAllPos = Vector2f { 410, 100 };
|
||||
|
||||
GuiButton* sellAllButton = new GuiButton { sellAllPath, sellAllPos, Vector2f { 97, 27 }, false, TextureManager::GetInstance() };
|
||||
sellAllButton->SetOnClick([this]()
|
||||
{
|
||||
this->SellAll();
|
||||
});
|
||||
this->AddElement(sellAllButton);
|
||||
|
||||
std::string totalSell = "Balls";
|
||||
Vector2f totalSellPos = Vector2f { 590, 105 };
|
||||
m_TotalMoneyText = new GuiText { totalSellPos, totalSell, "fonts/Arial.ttf", 18, Colors::GREEN };
|
||||
this->AddElement(m_TotalMoneyText);
|
||||
}
|
||||
SellScreen::~SellScreen() {
|
||||
for (SellSreenRow* row : m_Rows) {
|
||||
delete row;
|
||||
}
|
||||
}
|
||||
void SellScreen::Draw() const {
|
||||
Screen::Draw();
|
||||
for (const SellSreenRow* row : m_Rows) {
|
||||
row->Draw();
|
||||
}
|
||||
|
||||
// m_TotalMoneyText->Draw();
|
||||
utils::SetColor(Colors::GREEN);
|
||||
utils::DrawLine(550, 130, 650, 130);
|
||||
|
||||
}
|
||||
void SellScreen::Update(float elapsedSecs) {
|
||||
Screen::Update(elapsedSecs);
|
||||
if (m_AreRowsDirty) {
|
||||
//remake rows
|
||||
m_AreRowsDirty = false;
|
||||
|
||||
for (SellSreenRow* row : m_Rows) {
|
||||
delete row;
|
||||
}
|
||||
m_Rows.clear();
|
||||
|
||||
std::vector<ItemStack *> items = GameManager::GetInstance().GetInventory()->GetItems();
|
||||
int totalWorth { 0 };
|
||||
int index { 0 }; //Fix to not overshoot when an empty item is in the inventory
|
||||
for (ItemStack* item : items) {
|
||||
if (item->m_ItemType == InventoryItem::Empty) {
|
||||
continue;
|
||||
}
|
||||
SellSreenRow* row = new SellSreenRow(*item, Vector2f { 250, (float)360 - index * 30 }, Vector2f { 400, 30 });
|
||||
totalWorth += item->m_Quantity * PlayerInventory::GetItemValue(item->m_ItemType);
|
||||
m_Rows.push_back(std::move(row));
|
||||
index++;
|
||||
}
|
||||
|
||||
|
||||
m_TotalMoneyText->ChangeText("$" + std::to_string(GameManager::GetInstance().GetInventory()->GetTotalValue()));
|
||||
int characterCount = m_TotalMoneyText->GetText().length();
|
||||
m_TotalMoneyText->SetPosition(Vector2f { (float)610 - characterCount * 10, 105 });
|
||||
}
|
||||
|
||||
for (SellSreenRow* row : m_Rows) {
|
||||
row->Update(elapsedSecs);
|
||||
}
|
||||
}
|
||||
void SellScreen::MarkDirty() {
|
||||
m_AreRowsDirty = true;
|
||||
}
|
||||
void SellScreen::SellAll() {
|
||||
PlayerInventory* inventory = GameManager::GetInstance().GetInventory();
|
||||
std::vector<ItemStack *> items = inventory->GetItems();
|
||||
if (items.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int totalWorth { 0 };
|
||||
for (ItemStack* item : items) {
|
||||
if (item->m_ItemType == InventoryItem::Empty) {
|
||||
continue;
|
||||
}
|
||||
totalWorth += item->m_Quantity * PlayerInventory::GetItemValue(item->m_ItemType);
|
||||
inventory->RemoveItem(item);
|
||||
}
|
||||
GameManager::GetInstance().IncreaseMoney(totalWorth);
|
||||
}
|
||||
23
Game/Gui/Screens/SellScreen/SellScreen.h
Normal file
23
Game/Gui/Screens/SellScreen/SellScreen.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include "SellSreenRow.h"
|
||||
#include "../../Screen.h"
|
||||
#include "Gui/GuiText.h"
|
||||
|
||||
class SellScreen final : public Screen {
|
||||
public:
|
||||
SellScreen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager);
|
||||
virtual ~SellScreen() override;
|
||||
|
||||
virtual void Draw() const override;
|
||||
virtual void Update(float elapsedSecs) override;
|
||||
|
||||
void MarkDirty();
|
||||
void SellAll();
|
||||
|
||||
private:
|
||||
GuiText* m_TotalMoneyText;
|
||||
|
||||
std::vector<SellSreenRow *> m_Rows;
|
||||
|
||||
bool m_AreRowsDirty { true };
|
||||
};
|
||||
45
Game/Gui/Screens/SellScreen/SellSreenRow.cpp
Normal file
45
Game/Gui/Screens/SellScreen/SellSreenRow.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "pch.h"
|
||||
#include "SellSreenRow.h"
|
||||
|
||||
#include "colors.h"
|
||||
#include "utils.h"
|
||||
SellSreenRow::SellSreenRow(const ItemStack& item, const Vector2f& pos, const Vector2f& size): m_Item(item), m_Pos(pos), m_Size(size) {
|
||||
m_NameText = new Text(PlayerInventory::GetItemName(item.m_ItemType), "fonts/verdana.ttf", 12, Colors::GREEN);
|
||||
m_CalculationText = new Text("Hello World", "fonts/verdana.ttf", 14, Colors::GREEN);
|
||||
this->GenerateCalcString();
|
||||
m_Icon = PlayerInventory::GetItemIcon(item.m_ItemType);
|
||||
}
|
||||
SellSreenRow::~SellSreenRow() {
|
||||
delete m_NameText;
|
||||
delete m_CalculationText;
|
||||
}
|
||||
void SellSreenRow::Draw() const {
|
||||
//The row has, The icon, The name, The amount, an X, the value, an =, the total value
|
||||
//The icon
|
||||
|
||||
Vector2f iconPos { m_Pos.x + 10, m_Pos.y + 2 };
|
||||
m_Icon->Draw(iconPos);
|
||||
//The name
|
||||
Vector2f namePos { iconPos.x + 50, m_Pos.y + 8 };
|
||||
m_NameText->Draw(namePos);
|
||||
|
||||
Vector2f amountPos { namePos.x + 100, m_Pos.y + 8 };
|
||||
m_CalculationText->Draw(amountPos);
|
||||
|
||||
utils::SetColor(Colors::GREEN);
|
||||
utils::DrawRect(Rectf { m_Pos, m_Size });
|
||||
}
|
||||
void SellSreenRow::Update(float elapsedSecs) {
|
||||
// m_NameText->ChangeText("EXAMPLE");
|
||||
// m_CalculationText->ChangeText(std::to_string(m_Item.m_Quantity));
|
||||
GenerateCalcString();
|
||||
|
||||
}
|
||||
void SellSreenRow::GenerateCalcString() {
|
||||
std::string amount = std::to_string(m_Item.m_Quantity);
|
||||
std::string value = std::to_string(PlayerInventory::GetItemValue(m_Item.m_ItemType));
|
||||
std::string totalValue = std::to_string(PlayerInventory::GetItemValue(m_Item.m_ItemType) * m_Item.m_Quantity);
|
||||
// NAME AMOUNT X VALUE = TOTAL VALUE
|
||||
std::string text = amount + " x $" + value + " = " + totalValue + "$";
|
||||
m_CalculationText->ChangeText(text);
|
||||
}
|
||||
32
Game/Gui/Screens/SellScreen/SellSreenRow.h
Normal file
32
Game/Gui/Screens/SellScreen/SellSreenRow.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include "Text.h"
|
||||
#include "TextureManager.h"
|
||||
#include "Inventory/PlayerInventory.h"
|
||||
|
||||
class SellSreenRow {
|
||||
public:
|
||||
SellSreenRow(const ItemStack& item, const Vector2f& pos, const Vector2f& size);
|
||||
~SellSreenRow();
|
||||
|
||||
SellSreenRow(const SellSreenRow& other) = delete;
|
||||
SellSreenRow(SellSreenRow&& other) = delete;
|
||||
SellSreenRow& operator=(const SellSreenRow& other) = delete;
|
||||
SellSreenRow& operator=(SellSreenRow&& other) = delete;
|
||||
|
||||
void Draw() const;
|
||||
void Update(float elapsedSecs);
|
||||
|
||||
private:
|
||||
void GenerateCalcString();
|
||||
|
||||
ItemStack m_Item;
|
||||
Vector2f m_Pos;
|
||||
Vector2f m_Size;
|
||||
|
||||
Text* m_NameText;
|
||||
Text* m_CalculationText;
|
||||
|
||||
Texture* m_Icon;
|
||||
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user