Added inheritance for the screen system

basic edge detection for tile rendering
This commit is contained in:
Bram Verhulst
2024-04-04 13:49:38 +02:00
parent eb4c7b4d76
commit 71d364d9d8
23 changed files with 203 additions and 481 deletions

View File

@@ -1,6 +1,43 @@
#include "FuelScreen.h"
#include "ScreenManager.h"
#include "utils.h"
FuelScreen::FuelScreen(const std::string& filePath, Point2f pos, Point2f size, TextureManager* manager): Screen(filePath, pos, size, manager)
{
Point2f fuelScreenSize = Point2f { 492, 396 };
Point2f fuelScreenCenter = Point2f { utils::GetViewport().x / 2 - fuelScreenSize.x / 2, utils::GetViewport().y / 2 - fuelScreenSize.y / 2 };
Point2f closeButtonOffset = Point2f { 460, 396 - 14 };
Point2f closeButtonPos = fuelScreenCenter + closeButtonOffset;
closeButtonPos.y -= 18;
Button* closeFuelButton = new Button { "gui/close.png", closeButtonPos, Point2f{0,0}, TextureManager::GetInstance() };
closeFuelButton->SetOnClick([this]() { ScreenManager::GetInstance()->CloseScreen(); });
this->AddButton(closeFuelButton);
Point2f oneDollarButtonPos = Point2f { 451, 287 };
oneDollarButtonPos += fuelScreenCenter;
Button* fiveDollarButton = new Button { "gui/fuel/5dollars.png", oneDollarButtonPos , Point2f{0,0}, TextureManager::GetInstance() };
this->AddButton(fiveDollarButton);
Point2f tenDollarButtonPos = oneDollarButtonPos + Point2f { 113, -1 };
tenDollarButtonPos += fuelScreenCenter;
Button* tenDollarButton = new Button { "gui/fuel/10dollars.png", tenDollarButtonPos, Point2f{0,0}, TextureManager::GetInstance() };
this->AddButton(tenDollarButton);
Point2f twentyFiveDollarButtonPos = oneDollarButtonPos + Point2f { 0, -89 };
twentyFiveDollarButtonPos += fuelScreenCenter;
Button* twentyFiveDollarButton = new Button { "gui/fuel/25dollars.png", twentyFiveDollarButtonPos, Point2f{0,0}, TextureManager::GetInstance() };
this->AddButton(twentyFiveDollarButton);
Point2f fiftyDollarButtonPos = twentyFiveDollarButtonPos + Point2f { 114, 0 };
Button* fiftyDollarButton = new Button { "gui/fuel/50dollars.png", fiftyDollarButtonPos, Point2f{0,0}, TextureManager::GetInstance() };
this->AddButton(fiftyDollarButton);
Point2f fillTankButtonPos = Point2f { 450, 108 };
fillTankButtonPos += fuelScreenCenter;
Button* fillTankButton = new Button { "gui/fuel/fillTank.png", fillTankButtonPos, Point2f{0,0}, TextureManager::GetInstance() };
this->AddButton(fillTankButton);
}
void FuelScreen::Draw() const {
Screen::Draw();

View File

@@ -35,43 +35,12 @@ void ScreenManager::CloseScreen() {
void ScreenManager::InitializeScreens() {
Point2f fuelScreenSize = Point2f { 492, 396 };
Point2f fuelScreenCenter = Point2f { utils::GetViewport().x / 2 - fuelScreenSize.x / 2, utils::GetViewport().y / 2 - fuelScreenSize.y / 2 };
Fuel = new FuelScreen { "gui/fuel/background.png", fuelScreenCenter, fuelScreenSize, TextureManager::GetInstance() };
Fuel = new FuelScreen { "gui/fuel/background.png", fuelScreenCenter, Point2f { 0, 0 }, TextureManager::GetInstance() };
Point2f closeButtonOffset = Point2f { 460, 396 - 14 };
Point2f closeButtonPos = fuelScreenCenter + closeButtonOffset;
closeButtonPos.y -= 18;
Button* closeFuelButton = new Button { "gui/close.png", closeButtonPos, Point2f{0,0}, TextureManager::GetInstance() };
closeFuelButton->SetOnClick([this]() { CloseScreen(); });
Fuel->AddButton(closeFuelButton);
Point2f oneDollarButtonPos = Point2f { 451, 287 };
oneDollarButtonPos += fuelScreenCenter;
Button* fiveDollarButton = new Button { "gui/fuel/5dollars.png", oneDollarButtonPos , Point2f{0,0}, TextureManager::GetInstance() };
Fuel->AddButton(fiveDollarButton);
Point2f tenDollarButtonPos = oneDollarButtonPos + Point2f { 113, -1 };
tenDollarButtonPos += fuelScreenCenter;
Button* tenDollarButton = new Button { "gui/fuel/10dollars.png", tenDollarButtonPos, Point2f{0,0}, TextureManager::GetInstance() };
Fuel->AddButton(tenDollarButton);
Point2f twentyFiveDollarButtonPos = oneDollarButtonPos + Point2f { 0, -89 };
twentyFiveDollarButtonPos += fuelScreenCenter;
Button* twentyFiveDollarButton = new Button { "gui/fuel/25dollars.png", twentyFiveDollarButtonPos, Point2f{0,0}, TextureManager::GetInstance() };
Fuel->AddButton(twentyFiveDollarButton);
Point2f fiftyDollarButtonPos = twentyFiveDollarButtonPos + Point2f { 114, 0 };
Button* fiftyDollarButton = new Button { "gui/fuel/50dollars.png", fiftyDollarButtonPos, Point2f{0,0}, TextureManager::GetInstance() };
Fuel->AddButton(fiftyDollarButton);
Point2f fillTankButtonPos = Point2f { 450, 108 };
fillTankButtonPos += fuelScreenCenter;
Button* fillTankButton = new Button { "gui/fuel/fillTank.png", fillTankButtonPos, Point2f{0,0}, TextureManager::GetInstance() };
Fuel->AddButton(fillTankButton);
Point2f sellScreenSize = Point2f { 533, 398 };
Point2f sellScreenCenter = Point2f { utils::GetViewport().x / 2 - sellScreenSize.x / 2, utils::GetViewport().y / 2 - sellScreenSize.y / 2 };
SellScreen = new Screen { "gui/sell/background.png", sellScreenCenter, sellScreenSize, TextureManager::GetInstance() };
//m_Button = Button { "gui/close.png", closeButtonPos, closeButtonSize, TextureManager::GetInstance() };
}