From 53b9b646cc1cd57d3659ba314ea26fbba5ac3b08 Mon Sep 17 00:00:00 2001 From: Alexander Hunt Date: Thu, 8 Feb 2024 10:03:50 -0500 Subject: [PATCH] Updated MapViewState to use the new constructor and removed Population initialization from MapViewStateUI --- OPHD/States/MapViewState.cpp | 1 + OPHD/States/MapViewStateUi.cpp | 2 -- OPHD/UI/PopulationPanel.cpp | 30 +++------------------------ OPHD/UI/PopulationPanel.h | 1 - libOPHD/Population/PopulationPool.cpp | 12 +++++------ libOPHD/Population/PopulationPool.h | 12 +++++------ 6 files changed, 16 insertions(+), 42 deletions(-) diff --git a/OPHD/States/MapViewState.cpp b/OPHD/States/MapViewState.cpp index 4e1b6d348..60924b129 100644 --- a/OPHD/States/MapViewState.cpp +++ b/OPHD/States/MapViewState.cpp @@ -187,6 +187,7 @@ MapViewState::MapViewState(MainReportsUiState& mainReportsState, const Planet::A mStructures{"ui/structures.png", 46, constants::MarginTight}, mRobots{"ui/robots.png", 46, constants::MarginTight}, mConnections{"ui/structures.png", 46, constants::MarginTight}, + mPopulationPanel{mPopulation, mPopulationPool}, mResourceInfoBar{mResourcesCount, mPopulation, mCurrentMorale, mPreviousMorale, mFood}, mRobotDeploymentSummary{mRobotPool}, mMiniMap{std::make_unique(*mMapView, mTileMap, mRobotList, planetAttributes.mapImagePath)}, diff --git a/OPHD/States/MapViewStateUi.cpp b/OPHD/States/MapViewStateUi.cpp index d91ad0cd0..08a4dff95 100644 --- a/OPHD/States/MapViewStateUi.cpp +++ b/OPHD/States/MapViewStateUi.cpp @@ -75,8 +75,6 @@ void MapViewState::initUi() mFileIoDialog.hide(); mPopulationPanel.position({675, constants::ResourceIconSize + 4 + constants::MarginTight}); - mPopulationPanel.population(&mPopulation); - mPopulationPanel.populationPool(&mPopulationPool); mResourceBreakdownPanel.position({0, 22}); mResourceBreakdownPanel.playerResources(&mResourcesCount); diff --git a/OPHD/UI/PopulationPanel.cpp b/OPHD/UI/PopulationPanel.cpp index cbb2545cb..a71d18bba 100644 --- a/OPHD/UI/PopulationPanel.cpp +++ b/OPHD/UI/PopulationPanel.cpp @@ -48,6 +48,8 @@ static const std::array moraleStringColor Color{0, 185, 0} }; +PopulationPanel::PopulationPanel() : PopulationPanel::PopulationPanel(Population(), PopulationPool()){}; + PopulationPanel::PopulationPanel(const Population& pop, const PopulationPool& popPool) : mFont{fontCache.load(constants::FONT_PRIMARY, constants::FontPrimaryNormal)}, mFontBold{fontCache.load(constants::FONT_PRIMARY_BOLD, constants::FontPrimaryNormal)}, @@ -65,32 +67,7 @@ PopulationPanel::PopulationPanel(const Population& pop, const PopulationPool& po { mPopulation = &pop; mPopulationPool = &popPool; - PopulationPanel::init(); -} - -PopulationPanel::PopulationPanel() : - mFont{fontCache.load(constants::FONT_PRIMARY, constants::FontPrimaryNormal)}, - mFontBold{fontCache.load(constants::FONT_PRIMARY_BOLD, constants::FontPrimaryNormal)}, - mIcons{imageCache.load("ui/icons.png")}, - mSkin - { - imageCache.load("ui/skin/window_top_left.png"), - imageCache.load("ui/skin/window_top_middle.png"), - imageCache.load("ui/skin/window_top_right.png"), - imageCache.load("ui/skin/window_middle_left.png"), - imageCache.load("ui/skin/window_middle_middle.png"), - imageCache.load("ui/skin/window_middle_right.png"), - imageCache.load("ui/skin/window_bottom_left.png"), - imageCache.load("ui/skin/window_bottom_middle.png"), - imageCache.load("ui/skin/window_bottom_right.png") - } -{ - PopulationPanel::init(); -} - -void PopulationPanel::init() -{ - constexpr int linesOfText = 14; + constexpr int linesOfText = 16; constexpr int edgeBuffer = constants::Margin * 2; const int windowHeight = mFontBold.height() + (mFont.height() * linesOfText) + (edgeBuffer * 2 /* Times two to account for both the edge and the divider line. */); @@ -119,7 +96,6 @@ void PopulationPanel::addMoraleReason(const std::string& str, int val) mMoraleChangeReasons.push_back(std::make_pair(str, val)); } - void PopulationPanel::update() { auto& renderer = Utility::get(); diff --git a/OPHD/UI/PopulationPanel.h b/OPHD/UI/PopulationPanel.h index 9e33108f0..656e14e08 100644 --- a/OPHD/UI/PopulationPanel.h +++ b/OPHD/UI/PopulationPanel.h @@ -57,5 +57,4 @@ class PopulationPanel : public Control int mCrimeRate{0}; int mPopulationPanelWidth{0}; - void init(); }; diff --git a/libOPHD/Population/PopulationPool.cpp b/libOPHD/Population/PopulationPool.cpp index b22f86f7c..cc91e0557 100644 --- a/libOPHD/Population/PopulationPool.cpp +++ b/libOPHD/Population/PopulationPool.cpp @@ -19,13 +19,13 @@ void PopulationPool::population(Population* pop) } -const int PopulationPool::availableWorkers() const +int PopulationPool::availableWorkers() const { return mPopulation->getPopulations().worker - workersEmployed(); } -const int PopulationPool::availableScientists() const +int PopulationPool::availableScientists() const { return mPopulation->getPopulations().scientist - scientistsEmployed(); } @@ -67,7 +67,7 @@ void PopulationPool::clear() /** * Amount of Scientists employed as Workers. */ -int PopulationPool::scientistsAsWorkers() +int PopulationPool::scientistsAsWorkers() const { return mScientistsAsWorkers; } @@ -76,7 +76,7 @@ int PopulationPool::scientistsAsWorkers() /** * Amount of Scientists currently employed. */ -const int PopulationPool::scientistsEmployed() const +int PopulationPool::scientistsEmployed() const { return mScientistsUsed; } @@ -85,7 +85,7 @@ const int PopulationPool::scientistsEmployed() const /** * Amount of Workers currently employed. */ -const int PopulationPool::workersEmployed() const +int PopulationPool::workersEmployed() const { return mWorkersUsed; } @@ -94,7 +94,7 @@ const int PopulationPool::workersEmployed() const /** * Amount of population currently employed. */ -int PopulationPool::populationEmployed() +int PopulationPool::populationEmployed() const { return scientistsEmployed() + scientistsAsWorkers() + workersEmployed(); } diff --git a/libOPHD/Population/PopulationPool.h b/libOPHD/Population/PopulationPool.h index 547e5e354..33f7b09aa 100644 --- a/libOPHD/Population/PopulationPool.h +++ b/libOPHD/Population/PopulationPool.h @@ -15,17 +15,17 @@ class PopulationPool public: void population(Population* pop); - const int availableWorkers() const; - const int availableScientists() const; + int availableWorkers() const; + int availableScientists() const; bool usePopulation(PopulationRequirements populationRequirements); void clear(); - int scientistsAsWorkers(); - const int scientistsEmployed() const; - const int workersEmployed() const; - int populationEmployed(); + int scientistsAsWorkers() const; + int scientistsEmployed() const; + int workersEmployed() const; + int populationEmployed() const; int size() const;