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

126 lines
4.3 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/controls-menu.hpp"
  20. #include "game/states/keyboard-config-menu.hpp"
  21. #include "game/states/controller-config-menu.hpp"
  22. #include "game/states/options-menu.hpp"
  23. #include "application.hpp"
  24. #include "scene/text.hpp"
  25. #include "render/passes/clear-pass.hpp"
  26. #include "debug/logger.hpp"
  27. #include "game/menu.hpp"
  28. #include "animation/timeline.hpp"
  29. namespace game {
  30. namespace state {
  31. namespace controls_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* keyboard_text = new scene::text();
  37. scene::text* controller_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({keyboard_text, nullptr});
  41. ctx->menu_item_texts.push_back({controller_text, nullptr});
  42. ctx->menu_item_texts.push_back({back_text, nullptr});
  43. // Set content of menu item texts
  44. keyboard_text->set_content((*ctx->strings)["controls_menu_keyboard"]);
  45. controller_text->set_content((*ctx->strings)["controls_menu_controller"]);
  46. back_text->set_content((*ctx->strings)["back"]);
  47. // Init menu item index
  48. game::menu::init_menu_item_index(ctx, "controls");
  49. game::menu::update_text_color(ctx);
  50. game::menu::update_text_font(ctx);
  51. game::menu::align_text(ctx);
  52. game::menu::update_text_tweens(ctx);
  53. game::menu::add_text_to_ui(ctx);
  54. // Construct menu item callbacks
  55. auto select_keyboard_callback = [ctx]()
  56. {
  57. application::state next_state;
  58. next_state.name = "keyboard_config_menu";
  59. next_state.enter = std::bind(game::state::keyboard_config_menu::enter, ctx);
  60. next_state.exit = std::bind(game::state::keyboard_config_menu::exit, ctx);
  61. ctx->app->change_state(next_state);
  62. };
  63. auto select_controller_callback = [ctx]()
  64. {
  65. application::state next_state;
  66. next_state.name = "controller_config_menu";
  67. next_state.enter = std::bind(game::state::controller_config_menu::enter, ctx);
  68. next_state.exit = std::bind(game::state::controller_config_menu::exit, ctx);
  69. ctx->app->change_state(next_state);
  70. };
  71. auto select_back_callback = [ctx]()
  72. {
  73. application::state next_state;
  74. next_state.name = "options_menu";
  75. next_state.enter = std::bind(game::state::options_menu::enter, ctx);
  76. next_state.exit = std::bind(game::state::options_menu::exit, ctx);
  77. ctx->app->change_state(next_state);
  78. };
  79. // Build list of menu select callbacks
  80. ctx->menu_select_callbacks.push_back(select_keyboard_callback);
  81. ctx->menu_select_callbacks.push_back(select_controller_callback);
  82. ctx->menu_select_callbacks.push_back(select_back_callback);
  83. // Build list of menu left callbacks
  84. ctx->menu_left_callbacks.push_back(nullptr);
  85. ctx->menu_left_callbacks.push_back(nullptr);
  86. ctx->menu_left_callbacks.push_back(nullptr);
  87. // Build list of menu right callbacks
  88. ctx->menu_right_callbacks.push_back(nullptr);
  89. ctx->menu_right_callbacks.push_back(nullptr);
  90. ctx->menu_right_callbacks.push_back(nullptr);
  91. // Set menu back callback
  92. ctx->menu_back_callback = select_back_callback;
  93. // Schedule menu control setup
  94. timeline* timeline = ctx->timeline;
  95. float t = timeline->get_position();
  96. timeline->add_sequence({{t + game::menu::input_delay, std::bind(game::menu::setup_controls, ctx)}});
  97. }
  98. void exit(game::context* ctx)
  99. {
  100. // Destruct menu
  101. game::menu::clear_controls(ctx);
  102. game::menu::clear_callbacks(ctx);
  103. game::menu::remove_text_from_ui(ctx);
  104. game::menu::delete_text(ctx);
  105. ctx->ui_clear_pass->set_cleared_buffers(false, true, false);
  106. }
  107. } // namespace controls_menu
  108. } // namespace state
  109. } // namespace game