diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/menu.cpp | 12 | ||||
-rw-r--r-- | src/menu.h | 37 | ||||
-rw-r--r-- | src/menu_system.cpp | 6 | ||||
-rw-r--r-- | src/menu_system.h | 7 | ||||
-rw-r--r-- | src/renderer.cpp | 26 |
6 files changed, 88 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c8a1753..7e5c0ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -47,6 +47,7 @@ add_executable(tanetane | |||
47 | src/map.cpp | 47 | src/map.cpp |
48 | src/font.cpp | 48 | src/font.cpp |
49 | src/interpolation.cpp | 49 | src/interpolation.cpp |
50 | src/menu.cpp | ||
50 | src/transform_system.cpp | 51 | src/transform_system.cpp |
51 | src/camera_system.cpp | 52 | src/camera_system.cpp |
52 | src/animation_system.cpp | 53 | src/animation_system.cpp |
diff --git a/src/menu.cpp b/src/menu.cpp new file mode 100644 index 0000000..4da4574 --- /dev/null +++ b/src/menu.cpp | |||
@@ -0,0 +1,12 @@ | |||
1 | #include "menu.h" | ||
2 | |||
3 | std::vector<MenuItem> CreateMenu(const std::vector<MenuBuilder>& builders) { | ||
4 | std::vector<MenuItem> result; | ||
5 | result.reserve(builders.size()); | ||
6 | |||
7 | for (const MenuBuilder& builder : builders) { | ||
8 | result.push_back(builder.Build()); | ||
9 | } | ||
10 | |||
11 | return result; | ||
12 | } | ||
diff --git a/src/menu.h b/src/menu.h new file mode 100644 index 0000000..1b91b88 --- /dev/null +++ b/src/menu.h | |||
@@ -0,0 +1,37 @@ | |||
1 | #ifndef MENU_H_3F6E62B3 | ||
2 | #define MENU_H_3F6E62B3 | ||
3 | |||
4 | #include <memory> | ||
5 | #include <string> | ||
6 | #include <vector> | ||
7 | |||
8 | enum class MenuType { | ||
9 | Command | ||
10 | }; | ||
11 | |||
12 | struct MenuItem { | ||
13 | MenuType type = MenuType::Command; | ||
14 | std::string text; | ||
15 | }; | ||
16 | |||
17 | class MenuBuilder { | ||
18 | public: | ||
19 | |||
20 | MenuBuilder& Command(std::string text) { | ||
21 | result_.type = MenuType::Command; | ||
22 | result_.text = std::move(text); | ||
23 | return *this; | ||
24 | } | ||
25 | |||
26 | MenuItem Build() const { | ||
27 | return result_; | ||
28 | } | ||
29 | |||
30 | private: | ||
31 | |||
32 | MenuItem result_; | ||
33 | }; | ||
34 | |||
35 | std::vector<MenuItem> CreateMenu(const std::vector<MenuBuilder>& builders); | ||
36 | |||
37 | #endif /* end of include guard: MENU_H_3F6E62B3 */ | ||
diff --git a/src/menu_system.cpp b/src/menu_system.cpp index 7c7d162..00c4849 100644 --- a/src/menu_system.cpp +++ b/src/menu_system.cpp | |||
@@ -20,6 +20,12 @@ void MenuSystem::openPauseMenu() { | |||
20 | openState_ = OpenState::Animating; | 20 | openState_ = OpenState::Animating; |
21 | 21 | ||
22 | game_.pauseGameplay(); | 22 | game_.pauseGameplay(); |
23 | |||
24 | menu_ = CreateMenu({ | ||
25 | MenuBuilder().Command("Settings"), | ||
26 | MenuBuilder().Command("Return to Main Menu"), | ||
27 | MenuBuilder().Command("Resume Game") | ||
28 | }); | ||
23 | } | 29 | } |
24 | 30 | ||
25 | void MenuSystem::closePauseMenu() { | 31 | void MenuSystem::closePauseMenu() { |
diff --git a/src/menu_system.h b/src/menu_system.h index ded57b5..56f84d5 100644 --- a/src/menu_system.h +++ b/src/menu_system.h | |||
@@ -1,8 +1,10 @@ | |||
1 | #ifndef MENU_SYSTEM_H_205861EC | 1 | #ifndef MENU_SYSTEM_H_205861EC |
2 | #define MENU_SYSTEM_H_205861EC | 2 | #define MENU_SYSTEM_H_205861EC |
3 | 3 | ||
4 | #include "system.h" | 4 | #include <vector> |
5 | #include "interpolation.h" | 5 | #include "interpolation.h" |
6 | #include "menu.h" | ||
7 | #include "system.h" | ||
6 | 8 | ||
7 | class Game; | 9 | class Game; |
8 | 10 | ||
@@ -27,6 +29,8 @@ public: | |||
27 | 29 | ||
28 | bool isMenuOpen() const { return openState_ == OpenState::Open; } | 30 | bool isMenuOpen() const { return openState_ == OpenState::Open; } |
29 | 31 | ||
32 | const std::vector<MenuItem>& getMenu() const { return menu_; } | ||
33 | |||
30 | private: | 34 | private: |
31 | 35 | ||
32 | enum class OpenState { | 36 | enum class OpenState { |
@@ -38,6 +42,7 @@ private: | |||
38 | Game& game_; | 42 | Game& game_; |
39 | Interpolation pauseAnimation_; | 43 | Interpolation pauseAnimation_; |
40 | OpenState openState_ = OpenState::Closed; | 44 | OpenState openState_ = OpenState::Closed; |
45 | std::vector<MenuItem> menu_; | ||
41 | }; | 46 | }; |
42 | 47 | ||
43 | #endif /* end of include guard: MENU_SYSTEM_H_205861EC */ | 48 | #endif /* end of include guard: MENU_SYSTEM_H_205861EC */ |
diff --git a/src/renderer.cpp b/src/renderer.cpp index 314dd4f..81e6b9c 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp | |||
@@ -500,6 +500,32 @@ void Renderer::render(Game& game) { | |||
500 | SDL_SetRenderDrawBlendMode(ren_.get(), SDL_BLENDMODE_NONE); | 500 | SDL_SetRenderDrawBlendMode(ren_.get(), SDL_BLENDMODE_NONE); |
501 | SDL_SetRenderDrawColor(ren_.get(), 0, 0, 0, 255); | 501 | SDL_SetRenderDrawColor(ren_.get(), 0, 0, 0, 255); |
502 | SDL_RenderFillRect(ren_.get(), nullptr); | 502 | SDL_RenderFillRect(ren_.get(), nullptr); |
503 | |||
504 | const int lineHeight = 16; | ||
505 | int totalHeight = menus.getMenu().size() * lineHeight; | ||
506 | |||
507 | int index = 0; | ||
508 | for (const MenuItem& menuItem : menus.getMenu()) { | ||
509 | switch (menuItem.type) { | ||
510 | case MenuType::Command: { | ||
511 | MessageCache output; | ||
512 | renderMessageLine(output, menuItem.text, game); | ||
513 | |||
514 | SDL_Rect dest { | ||
515 | (CANVAS_WIDTH - output.charIndexToWidth.back()) / 2, | ||
516 | (CANVAS_HEIGHT - totalHeight) / 2 + lineHeight * index, | ||
517 | MESSAGE_TEXT_WIDTH, | ||
518 | game.getFont().getCharacterHeight() | ||
519 | }; | ||
520 | |||
521 | SDL_SetRenderTarget(ren_.get(), cameraTex.get()); | ||
522 | SDL_RenderCopy(ren_.get(), output.renderedTex.get(), nullptr, &dest); | ||
523 | |||
524 | break; | ||
525 | } | ||
526 | } | ||
527 | index++; | ||
528 | } | ||
503 | } else if (menus.getPauseAnimationProgress() > 0.0) { | 529 | } else if (menus.getPauseAnimationProgress() > 0.0) { |
504 | SDL_SetRenderTarget(ren_.get(), cameraTex.get()); | 530 | SDL_SetRenderTarget(ren_.get(), cameraTex.get()); |
505 | SDL_SetRenderDrawBlendMode(ren_.get(), SDL_BLENDMODE_NONE); | 531 | SDL_SetRenderDrawBlendMode(ren_.get(), SDL_BLENDMODE_NONE); |