summary refs log tree commit diff stats
path: root/src/renderer.cpp
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2021-03-13 12:24:05 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2021-03-13 15:34:50 -0500
commitfce37403bbc29521b2b5bd983291b3730f8ad7b4 (patch)
treec7bdf0fa62f6d67f85b97a7cda746da31470def2 /src/renderer.cpp
parentc6b5e936ff9869d8a3de9ea41db784a4cb46a818 (diff)
downloadtanetane-fce37403bbc29521b2b5bd983291b3730f8ad7b4.tar.gz
tanetane-fce37403bbc29521b2b5bd983291b3730f8ad7b4.tar.bz2
tanetane-fce37403bbc29521b2b5bd983291b3730f8ad7b4.zip
Added submenus
#7
Diffstat (limited to 'src/renderer.cpp')
-rw-r--r--src/renderer.cpp26
1 files changed, 19 insertions, 7 deletions
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 @@
3#include "consts.h" 3#include "consts.h"
4#include "game.h" 4#include "game.h"
5#include "map.h" 5#include "map.h"
6#include "menu.h"
6#include "transform_system.h" 7#include "transform_system.h"
7#include "camera_system.h" 8#include "camera_system.h"
8#include "message_system.h" 9#include "message_system.h"
@@ -142,11 +143,22 @@ void Renderer::render(Game& game) {
142 } 143 }
143 144
144 if (menus.getPauseAnimationProgress() > 0.0) { 145 if (menus.getPauseAnimationProgress() > 0.0) {
145 renderMenu(game); 146 renderMenu(game, menus.getMenu());
146 147
147 SDL_SetRenderTarget(ren_.get(), canvas.get()); 148 SDL_SetRenderTarget(ren_.get(), canvas.get());
148 if (menus.getPauseAnimationProgress() == 1.0) { 149 if (menus.getPauseAnimationProgress() == 1.0) {
149 SDL_RenderCopy(ren_.get(), menuTex_.get(), nullptr, nullptr); 150 if (menus.isMenuChanging()) {
151 SDL_Rect dest { static_cast<int>(CANVAS_WIDTH * (1.0 - menus.getMenuChangeAnimationProgress())), 0, CANVAS_WIDTH, CANVAS_HEIGHT };
152 SDL_RenderCopy(ren_.get(), menuTex_.get(), nullptr, &dest);
153
154 renderMenu(game, menus.getParentMenu());
155
156 dest.x -= CANVAS_WIDTH;
157 SDL_SetRenderTarget(ren_.get(), canvas.get());
158 SDL_RenderCopy(ren_.get(), menuTex_.get(), nullptr, &dest);
159 } else {
160 SDL_RenderCopy(ren_.get(), menuTex_.get(), nullptr, nullptr);
161 }
150 } else { 162 } else {
151 int barHeight = CANVAS_HEIGHT / 2 * menus.getPauseAnimationProgress(); 163 int barHeight = CANVAS_HEIGHT / 2 * menus.getPauseAnimationProgress();
152 SDL_Rect topHalf { 0, 0, CANVAS_WIDTH, barHeight }; 164 SDL_Rect topHalf { 0, 0, CANVAS_WIDTH, barHeight };
@@ -536,7 +548,7 @@ void Renderer::renderGame(Game& game) {
536 } 548 }
537} 549}
538 550
539void Renderer::renderMenu(Game& game) { 551void Renderer::renderMenu(Game& game, const Menu& menu) {
540 auto& menus = game.getSystem<MenuSystem>(); 552 auto& menus = game.getSystem<MenuSystem>();
541 553
542 if (!menuTex_) { 554 if (!menuTex_) {
@@ -558,11 +570,11 @@ void Renderer::renderMenu(Game& game) {
558 SDL_RenderFillRect(ren_.get(), nullptr); 570 SDL_RenderFillRect(ren_.get(), nullptr);
559 571
560 const int lineHeight = 16; 572 const int lineHeight = 16;
561 int totalHeight = menus.getMenu().size() * lineHeight; 573 int totalHeight = menu.getItems().size() * lineHeight;
562 std::vector<vec2i> positions; 574 std::vector<vec2i> positions;
563 575
564 int index = 0; 576 int index = 0;
565 for (const MenuItem& menuItem : menus.getMenu()) { 577 for (const MenuItem& menuItem : menu.getItems()) {
566 switch (menuItem.type) { 578 switch (menuItem.type) {
567 case MenuType::Command: { 579 case MenuType::Command: {
568 MessageCache output; 580 MessageCache output;
@@ -589,8 +601,8 @@ void Renderer::renderMenu(Game& game) {
589 601
590 int cursorTexId = loadImageFromFile("../res/feather_pen.png"); 602 int cursorTexId = loadImageFromFile("../res/feather_pen.png");
591 const SDL_Rect cursorDest { 603 const SDL_Rect cursorDest {
592 positions[menus.getCursorPosition()].x() - 2 - 16 - menus.getCursorBob(), 604 positions[menu.getCursorPosition()].x() - 2 - 16 - menus.getCursorBob(),
593 positions[menus.getCursorPosition()].y() - 8 - menus.getCursorBob(), 605 positions[menu.getCursorPosition()].y() - 8 - menus.getCursorBob(),
594 16, 606 16,
595 16 }; 607 16 };
596 SDL_RenderCopy(ren_.get(), textures_.at(cursorTexId).get(), nullptr, &cursorDest); 608 SDL_RenderCopy(ren_.get(), textures_.at(cursorTexId).get(), nullptr, &cursorDest);