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 dfbb49807..a71d18bba 100644 --- a/OPHD/UI/PopulationPanel.cpp +++ b/OPHD/UI/PopulationPanel.cpp @@ -48,13 +48,13 @@ static const std::array moraleStringColor Color{0, 185, 0} }; +PopulationPanel::PopulationPanel() : PopulationPanel::PopulationPanel(Population(), PopulationPool()){}; -PopulationPanel::PopulationPanel() : +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)}, mIcons{imageCache.load("ui/icons.png")}, - mSkin - { + 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"), @@ -63,9 +63,10 @@ PopulationPanel::PopulationPanel() : 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") - } + imageCache.load("ui/skin/window_bottom_right.png")} { + mPopulation = &pop; + mPopulationPool = &popPool; 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. */); @@ -89,23 +90,12 @@ PopulationPanel::PopulationPanel() : size({windowWidth, windowHeight}); } -void PopulationPanel::population(Population* pop) -{ - mPopulation = pop; -} - -void PopulationPanel::populationPool(PopulationPool* popPool) -{ - mPopulationPool = popPool; -} - void PopulationPanel::addMoraleReason(const std::string& str, int val) { if (val == 0) { return; } 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 34acf0a8f..656e14e08 100644 --- a/OPHD/UI/PopulationPanel.h +++ b/OPHD/UI/PopulationPanel.h @@ -22,9 +22,7 @@ class PopulationPanel : public Control { public: PopulationPanel(); - - void population(Population* pop); - void populationPool(PopulationPool* popPool); + PopulationPanel(const Population& pop, const PopulationPool& popPool); void morale(int val) { mMorale = val; } void old_morale(int val) { mPreviousMorale = val; } @@ -50,12 +48,13 @@ class PopulationPanel : public Control std::vector> mMoraleChangeReasons; - Population* mPopulation = nullptr; - PopulationPool* mPopulationPool = nullptr; + const Population* mPopulation; + const PopulationPool* mPopulationPool; int mMorale{0}; int mPreviousMorale{0}; int mResidentialCapacity{0}; int mCrimeRate{0}; int mPopulationPanelWidth{0}; + }; diff --git a/libOPHD/Population/PopulationPool.cpp b/libOPHD/Population/PopulationPool.cpp index b51fe425a..cc91e0557 100644 --- a/libOPHD/Population/PopulationPool.cpp +++ b/libOPHD/Population/PopulationPool.cpp @@ -9,7 +9,7 @@ /** * Sets a pointer to a Population object. - * + * * \note PopulationPool expects a valid object and does no checking * for invalid states. */ @@ -19,13 +19,13 @@ void PopulationPool::population(Population* pop) } -int PopulationPool::availableWorkers() +int PopulationPool::availableWorkers() const { return mPopulation->getPopulations().worker - workersEmployed(); } -int PopulationPool::availableScientists() +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. */ -int PopulationPool::scientistsEmployed() +int PopulationPool::scientistsEmployed() const { return mScientistsUsed; } @@ -85,7 +85,7 @@ int PopulationPool::scientistsEmployed() /** * Amount of Workers currently employed. */ -int PopulationPool::workersEmployed() +int PopulationPool::workersEmployed() const { return mWorkersUsed; } @@ -94,7 +94,7 @@ int PopulationPool::workersEmployed() /** * 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 ed2ec80a0..33f7b09aa 100644 --- a/libOPHD/Population/PopulationPool.h +++ b/libOPHD/Population/PopulationPool.h @@ -15,17 +15,17 @@ class PopulationPool public: void population(Population* pop); - int availableWorkers(); - int availableScientists(); + int availableWorkers() const; + int availableScientists() const; bool usePopulation(PopulationRequirements populationRequirements); void clear(); - int scientistsAsWorkers(); - int scientistsEmployed(); - int workersEmployed(); - int populationEmployed(); + int scientistsAsWorkers() const; + int scientistsEmployed() const; + int workersEmployed() const; + int populationEmployed() const; int size() const;