InstalledItem.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #include <cpp3ds/System/I18n.hpp>
  2. #include "InstalledItem.hpp"
  3. #include "AssetManager.hpp"
  4. #include "AppList.hpp"
  5. #include "TitleKeys.hpp"
  6. namespace FreeShop {
  7. InstalledItem::InstalledItem(cpp3ds::Uint64 titleId)
  8. : m_titleId(titleId)
  9. , m_updateInstallCount(0)
  10. , m_dlcInstallCount(0)
  11. {
  12. TitleKeys::TitleType titleType = static_cast<TitleKeys::TitleType>(titleId >> 32);
  13. if (titleType == TitleKeys::SystemApplication || titleType == TitleKeys::SystemApplet)
  14. {
  15. m_appItem = std::make_shared<AppItem>();
  16. m_appItem->loadFromSystemTitleId(titleId);
  17. }
  18. else
  19. {
  20. bool found = false;
  21. for (auto& appItem : AppList::getInstance().getList())
  22. {
  23. m_appItem = appItem->getAppItem();
  24. if (titleId == m_appItem->getTitleId())
  25. {
  26. found = true;
  27. break;
  28. }
  29. }
  30. if (!found)
  31. {
  32. throw 0;
  33. }
  34. }
  35. m_appItem->setInstalled(true);
  36. m_background.setTexture(&AssetManager<cpp3ds::Texture>::get("images/installed_item_bg.9.png"));
  37. m_textTitle.setString(m_appItem->getTitle());
  38. m_textTitle.setCharacterSize(11);
  39. m_textTitle.setPosition(m_background.getPadding().left, m_background.getPadding().top);
  40. m_textTitle.setFillColor(cpp3ds::Color::Black);
  41. m_textTitle.useSystemFont();
  42. m_textWarningUpdate.setFont(AssetManager<cpp3ds::Font>::get("fonts/fontawesome.ttf"));
  43. m_textWarningUpdate.setString(L"\uf071");
  44. m_textWarningUpdate.setCharacterSize(14);
  45. m_textWarningUpdate.setFillColor(cpp3ds::Color(50, 50, 50));
  46. m_textWarningUpdate.setOutlineColor(cpp3ds::Color(0, 200, 0));
  47. m_textWarningUpdate.setOutlineThickness(1.f);
  48. m_textWarningUpdate.setOrigin(0, m_textWarningUpdate.getLocalBounds().top + m_textWarningUpdate.getLocalBounds().height / 2.f);
  49. m_textWarningDLC = m_textWarningUpdate;
  50. m_textWarningDLC.setOutlineColor(cpp3ds::Color(255, 255, 0, 255));
  51. setHeight(16.f);
  52. }
  53. void InstalledItem::draw(cpp3ds::RenderTarget &target, cpp3ds::RenderStates states) const
  54. {
  55. states.transform *= getTransform();
  56. target.draw(m_background, states);
  57. target.draw(m_textTitle, states);
  58. if (m_updates.size() - m_updateInstallCount > 0)
  59. target.draw(m_textWarningUpdate, states);
  60. if (m_dlc.size() - m_dlcInstallCount > 0)
  61. target.draw(m_textWarningDLC, states);
  62. }
  63. cpp3ds::Uint64 InstalledItem::getTitleId() const
  64. {
  65. return m_titleId;
  66. }
  67. void InstalledItem::setUpdateStatus(cpp3ds::Uint64 titleId, bool installed)
  68. {
  69. m_updates[titleId] = installed;
  70. m_updateInstallCount = 0;
  71. for (auto& update : m_updates)
  72. if (update.second)
  73. m_updateInstallCount++;
  74. }
  75. void InstalledItem::setDLCStatus(cpp3ds::Uint64 titleId, bool installed)
  76. {
  77. m_dlc[titleId] = installed;
  78. m_dlcInstallCount = 0;
  79. for (auto& dlc : m_dlc)
  80. if (dlc.second)
  81. m_dlcInstallCount++;
  82. }
  83. std::shared_ptr<AppItem> InstalledItem::getAppItem() const
  84. {
  85. return m_appItem;
  86. }
  87. void InstalledItem::processEvent(const cpp3ds::Event &event)
  88. {
  89. }
  90. void InstalledItem::setValues(int tweenType, float *newValues)
  91. {
  92. switch (tweenType) {
  93. case HEIGHT:
  94. setHeight(newValues[0]);
  95. break;
  96. default:
  97. TweenTransformable::setValues(tweenType, newValues);
  98. }
  99. }
  100. int InstalledItem::getValues(int tweenType, float *returnValues)
  101. {
  102. switch (tweenType) {
  103. case HEIGHT:
  104. returnValues[0] = getHeight();
  105. return 1;
  106. default:
  107. return TweenTransformable::getValues(tweenType, returnValues);
  108. }
  109. }
  110. void InstalledItem::setHeight(float height)
  111. {
  112. m_height = height;
  113. m_background.setContentSize(320.f + m_background.getPadding().width - m_background.getTexture()->getSize().x + 2.f, height);
  114. float paddingRight = m_background.getSize().x - m_background.getContentSize().x - m_background.getPadding().left;
  115. float paddingBottom = m_background.getSize().y - m_background.getContentSize().y - m_background.getPadding().top;
  116. m_textWarningUpdate.setPosition(m_background.getSize().x - paddingRight - m_textWarningUpdate.getLocalBounds().width - 7.f,
  117. m_background.getPadding().top + height - height * 0.4f - 3.f);
  118. m_textWarningDLC.setPosition(m_textWarningUpdate.getPosition());
  119. m_textWarningDLC.move(-20.f, 0);
  120. }
  121. float InstalledItem::getHeight() const
  122. {
  123. return m_height;
  124. }
  125. } // namespace FreeShop