Add Alot
This commit is contained in:
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