Etterna 0.74.4
Loading...
Searching...
No Matches
ThemeManager.h
1#ifndef THEMEMANAGER_H
2#define THEMEMANAGER_H
3
4#include "Etterna/Models/Lua/LuaReference.h"
5#include "RageUtil/Misc/RageTypes.h"
6
7#include <set>
8
9class IThemeMetric;
10class IniFile;
11struct lua_State;
12
13enum ElementCategory
14{
15 EC_BGANIMATIONS,
16 EC_FONTS,
17 EC_GRAPHICS,
18 EC_SOUNDS,
19 EC_OTHER,
20 NUM_ElementCategory,
21 ElementCategory_Invalid
22};
24#define FOREACH_ElementCategory(ec) FOREACH_ENUM(ElementCategory, ec)
25auto
26ElementCategoryToString(ElementCategory ec) -> const std::string&;
27auto
28StringToElementCategory(const std::string& s) -> ElementCategory;
29
30struct Theme;
33{
34 public:
37
38 void GetThemeNames(std::vector<std::string>& AddTo);
39 void GetSelectableThemeNames(std::vector<std::string>& AddTo);
40 auto GetNumSelectableThemes() -> int;
41 auto DoesThemeExist(const std::string& sThemeName) -> bool;
42 auto IsThemeSelectable(std::string const& name) -> bool;
43 auto IsThemeNameValid(std::string const& name) -> bool;
44 auto GetThemeDisplayName(const std::string& sThemeName) -> std::string;
45 auto GetThemeAuthor(const std::string& sThemeName) -> std::string;
46 void GetLanguages(std::vector<std::string>& AddTo);
47 auto DoesLanguageExist(const std::string& sLanguage) -> bool;
48 void SwitchThemeAndLanguage(const std::string& sThemeName,
49 const std::string& sLanguage,
50 bool bPseudoLocalize,
51 bool bForceThemeReload = false);
52 void UpdateLuaGlobals();
53 [[nodiscard]] auto GetCurThemeName() const -> std::string
54 {
55 return m_sCurThemeName;
56 };
57 [[nodiscard]] auto GetRealCurThemeName() const -> std::string
58 {
59 return m_sRealCurThemeName;
60 };
61 [[nodiscard]] auto IsThemeLoaded() const -> bool
62 {
63 return !m_sCurThemeName.empty();
64 };
65 [[nodiscard]] auto GetCurLanguage() const -> std::string
66 {
67 return m_sCurLanguage;
68 };
69 [[nodiscard]] auto GetCurThemeDir() const -> std::string
70 {
71 return GetThemeDirFromName(m_sCurThemeName);
72 };
73 auto GetNextTheme() -> std::string;
74 auto GetNextSelectableTheme() -> std::string;
75 void ReloadMetrics();
76 void ReloadSubscribers();
77 void ClearSubscribers();
78 void GetOptionNames(std::vector<std::string>& AddTo);
79
80 static void EvaluateString(std::string& sText);
81
82 struct PathInfo
83 {
84 std::string sResolvedPath;
85 std::string sMatchingMetricsGroup;
86 std::string sMatchingElement;
87 };
88
89 auto GetPathInfo(PathInfo& out,
90 ElementCategory category,
91 const std::string& sMetricsGroup,
92 const std::string& sElement,
93 bool bOptional = false) -> bool;
94 auto GetPath(ElementCategory category,
95 const std::string& sMetricsGroup,
96 const std::string& sElement,
97 bool bOptional = false) -> std::string;
98 auto GetPathB(const std::string& sMetricsGroup,
99 const std::string& sElement,
100 bool bOptional = false) -> std::string
101 {
102 return GetPath(EC_BGANIMATIONS, sMetricsGroup, sElement, bOptional);
103 };
104 auto GetPathF(const std::string& sMetricsGroup,
105 const std::string& sElement,
106 bool bOptional = false) -> std::string
107 {
108 return GetPath(EC_FONTS, sMetricsGroup, sElement, bOptional);
109 };
110 auto GetPathG(const std::string& sMetricsGroup,
111 const std::string& sElement,
112 bool bOptional = false) -> std::string
113 {
114 return GetPath(EC_GRAPHICS, sMetricsGroup, sElement, bOptional);
115 };
116 auto GetPathS(const std::string& sMetricsGroup,
117 const std::string& sElement,
118 bool bOptional = false) -> std::string
119 {
120 return GetPath(EC_SOUNDS, sMetricsGroup, sElement, bOptional);
121 };
122 auto GetPathO(const std::string& sMetricsGroup,
123 const std::string& sElement,
124 bool bOptional = false) -> std::string
125 {
126 return GetPath(EC_OTHER, sMetricsGroup, sElement, bOptional);
127 };
128 void ClearThemePathCache();
129
130 auto HasMetric(const std::string& sMetricsGroup,
131 const std::string& sValueName) -> bool;
132 void PushMetric(Lua* L,
133 const std::string& sMetricsGroup,
134 const std::string& sValueName);
135 auto GetMetric(const std::string& sMetricsGroup,
136 const std::string& sValueName) -> std::string;
137 auto GetMetricI(const std::string& sMetricsGroup,
138 const std::string& sValueName) -> int;
139 auto GetMetricF(const std::string& sMetricsGroup,
140 const std::string& sValueName) -> float;
141 auto GetMetricB(const std::string& sMetricsGroup,
142 const std::string& sValueName) -> bool;
143 auto GetMetricC(const std::string& sMetricsGroup,
144 const std::string& sValueName) -> RageColor;
145 auto GetMetricR(const std::string& sMetricsGroup,
146 const std::string& sValueName) -> LuaReference;
147#if !defined(SMPACKAGE)
148 auto GetMetricA(const std::string& sMetricsGroup,
149 const std::string& sValueName) -> apActorCommands;
150#endif
151
152 void GetMetric(const std::string& sMetricsGroup,
153 const std::string& sValueName,
154 LuaReference& valueOut);
155
156 // Languages
157 auto HasString(const std::string& sMetricsGroup,
158 const std::string& sValueName) -> bool;
159 auto GetString(const std::string& sMetricsGroup,
160 const std::string& sValueName) -> std::string;
161 void GetString(const std::string& sMetricsGroup,
162 const std::string& sValueName,
163 std::string& valueOut)
164 {
165 valueOut = GetString(sMetricsGroup, sValueName);
166 }
167 void FilterFileLanguages(std::vector<std::string>& asElementPaths);
168
169 void GetMetricsThatBeginWith(const std::string& sMetricsGroup,
170 const std::string& sValueName,
171 std::set<std::string>& vsValueNamesOut);
172
173 auto GetMetricsGroupFallback(const std::string& sMetricsGroup)
174 -> std::string;
175
176 static auto GetBlankGraphicPath() -> std::string;
177
178 // needs to be public for its binding to work
179 void RunLuaScripts(const std::string& sMask, bool bUseThemeDir = false);
180
181 // For self-registering metrics
182 static void Subscribe(IThemeMetric* p);
183 static void Unsubscribe(IThemeMetric* p);
184
185 // Lua
186 void PushSelf(lua_State* L);
187
188 protected:
189 void LoadThemeMetrics(const std::string& sThemeName,
190 const std::string& sLanguage_);
191 auto GetMetricRaw(const IniFile& ini,
192 const std::string& sMetricsGroup,
193 const std::string& sValueName) -> std::string;
194 auto GetMetricRawRecursive(const IniFile& ini,
195 const std::string& sMetricsGroup,
196 const std::string& sValueName,
197 std::string& sRet) -> bool;
198
199 auto GetPathInfoToAndFallback(PathInfo& out,
200 ElementCategory category,
201 const std::string& sMetricsGroup,
202 const std::string& sFile) -> bool;
203 auto GetPathInfoToRaw(PathInfo& out,
204 const std::string& sThemeName,
205 ElementCategory category,
206 const std::string& sMetricsGroup,
207 const std::string& sFile) -> bool;
208 static auto GetThemeDirFromName(const std::string& sThemeName)
209 -> std::string;
210 auto GetElementDir(const std::string& sThemeName) -> std::string;
211 static auto GetMetricsIniPath(const std::string& sThemeName) -> std::string;
212 static void GetLanguagesForTheme(const std::string& sThemeName,
213 std::vector<std::string>& asLanguagesOut);
214 static auto GetLanguageIniPath(const std::string& sThemeName,
215 const std::string& sLanguage) -> std::string;
216 void GetOptionalLanguageIniPaths(std::vector<std::string>& vsPathsOut,
217 const std::string& sThemeName,
218 const std::string& sLanguage);
219 auto GetDefaultLanguage() -> std::string;
220
221 std::string m_sCurThemeName;
222 std::string m_sRealCurThemeName = "";
223 std::string m_sCurLanguage;
224 bool m_bPseudoLocalize;
225};
226
227extern ThemeManager*
228 THEME; // global and accessible from anywhere in our program
229
230#endif
The general interface for reading ThemeMetrics.
Definition ThemeMetric.h:12
The functions to read and write .INI files.
Definition IniFile.h:11
A self-cleaning Lua reference.
Definition LuaReference.h:10
Manages theme paths and metrics.
Definition ThemeManager.h:33
Definition RageTypes.h:332
Definition ThemeManager.h:83
Definition ThemeManager.cpp:48