LoadingState.cpp 2.5 KB

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