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

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