AppList.hpp 2.2 KB

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