Skip to content
Snippets Groups Projects
Commit d1d187b3 authored by Frederik Alexander Keens's avatar Frederik Alexander Keens
Browse files

Merge branch 'helpMenu' into 'main'

Help menu

See merge request !32
parents 58267556 71b25f18
Branches
No related tags found
2 merge requests!32Help menu,!29Merge main into box2d to implement physics
......@@ -106,7 +106,7 @@ void Engine::render()
std::shared_ptr<Scene> currentScene = m_scenes.back();
currentScene->render(*this);
SDL_SetRenderDrawColor(this->m_SDLRenderer, 0, 0, 0, 255);
SDL_RenderPresent(this->m_SDLRenderer);
}
......
......@@ -8,6 +8,7 @@
#include "highfive/H5File.hpp"
#include "ui/Contextmenu.hpp"
#include "ui/Pausemenu.hpp"
#include "ui/Helpmenu.hpp"
#include <SDL.h>
#include <algorithm>
#include <boost/property_tree/ptree.hpp>
......@@ -178,6 +179,11 @@ int Level::selectBuilding(int tileX, int tileY)
void Level::handleEvent(Engine& engine, SDL_Event& event)
{
if (event.type == SDL_KEYDOWN) {
if (event.key.keysym.sym == SDLK_h) {
toggle_Helpmenu = !toggle_Helpmenu;
}
}
switch (m_state)
{
case LevelState::MENUACTIVE_STATE:
......@@ -348,6 +354,11 @@ void Level::render(Engine& engine)
m_recruitingMenu.render(engine);
}
m_currentPos.render(engine);
if(toggle_Helpmenu) {
m_helpMenu.render(engine);
}
}
int Level::addBuilding(Building building)
......
......@@ -10,6 +10,7 @@
#include "ui/Contextmenu.hpp"
#include "ui/Recruitingmenu.hpp"
#include "ui/TileMarker.hpp"
#include "ui/Helpmenu.hpp"
#include <SDL.h>
#include <array>
#include <queue>
......@@ -135,6 +136,8 @@ class Level : public Scene
int m_selectedBuilding;
ContextMenu m_contextMenu;
RecruitingMenu m_recruitingMenu;
bool toggle_Helpmenu = false;
HelpMenu m_helpMenu;
int m_id;
LevelState m_state;
......
#include "Helpmenu.hpp"
#include <SDL_ttf.h>
#include <iostream>
namespace advanced_wars
{
HelpMenu::HelpMenu() {}
void HelpMenu::handleEvent(Engine& engine, SDL_Event& event) {}
std::vector<std::string> helpTable = {
"Willkommen im Tutorial!", // 0
"Nutzen Sie die PFEILTASTEN zur Navigation in allen Menus! ", // 1
"Wenn Sie an der Reihe sind nutzen Sie die PFEILTASTEN um den " // 2
"Selectioncursor !das kleine farbige Quadrat! auf dem Spielfeld zu verschieben! Nutzen Sie " // 3
"RETURN um eine Einheit zu selektieren! Nutzen Sie die PFEILTASTEN um eine Option " // 4
"auszuwaehlen und RETURN um ihre Auswahl zu bestaetigen! ", // 5
"Spielregeln! ", // 6
"Einheiten daerfen sich in einer Runde nur ein Mal bewegen und ein Mal angreifen! ", // 7
"Gegnerische Einheiten muessen sich in REICHWEITE befinden! ", // 8
"Einheiten kosten Geld! ", // 9
"Am Start ihres Zuges erhalten Sie pro Stadt 1000 Geld! ", // 10
"Angreifer schiessen immer zuerst! ", // 11
"Achten Sie auf die Einheitenklassen um Schadensboni auszunutzen! ", // 12
"Nutzen Sie diese Werkzeuge um das Spiel gegen ihren Gegner zu gewinnen! "}; // 13
void HelpMenu::render(advanced_wars::Engine& engine)
{
if (TTF_Init() == -1)
{
std::cerr << "Failed to initialize TTF: " << TTF_GetError() << std::endl;
return;
}
std::string basePath = SDL_GetBasePath();
std::string relativePath = "res/ARCADECLASSIC.TTF";
std::string fullPath = basePath + relativePath;
TTF_Font* font = TTF_OpenFont(fullPath.c_str(), 16);
if (!font)
{
std::cerr << "Failed to load font: " << TTF_GetError() << std::endl;
return;
}
SDL_Color white = {200, 200, 0, 255};
int spacing = 25;
int boxWidth = 600;
int boxHeight = static_cast<int>(610);
SDL_SetRenderDrawColor(engine.renderer(), 75, 87, 219, 255);
SDL_Rect box = {50, 50, boxWidth, boxHeight};
SDL_RenderFillRect(engine.renderer(), &box);
int text_x = 60;
int text_y = 60;
renderTextPortion(engine, helpTable[0], font, white, boxWidth, text_x, text_y);
text_y += spacing;
std::string text = helpTable[1] + helpTable[2] + helpTable[3] + helpTable[4] + helpTable[5];
renderTextPortion(engine, text, font, white, boxWidth, text_x, text_y);
text_y += 150;
text = helpTable[6] + helpTable[7] + helpTable[8] + helpTable[9] + helpTable[10];
renderTextPortion(engine, text, font, white, boxWidth, text_x, text_y);
text_y += 125;
SDL_Rect divider = {60, text_y - 25, boxWidth - 20, 2};
SDL_SetRenderDrawColor(engine.renderer(), 239, 235, 216, 255);
SDL_RenderFillRect(engine.renderer(), &divider);
Spritesheet* spritesheet = engine.getSpritesheet();
SDL_Texture* buildingTexture = spritesheet->getBuildingTextures().at(0);
int renderingScale = 2;
SDL_Rect trgt_rect = {65, text_y, 16 * renderingScale, 16 * renderingScale * 2};
SDL_Rect src_rect = {0, 0, 16, 32};
SDL_RenderCopy(engine.renderer(), buildingTexture, &src_rect, &trgt_rect);
renderTextPortion(
engine, "Das ist das Hauptquartier! Wenn es faellt, haben Sie das Spiel verloren!", font,
white, boxWidth - 120 - 5, 120, text_y);
text_y += 48;
renderTexture(buildingTexture, engine, 55, text_y + 48, 16, 16);
renderTexture(buildingTexture, engine, 55, text_y + 96, 32, 16);
renderTexture(buildingTexture, engine, 55, text_y + 144, 48, 16);
renderTexture(buildingTexture, engine, 55, text_y + 192, 64, 16);
renderTextPortion(
engine,
"Nehmen Sie Staedte auf der Karte ein um jede Runde Geld fuer das Rekrutieren der Einheiten "
"zu bekommen!",
font, white, boxWidth - 120 - 5, 120, text_y + 48);
renderTextPortion(
engine, "Aus der Kaserne koennen Sie Landeinheiten anfordern!", font, white,
boxWidth - 120 - 5, 120, text_y + 96);
renderTextPortion(
engine,
"Mit einem Flughafen koennen Sie die Lufthoheit erkaempfen! Achten Sie auf Flugabwehr!", font,
white, boxWidth - 120 - 5, 120, text_y + 144);
renderTextPortion(
engine,
"Der Hafen stellt ihnen verschiedene Marineeinheiten zur Verfuegung! Um den Sieg zu "
"erringen sollten Sie Ihre Flotte nicht vernachlaessigen!",
font, white, boxWidth - 120 - 5, 120, text_y + 192);
TTF_CloseFont(font);
TTF_Quit();
}
void HelpMenu::renderTextPortion(
Engine& engine, std::string text, TTF_Font* font, SDL_Color color, int boxWidth, int text_x,
int text_y)
{
SDL_Surface* textSurface =
TTF_RenderUTF8_Solid_Wrapped(font, text.c_str(), color, boxWidth - 5);
if (!textSurface)
return;
SDL_Texture* textTexture = SDL_CreateTextureFromSurface(engine.renderer(), textSurface);
SDL_Rect textRect = {text_x, text_y, textSurface->w, textSurface->h};
SDL_RenderCopy(engine.renderer(), textTexture, nullptr, &textRect);
SDL_DestroyTexture(textTexture);
SDL_FreeSurface(textSurface);
}
void HelpMenu::renderTexture(
SDL_Texture* texture, Engine& engine, int x, int y, int src_x, int src_y)
{
SDL_Texture* buildingTexture = texture;
int renderingScale = 2;
SDL_Rect trgt_rect = {65, y, 16 * renderingScale, 16 * renderingScale};
SDL_Rect src_rect = {src_x, src_y, 16, 16};
SDL_RenderCopy(engine.renderer(), buildingTexture, &src_rect, &trgt_rect);
}
} // namespace advanced_wars
\ No newline at end of file
#pragma once
#include "../Scene.hpp"
#include <SDL_ttf.h>
namespace advanced_wars
{
class HelpMenu : public Scene
{
private:
size_t m_selectedOption;
std::vector<std::pair<std::string, int>> m_options;
int m_x;
int m_y;
void renderTextPortion(
Engine& engine, std::string text, TTF_Font* font, SDL_Color color, int boxWidth,
int text_x, int text_y);
void
renderTexture(SDL_Texture* texture, Engine& engine, int x, int y, int src_x, int src_y);
public:
void handleEvent(Engine& engine, SDL_Event& event);
void update(int x, int y);
HelpMenu();
void render(Engine& engine) override;
};
} // namespace advanced_wars
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment