Skip to content
Snippets Groups Projects
Commit 3f727f13 authored by fdai7466's avatar fdai7466
Browse files

change sizing of context menu. add backround

parent 7a1ee6d1
Branches
No related tags found
1 merge request!14Refactoring CMakeLists.txt
#include "engine.hpp"
#include "spritesheet.hpp"
#include "ui/Menu.hpp"
#include "ui/ContextMenu.hpp"
#include "window.hpp"
#include <memory>
......@@ -15,13 +16,16 @@ int main() {
// render main menu
std::shared_ptr<Menu> menu = std::make_shared<Menu>(0);
std::shared_ptr<ContextMenu> context_menu = std::make_shared<ContextMenu>();
context_menu->setOptions({"Move", "Info", "Wait"});
std::string basePath = SDL_GetBasePath();
std::string relativePath = "assets/main_background.png";
std::string fullPath = basePath + relativePath;
menu->loadBackground(engine.renderer(), fullPath.c_str());
engine.push_scene(menu);
engine.push_scene(context_menu);
/* Level level("Osnabrück", 20, 20, std::vector<Tile>(),
std::vector<Building>(), std::vector<Unit>());
......
......@@ -15,6 +15,7 @@ namespace advanced_wars {
}
void ContextMenu::render(Engine* engine) {
if (!options.empty()) {
if (TTF_Init() == -1) {
std::cerr << "Failed to initialize TTF: " << TTF_GetError() << std::endl;
......@@ -24,7 +25,7 @@ namespace advanced_wars {
std::string basePath = SDL_GetBasePath();
std::string relativePath = "assets/ARCADECLASSIC.TTF";
std::string fullPath = basePath + relativePath;
TTF_Font *font = TTF_OpenFont(fullPath.c_str(), 48);
TTF_Font *font = TTF_OpenFont(fullPath.c_str(), 16);
if (!font) {
std::cerr << "Failed to load font: " << TTF_GetError() << std::endl;
return;
......@@ -34,7 +35,14 @@ namespace advanced_wars {
SDL_Color yellow = {255, 255, 0, 255};
int startY = 100; // Startposition für das Menü
int spacing = 40; // Abstand zwischen den Optionen
int spacing = 20; // Abstand zwischen den Optionen
//box around options
SDL_SetRenderDrawColor(engine->renderer(), 0, 0, 255, 128);
SDL_Rect box = {190, startY - 3, 50, static_cast<int>(options.size() * spacing)};
SDL_RenderFillRect(engine->renderer(), &box);
SDL_SetRenderDrawColor(engine->renderer(), 0, 0, 0, 255);
for (size_t i = 0; i < options.size(); ++i) {
SDL_Surface* textSurface = TTF_RenderText_Solid(font, options[i].c_str(), (i == selectedOption) ? yellow : white);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment