InstalledItem.cpp 4.1 KB

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