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

123 lines
4.1 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. namespace game {
  29. namespace state {
  30. namespace controls_menu {
  31. void enter(game::context* ctx)
  32. {
  33. ctx->ui_clear_pass->set_cleared_buffers(true, true, false);
  34. // Construct menu item texts
  35. scene::text* keyboard_text = new scene::text();
  36. scene::text* controller_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({keyboard_text, nullptr});
  40. ctx->menu_item_texts.push_back({controller_text, nullptr});
  41. ctx->menu_item_texts.push_back({back_text, nullptr});
  42. // Set content of menu item texts
  43. keyboard_text->set_content((*ctx->strings)["controls_menu_keyboard"]);
  44. controller_text->set_content((*ctx->strings)["controls_menu_controller"]);
  45. back_text->set_content((*ctx->strings)["back"]);
  46. // Init menu item index
  47. game::menu::init_menu_item_index(ctx, "controls");
  48. game::menu::update_text_color(ctx);
  49. game::menu::update_text_font(ctx);
  50. game::menu::align_text(ctx);
  51. game::menu::update_text_tweens(ctx);
  52. game::menu::add_text_to_ui(ctx);
  53. // Construct menu item callbacks
  54. auto select_keyboard_callback = [ctx]()
  55. {
  56. application::state next_state;
  57. next_state.name = "keyboard_config_menu";
  58. next_state.enter = std::bind(game::state::keyboard_config_menu::enter, ctx);
  59. next_state.exit = std::bind(game::state::keyboard_config_menu::exit, ctx);
  60. ctx->app->change_state(next_state);
  61. };
  62. auto select_controller_callback = [ctx]()
  63. {
  64. application::state next_state;
  65. next_state.name = "controller_config_menu";
  66. next_state.enter = std::bind(game::state::controller_config_menu::enter, ctx);
  67. next_state.exit = std::bind(game::state::controller_config_menu::exit, ctx);
  68. ctx->app->change_state(next_state);
  69. };
  70. auto select_back_callback = [ctx]()
  71. {
  72. application::state next_state;
  73. next_state.name = "options_menu";
  74. next_state.enter = std::bind(game::state::options_menu::enter, ctx);
  75. next_state.exit = std::bind(game::state::options_menu::exit, ctx);
  76. ctx->app->change_state(next_state);
  77. };
  78. // Build list of menu select callbacks
  79. ctx->menu_select_callbacks.push_back(select_keyboard_callback);
  80. ctx->menu_select_callbacks.push_back(select_controller_callback);
  81. ctx->menu_select_callbacks.push_back(select_back_callback);
  82. // Build list of menu left callbacks
  83. ctx->menu_left_callbacks.push_back(nullptr);
  84. ctx->menu_left_callbacks.push_back(nullptr);
  85. ctx->menu_left_callbacks.push_back(nullptr);
  86. // Build list of menu right callbacks
  87. ctx->menu_right_callbacks.push_back(nullptr);
  88. ctx->menu_right_callbacks.push_back(nullptr);
  89. ctx->menu_right_callbacks.push_back(nullptr);
  90. // Set menu back callback
  91. ctx->menu_back_callback = select_back_callback;
  92. // Setup menu controls
  93. game::menu::setup_controls(ctx);
  94. }
  95. void exit(game::context* ctx)
  96. {
  97. // Destruct menu
  98. game::menu::clear_controls(ctx);
  99. game::menu::clear_callbacks(ctx);
  100. game::menu::remove_text_from_ui(ctx);
  101. game::menu::delete_text(ctx);
  102. ctx->ui_clear_pass->set_cleared_buffers(false, true, false);
  103. }
  104. } // namespace controls_menu
  105. } // namespace state
  106. } // namespace game