Skip to content
Snippets Groups Projects
Commit 8f3e3495 authored by David Maul's avatar David Maul :crab:
Browse files

cleanup clang-tidy warnings

parent 3288c79f
No related branches found
No related tags found
1 merge request!48cleanup clang-tidy warnings
...@@ -26,10 +26,9 @@ class HelpMenu : public Scene ...@@ -26,10 +26,9 @@ class HelpMenu : public Scene
void renderTextPortion( void renderTextPortion(
Engine& engine, std::string text, TTF_Font* font, SDL_Color color, int boxWidth, Engine& engine, std::string text, TTF_Font* font, SDL_Color color, int boxWidth,
int text_x, int text_y); int textX, int textY);
void void renderTexture(SDL_Texture* texture, Engine& engine, int x, int y, int srcX, int srcY);
renderTexture(SDL_Texture* texture, Engine& engine, int x, int y, int src_x, int src_y);
}; };
} // namespace advanced_wars } // namespace advanced_wars
...@@ -60,12 +60,7 @@ std::unordered_map<UnitTypeId, std::string> unitDescriptions = { ...@@ -60,12 +60,7 @@ std::unordered_map<UnitTypeId, std::string> unitDescriptions = {
{ UnitTypeId::SUBMARINE, "U-Boot Versteckt sich und kann Ueberwasserziele angreifen"} { UnitTypeId::SUBMARINE, "U-Boot Versteckt sich und kann Ueberwasserziele angreifen"}
}; };
void UnitInfoMenu::handleEvent(Engine& engine, SDL_Event& event) void UnitInfoMenu::handleEvent(Engine& /*engine*/, SDL_Event& /*event*/) {}
{
// Hier kannst du den Code hinzufügen, um die Ereignisse für das UnitInfoMenu zu behandeln
// Wenn keine spezifische Ereignisbehandlung erforderlich ist, kann diese Methode auch leer
// bleiben.
}
void UnitInfoMenu::setUnit(Unit& unit) void UnitInfoMenu::setUnit(Unit& unit)
{ {
...@@ -75,8 +70,10 @@ void UnitInfoMenu::setUnit(Unit& unit) ...@@ -75,8 +70,10 @@ void UnitInfoMenu::setUnit(Unit& unit)
void UnitInfoMenu::render(Engine& engine) void UnitInfoMenu::render(Engine& engine)
{ {
if (!m_currentUnit || !m_isVisible) if ((m_currentUnit == nullptr) || !m_isVisible)
{
return; return;
}
// TTF Initialisierung // TTF Initialisierung
if (TTF_Init() == -1) if (TTF_Init() == -1)
...@@ -89,7 +86,7 @@ void UnitInfoMenu::render(Engine& engine) ...@@ -89,7 +86,7 @@ void UnitInfoMenu::render(Engine& engine)
std::string fullPath = basePath + "res/ARCADECLASSIC.TTF"; std::string fullPath = basePath + "res/ARCADECLASSIC.TTF";
TTF_Font* font = TTF_OpenFont(fullPath.c_str(), 16); TTF_Font* font = TTF_OpenFont(fullPath.c_str(), 16);
if (!font) if (font == nullptr)
{ {
std::cerr << "Failed to load font: " << TTF_GetError() << "\n"; std::cerr << "Failed to load font: " << TTF_GetError() << "\n";
return; return;
...@@ -100,7 +97,7 @@ void UnitInfoMenu::render(Engine& engine) ...@@ -100,7 +97,7 @@ void UnitInfoMenu::render(Engine& engine)
UnitTypeId unitId = m_currentUnit->getUnitTypeId(); UnitTypeId unitId = m_currentUnit->getUnitTypeId();
// Textzeilen, einschließlich der Beschreibung // Textzeilen, einschließlich der Beschreibung
std::vector<std::string> info_lines = { std::vector<std::string> infoLines = {
"HP " + std::to_string(m_currentUnit->getHealth()), "HP " + std::to_string(m_currentUnit->getHealth()),
"Movement " + std::to_string(m_currentUnit->getMovementPoints()), "Movement " + std::to_string(m_currentUnit->getMovementPoints()),
"Ammo " + std::to_string(m_currentUnit->getAmmo()), "Ammo " + std::to_string(m_currentUnit->getAmmo()),
...@@ -109,26 +106,28 @@ void UnitInfoMenu::render(Engine& engine) ...@@ -109,26 +106,28 @@ void UnitInfoMenu::render(Engine& engine)
unitDescriptions[unitId] // Beschreibung einfügen unitDescriptions[unitId] // Beschreibung einfügen
}; };
int max_text_width = 0; int maxTextWidth = 0;
int total_height = 0; int totalHeight = 0;
std::vector<SDL_Texture*> textures; std::vector<SDL_Texture*> textures;
for (const auto& line : info_lines) for (const auto& line : infoLines)
{ {
SDL_Surface* textSurface = TTF_RenderText_Solid(font, line.c_str(), yellow); SDL_Surface* textSurface = TTF_RenderText_Solid(font, line.c_str(), yellow);
if (!textSurface) if (textSurface == nullptr)
{
continue; continue;
}
max_text_width = std::max(max_text_width, textSurface->w); maxTextWidth = std::max(maxTextWidth, textSurface->w);
total_height += textSurface->h + spacing; totalHeight += textSurface->h + spacing;
SDL_Texture* textTexture = SDL_CreateTextureFromSurface(engine.renderer(), textSurface); SDL_Texture* textTexture = SDL_CreateTextureFromSurface(engine.renderer(), textSurface);
textures.push_back(textTexture); textures.push_back(textTexture);
SDL_FreeSurface(textSurface); SDL_FreeSurface(textSurface);
} }
int width = std::max(max_text_width + 20 * RENDERING_SCALE, 16 * RENDERING_SCALE + 20); int width = std::max(maxTextWidth + (20 * RENDERING_SCALE), (16 * RENDERING_SCALE) + 20);
int height = int height = totalHeight +
total_height + 30 * RENDERING_SCALE; // Die Höhe anpassen, um alle Textzeilen zu integrieren (30 * RENDERING_SCALE); // Die Höhe anpassen, um alle Textzeilen zu integrieren
SDL_Rect box = {m_x, m_y, width, height}; SDL_Rect box = {m_x, m_y, width, height};
SDL_SetRenderDrawColor(engine.renderer(), 75, 87, 219, 255); // Schwarzes Hintergrundrechteck SDL_SetRenderDrawColor(engine.renderer(), 75, 87, 219, 255); // Schwarzes Hintergrundrechteck
...@@ -139,26 +138,27 @@ void UnitInfoMenu::render(Engine& engine) ...@@ -139,26 +138,27 @@ void UnitInfoMenu::render(Engine& engine)
// Render unit sprite // Render unit sprite
Spritesheet* spritesheet = engine.getSpritesheet(); Spritesheet* spritesheet = engine.getSpritesheet();
SDL_Texture* unit_texture = spritesheet->getUnitTextures() SDL_Texture* unitTexture = spritesheet->getUnitTextures()
.at(static_cast<int>(m_currentUnit->getFaction())) .at(static_cast<int>(m_currentUnit->getFaction()))
.at(static_cast<int>(unitId)) .at(static_cast<int>(unitId))
.at(static_cast<int>(UnitState::IDLE)) .at(static_cast<int>(UnitState::IDLE))
.first; .first;
SDL_Rect sprite_rect = {m_x + 10, m_y + 10, 16 * RENDERING_SCALE, 16 * RENDERING_SCALE}; SDL_Rect spriteRect = {m_x + 10, m_y + 10, 16 * RENDERING_SCALE, 16 * RENDERING_SCALE};
SDL_Rect source_rect = {0, 0, 16, 16}; SDL_Rect sourceRect = {0, 0, 16, 16};
SDL_RenderCopy(engine.renderer(), unit_texture, &source_rect, &sprite_rect); SDL_RenderCopy(engine.renderer(), unitTexture, &sourceRect, &spriteRect);
// Text zeichnen // Text zeichnen
int text_y = m_y + 20 * RENDERING_SCALE; // Starte etwas unterhalb des Sprites int textY = m_y + (20 * RENDERING_SCALE); // Starte etwas unterhalb des Sprites
for (auto* texture : textures) for (auto* texture : textures)
{ {
int w, h; int w;
int h;
SDL_QueryTexture(texture, nullptr, nullptr, &w, &h); SDL_QueryTexture(texture, nullptr, nullptr, &w, &h);
SDL_Rect textRect = {m_x + 10, text_y, w, h}; SDL_Rect textRect = {m_x + 10, textY, w, h};
SDL_RenderCopy(engine.renderer(), texture, nullptr, &textRect); SDL_RenderCopy(engine.renderer(), texture, nullptr, &textRect);
SDL_DestroyTexture(texture); SDL_DestroyTexture(texture);
text_y += (h + spacing); textY += (h + spacing);
} }
TTF_CloseFont(font); TTF_CloseFont(font);
......
...@@ -16,11 +16,11 @@ class UnitInfoMenu : public Scene ...@@ -16,11 +16,11 @@ class UnitInfoMenu : public Scene
void handleEvent(Engine& engine, SDL_Event& event) override; void handleEvent(Engine& engine, SDL_Event& event) override;
void setUnit(Unit& unit); void setUnit(Unit& unit);
void render(Engine& engine); void render(Engine& engine) override;
void update(int x, int y); void update(int x, int y);
private: private:
int RENDERING_SCALE = 3; const int RENDERING_SCALE = 3;
int m_x; int m_x;
int m_y; int m_y;
Unit* m_currentUnit; Unit* m_currentUnit;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment