LoadingState.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "LoadingState.hpp"
  2. #include "../AssetManager.hpp"
  3. #include "../Theme.hpp"
  4. #include <TweenEngine/Tween.h>
  5. #include <cpp3ds/Window/Window.hpp>
  6. #include <cpp3ds/System/I18n.hpp>
  7. #include <cpp3ds/System/Service.hpp>
  8. #include <cpp3ds/System/FileSystem.hpp>
  9. namespace FreeShop {
  10. LoadingState::LoadingState(StateStack& stack, Context& context, StateCallback callback)
  11. : State(stack, context, callback)
  12. , m_topBG(false)
  13. , m_botBG(false)
  14. {
  15. std::string path = cpp3ds::FileSystem::getFilePath(FREESHOP_DIR "/theme/texts.json");
  16. if (pathExists(path.c_str(), false)) {
  17. if (Theme::loadFromFile()) {
  18. Theme::isTextThemed = true;
  19. //Load differents colors
  20. std::string loadingColorValue = Theme::get("loadingColor").GetString();
  21. //Set the colors
  22. int R, G, B;
  23. hexToRGB(loadingColorValue, &R, &G, &B);
  24. Theme::loadingIcon = cpp3ds::Color(R, G, B);
  25. }
  26. }
  27. m_background.setSize(cpp3ds::Vector2f(400.f, 240.f));
  28. m_background.setFillColor(cpp3ds::Color(0, 0, 0, 50));
  29. m_icon.setFont(AssetManager<cpp3ds::Font>::get("fonts/fontawesome.ttf"));
  30. if (Theme::isTextThemed)
  31. m_icon.setFillColor(Theme::loadingIcon);
  32. else
  33. m_icon.setFillColor(cpp3ds::Color(110, 110, 110, 255));
  34. m_icon.setCharacterSize(80);
  35. m_icon.setString(L"\uf110");
  36. cpp3ds::FloatRect textRect = m_icon.getLocalBounds();
  37. m_icon.setOrigin(textRect.left + textRect.width / 2.f, textRect.top + 1.f + textRect.height / 2.f);
  38. m_icon.setPosition(160.f, 120.f);
  39. m_icon.setScale(0.5f, 0.5f);
  40. if (pathExists(FREESHOP_DIR "/theme/images/topBG.png", true)) {
  41. m_rectTopBG.setTexture(&AssetManager<cpp3ds::Texture>::get(FREESHOP_DIR "/theme/images/topBG.png"));
  42. m_rectTopBG.setPosition(0.f, 0.f);
  43. m_topBG = true;
  44. }
  45. if (pathExists(FREESHOP_DIR "/theme/images/botBG.png", true)) {
  46. m_rectBotBG.setTexture(&AssetManager<cpp3ds::Texture>::get(FREESHOP_DIR "/theme/images/botBG.png"));
  47. m_rectBotBG.setPosition(0.f, 0.f);
  48. m_botBG = true;
  49. }
  50. }
  51. void LoadingState::renderTopScreen(cpp3ds::Window& window)
  52. {
  53. if (m_topBG == true)
  54. window.draw(m_rectTopBG);
  55. }
  56. void LoadingState::renderBottomScreen(cpp3ds::Window& window)
  57. {
  58. if (m_botBG == true)
  59. window.draw(m_rectBotBG);
  60. window.draw(m_icon);
  61. }
  62. bool LoadingState::update(float delta)
  63. {
  64. if (m_rotateClock.getElapsedTime() > cpp3ds::milliseconds(80))
  65. {
  66. m_icon.rotate(45);
  67. m_rotateClock.restart();
  68. }
  69. return true;
  70. }
  71. bool LoadingState::processEvent(const cpp3ds::Event& event)
  72. {
  73. return false;
  74. }
  75. } // namespace FreeShop