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

213 lines
5.8 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. /*
  2. * Copyright (C) 2017 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 "title-state.hpp"
  20. #include "../application.hpp"
  21. #include "../camera-rig.hpp"
  22. #include "../ui/menu.hpp"
  23. #include <iostream>
  24. #include <SDL2/SDL.h>
  25. TitleState::TitleState(Application* application):
  26. ApplicationState(application)
  27. {}
  28. TitleState::~TitleState()
  29. {}
  30. void TitleState::enter()
  31. {
  32. application->inputManager->addWindowObserver(this);
  33. windowResized(application->resolution.x, application->resolution.y);
  34. application->camera.setPerspective(
  35. glm::radians(30.0f),
  36. application->resolution.x / application->resolution.y,
  37. 0.5f,
  38. 500.0f);
  39. // Setup camera controller
  40. application->orbitCam->attachCamera(&application->camera);
  41. application->orbitCam->setFocalPoint(Vector3(0.0f));
  42. application->orbitCam->setFocalDistance(50.0f);
  43. application->orbitCam->setElevation(glm::radians(-30.0f));
  44. application->orbitCam->setAzimuth(glm::radians(180.0f));
  45. application->orbitCam->setTargetFocalPoint(application->orbitCam->getFocalPoint());
  46. application->orbitCam->setTargetFocalDistance(application->orbitCam->getFocalDistance());
  47. application->orbitCam->setTargetElevation(application->orbitCam->getElevation());
  48. application->orbitCam->setTargetAzimuth(application->orbitCam->getAzimuth());
  49. application->orbitCam->update(0.0f);
  50. // Dim background
  51. application->darkenImage->setVisible(true);
  52. // Show title
  53. application->titleImage->setVisible(true);
  54. application->titleImage->setTintColor(Vector4(1.0f));
  55. application->copyrightLabel->setVisible(true);
  56. // Show "Press any key"
  57. application->anyKeyLabel->setVisible(true);
  58. application->anyKeyLabel->setActive(true);
  59. application->anyKeyFadeInTween->reset();
  60. application->anyKeyFadeInTween->start();
  61. // Position options menu
  62. application->optionsMenu->getUIContainer()->setAnchor(Vector2(0.5f, 0.8f));
  63. application->controlsMenu->getUIContainer()->setAnchor(Vector2(0.5f, 0.8f));
  64. application->levelsMenu->getUIContainer()->setAnchor(Vector2(0.5f, 0.8f));
  65. // Setup fade-in
  66. application->blackoutImage->setVisible(true);
  67. application->fadeInTween->start();
  68. }
  69. void TitleState::execute()
  70. {
  71. if (application->anyKeyLabel->isActive())
  72. {
  73. InputEvent event;
  74. application->inputManager->listen(&event);
  75. if (event.type != InputEvent::Type::NONE)
  76. {
  77. application->anyKeyLabel->setVisible(false);
  78. application->anyKeyLabel->setActive(false);
  79. application->anyKeyFadeInTween->stop();
  80. application->anyKeyFadeOutTween->stop();
  81. application->inputManager->update();
  82. application->openMenu(application->mainMenu);
  83. }
  84. }
  85. else
  86. {
  87. // Navigate menu
  88. if (application->activeMenu != nullptr)
  89. {
  90. MenuItem* selectedItem = application->activeMenu->getSelectedItem();
  91. if (application->menuDown.isTriggered() && !application->menuDown.wasTriggered())
  92. {
  93. if (selectedItem != nullptr)
  94. {
  95. if (selectedItem->getItemIndex() < application->activeMenu->getItemCount() - 1)
  96. {
  97. application->selectMenuItem(selectedItem->getItemIndex() + 1);
  98. }
  99. else
  100. {
  101. application->selectMenuItem(0);
  102. }
  103. }
  104. else
  105. {
  106. application->selectMenuItem(0);
  107. }
  108. }
  109. else if (application->menuUp.isTriggered() && !application->menuUp.wasTriggered())
  110. {
  111. if (selectedItem != nullptr)
  112. {
  113. if (selectedItem->getItemIndex() > 0)
  114. {
  115. application->selectMenuItem(selectedItem->getItemIndex() - 1);
  116. }
  117. else
  118. {
  119. application->selectMenuItem(application->activeMenu->getItemCount() - 1);
  120. }
  121. }
  122. else
  123. {
  124. application->selectMenuItem(application->activeMenu->getItemCount() - 1);
  125. }
  126. }
  127. if (application->menuLeft.isTriggered() && !application->menuLeft.wasTriggered())
  128. {
  129. application->decrementMenuItem();
  130. }
  131. else if (application->menuRight.isTriggered() && !application->menuRight.wasTriggered())
  132. {
  133. application->incrementMenuItem();
  134. }
  135. if (application->menuSelect.isTriggered() && !application->menuSelect.wasTriggered())
  136. {
  137. application->activateMenuItem();
  138. }
  139. }
  140. }
  141. if (application->escape.isTriggered())
  142. {
  143. application->close(EXIT_SUCCESS);
  144. }
  145. }
  146. void TitleState::exit()
  147. {
  148. // Remove input observers
  149. application->inputManager->removeWindowObserver(this);
  150. // Hide UI
  151. application->titleImage->setVisible(false);
  152. application->copyrightLabel->setVisible(false);
  153. application->anyKeyLabel->setVisible(false);
  154. application->darkenImage->setVisible(false);
  155. }
  156. void TitleState::windowClosed()
  157. {
  158. application->close(EXIT_SUCCESS);
  159. }
  160. void TitleState::windowResized(int width, int height)
  161. {
  162. /*
  163. // Update application dimensions
  164. application->width = width;
  165. application->height = height;
  166. if (application->fullscreen)
  167. {
  168. application->fullscreenWidth = width;
  169. application->fullscreenHeight = height;
  170. }
  171. else
  172. {
  173. application->windowedWidth = width;
  174. application->windowedHeight = height;
  175. }
  176. // Setup default render target
  177. application->defaultRenderTarget.width = application->width;
  178. application->defaultRenderTarget.height = application->height;
  179. // Resize UI
  180. application->resizeUI();
  181. // 3D camera
  182. application->camera.setPerspective(
  183. glm::radians(25.0f),
  184. (float)application->width / (float)application->height,
  185. 0.1f,
  186. 1000.0f);
  187. */
  188. }