Theme.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #include <cpp3ds/System/FileSystem.hpp>
  2. #include <cpp3ds/System/I18n.hpp>
  3. #include <fstream>
  4. #include <rapidjson/ostreamwrapper.h>
  5. #include <rapidjson/writer.h>
  6. #include <cpp3ds/System/FileInputStream.hpp>
  7. #include "Theme.hpp"
  8. #include "Util.hpp"
  9. namespace FreeShop {
  10. //Images vars
  11. bool Theme::isFlagsThemed = false;
  12. bool Theme::isItemBG9Themed = false;
  13. bool Theme::isButtonRadius9Themed = false;
  14. bool Theme::isFSBGSD9Themed = false;
  15. bool Theme::isFSBGNAND9Themed = false;
  16. bool Theme::isInstalledItemBG9Themed = false;
  17. bool Theme::isItemBGSelected9Themed = false;
  18. bool Theme::isListItemBG9Themed = false;
  19. bool Theme::isMissingIconThemed = false;
  20. bool Theme::isNotification9Themed = false;
  21. bool Theme::isQrSelector9Themed = false;
  22. bool Theme::isScrollbar9Themed = false;
  23. //Sounds vars
  24. bool Theme::isSoundBlipThemed = false;
  25. bool Theme::isSoundChimeThemed = false;
  26. bool Theme::isSoundStartupThemed = false;
  27. //Text theming
  28. bool Theme::isTextThemed = false;
  29. cpp3ds::Color Theme::primaryTextColor = cpp3ds::Color::Black;
  30. cpp3ds::Color Theme::secondaryTextColor = cpp3ds::Color(130, 130, 130, 255);
  31. cpp3ds::Color Theme::iconSetColor = cpp3ds::Color(100, 100, 100);
  32. cpp3ds::Color Theme::iconSetColorActive = cpp3ds::Color(0, 0, 0);
  33. cpp3ds::Color Theme::transitionScreenColor = cpp3ds::Color(255, 255, 255);
  34. cpp3ds::Color Theme::loadingIcon = cpp3ds::Color(110, 110, 110, 255);
  35. cpp3ds::Color Theme::loadingText = cpp3ds::Color::Black;
  36. cpp3ds::Color Theme::freText = cpp3ds::Color(255, 255, 255, 0);
  37. cpp3ds::Color Theme::versionText = cpp3ds::Color(0, 0, 0, 100);
  38. cpp3ds::Color Theme::percentageText = cpp3ds::Color::Black;
  39. cpp3ds::Color Theme::boxColor = cpp3ds::Color(245, 245, 245);
  40. cpp3ds::Color Theme::boxOutlineColor = cpp3ds::Color(158, 158, 158, 255);
  41. cpp3ds::Color Theme::dialogBackground = cpp3ds::Color(255, 255, 255, 128);
  42. cpp3ds::Color Theme::dialogButton = cpp3ds::Color(158, 158, 158, 0);
  43. cpp3ds::Color Theme::dialogButtonText = cpp3ds::Color(3, 169, 244, 0);
  44. //Theme informations
  45. std::string Theme::themeName = _("Classic").toAnsiString();
  46. std::string Theme::themeDesc = _("The default theme of freeShop.\nMade by arc13 / Cruel.").toAnsiString();
  47. std::string Theme::themeVersion = FREESHOP_VERSION;
  48. Theme &Theme::getInstance()
  49. {
  50. static Theme theme;
  51. return theme;
  52. }
  53. #define ADD_DEFAULT(key, val) \
  54. if (!m_json.HasMember(key)) \
  55. m_json.AddMember(rapidjson::StringRef(key), val, m_json.GetAllocator());
  56. void Theme::loadDefaults()
  57. {
  58. if (!m_json.IsObject())
  59. m_json.SetObject();
  60. ADD_DEFAULT("primaryText", "000000");
  61. ADD_DEFAULT("secondaryText", "828282");
  62. ADD_DEFAULT("iconSet", "646464");
  63. ADD_DEFAULT("iconSetActive", "363636");
  64. ADD_DEFAULT("transitionScreen", "FFFFFF");
  65. ADD_DEFAULT("loadingColor", "898989");
  66. ADD_DEFAULT("loadingText", "353535");
  67. ADD_DEFAULT("freText", "420420");
  68. ADD_DEFAULT("versionText", "546978");
  69. ADD_DEFAULT("percentageText", "115599");
  70. ADD_DEFAULT("boxColor", "00FF7F");
  71. ADD_DEFAULT("boxOutlineColor", "008899");
  72. ADD_DEFAULT("dialogBackground", "CE2F06");
  73. ADD_DEFAULT("dialogButton", "FDE243");
  74. ADD_DEFAULT("dialogButtonText", "320F3C");
  75. ADD_DEFAULT("themeName", "My custom theme");
  76. ADD_DEFAULT("themeDesc", "Theme made by someone.");
  77. ADD_DEFAULT("themeVer", "x.y");
  78. getInstance().saveToFile();
  79. }
  80. bool Theme::loadFromFile(const std::string &filename)
  81. {
  82. rapidjson::Document &json = getInstance().m_json;
  83. std::string path = cpp3ds::FileSystem::getFilePath(filename);
  84. std::string jsonString;
  85. cpp3ds::FileInputStream file;
  86. if (!file.open(filename))
  87. return false;
  88. jsonString.resize(file.getSize());
  89. file.read(&jsonString[0], jsonString.size());
  90. json.Parse(jsonString.c_str());
  91. getInstance().loadDefaults();
  92. return !json.HasParseError();
  93. }
  94. const rapidjson::Value &Theme::get(std::string key)
  95. {
  96. return getInstance().m_json[key.c_str()];
  97. }
  98. void Theme::saveToFile(const std::string &filename)
  99. {
  100. std::string path = cpp3ds::FileSystem::getFilePath(filename);
  101. std::ofstream file(path);
  102. rapidjson::OStreamWrapper osw(file);
  103. rapidjson::Writer<rapidjson::OStreamWrapper> writer(osw);
  104. getInstance().m_json.Accept(writer);
  105. }
  106. void Theme::loadNameDesc()
  107. {
  108. themeName = _("Classic").toAnsiString();
  109. themeDesc = _("The default theme of freeShop.\nMade by arc13 / Cruel.").toAnsiString();
  110. }
  111. } // namespace FreeShop