Theme.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. cpp3ds::Color Theme::themeDescColor = cpp3ds::Color(0, 0, 0, 0);
  45. //Theme informations
  46. std::string Theme::themeName = _("Classic").toAnsiString();
  47. std::string Theme::themeDesc = _("The default theme of freeShop.\nMade by arc13 / Cruel.").toAnsiString();
  48. std::string Theme::themeVersion = FREESHOP_VERSION;
  49. Theme &Theme::getInstance()
  50. {
  51. static Theme theme;
  52. return theme;
  53. }
  54. #define ADD_DEFAULT(key, val) \
  55. if (!m_json.HasMember(key)) \
  56. m_json.AddMember(rapidjson::StringRef(key), val, m_json.GetAllocator());
  57. void Theme::loadDefaults()
  58. {
  59. if (!m_json.IsObject())
  60. m_json.SetObject();
  61. ADD_DEFAULT("primaryText", "000000");
  62. ADD_DEFAULT("secondaryText", "828282");
  63. ADD_DEFAULT("iconSet", "646464");
  64. ADD_DEFAULT("iconSetActive", "363636");
  65. ADD_DEFAULT("transitionScreen", "FFFFFF");
  66. ADD_DEFAULT("loadingColor", "898989");
  67. ADD_DEFAULT("loadingText", "353535");
  68. ADD_DEFAULT("freText", "420420");
  69. ADD_DEFAULT("versionText", "546978");
  70. ADD_DEFAULT("percentageText", "115599");
  71. ADD_DEFAULT("boxColor", "00FF7F");
  72. ADD_DEFAULT("boxOutlineColor", "008899");
  73. ADD_DEFAULT("dialogBackground", "CE2F06");
  74. ADD_DEFAULT("dialogButton", "FDE243");
  75. ADD_DEFAULT("dialogButtonText", "320F3C");
  76. ADD_DEFAULT("themeName", "My custom theme");
  77. ADD_DEFAULT("themeDesc", "Theme made by someone.");
  78. ADD_DEFAULT("themeVer", "x.y");
  79. getInstance().saveToFile();
  80. }
  81. bool Theme::loadFromFile(const std::string &filename)
  82. {
  83. rapidjson::Document &json = getInstance().m_json;
  84. std::string path = cpp3ds::FileSystem::getFilePath(filename);
  85. std::string jsonString;
  86. cpp3ds::FileInputStream file;
  87. if (!file.open(filename))
  88. return false;
  89. jsonString.resize(file.getSize());
  90. file.read(&jsonString[0], jsonString.size());
  91. json.Parse(jsonString.c_str());
  92. getInstance().loadDefaults();
  93. return !json.HasParseError();
  94. }
  95. const rapidjson::Value &Theme::get(std::string key)
  96. {
  97. return getInstance().m_json[key.c_str()];
  98. }
  99. void Theme::saveToFile(const std::string &filename)
  100. {
  101. std::string path = cpp3ds::FileSystem::getFilePath(filename);
  102. std::ofstream file(path);
  103. rapidjson::OStreamWrapper osw(file);
  104. rapidjson::Writer<rapidjson::OStreamWrapper> writer(osw);
  105. getInstance().m_json.Accept(writer);
  106. }
  107. void Theme::loadNameDesc()
  108. {
  109. themeName = _("Classic").toAnsiString();
  110. themeDesc = _("The default theme of freeShop.\nMade by arc13 / Cruel.").toAnsiString();
  111. }
  112. } // namespace FreeShop