Skip to content
Snippets Groups Projects
Commit cfab59a6 authored by Lorenz Martin Diel's avatar Lorenz Martin Diel
Browse files

Info now only shows if it is chosen in the context menu

parent 24d94fbc
Branches
No related tags found
2 merge requests!36Unit info menu,!29Merge main into box2d to implement physics
......@@ -138,12 +138,15 @@ std::pair<int, int> Level::calcTilePos(int mouseX, int mouseY)
return {tileX, tileY};
}
void Level::selectEntity(int x, int y) {
void Level::selectEntity(int x, int y)
{
std::pair<int, int> tilePos = calcTilePos(x, y);
if ((m_selectedUnit = selectUnit(tilePos.first, tilePos.second)) >= 0) {
if ((m_selectedUnit = selectUnit(tilePos.first, tilePos.second)) >= 0)
{
auto it = m_units.find(m_selectedUnit);
if (it != m_units.end()) {
if (it != m_units.end())
{
Unit& unit = it->second;
m_unitInfoMenu.setUnit(unit);
// Position das Menu rechts neben der ausgewählten Einheit
......@@ -154,7 +157,8 @@ void Level::selectEntity(int x, int y) {
}
return;
}
if ((m_selectedBuilding = selectBuilding(tilePos.first, tilePos.second)) >= 0) {
if ((m_selectedBuilding = selectBuilding(tilePos.first, tilePos.second)) >= 0)
{
// Optionale Handhabung für Gebäude
return;
}
......@@ -356,13 +360,10 @@ void Level::render(Engine& engine)
m_recruitingMenu.render(engine);
}
if (m_showUnitInfoMenu)
{
m_unitInfoMenu.render(engine);
}
m_currentPos.render(engine);
}
......@@ -695,6 +696,7 @@ void Level::handleMenuActiveEvents(Engine& engine, SDL_Event& event)
m_state = LevelState::SELECTING_STATE;
m_showAttackableTiles = false;
m_showReachableTiles = false;
m_showUnitInfoMenu = false;
}
if (event.key.keysym.sym == SDLK_UP || event.key.keysym.sym == SDLK_DOWN)
{
......@@ -706,15 +708,18 @@ void Level::handleMenuActiveEvents(Engine& engine, SDL_Event& event)
if (cmd == "Wait")
{
m_state = LevelState::SELECTING_STATE;
m_showUnitInfoMenu = false;
}
if (cmd == "Move")
{
m_state = LevelState::MOVEMENT_STATE;
m_showUnitInfoMenu = false;
// Hier Pathfinding einsetzen
}
if (cmd == "Attack")
{
m_state = LevelState::ATTACKING_STATE;
m_showUnitInfoMenu = false;
}
if (cmd == "Info")
{
......@@ -723,6 +728,7 @@ void Level::handleMenuActiveEvents(Engine& engine, SDL_Event& event)
{
Unit& u = m_units.at(m_selectedUnit);
std::cout << "Health: " << u.m_health << std::endl;
m_showUnitInfoMenu = !m_showUnitInfoMenu;
}
if (m_selectedBuilding > -1)
{
......@@ -751,6 +757,7 @@ void Level::handleMenuActiveEvents(Engine& engine, SDL_Event& event)
m_showAttackableTiles = false;
m_showReachableTiles = false;
changeTurn();
m_showUnitInfoMenu = false;
}
}
......
......@@ -168,6 +168,8 @@ class Level : public Scene
void handlePositionMarker(Engine& engine, SDL_Event& event);
UnitInfoMenu m_unitInfoMenu;
bool m_showUnitInfoMenu = false;
};
} // namespace advanced_wars
......@@ -125,6 +125,7 @@ class Unit
int getAmmo() const { return m_ammo; }
int getHealth() const { return m_health; }
UnitId getId() const { return m_id;}
void setState(UnitState state);
......
......@@ -10,20 +10,20 @@ namespace advanced_wars
UnitInfoMenu::UnitInfoMenu() : m_currentUnit(nullptr) {
}
std::string UnitInfoMenu::getMovementTypeString(MovementType type)
{
switch (type)
{
std::string UnitInfoMenu::getMovementTypeString(MovementType type) {
switch (type) {
case MovementType::FOOT:
return "Foot";
case MovementType::WHEELED:
return "Wheeled";
case MovementType::TREAD:
return "Tracked";
case MovementType::SEA:
return "Ship";
case MovementType::AIR:
return "Aircraft";
case MovementType::SEA:
return "Ship";
case MovementType::LANDER:
return "Lander";
default:
return "Unknown";
}
......@@ -84,7 +84,7 @@ void UnitInfoMenu::render(Engine& engine)
Spritesheet* spritesheet = engine.getSpritesheet();
SDL_Texture* unit_texture = spritesheet->getUnitTextures()
.at(static_cast<int>(m_currentUnit->getFaction()))
.at(static_cast<int>(UnitId::INFANTERY))
.at(static_cast<int>(m_currentUnit->getId()))
.at(static_cast<int>(UnitState::IDLE))
.first;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment