Skip to content
Snippets Groups Projects
Commit 987d6913 authored by Max Cherris's avatar Max Cherris
Browse files

Got the actual recruiting to work :)

parent fa847edb
No related branches found
No related tags found
1 merge request!24Ui interaction/building
......@@ -277,17 +277,22 @@ Effect Level::removeEffect(int id)
void Level::handleRecruitingEvent(Engine& engine, SDL_Event& event) {
switch (event.type)
{
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_ESCAPE)
{
m_state = LevelState::MENUACTIVE_STATE;
}
if (event.key.keysym.sym == SDLK_UP || event.key.keysym.sym == SDLK_DOWN)
{
m_recruitingMenu.handleEvent(engine, event);
}
if (event.key.keysym.sym == SDLK_RETURN)
{
Building& b = m_buildings.at(m_selectedBuilding);
UnitFaction u_faction = static_cast<UnitFaction> (b.m_faction);
std::vector<UnitId> recruitableUnits = b.recruitableUnits();
//m_recruitingmenu.setoptions(recruitableUnits)
//show appropriate interface -> provide vector of UnitId
//show Interface here
//select UnitId
UnitId unit_id = UnitId::INFANTERY;
UnitId unit_id = m_recruitingMenu.getSelectedOption();
if(b.check_money(500)) {
if(b.check_spawn(m_units)){
......@@ -297,6 +302,7 @@ void Level::handleRecruitingEvent(Engine& engine, SDL_Event& event) {
}
}
}
}}
//*******************helper functions for event Handling*************************************
......
......@@ -84,6 +84,9 @@ namespace advanced_wars
for (auto& [render_name, cost] : m_options)
{
//std::pair<std::string, int> unit_option = unitNames.at(cost2UnitId.at(cost));
if(i == m_selectedOption) {
m_selectedId = cost2UnitId.at(cost);
}
SDL_Surface* textSurface = TTF_RenderText_Solid(
font, render_name.c_str(), (i == m_selectedOption) ? yellow : white);
......@@ -169,4 +172,8 @@ void RecruitingMenu::update(int x, int y)
this->m_y = y;
}
UnitId RecruitingMenu::getSelectedOption(){
return m_selectedId;
}
}//namespace advance_wars
\ No newline at end of file
......@@ -16,17 +16,16 @@ namespace advanced_wars
int m_y;
const std::unordered_map <UnitId ,std::pair <std::string, int>> unitNames;
std::unordered_map<int, UnitId> cost2UnitId;
void handleEvent(Engine& engine, SDL_Event& event);
UnitId m_selectedId;
void selectSprite();
std::string getSelectedOption();
public:
UnitId getSelectedOption();
void handleEvent(Engine& engine, SDL_Event& event);
void update(int x, int y);
RecruitingMenu();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment