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

144 lines
3.7 KiB

  1. /*
  2. * Copyright (C) 2021 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/logger.hpp"
  25. #include "game/fonts.hpp"
  26. #include "game/menu.hpp"
  27. namespace game {
  28. namespace state {
  29. extras_menu::extras_menu(game::context& ctx):
  30. game::state::base(ctx)
  31. {
  32. ctx.logger->push_task("Entering extras menu state");
  33. // Construct menu item texts
  34. scene::text* credits_text = new scene::text();
  35. scene::text* back_text = new scene::text();
  36. // Build list of menu item texts
  37. ctx.menu_item_texts.push_back({credits_text, nullptr});
  38. ctx.menu_item_texts.push_back({back_text, nullptr});
  39. // Set content of menu item texts
  40. credits_text->set_content((*ctx.strings)["extras_menu_credits"]);
  41. back_text->set_content((*ctx.strings)["back"]);
  42. // Init menu item index
  43. game::menu::init_menu_item_index(ctx, "extras");
  44. game::menu::update_text_color(ctx);
  45. game::menu::update_text_font(ctx);
  46. game::menu::align_text(ctx);
  47. game::menu::update_text_tweens(ctx);
  48. game::menu::add_text_to_ui(ctx);
  49. game::menu::setup_animations(ctx);
  50. // Construct menu item callbacks
  51. auto select_credits_callback = [&ctx]()
  52. {
  53. // Disable controls
  54. game::menu::clear_controls(ctx);
  55. game::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(new game::state::credits(ctx));
  67. }
  68. );
  69. }
  70. );
  71. };
  72. auto select_back_callback = [&ctx]()
  73. {
  74. // Disable controls
  75. game::menu::clear_controls(ctx);
  76. game::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(new game::state::main_menu(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. // Queue menu control setup
  105. ctx.function_queue.push(std::bind(game::menu::setup_controls, std::ref(ctx)));
  106. // Fade in menu
  107. game::menu::fade_in(ctx, nullptr);
  108. ctx.logger->pop_task(EXIT_SUCCESS);
  109. }
  110. extras_menu::~extras_menu()
  111. {
  112. ctx.logger->push_task("Exiting extras menu state");
  113. // Destruct menu
  114. game::menu::clear_controls(ctx);
  115. game::menu::clear_callbacks(ctx);
  116. game::menu::delete_animations(ctx);
  117. game::menu::remove_text_from_ui(ctx);
  118. game::menu::delete_text(ctx);
  119. ctx.logger->pop_task(EXIT_SUCCESS);
  120. }
  121. } // namespace state
  122. } // namespace game