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

129 lines
3.6 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/states/extras-menu.hpp"
  20. #include "game/states/main-menu.hpp"
  21. #include "game/states/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. namespace extras_menu {
  30. void enter(game::context* ctx)
  31. {
  32. // Construct menu item texts
  33. scene::text* credits_text = new scene::text();
  34. scene::text* back_text = new scene::text();
  35. // Build list of menu item texts
  36. ctx->menu_item_texts.push_back({credits_text, nullptr});
  37. ctx->menu_item_texts.push_back({back_text, nullptr});
  38. // Set content of menu item texts
  39. credits_text->set_content((*ctx->strings)["extras_menu_credits"]);
  40. back_text->set_content((*ctx->strings)["back"]);
  41. // Init menu item index
  42. game::menu::init_menu_item_index(ctx, "extras");
  43. game::menu::update_text_color(ctx);
  44. game::menu::update_text_font(ctx);
  45. game::menu::align_text(ctx);
  46. game::menu::update_text_tweens(ctx);
  47. game::menu::add_text_to_ui(ctx);
  48. game::menu::setup_animations(ctx);
  49. // Construct menu item callbacks
  50. auto select_credits_callback = [ctx]()
  51. {
  52. // Disable controls
  53. game::menu::clear_controls(ctx);
  54. game::menu::fade_out
  55. (
  56. ctx,
  57. [ctx]()
  58. {
  59. application::state next_state;
  60. next_state.name = "credits";
  61. next_state.enter = std::bind(game::state::credits::enter, ctx);
  62. next_state.exit = std::bind(game::state::credits::exit, ctx);
  63. ctx->app->queue_state(next_state);
  64. }
  65. );
  66. };
  67. auto select_back_callback = [ctx]()
  68. {
  69. // Disable controls
  70. game::menu::clear_controls(ctx);
  71. game::menu::fade_out
  72. (
  73. ctx,
  74. [ctx]()
  75. {
  76. application::state next_state;
  77. next_state.name = "main_menu";
  78. next_state.enter = std::bind(game::state::main_menu::enter, ctx, false);
  79. next_state.exit = std::bind(game::state::main_menu::exit, ctx);
  80. ctx->app->queue_state(next_state);
  81. }
  82. );
  83. };
  84. // Build list of menu select callbacks
  85. ctx->menu_select_callbacks.push_back(select_credits_callback);
  86. ctx->menu_select_callbacks.push_back(select_back_callback);
  87. // Build list of menu left callbacks
  88. ctx->menu_left_callbacks.push_back(nullptr);
  89. ctx->menu_left_callbacks.push_back(nullptr);
  90. // Build list of menu right callbacks
  91. ctx->menu_right_callbacks.push_back(nullptr);
  92. ctx->menu_right_callbacks.push_back(nullptr);
  93. // Set menu back callback
  94. ctx->menu_back_callback = select_back_callback;
  95. // Queue menu control setup
  96. ctx->function_queue.push(std::bind(game::menu::setup_controls, ctx));
  97. // Fade in menu
  98. game::menu::fade_in(ctx, nullptr);
  99. }
  100. void exit(game::context* ctx)
  101. {
  102. // Destruct menu
  103. game::menu::clear_controls(ctx);
  104. game::menu::clear_callbacks(ctx);
  105. game::menu::delete_animations(ctx);
  106. game::menu::remove_text_from_ui(ctx);
  107. game::menu::delete_text(ctx);
  108. }
  109. } // namespace extras_menu
  110. } // namespace state
  111. } // namespace game