From fce37403bbc29521b2b5bd983291b3730f8ad7b4 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 13 Mar 2021 12:24:05 -0500 Subject: Added submenus #7 --- src/renderer.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/renderer.cpp') diff --git a/src/renderer.cpp b/src/renderer.cpp index fc16e20..f7644ca 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -3,6 +3,7 @@ #include "consts.h" #include "game.h" #include "map.h" +#include "menu.h" #include "transform_system.h" #include "camera_system.h" #include "message_system.h" @@ -142,11 +143,22 @@ void Renderer::render(Game& game) { } if (menus.getPauseAnimationProgress() > 0.0) { - renderMenu(game); + renderMenu(game, menus.getMenu()); SDL_SetRenderTarget(ren_.get(), canvas.get()); if (menus.getPauseAnimationProgress() == 1.0) { - SDL_RenderCopy(ren_.get(), menuTex_.get(), nullptr, nullptr); + if (menus.isMenuChanging()) { + SDL_Rect dest { static_cast(CANVAS_WIDTH * (1.0 - menus.getMenuChangeAnimationProgress())), 0, CANVAS_WIDTH, CANVAS_HEIGHT }; + SDL_RenderCopy(ren_.get(), menuTex_.get(), nullptr, &dest); + + renderMenu(game, menus.getParentMenu()); + + dest.x -= CANVAS_WIDTH; + SDL_SetRenderTarget(ren_.get(), canvas.get()); + SDL_RenderCopy(ren_.get(), menuTex_.get(), nullptr, &dest); + } else { + SDL_RenderCopy(ren_.get(), menuTex_.get(), nullptr, nullptr); + } } else { int barHeight = CANVAS_HEIGHT / 2 * menus.getPauseAnimationProgress(); SDL_Rect topHalf { 0, 0, CANVAS_WIDTH, barHeight }; @@ -536,7 +548,7 @@ void Renderer::renderGame(Game& game) { } } -void Renderer::renderMenu(Game& game) { +void Renderer::renderMenu(Game& game, const Menu& menu) { auto& menus = game.getSystem(); if (!menuTex_) { @@ -558,11 +570,11 @@ void Renderer::renderMenu(Game& game) { SDL_RenderFillRect(ren_.get(), nullptr); const int lineHeight = 16; - int totalHeight = menus.getMenu().size() * lineHeight; + int totalHeight = menu.getItems().size() * lineHeight; std::vector positions; int index = 0; - for (const MenuItem& menuItem : menus.getMenu()) { + for (const MenuItem& menuItem : menu.getItems()) { switch (menuItem.type) { case MenuType::Command: { MessageCache output; @@ -589,8 +601,8 @@ void Renderer::renderMenu(Game& game) { int cursorTexId = loadImageFromFile("../res/feather_pen.png"); const SDL_Rect cursorDest { - positions[menus.getCursorPosition()].x() - 2 - 16 - menus.getCursorBob(), - positions[menus.getCursorPosition()].y() - 8 - menus.getCursorBob(), + positions[menu.getCursorPosition()].x() - 2 - 16 - menus.getCursorBob(), + positions[menu.getCursorPosition()].y() - 8 - menus.getCursorBob(), 16, 16 }; SDL_RenderCopy(ren_.get(), textures_.at(cursorTexId).get(), nullptr, &cursorDest); -- cgit 1.4.1