AppList.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 setFilterFeatures(const std::vector<int> &features);
  42. void setFilterPlatforms(const std::vector<int> &genres);
  43. void setFilterLanguages(int languages);
  44. void setFilterRegions(int regions);
  45. void setFilterPublishers(const std::vector<int> &publishers);
  46. void setIndexDelta(int indexDelta);
  47. int calculateGameCount();
  48. protected:
  49. AppList(std::string jsonFilename);
  50. virtual void draw(cpp3ds::RenderTarget& target, cpp3ds::RenderStates states) const;
  51. void sort();
  52. void filter();
  53. void reposition();
  54. void processKeyRepeat();
  55. private:
  56. SortType m_sortType;
  57. bool m_sortAscending;
  58. float m_targetPosX;
  59. cpp3ds::Sound m_soundBlip;
  60. cpp3ds::Clock m_clockKeyRepeat;
  61. int m_indexDelta;
  62. bool m_processedFirstKey;
  63. bool m_startKeyRepeat;
  64. std::string m_currentSearchTerm;
  65. std::vector<int> m_filterGenres;
  66. std::vector<int> m_filterPlatforms;
  67. int m_filterRegions;
  68. std::vector<int> m_filterPublishers;
  69. int m_filterLanguages;
  70. std::vector<int> m_filterFeatures;
  71. std::string m_jsonFilename;
  72. int m_selectedIndex;
  73. std::vector<std::shared_ptr<AppItem>> m_appItems;
  74. std::vector<std::unique_ptr<GUI::AppItem>> m_guiAppItems;
  75. std::vector<cpp3ds::Texture*> m_iconTextures;
  76. bool m_collapsed;
  77. TweenEngine::TweenManager m_tweenManager;
  78. AppInfo m_appInfo;
  79. };
  80. } // namespace FreeShop
  81. #endif // FREESHOP_APPLIST_HPP