LoadInformations.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #include "LoadInformations.hpp"
  2. #include "AssetManager.hpp"
  3. #include "DownloadQueue.hpp"
  4. #include "Notification.hpp"
  5. #include "Theme.hpp"
  6. #include "Util.hpp"
  7. #include "States/StateIdentifiers.hpp"
  8. #include <cpp3ds/System/I18n.hpp>
  9. #include <cpp3ds/System/FileSystem.hpp>
  10. namespace FreeShop {
  11. LoadInformations::LoadInformations()
  12. : m_loadingPercentage(0)
  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 percentageColorValue = Theme::get("percentageText").GetString();
  20. //Set the colors
  21. int R, G, B;
  22. hexToRGB(percentageColorValue, &R, &G, &B);
  23. Theme::percentageText = cpp3ds::Color(R, G, B);
  24. }
  25. }
  26. //Texts
  27. m_textLoadingPercentage.setCharacterSize(14);
  28. if (Theme::isTextThemed)
  29. m_textLoadingPercentage.setFillColor(Theme::percentageText);
  30. else
  31. m_textLoadingPercentage.setFillColor(cpp3ds::Color::Black);
  32. m_textLoadingPercentage.setOutlineColor(cpp3ds::Color(0, 0, 0, 70));
  33. m_textLoadingPercentage.setOutlineThickness(2.f);
  34. m_textLoadingPercentage.setPosition(160.f, 230.f);
  35. m_textLoadingPercentage.useSystemFont();
  36. m_textLoadingPercentage.setString(_("0%%"));
  37. m_textStatus.setCharacterSize(14);
  38. if (Theme::isTextThemed)
  39. m_textStatus.setFillColor(Theme::loadingText);
  40. else
  41. m_textStatus.setFillColor(cpp3ds::Color::Black);
  42. m_textStatus.setOutlineColor(cpp3ds::Color(0, 0, 0, 70));
  43. m_textStatus.setOutlineThickness(2.f);
  44. m_textStatus.setPosition(160.f, 155.f);
  45. m_textStatus.useSystemFont();
  46. TweenEngine::Tween::to(m_textStatus, util3ds::TweenText::FILL_COLOR_ALPHA, 0.3f)
  47. .target(180)
  48. .repeatYoyo(-1, 0)
  49. .start(m_tweenManager);
  50. }
  51. LoadInformations::~LoadInformations()
  52. {
  53. }
  54. void LoadInformations::draw(cpp3ds::RenderTarget &target, cpp3ds::RenderStates states) const
  55. {
  56. states.transform *= getTransform();
  57. if (m_loadingPercentage > -1)
  58. target.draw(m_textLoadingPercentage);
  59. target.draw(m_textStatus);
  60. }
  61. void LoadInformations::update(float delta)
  62. {
  63. m_tweenManager.update(delta);
  64. }
  65. void LoadInformations::updateLoadingPercentage(int newPercentage)
  66. {
  67. // If the new percentage is the same than the actual percentage, no need to recalculate the text
  68. if (newPercentage == m_loadingPercentage)
  69. return;
  70. // Check that percentage is between 0 and 100
  71. if (newPercentage <= -1)
  72. m_loadingPercentage = -1;
  73. else if (newPercentage >= 100)
  74. m_loadingPercentage = 100;
  75. else
  76. m_loadingPercentage = newPercentage;
  77. // Set the text to the percentage and center it
  78. m_textLoadingPercentage.setString(_("%i%%", m_loadingPercentage));
  79. cpp3ds::FloatRect rect = m_textLoadingPercentage.getLocalBounds();
  80. m_textLoadingPercentage.setOrigin(rect.width / 2.f, rect.height / 2.f);
  81. }
  82. LoadInformations &LoadInformations::getInstance()
  83. {
  84. static LoadInformations loadInfos;
  85. return loadInfos;
  86. }
  87. void LoadInformations::reset()
  88. {
  89. updateLoadingPercentage(-1);
  90. setStatus("");
  91. }
  92. void LoadInformations::setStatus(const std::string &message)
  93. {
  94. m_textStatus.setString(message);
  95. cpp3ds::FloatRect rect = m_textStatus.getLocalBounds();
  96. m_textStatus.setOrigin(rect.width / 2.f, rect.height / 2.f);
  97. }
  98. } // namespace FreeShop