💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
3.8 KiB

  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. #include "game/state/extras-menu.hpp"
  20. #include "game/state/main-menu.hpp"
  21. #include "game/state/credits.hpp"
  22. #include "application.hpp"
  23. #include "scene/text.hpp"
  24. #include "debug/log.hpp"
  25. #include "game/fonts.hpp"
  26. #include "game/menu.hpp"
  27. #include "game/strings.hpp"
  28. #include "utility/hash/fnv1a.hpp"
  29. using namespace hash::literals;
  30. namespace game {
  31. namespace state {
  32. extras_menu::extras_menu(game::context& ctx):
  33. game::state::base(ctx)
  34. {
  35. debug::log::trace("Entering extras menu state...");
  36. // Construct menu item texts
  37. scene::text* credits_text = new scene::text();
  38. scene::text* back_text = new scene::text();
  39. // Build list of menu item texts
  40. ctx.menu_item_texts.push_back({credits_text, nullptr});
  41. ctx.menu_item_texts.push_back({back_text, nullptr});
  42. // Set content of menu item texts
  43. credits_text->set_content(get_string(ctx, "extras_menu_credits"_fnv1a32));
  44. back_text->set_content(get_string(ctx, "back"_fnv1a32));
  45. // Init menu item index
  46. game::menu::init_menu_item_index(ctx, "extras");
  47. game::menu::update_text_color(ctx);
  48. game::menu::update_text_font(ctx);
  49. game::menu::align_text(ctx);
  50. game::menu::update_text_tweens(ctx);
  51. game::menu::add_text_to_ui(ctx);
  52. game::menu::setup_animations(ctx);
  53. // Construct menu item callbacks
  54. auto select_credits_callback = [&ctx]()
  55. {
  56. // Disable controls
  57. game::menu::clear_controls(ctx);
  58. game::menu::fade_out
  59. (
  60. ctx,
  61. [&ctx]()
  62. {
  63. // Queue change to credits state
  64. ctx.function_queue.push
  65. (
  66. [&ctx]()
  67. {
  68. ctx.state_machine.pop();
  69. ctx.state_machine.emplace(new game::state::credits(ctx));
  70. }
  71. );
  72. }
  73. );
  74. };
  75. auto select_back_callback = [&ctx]()
  76. {
  77. // Disable controls
  78. game::menu::clear_controls(ctx);
  79. game::menu::fade_out
  80. (
  81. ctx,
  82. [&ctx]()
  83. {
  84. // Queue change to main menu state
  85. ctx.function_queue.push
  86. (
  87. [&ctx]()
  88. {
  89. ctx.state_machine.pop();
  90. ctx.state_machine.emplace(new game::state::main_menu(ctx, false));
  91. }
  92. );
  93. }
  94. );
  95. };
  96. // Build list of menu select callbacks
  97. ctx.menu_select_callbacks.push_back(select_credits_callback);
  98. ctx.menu_select_callbacks.push_back(select_back_callback);
  99. // Build list of menu left callbacks
  100. ctx.menu_left_callbacks.push_back(nullptr);
  101. ctx.menu_left_callbacks.push_back(nullptr);
  102. // Build list of menu right callbacks
  103. ctx.menu_right_callbacks.push_back(nullptr);
  104. ctx.menu_right_callbacks.push_back(nullptr);
  105. // Set menu back callback
  106. ctx.menu_back_callback = select_back_callback;
  107. // Queue menu control setup
  108. ctx.function_queue.push(std::bind(game::menu::setup_controls, std::ref(ctx)));
  109. // Fade in menu
  110. game::menu::fade_in(ctx, nullptr);
  111. debug::log::trace("Entered extras menu state");
  112. }
  113. extras_menu::~extras_menu()
  114. {
  115. debug::log::trace("Exiting extras menu state...");
  116. // Destruct menu
  117. game::menu::clear_controls(ctx);
  118. game::menu::clear_callbacks(ctx);
  119. game::menu::delete_animations(ctx);
  120. game::menu::remove_text_from_ui(ctx);
  121. game::menu::delete_text(ctx);
  122. debug::log::trace("Exited extras menu state");
  123. }
  124. } // namespace state
  125. } // namespace game