AppList.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #ifndef FREESHOP_APPLIST_HPP
  2. #define FREESHOP_APPLIST_HPP
  3. #include <vector>
  4. #include <string>
  5. #include <memory>
  6. #include <TweenEngine/TweenManager.h>
  7. #include <cpp3ds/System/Thread.hpp>
  8. #include <cpp3ds/Window/Event.hpp>
  9. #include <cpp3ds/System/Clock.hpp>
  10. #include <cpp3ds/Audio/Sound.hpp>
  11. #include "GUI/AppItem.hpp"
  12. #include "RichText.hpp"
  13. #include "AppInfo.hpp"
  14. namespace FreeShop
  15. {
  16. class AppList : public cpp3ds::Drawable, public util3ds::TweenTransformable<cpp3ds::Transformable> {
  17. public:
  18. enum SortType {
  19. Name,
  20. Size,
  21. VoteScore,
  22. VoteCount,
  23. ReleaseDate,
  24. };
  25. static AppList &getInstance();
  26. ~AppList();
  27. void refresh();
  28. void setSortType(SortType sortType, bool ascending);
  29. void setSelectedIndex(int index);
  30. int getSelectedIndex() const;
  31. size_t getCount() const;
  32. size_t getVisibleCount() const;
  33. GUI::AppItem* getSelected();
  34. std::vector<std::unique_ptr<GUI::AppItem>> &getList();
  35. void setCollapsed(bool collapsed);
  36. bool isCollapsed() const;
  37. void filterBySearch(const std::string& searchTerm, std::vector<util3ds::RichText> &textMatches);
  38. void update(float delta);
  39. bool processEvent(const cpp3ds::Event& event);
  40. void setFilterGenres(const std::vector<int> &genres);
  41. void setFilterPlatforms(const std::vector<int> &genres);
  42. void setFilterLanguages(int languages);
  43. void setFilterRegions(int regions);
  44. void setIndexDelta(int indexDelta);
  45. int calculateGameCount();
  46. protected:
  47. AppList(std::string jsonFilename);
  48. virtual void draw(cpp3ds::RenderTarget& target, cpp3ds::RenderStates states) const;
  49. void sort();
  50. void filter();
  51. void reposition();
  52. void processKeyRepeat();
  53. private:
  54. SortType m_sortType;
  55. bool m_sortAscending;
  56. float m_targetPosX;
  57. cpp3ds::Sound m_soundBlip;
  58. cpp3ds::Clock m_clockKeyRepeat;
  59. int m_indexDelta;
  60. bool m_processedFirstKey;
  61. bool m_startKeyRepeat;
  62. std::vector<int> m_filterGenres;
  63. std::vector<int> m_filterPlatforms;
  64. int m_filterRegions;
  65. int m_filterLanguages;
  66. std::string m_jsonFilename;
  67. int m_selectedIndex;
  68. std::vector<std::shared_ptr<AppItem>> m_appItems;
  69. std::vector<std::unique_ptr<GUI::AppItem>> m_guiAppItems;
  70. std::vector<cpp3ds::Texture*> m_iconTextures;
  71. bool m_collapsed;
  72. TweenEngine::TweenManager m_tweenManager;
  73. AppInfo m_appInfo;
  74. };
  75. } // namespace FreeShop
  76. #endif // FREESHOP_APPLIST_HPP