Skip to content

Commit

Permalink
Updated MapViewState to use the new constructor and removed Populatio…
Browse files Browse the repository at this point in the history
…n initialization from MapViewStateUI
  • Loading branch information
oscar139 committed Feb 19, 2024
1 parent be83ef8 commit 53b9b64
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 42 deletions.
1 change: 1 addition & 0 deletions OPHD/States/MapViewState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MiniMap>(*mMapView, mTileMap, mRobotList, planetAttributes.mapImagePath)},
Expand Down
2 changes: 0 additions & 2 deletions OPHD/States/MapViewStateUi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 3 additions & 27 deletions OPHD/UI/PopulationPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand All @@ -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. */);

Expand Down Expand Up @@ -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<Renderer>::get();
Expand Down
1 change: 0 additions & 1 deletion OPHD/UI/PopulationPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,4 @@ class PopulationPanel : public Control
int mCrimeRate{0};
int mPopulationPanelWidth{0};

void init();
};
12 changes: 6 additions & 6 deletions libOPHD/Population/PopulationPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -67,7 +67,7 @@ void PopulationPool::clear()
/**
* Amount of Scientists employed as Workers.
*/
int PopulationPool::scientistsAsWorkers()
int PopulationPool::scientistsAsWorkers() const
{
return mScientistsAsWorkers;
}
Expand All @@ -76,7 +76,7 @@ int PopulationPool::scientistsAsWorkers()
/**
* Amount of Scientists currently employed.
*/
const int PopulationPool::scientistsEmployed() const
int PopulationPool::scientistsEmployed() const
{
return mScientistsUsed;
}
Expand All @@ -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;
}
Expand All @@ -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();
}
Expand Down
12 changes: 6 additions & 6 deletions libOPHD/Population/PopulationPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 53b9b64

Please sign in to comment.