Antkeeper  0.0.1
extras-menu-state.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
23 #include "game/controls.hpp"
24 #include <engine/scene/text.hpp>
25 #include <engine/debug/log.hpp>
26 #include "game/fonts.hpp"
27 #include "game/menu.hpp"
28 #include "game/strings.hpp"
30 
31 using namespace hash::literals;
32 
34  game_state(ctx)
35 {
36  debug::log_trace("Entering extras menu state...");
37 
38  // Construct menu item texts
39  credits_text = std::make_unique<scene::text>();
40  back_text = std::make_unique<scene::text>();
41 
42  // Build list of menu item texts
43  ctx.menu_item_texts.push_back({credits_text.get(), nullptr});
44  ctx.menu_item_texts.push_back({back_text.get(), nullptr});
45 
46  // Set content of menu item texts
47  credits_text->set_content(get_string(ctx, "extras_menu_credits"));
48  back_text->set_content(get_string(ctx, "back"));
49 
50  // Init menu item index
52 
58 
59  // Construct menu item callbacks
60  auto select_credits_callback = [&ctx]()
61  {
62  // Disable menu controls
63  ctx.function_queue.push(std::bind(::disable_menu_controls, std::ref(ctx)));
64 
66  (
67  ctx,
68  [&ctx]()
69  {
70  // Queue change to credits state
71  ctx.function_queue.push
72  (
73  [&ctx]()
74  {
75  ctx.state_machine.pop();
76  ctx.state_machine.emplace(std::make_unique<credits_state>(ctx));
77  }
78  );
79  }
80  );
81  };
82  auto select_back_callback = [&ctx]()
83  {
84  // Disable menu controls
85  ctx.function_queue.push(std::bind(::disable_menu_controls, std::ref(ctx)));
86 
88  (
89  ctx,
90  [&ctx]()
91  {
92  // Queue change to main menu state
93  ctx.function_queue.push
94  (
95  [&ctx]()
96  {
97  ctx.state_machine.pop();
98  ctx.state_machine.emplace(std::make_unique<main_menu_state>(ctx, false));
99  }
100  );
101  }
102  );
103  };
104 
105  // Build list of menu select callbacks
106  ctx.menu_select_callbacks.push_back(select_credits_callback);
107  ctx.menu_select_callbacks.push_back(select_back_callback);
108 
109  // Build list of menu left callbacks
110  ctx.menu_left_callbacks.push_back(nullptr);
111  ctx.menu_left_callbacks.push_back(nullptr);
112 
113  // Build list of menu right callbacks
114  ctx.menu_right_callbacks.push_back(nullptr);
115  ctx.menu_right_callbacks.push_back(nullptr);
116 
117  // Set menu back callback
118  ctx.menu_back_callback = select_back_callback;
119 
120  // Fade in menu
121  ::menu::fade_in(ctx, nullptr);
122 
123  // Queue enable menu controls
124  ctx.function_queue.push(std::bind(::enable_menu_controls, std::ref(ctx)));
125 
126  debug::log_trace("Entered extras menu state");
127 }
128 
130 {
131  debug::log_trace("Exiting extras menu state...");
132 
133  // Destruct menu
139 
140  debug::log_trace("Exited extras menu state");
141 }
142 
extras_menu_state(::game &ctx)
Abstract base class for game states.
Definition: game-state.hpp:29
::game & ctx
Definition: game-state.hpp:44
Definition: game.hpp:121
std::vector< std::function< void()> > menu_left_callbacks
Definition: game.hpp:348
std::vector< std::function< void()> > menu_right_callbacks
Definition: game.hpp:349
hsm::state_machine< game_state > state_machine
Definition: game.hpp:299
std::vector< std::function< void()> > menu_select_callbacks
Definition: game.hpp:347
std::vector< std::tuple< scene::text *, scene::text * > > menu_item_texts
Definition: game.hpp:351
std::queue< std::function< void()> > function_queue
Definition: game.hpp:303
std::function< void()> menu_back_callback
Definition: game.hpp:350
void enable_menu_controls(::game &ctx)
void disable_menu_controls(::game &ctx)
log_message< log_message_severity::trace, Args... > log_trace
Formats and logs a trace message.
Definition: log.hpp:88
User-defined literals for compile-time string hashing.
Definition: fnv1a.hpp:232
void init_menu_item_index(::game &ctx, hash::fnv1a32_t menu_name)
Definition: menu.cpp:31
void update_text_color(::game &ctx)
Definition: menu.cpp:59
void clear_callbacks(::game &ctx)
Definition: menu.cpp:197
void delete_animations(::game &ctx)
Definition: menu.cpp:191
void align_text(::game &ctx, bool center, bool has_back, float anchor_y)
Definition: menu.cpp:73
void setup_animations(::game &ctx)
Definition: menu.cpp:206
void add_text_to_ui(::game &ctx)
Definition: menu.cpp:166
void fade_out(::game &ctx, const std::function< void()> &end_callback)
Definition: menu.cpp:263
void update_text_font(::game &ctx)
Definition: menu.cpp:44
void fade_in(::game &ctx, const std::function< void()> &end_callback)
Definition: menu.cpp:233
void remove_text_from_ui(::game &ctx)
Definition: menu.cpp:176
void delete_text(::game &ctx)
Definition: menu.cpp:186
std::string get_string(const ::game &ctx, hash::fnv1a32_t key)
Returns a localized string.
Definition: strings.cpp:23