💿🐜 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.

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