-
Notifications
You must be signed in to change notification settings - Fork 0
/
QRetroOptions.h
223 lines (178 loc) · 5.55 KB
/
QRetroOptions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#ifndef QRETRO_SETTINGS_H
#define QRETRO_SETTINGS_H
#include <QString>
#include <QStringList>
#include <QWidget>
#include <map>
#include "libretro.h"
enum Language
{
/// The index of a string with default language, defined as American English.
/// Used as a fallback if a localized string does not exist.
Default = 0,
/// The index of a localized string, determined via the frontend's reported
/// language. If this index leads to a blank string, the default language
/// string should be used instead.
Local,
Language_Size
};
class QRetroOptionCategory
{
public:
QRetroOptionCategory(retro_core_option_v2_category* us,
retro_core_option_v2_category* local = nullptr);
const char* title(Language lang = Default);
const char* description(Language lang = Default);
private:
std::string m_Title[Language_Size];
std::string m_Description[Language_Size];
};
class QRetroOption
{
public:
enum Type
{
/**
* The key exists, but has no defined values.
**/
None = 0,
/**
* The key is representitive of a choice between multiple defined string
* values.
**/
Choice,
/**
* The key is representitive of a bool. There should be two values:
* "enabled" and "disabled".
**/
Bool,
/**
* The key is representitive of an integer. All values should be strings
* that represent integers.
**/
Int,
/**
* The key is representitive of a float or double. All values should be
* strings that represent floating-point values.
**/
Float,
/**
* The key is representitive of an unknown data type.
**/
Type_Size
};
QRetroOption(retro_variable* var);
QRetroOption(retro_core_option_definition* us,
retro_core_option_definition* local = nullptr);
QRetroOption(retro_core_option_v2_definition* us,
retro_core_option_v2_definition* local = nullptr);
const char* title(Language lang = Local);
const char* getValue() { return m_CurrentValue.c_str(); }
void setValue(std::string val) { m_CurrentValue = val; }
bool getVisibility() { return m_Visible; }
void setVisibility(bool enabled) { m_Visible = enabled; }
bool setToDefaultValue();
QStringList possibleValues() { return m_PossibleValues[Default]; }
Type type() { return m_Type; }
private:
bool determineType();
const QRetroOptionCategory* m_Category;
std::string m_Title[Language_Size];
std::string m_TitleCategorized[Language_Size];
Type m_Type = None;
bool m_Visible = true;
std::string m_CurrentValue;
std::string m_DefaultValue;
QStringList m_PossibleValues[Language_Size];
};
class QRetroOptions : public QWidget
{
Q_OBJECT
public:
enum Version
{
/// Legacy format used by RETRO_ENVIRONMENT_SET_VARIABLES.
v0 = 0,
/// Format used by RETRO_ENVIRONMENT_SET_CORE_OPTIONS.
v1,
/// Format used by RETRO_ENVIRONMENT_SET_CORE_OPTIONS_V2.
v2
};
QRetroOptions();
~QRetroOptions();
QRetroOption* getOption(const char* key);
const char* getOptionValue(const char* key);
/**
* Sets the name of the core these options belong to. When writing options
* to a file, this will be used as a group header to separate the options
* of different cores.
*/
void setCoreName(const char *name) { m_CoreName = QString(name); }
/**
* Sets the filename that core options will be written to.
*/
void setFilename(const QString& filename) { m_Filename = filename; }
/**
* Sets the maximum core options API version the frontend reports to support.
* Used for RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION.
*/
void setMaxVersion(Version version) { m_MaxVersion = version; }
/**
* Sets the current value of an option with a given key.
*/
void setOptionValue(const char* key, const char* value);
/**
* Initializes core options using the legacy API format 0.
* Used for RETRO_ENVIRONMENT_SET_VARIABLES.
*/
void setOptions(retro_variable* vars);
/**
* Initializes core options using the API format 1.
* Used for RETRO_ENVIRONMENT_SET_CORE_OPTIONS.
*/
void setOptions(retro_core_option_definition** vars);
/**
* Initializes core options using the API format 1, with localization.
* Used for RETRO_ENVIRONMENT_SET_CORE_OPTIONS_INTL.
*/
void setOptions(retro_core_options_intl* vars);
/**
* Initializes core options using the API format 2.
* Used for RETRO_ENVIRONMENT_SET_CORE_OPTIONS_V2.
*/
void setOptions(retro_core_options_v2* vars);
/**
* Initializes core options using the API format 2, with localization.
* Used for RETRO_ENVIRONMENT_SET_CORE_OPTIONS_V2_INTL.
*/
void setOptions(retro_core_options_v2_intl* vars);
/**
* Toggles the visibility of an option with a given key.
* Used for RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY.
*/
void setVisibility(const char* key, bool enabled);
/**
* Returns whether or not option values have been updated. Will automatically
* reset to false if "quiet" is not true.
* Used for RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE.
*/
bool variablesUpdated(bool quiet = false);
/**
* Returns the greatest supported core options API version.
* Used for RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION.
*/
Version maxVersion() { return m_MaxVersion; }
void update();
public slots:
void onOptionBoolChanged(int state);
void onOptionChoiceChanged(const QString&);
private:
std::map<std::string, QRetroOptionCategory*> m_Categories;
QString m_CoreName;
QString m_Filename;
Version m_MaxVersion = Version::v1;
std::map<std::string, QRetroOption*> m_Variables;
Version m_Version;
bool m_VariablesUpdated;
};
#endif