LoadInformations.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. , m_isTopBGThemeAllowed(false)
  14. , m_isBotBGThemeAllowed(false)
  15. {
  16. std::string path = cpp3ds::FileSystem::getFilePath(FREESHOP_DIR "/theme/texts.json");
  17. if (pathExists(path.c_str(), false)) {
  18. if (Theme::loadFromFile()) {
  19. Theme::isTextThemed = true;
  20. //Load differents colors
  21. std::string percentageColorValue = Theme::get("percentageText").GetString();
  22. //Set the colors
  23. int R, G, B;
  24. hexToRGB(percentageColorValue, &R, &G, &B);
  25. Theme::percentageText = cpp3ds::Color(R, G, B);
  26. }
  27. }
  28. //Texts
  29. m_textLoadingPercentage.setCharacterSize(14);
  30. if (Theme::isTextThemed)
  31. m_textLoadingPercentage.setFillColor(Theme::percentageText);
  32. else
  33. m_textLoadingPercentage.setFillColor(cpp3ds::Color::Black);
  34. m_textLoadingPercentage.setOutlineColor(cpp3ds::Color(0, 0, 0, 70));
  35. m_textLoadingPercentage.setOutlineThickness(2.f);
  36. m_textLoadingPercentage.setPosition(160.f, 230.f);
  37. m_textLoadingPercentage.useSystemFont();
  38. m_textLoadingPercentage.setString(_("0%%"));
  39. }
  40. LoadInformations::~LoadInformations()
  41. {
  42. }
  43. void LoadInformations::draw(cpp3ds::RenderTarget &target, cpp3ds::RenderStates states) const
  44. {
  45. states.transform *= getTransform();
  46. if (m_loadingPercentage > 0)
  47. target.draw(m_textLoadingPercentage);
  48. }
  49. void LoadInformations::update(float delta)
  50. {
  51. m_tweenManager.update(delta);
  52. }
  53. void LoadInformations::updateLoadingPercentage(int newPercentage)
  54. {
  55. // If the new percentage is the same than the actual percentage, no need to recalculate the text
  56. if (newPercentage == m_loadingPercentage)
  57. return;
  58. // Check that percentage is between 0 and 100
  59. if (newPercentage <= 0)
  60. m_loadingPercentage = 0;
  61. else if (newPercentage >= 100)
  62. m_loadingPercentage = 100;
  63. else
  64. m_loadingPercentage = newPercentage;
  65. // Set the text to the percentage and center it
  66. m_textLoadingPercentage.setString(_("%i%%", m_loadingPercentage));
  67. cpp3ds::FloatRect rect = m_textLoadingPercentage.getLocalBounds();
  68. m_textLoadingPercentage.setOrigin(rect.width / 2.f, rect.height / 2.f);
  69. }
  70. LoadInformations &LoadInformations::getInstance()
  71. {
  72. static LoadInformations loadInfos;
  73. return loadInfos;
  74. }
  75. void LoadInformations::reset()
  76. {
  77. updateLoadingPercentage(0);
  78. m_isBotBGThemeAllowed = false;
  79. m_isTopBGThemeAllowed = false;
  80. }
  81. } // namespace FreeShop