-
Notifications
You must be signed in to change notification settings - Fork 341
/
gamesettings.cpp
434 lines (378 loc) · 13.2 KB
/
gamesettings.cpp
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
#include <QCoreApplication>
#include <mythdb.h>
#include <mythdirs.h>
#include "gamesettings.h"
struct GameTypes {
QString m_nameStr;
QString m_idStr;
QString m_extensions;
};
const std::array<GameTypes,12> GameTypeList
{{
{ QT_TRANSLATE_NOOP("(GameTypes)", "OTHER"), "OTHER", "" },
{ QT_TRANSLATE_NOOP("(GameTypes)", "AMIGA"), "AMIGA", "adf,ipf" },
{ QT_TRANSLATE_NOOP("(GameTypes)", "ATARI"), "ATARI", "bin,a26" },
{ QT_TRANSLATE_NOOP("(GameTypes)", "GAMEGEAR"), "GAMEGEAR", "gg" },
{ QT_TRANSLATE_NOOP("(GameTypes)", "GENESIS/MEGADRIVE"), "GENESIS", "smd,bin,md" },
{ QT_TRANSLATE_NOOP("(GameTypes)", "MAME"), "MAME", "" },
{ QT_TRANSLATE_NOOP("(GameTypes)", "N64"), "N64", "v64,n64" },
{ QT_TRANSLATE_NOOP("(GameTypes)", "NES"), "NES", "zip,nes" },
{ QT_TRANSLATE_NOOP("(GameTypes)", "PC GAME"), "PC", "" },
{ QT_TRANSLATE_NOOP("(GameTypes)", "PCE/TG16"),"PCE", "pce" },
{ QT_TRANSLATE_NOOP("(GameTypes)", "SEGA/MASTER SYSTEM"), "SEGA", "sms" },
{ QT_TRANSLATE_NOOP("(GameTypes)", "SNES"), "SNES", "zip,smc,sfc,fig,swc" }
}};
QString GetGameTypeName(const QString &GameType)
{
QString result = "";
for (const auto & console : GameTypeList)
{
if (console.m_idStr == GameType) {
result = QCoreApplication::translate("(GameTypes)",
console.m_nameStr.toUtf8());
break;
}
}
return result;
}
QString GetGameTypeExtensions(const QString &GameType)
{
QString result = "";
for (const auto & console : GameTypeList)
{
if (console.m_idStr == GameType) {
result = console.m_extensions;
break;
}
}
return result;
}
// -----------------------------------------------------------------------
// General Settings
#undef TR
#define TR GameGeneralSettings::tr
static HostTextEditSetting *GameAllTreeLevels()
{
auto *gc = new HostTextEditSetting("GameAllTreeLevels");
gc->setLabel(TR("Game display order"));
gc->setValue("system gamename");
gc->setHelpText(TR("Order in which to sort the "
"games - this is for all "
"systems. Available choices: "
"system, year, genre and "
"gamename"));
return gc;
}
static HostTextEditSetting *GameFavTreeLevels()
{
auto *gc = new HostTextEditSetting("GameFavTreeLevels");
gc->setLabel(TR("Favorite display order"));
gc->setValue("gamename");
gc->setHelpText(TR("Order in which to sort the "
"games marked as favorites "
"- this is for all systems. "
"Available choices: system, "
"year, genre and gamename"));
return gc;
}
static HostCheckBoxSetting *GameDeepScan()
{
auto *gc = new HostCheckBoxSetting("GameDeepScan");
gc->setLabel(TR("Indepth Game Scan"));
gc->setHelpText(
TR("Enabling this causes a game scan to "
"gather CRC values and attempt to find out "
"more detailed information about the game: "
"NOTE this can greatly increase the time a "
"game scan takes based on the amount of "
"games scanned."));
return gc;
}
static HostCheckBoxSetting *GameRemovalPrompt()
{
auto *gc = new HostCheckBoxSetting("GameRemovalPrompt");
gc->setLabel(TR("Prompt for removal of deleted ROM(s)"));
gc->setHelpText(TR("This enables a prompt for "
"removing deleted ROMs from "
"the database during a game "
"scan"));
return gc;
}
static HostCheckBoxSetting *GameShowFileNames()
{
auto *gc = new HostCheckBoxSetting("GameShowFileNames");
gc->setLabel(TR("Display Files Names in Game "
"Tree"));
gc->setHelpText(TR("Enabling this causes the "
"filenames to be displayed in "
"the game tree rather than the "
"trimmed/looked up game name"));
return gc;
}
static HostCheckBoxSetting *GameTreeView()
{
auto *gc = new HostCheckBoxSetting("GameTreeView");
gc->setLabel(TR("Hash filenames in display"));
gc->setValue(0);
gc->setHelpText(TR("Enable hashing of names in "
"the display tree. This can "
"make navigating long lists "
"a little faster"));
return gc;
}
static HostTextEditSetting *GetScreenshotDir()
{
auto *gc = new HostTextEditSetting("mythgame.screenshotdir");
gc->setLabel(TR("Directory where Game Screenshots "
"are stored"));
gc->setValue(GetConfDir() + "/MythGame/Screenshots");
gc->setHelpText(TR("This directory will be the "
"default browse location when "
"assigning screenshots."));
return gc;
}
static HostTextEditSetting *GetFanartDir()
{
auto *gc = new HostTextEditSetting("mythgame.fanartdir");
gc->setLabel(TR("Directory where Game Fanart is "
"stored"));
gc->setValue(GetConfDir() + "/MythGame/Fanart");
gc->setHelpText(TR("This directory will be the "
"default browse location when "
"assigning fanart."));
return gc;
}
static HostTextEditSetting *GetBoxartDir()
{
auto *gc = new HostTextEditSetting("mythgame.boxartdir");
gc->setLabel(TR("Directory where Game Boxart is "
"stored"));
gc->setValue(GetConfDir() + "/MythGame/Boxart");
gc->setHelpText(TR("This directory will be the "
"default browse location when "
"assigning boxart."));
return gc;
}
GameGeneralSettings::GameGeneralSettings()
{
setLabel(tr("MythGame Settings -- General"));
addChild(GameAllTreeLevels());
addChild(GameFavTreeLevels());
addChild(GameDeepScan());
addChild(GameRemovalPrompt());
addChild(GameShowFileNames());
addChild(GameTreeView());
addChild(GetScreenshotDir());
addChild(GetFanartDir());
addChild(GetBoxartDir());
}
// -----------------------------------------------------------------------
// Player Settings
#undef TR
#define TR GamePlayerSetting::tr
/// Game player database table reader/writer
struct GameDBStorage : public SimpleDBStorage
{
GameDBStorage(StorageUser *user, const PlayerId &id, const QString &name)
: SimpleDBStorage(user, "gameplayers", name), m_id(id) {}
protected:
const PlayerId &m_id;
QString GetWhereClause(MSqlBindings &bindings) const override // SimpleStorage
{
bindings.insert(":PLAYERID", m_id.Value());
return "gameplayerid = :PLAYERID";
}
QString GetSetClause(MSqlBindings &bindings) const override // SimpleStorage
{
bindings.insert(":SETPLAYERID", m_id.Value());
bindings.insert(":SETCOLUMN", m_user->GetDBValue());
return QString("gameplayerid = :SETPLAYERID, "
"%2 = :SETCOLUMN").arg(GetColumnName());
}
};
/// Base for Game textual settings
struct TextEdit : public MythUITextEditSetting
{
explicit TextEdit(const PlayerId &parent, const QString& column) :
MythUITextEditSetting(new GameDBStorage(this, parent, column))
{}
};
struct Name : public TextEdit
{
explicit Name(const PlayerId &parent)
: TextEdit(parent, "playername")
{
setLabel(TR("Player Name"));
setHelpText(TR("Name of this Game and or Emulator"));
}
};
struct Command : public TextEdit
{
explicit Command(const PlayerId &parent)
: TextEdit(parent, "commandline")
{
setLabel(TR("Command"));
setHelpText(TR("Binary and optional parameters. Multiple commands "
"separated with \';\' . Use \%s for the ROM name. "
"\%d1, \%d2, \%d3 and \%d4 represent disks in a "
"multidisk/game. %s auto appended if not specified"));
}
};
struct GameType : public MythUIComboBoxSetting
{
explicit GameType(const PlayerId &parent) :
MythUIComboBoxSetting(new GameDBStorage(this, parent, "gametype"))
{
//: Game type
setLabel(TR("Type"));
for (const auto & console : GameTypeList)
{
addSelection(QCoreApplication::translate("(GameTypes)",
console.m_nameStr.toUtf8()),
console.m_idStr);
}
setValue(0);
setHelpText(TR("Type of Game/Emulator. Mostly for informational "
"purposes and has little effect on the "
"function of your system."));
}
};
struct RomPath : public TextEdit
{
explicit RomPath(const PlayerId &parent)
: TextEdit(parent, "rompath")
{
setLabel(TR("ROM Path"));
setHelpText(TR("Location of the ROM files for this emulator"));
}
};
struct WorkingDirPath : public TextEdit
{
explicit WorkingDirPath(const PlayerId &parent)
: TextEdit(parent, "workingpath")
{
setLabel(TR("Working Directory"));
setHelpText(TR("Directory to change to before launching emulator. "
"Blank is usually fine"));
}
};
struct Extensions : public TextEdit
{
explicit Extensions(const PlayerId &parent)
: TextEdit(parent, "extensions")
{
setLabel(TR("File Extensions"));
setHelpText(TR("A comma separated list of all file extensions for this "
"emulator. Blank means any file under ROM PATH is "
"considered to be used with this emulator"));
}
};
struct AllowMultipleRoms : public MythUICheckBoxSetting
{
explicit AllowMultipleRoms(const PlayerId &parent) :
MythUICheckBoxSetting(new GameDBStorage(this, parent, "spandisks"))
{
setLabel(TR("Allow games to span multiple ROMs/disks"));
setHelpText(TR("This setting means that we will look for items like "
"game.1.rom, game.2.rom and consider them a single game."));
}
};
/// Settings for a game player
GamePlayerSetting::GamePlayerSetting(const QString& name, uint id)
: m_id(id)
{
setName(name);
// Pre-set name for new players
auto *nameChild = new Name(m_id);
nameChild->setValue(name);
addChild(nameChild);
addChild(new GameType(m_id));
addChild(new Command(m_id));
addChild(new RomPath(m_id));
addChild(new WorkingDirPath(m_id));
addChild(new Extensions(m_id));
addChild(new AllowMultipleRoms(m_id));
}
void GamePlayerSetting::Save()
{
// Allocate id for new player
m_id.Save();
GroupSetting::Save();
}
void GamePlayerSetting::deleteEntry()
{
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("DELETE FROM gameplayers "
"WHERE gameplayerid = :PLAYERID");
query.bindValue(":PLAYERID", m_id.Value());
if (!query.exec() || !query.isActive())
MythDB::DBError("Deleting MythGamePlayerSettings:", query);
}
// -----------------------------------------------------------------------
GamePlayersList::GamePlayersList()
{
setLabel(tr("Game Players"));
}
void GamePlayersList::Load()
{
clearSettings();
auto *newPlayer = new ButtonStandardSetting(tr("(New Game Player)"));
addChild(newPlayer);
connect(newPlayer, &ButtonStandardSetting::clicked,
this, &GamePlayersList::NewPlayerDialog);
//: %1 is the player/emulator name, %2 is the type of player/emulator
QString playerDisp = tr("%1 (%2)", "Game player/emulator display");
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT gameplayerid, playername, gametype "
"FROM gameplayers "
"WHERE playername <> '' "
"ORDER BY playername;");
if (!query.exec() || !query.isActive())
{
MythDB::DBError("GamePlayersSetting::Load", query);
}
else
{
while (query.next())
{
int id = query.value(0).toInt();
QString name = query.value(1).toString();
QString type = query.value(2).toString();
auto *child = new GamePlayerSetting(name, id);
addChild(child);
child->setLabel(playerDisp.arg(name, GetGameTypeName(type)));
}
}
GroupSetting::Load();
}
void GamePlayersList::NewPlayerDialog() const
{
MythScreenStack *stack = GetMythMainWindow()->GetStack("popup stack");
auto *nameDialog = new MythTextInputDialog(stack, tr("Player Name"));
if (nameDialog->Create())
{
stack->AddScreen(nameDialog);
connect(nameDialog, &MythTextInputDialog::haveResult,
this, &GamePlayersList::CreateNewPlayer);
}
else
delete nameDialog;
}
void GamePlayersList::CreateNewPlayer(const QString& name)
{
if (name.isEmpty())
return;
// Database name must be unique
for (StandardSetting* child : *getSubSettings())
{
if (child->getName() == name)
{
LOG(VB_GENERAL, LOG_ERR,
QString("Player name %1 is already used").arg(name));
return;
}
}
addChild(new GamePlayerSetting(name));
// Redraw list
setVisible(true);
}