Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/UI/GameScreen.cpp
5654 views
1
// Copyright (c) 2013- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#include <algorithm>
19
20
#include "ppsspp_config.h"
21
22
#include "Common/Render/DrawBuffer.h"
23
#include "Common/UI/Context.h"
24
#include "Common/UI/View.h"
25
#include "Common/UI/ViewGroup.h"
26
#include "Common/UI/PopupScreens.h"
27
#include "Common/UI/Notice.h"
28
#include "Common/Data/Text/I18n.h"
29
#include "Common/Data/Text/Parsers.h"
30
#include "Common/Data/Encoding/Utf8.h"
31
#include "Common/File/FileUtil.h"
32
#include "Common/StringUtils.h"
33
#include "Common/System/System.h"
34
#include "Common/System/OSD.h"
35
#include "Common/System/Request.h"
36
#include "Common/System/NativeApp.h"
37
#include "Core/Config.h"
38
#include "Core/Reporting.h"
39
#include "Core/System.h"
40
#include "Core/Loaders.h"
41
#include "Core/HLE/Plugins.h"
42
#include "Core/Util/GameDB.h"
43
#include "Core/Util/RecentFiles.h"
44
#include "Core/Util/PathUtil.h"
45
#include "UI/OnScreenDisplay.h"
46
#include "UI/Background.h"
47
#include "UI/CwCheatScreen.h"
48
#include "UI/EmuScreen.h"
49
#include "UI/GameScreen.h"
50
#include "UI/GameSettingsScreen.h"
51
#include "UI/GameInfoCache.h"
52
#include "UI/BaseScreens.h"
53
#include "UI/MiscScreens.h"
54
#include "UI/MainScreen.h"
55
#include "UI/BackgroundAudio.h"
56
#include "UI/SavedataScreen.h"
57
#include "UI/MiscViews.h"
58
59
constexpr GameInfoFlags g_desiredFlags = GameInfoFlags::PARAM_SFO | GameInfoFlags::ICON | GameInfoFlags::PIC0 | GameInfoFlags::PIC1 | GameInfoFlags::UNCOMPRESSED_SIZE | GameInfoFlags::SIZE;
60
61
GameScreen::GameScreen(const Path &gamePath, bool inGame) : UITwoPaneBaseDialogScreen(gamePath, TwoPaneFlags::SettingsToTheRight | TwoPaneFlags::CustomContextMenu), inGame_(inGame) {
62
g_BackgroundAudio.SetGame(gamePath);
63
System_PostUIMessage(UIMessage::GAME_SELECTED, gamePath.ToString());
64
65
info_ = g_gameInfoCache->GetInfo(NULL, gamePath_, g_desiredFlags, &knownFlags_);
66
}
67
68
GameScreen::~GameScreen() {
69
if (CRC32string == "...") {
70
Reporting::CancelCRC();
71
}
72
System_PostUIMessage(UIMessage::GAME_SELECTED, "");
73
}
74
75
template <typename I> std::string int2hexstr(I w, size_t hex_len = sizeof(I) << 1) {
76
static const char* digits = "0123456789ABCDEF";
77
std::string rc(hex_len, '0');
78
for (size_t i = 0, j = (hex_len - 1) * 4; i < hex_len; ++i, j -= 4)
79
rc[i] = digits[(w >> j) & 0x0f];
80
return rc;
81
}
82
83
void GameScreen::update() {
84
UIScreen::update();
85
86
GameInfoFlags hasFlags;
87
g_gameInfoCache->GetInfo(NULL, gamePath_, g_desiredFlags, &hasFlags);
88
89
bool recreate = false;
90
91
if (knownFlags_ != hasFlags) {
92
knownFlags_ = hasFlags;
93
recreate = true;
94
}
95
96
// Has the user requested a CRC32?
97
if (CRC32string == "...") {
98
// Wait until the CRC32 is ready. It might take time on some devices.
99
const bool hasCRC = Reporting::HasCRC(gamePath_);
100
if (hasCRC != knownHasCRC_) {
101
knownHasCRC_ = hasCRC;
102
recreate = true;
103
}
104
}
105
106
if (recreate) {
107
RecreateViews();
108
}
109
}
110
111
static bool FileTypeSupportsCRC(IdentifiedFileType fileType) {
112
switch (fileType) {
113
case IdentifiedFileType::PSP_PBP:
114
case IdentifiedFileType::PSP_PBP_DIRECTORY:
115
case IdentifiedFileType::PSP_ISO_NP:
116
case IdentifiedFileType::PSP_ISO:
117
return true;
118
default:
119
return false;
120
}
121
}
122
123
static bool FileTypeHasIcon(IdentifiedFileType fileType) {
124
switch (fileType) {
125
case IdentifiedFileType::PSP_PBP:
126
case IdentifiedFileType::PSP_PBP_DIRECTORY:
127
case IdentifiedFileType::PSP_ISO_NP:
128
case IdentifiedFileType::PSP_ISO:
129
case IdentifiedFileType::PSP_UMD_VIDEO_ISO:
130
return true;
131
default:
132
return false;
133
}
134
}
135
136
static bool FileTypeIsPlayable(IdentifiedFileType fileType) {
137
switch (fileType) {
138
case IdentifiedFileType::ERROR_IDENTIFYING:
139
case IdentifiedFileType::UNKNOWN:
140
case IdentifiedFileType::PSX_ISO:
141
case IdentifiedFileType::PS2_ISO:
142
case IdentifiedFileType::PS3_ISO:
143
case IdentifiedFileType::UNKNOWN_BIN:
144
case IdentifiedFileType::UNKNOWN_ELF:
145
case IdentifiedFileType::UNKNOWN_ISO:
146
case IdentifiedFileType::NORMAL_DIRECTORY:
147
case IdentifiedFileType::PSP_SAVEDATA_DIRECTORY:
148
case IdentifiedFileType::PSP_UMD_VIDEO_ISO:
149
// Reverse logic.
150
return false;
151
default:
152
return true;
153
}
154
}
155
156
void GameScreen::CreateContentViews(UI::ViewGroup *parent) {
157
if (!info_) {
158
// Shouldn't happen
159
return;
160
}
161
162
const bool portrait = GetDeviceOrientation() == DeviceOrientation::Portrait;
163
164
auto di = GetI18NCategory(I18NCat::DIALOG);
165
auto ga = GetI18NCategory(I18NCat::GAME);
166
167
// Information in the top left.
168
// Back button to the bottom left.
169
// Scrolling action menu to the right.
170
using namespace UI;
171
172
Margins actionMenuMargins(0, 15, 15, 0);
173
174
ScrollView *leftScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(1.0f, Margins(8)));
175
176
ViewGroup *leftColumn = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT));
177
178
leftScroll->Add(leftColumn);
179
180
parent->Add(leftScroll);
181
182
const bool fileTypeSupportCRC = FileTypeSupportsCRC(info_->fileType);
183
const bool fileTypeHasIcon = FileTypeHasIcon(info_->fileType);
184
185
// Need an explicit size here because homebrew uses screenshots as icons.
186
LinearLayout *mainGameInfo;
187
if (portrait) {
188
mainGameInfo = new LinearLayout(ORIENT_VERTICAL);
189
leftColumn->Add(new Spacer(8.0f));
190
if (fileTypeHasIcon) {
191
leftColumn->Add(new GameImageView(gamePath_, GameInfoFlags::ICON, 2.0f, new LinearLayoutParams(UI::Margins(0))));
192
}
193
leftColumn->Add(mainGameInfo);
194
} else {
195
mainGameInfo = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(1.0f));
196
ViewGroup *badgeHolder = new LinearLayout(ORIENT_HORIZONTAL);
197
if (fileTypeHasIcon) {
198
badgeHolder->Add(new GameImageView(gamePath_, GameInfoFlags::ICON, 2.0f, new LinearLayoutParams(144 * 2, 80 * 2, UI::Margins(0))));
199
}
200
badgeHolder->Add(mainGameInfo);
201
leftColumn->Add(badgeHolder);
202
}
203
mainGameInfo->SetSpacing(3.0f);
204
205
GameDBInfo dbInfo;
206
std::vector<GameDBInfo> dbInfos;
207
const bool inGameDB = g_gameDB.GetGameInfos(info_->id_version, &dbInfos);
208
209
if (knownFlags_ & GameInfoFlags::PARAM_SFO) {
210
std::string regionID = ReplaceAll(info_->id_version, "_", " v");
211
if (!regionID.empty()) {
212
regionID += ": ";
213
214
// Show the game ID title below the icon. The top title will be from the DB.
215
std::string title = info_->GetTitle();
216
217
TextView *tvTitle = mainGameInfo->Add(new TextView(title, ALIGN_LEFT | FLAG_WRAP_TEXT, false, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
218
tvTitle->SetShadow(true);
219
}
220
221
if (info_->region != GameRegion::UNKNOWN) {
222
regionID += GameRegionToString(info_->region);
223
} else {
224
regionID += IdentifiedFileTypeToString(info_->fileType);
225
}
226
227
TextView *tvID = mainGameInfo->Add(new TextView(regionID, ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
228
tvID->SetShadow(true);
229
230
if (!info_->errorString.empty()) {
231
mainGameInfo->Add(new NoticeView(NoticeLevel::WARN, info_->errorString, ""));
232
}
233
}
234
235
LinearLayout *infoLayout = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(10, 200, NONE, NONE));
236
leftColumn->Add(infoLayout);
237
238
if (info_->fileType == IdentifiedFileType::PSP_UMD_VIDEO_ISO) {
239
auto er = GetI18NCategory(I18NCat::ERRORS);
240
leftColumn->Add(new NoticeView(NoticeLevel::INFO, er->T("PPSSPP doesn't support UMD Video."), ""));
241
leftColumn->Add(new Choice(di->T("More info"), ImageID("I_LINK_OUT_QUESTION"), new LinearLayoutParams(WRAP_CONTENT, WRAP_CONTENT)))->OnClick.Add([](UI::EventParams &e) {
242
System_LaunchUrl(LaunchUrlType::BROWSER_URL, "https://www.ppsspp.org/docs/reference/umd-video/");
243
});
244
}
245
246
if ((knownFlags_ & GameInfoFlags::UNCOMPRESSED_SIZE) && (knownFlags_ & GameInfoFlags::SIZE)) {
247
auto st = GetI18NCategory(I18NCat::STORE); // Borrow the size string from here
248
char temp[256];
249
snprintf(temp, sizeof(temp), "%s: %s", st->T_cstr("Size"), NiceSizeFormat(info_->gameSizeOnDisk).c_str());
250
if (info_->gameSizeUncompressed != info_->gameSizeOnDisk) {
251
size_t len = strlen(temp);
252
snprintf(temp + len, sizeof(temp) - len, " (%s: %s)", ga->T_cstr("Uncompressed"), NiceSizeFormat(info_->gameSizeUncompressed).c_str());
253
}
254
TextView *tvGameSize = mainGameInfo->Add(new TextView(temp, ALIGN_LEFT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
255
tvGameSize->SetShadow(true);
256
257
if (info_->saveDataSize > 0) {
258
snprintf(temp, sizeof(temp), "%s: %s", ga->T_cstr("SaveData"), NiceSizeFormat(info_->saveDataSize).c_str());
259
TextView *tvSaveDataSize = infoLayout->Add(new TextView(temp, ALIGN_LEFT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
260
tvSaveDataSize->SetShadow(true);
261
}
262
if (info_->installDataSize > 0) {
263
snprintf(temp, sizeof(temp), "%s: %1.2f %s", ga->T_cstr("InstallData"), (float)(info_->installDataSize) / 1024.f / 1024.f, ga->T_cstr("MB"));
264
TextView *tvInstallDataSize = infoLayout->Add(new TextView(temp, ALIGN_LEFT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
265
tvInstallDataSize->SetShadow(true);
266
}
267
}
268
269
infoLayout->Add(new TextView(GetFriendlyPath(gamePath_), ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)))->SetShadow(true);
270
271
std::string timeStr;
272
if (g_Config.TimeTracker().GetPlayedTimeString(info_->id, &timeStr)) {
273
LinearLayout *timeHoriz = infoLayout->Add(new LinearLayout(ORIENT_HORIZONTAL));
274
275
TextView *tvPlayTime = timeHoriz->Add(new TextView(timeStr, ALIGN_LEFT, true, new LinearLayoutParams(0.0f, Gravity::G_VCENTER)));
276
tvPlayTime->SetShadow(true);
277
tvPlayTime->SetText(timeStr);
278
279
auto di = GetI18NCategory(I18NCat::DIALOG);
280
Choice *btnResetTime = timeHoriz->Add(new Choice(di->T("Reset"), new LinearLayoutParams(0.0f, Gravity::G_VCENTER)));
281
btnResetTime->OnClick.Add([this, ga, timeStr](UI::EventParams &) {
282
auto di = GetI18NCategory(I18NCat::DIALOG);
283
auto gta = GetI18NCategory(I18NCat::GAME);
284
std::string id = info_->id;
285
std::string questionText(ga->T("Are you sure you want to reset the played time counter?"));
286
questionText += "\n";
287
questionText += timeStr;
288
screenManager()->push(
289
new PromptScreen(gamePath_, questionText, di->T("Reset"), di->T("Cancel"), [id](bool yes) {
290
if (yes) {
291
g_Config.TimeTracker().Reset(id);
292
}
293
}));
294
RecreateViews();
295
});
296
}
297
298
LinearLayout *crcHoriz = infoLayout->Add(new LinearLayout(ORIENT_HORIZONTAL));
299
300
if (fileTypeSupportCRC) {
301
if (Reporting::HasCRC(gamePath_)) {
302
auto rp = GetI18NCategory(I18NCat::REPORTING);
303
uint32_t crcVal = Reporting::RetrieveCRC(gamePath_);
304
std::string crc = StringFromFormat("%08X", crcVal);
305
306
// CRC button makes sense.
307
TextView *tvCRC = crcHoriz->Add(new TextView(ReplaceAll(rp->T("FeedbackCRCValue", "Disc CRC: %1"), "%1", crc), ALIGN_LEFT, true, new LinearLayoutParams(0.0, Gravity::G_VCENTER)));
308
tvCRC->SetShadow(true);
309
310
if (System_GetPropertyBool(SYSPROP_HAS_TEXT_CLIPBOARD)) {
311
Choice *tvCRCCopy = crcHoriz->Add(new Choice(ImageID("I_FILE_COPY"), new LinearLayoutParams(0.0, Gravity::G_VCENTER)));
312
tvCRCCopy->OnClick.Add([this](UI::EventParams &) {
313
u32 crc = Reporting::RetrieveCRC(gamePath_);
314
char buffer[16];
315
snprintf(buffer, sizeof(buffer), "%08X", crc);
316
System_CopyStringToClipboard(buffer);
317
// Success indication. Not worth a translatable string.
318
g_OSD.Show(OSDType::MESSAGE_SUCCESS, buffer, 1.0f);
319
});
320
}
321
322
// Let's check the CRC in the game database, looking up the ID and also matching the crc.
323
std::vector<GameDBInfo> dbInfos;
324
if ((knownFlags_ & GameInfoFlags::PARAM_SFO) && g_gameDB.GetGameInfos(info_->id_version, &dbInfos)) {
325
bool found = false;
326
for (const auto &dbInfo : dbInfos) {
327
if (dbInfo.crc == crcVal) {
328
found = true;
329
}
330
}
331
if (found) {
332
NoticeView *tvVerified = infoLayout->Add(new NoticeView(NoticeLevel::INFO, ga->T("ISO OK according to the ReDump project"), "", new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
333
tvVerified->SetLevel(NoticeLevel::SUCCESS);
334
}
335
}
336
} else if (!isHomebrew_) {
337
if ((knownFlags_ & GameInfoFlags::PARAM_SFO) && !inGameDB) {
338
// tvVerified_->SetText(ga->T("Game ID unknown - not in the ReDump database"));
339
// tvVerified_->SetVisibility(UI::V_VISIBLE);
340
// tvVerified_->SetLevel(NoticeLevel::WARN);
341
} else if ((knownFlags_ & GameInfoFlags::UNCOMPRESSED_SIZE) && info_->gameSizeUncompressed != 0) { // don't do this check if info_ still pending
342
bool found = false;
343
for (auto &dbInfo : dbInfos) {
344
// TODO: Doesn't take CSO/CHD into account.
345
if (info_->gameSizeUncompressed == dbInfo.size) {
346
found = true;
347
}
348
}
349
if (!found) {
350
// tvVerified_->SetText(ga->T("File size incorrect, bad or modified ISO"));
351
// tvVerified_->SetVisibility(UI::V_VISIBLE);
352
// tvVerified_->SetLevel(NoticeLevel::ERROR);
353
// INFO_LOG(Log::Loader, "File size %d not matching game DB", (int)info_->gameSizeUncompressed);
354
}
355
356
NoticeView *tvVerified = infoLayout->Add(new NoticeView(NoticeLevel::INFO, ga->T("Click \"Calculate CRC\" to verify ISO"), "", new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
357
tvVerified->SetVisibility(UI::V_VISIBLE);
358
tvVerified->SetLevel(NoticeLevel::INFO);
359
}
360
}
361
}
362
363
NoticeView *tvVerified = infoLayout->Add(new NoticeView(NoticeLevel::INFO, ga->T("Click \"Calculate CRC\" to verify ISO"), "", new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
364
tvVerified->SetVisibility(UI::V_GONE);
365
tvVerified->SetSquishy(true);
366
367
// Show plugin info_, if any. Later might add checkboxes.
368
auto plugins = HLEPlugins::FindPlugins(info_->id, g_Config.sLanguageIni);
369
if (!plugins.empty()) {
370
auto sy = GetI18NCategory(I18NCat::SYSTEM);
371
infoLayout->Add(new ItemHeader(sy->T("Plugins")));
372
for (const auto &plugin : plugins) {
373
infoLayout->Add(new TextView(plugin.name, ALIGN_LEFT, true))->SetBullet(true);
374
}
375
}
376
377
infoLayout->Add(new GameImageView(gamePath_, GameInfoFlags::PIC0, 2.0f, new LinearLayoutParams(UI::Margins(0))));
378
}
379
380
void GameScreen::CreateSettingsViews(UI::ViewGroup *rightColumn) {
381
using namespace UI;
382
383
auto di = GetI18NCategory(I18NCat::DIALOG);
384
auto ga = GetI18NCategory(I18NCat::GAME);
385
386
const bool fileTypeSupportCRC = FileTypeSupportsCRC(info_->fileType);
387
const bool portrait = GetDeviceOrientation() == DeviceOrientation::Portrait;
388
389
LinearLayout *rightColumnItems = new LinearLayout(ORIENT_VERTICAL);
390
rightColumnItems->SetSpacing(0.0f);
391
rightColumn->Add(rightColumnItems);
392
393
if (!inGame_ && FileTypeIsPlayable(info_->fileType)) {
394
rightColumnItems->Add(new Choice(ga->T("Play"), ImageID("I_PLAY")))->OnClick.Handle(this, &GameScreen::OnPlay);
395
}
396
397
if (!info_->id.empty() && !inGame_) {
398
if (info_->hasConfig) {
399
// Only show the Game Settings button here if the game has a config. Always showing it
400
// is confusing since it'll just control the global settings.
401
Choice *btnGameSettings = rightColumnItems->Add(new Choice(ga->T("Game Settings"), ImageID("I_GEAR")));
402
btnGameSettings->OnClick.Handle(this, &GameScreen::OnGameSettings);
403
404
Choice *btnDeleteGameConfig = rightColumnItems->Add(new Choice(ga->T("Delete Game Config"), ImageID("I_TRASHCAN")));
405
btnDeleteGameConfig->OnClick.Handle(this, &GameScreen::OnDeleteConfig);
406
} else {
407
Choice *btnCreateGameConfig = rightColumnItems->Add(new Choice(ga->T("Create Game Config"), ImageID("I_GEAR_STAR")));
408
btnCreateGameConfig->OnClick.Handle(this, &GameScreen::OnCreateConfig);
409
}
410
}
411
412
if (g_Config.bEnableCheats) {
413
auto pa = GetI18NCategory(I18NCat::PAUSE);
414
rightColumnItems->Add(new Choice(pa->T("Cheats"), ImageID("I_CHEAT")))->OnClick.Handle(this, &GameScreen::OnCwCheat);
415
}
416
417
isHomebrew_ = info_ && info_->region == GameRegion::HOMEBREW;
418
419
if (fileTypeSupportCRC && !isHomebrew_ && !Reporting::HasCRC(gamePath_) ) {
420
rightColumnItems->Add(new Choice(ga->T("Calculate CRC"), ImageID("I_CHECKMARK")))->OnClick.Add([this](UI::EventParams &) {
421
Reporting::QueueCRC(gamePath_);
422
CRC32string = "..."; // signal that we're waiting for it. Kinda ugly.
423
});
424
}
425
}
426
427
void GameScreen::CreateContextMenu(UI::ViewGroup *parent) {
428
using namespace UI;
429
430
auto di = GetI18NCategory(I18NCat::DIALOG);
431
auto ga = GetI18NCategory(I18NCat::GAME);
432
433
if (System_GetPropertyBool(SYSPROP_CAN_SHOW_FILE)) {
434
parent->Add(new Choice(di->T("Show in folder"), ImageID("I_FOLDER")))->OnClick.Add([this](UI::EventParams &e) {
435
System_ShowFileInFolder(gamePath_);
436
});
437
}
438
439
// TODO: This is synchronous, bad!
440
if (!inGame_ && g_recentFiles.ContainsFile(gamePath_.ToString())) {
441
Choice *removeButton = parent->Add(new Choice(ga->T("Remove From Recent")));
442
removeButton->OnClick.Handle(this, &GameScreen::OnRemoveFromRecent);
443
}
444
445
if (info_->saveDataSize) {
446
Choice *btnDeleteSaveData = new Choice(ga->T("Delete Save Data"), ImageID("I_TRASHCAN"));
447
parent->Add(btnDeleteSaveData)->OnClick.Handle(this, &GameScreen::OnDeleteSaveData);
448
}
449
450
if (info_->pic1.texture) {
451
Choice *btnSetBackground = parent->Add(new Choice(ga->T("Use background as UI background")));
452
btnSetBackground->OnClick.Handle(this, &GameScreen::OnSetBackground);
453
}
454
455
if ((knownFlags_ & GameInfoFlags::PARAM_SFO) && System_GetPropertyBool(SYSPROP_CAN_CREATE_SHORTCUT)) {
456
parent->Add(new Choice(ga->T("Create Shortcut")))->OnClick.Add([this](UI::EventParams &e) {
457
GameInfoFlags hasFlags;
458
std::shared_ptr<GameInfo> info_ = g_gameInfoCache->GetInfo(NULL, gamePath_, GameInfoFlags::PARAM_SFO, &hasFlags);
459
if (hasFlags & GameInfoFlags::PARAM_SFO) {
460
System_CreateGameShortcut(gamePath_, info_->GetTitle());
461
g_OSD.Show(OSDType::MESSAGE_SUCCESS, GetI18NCategory(I18NCat::DIALOG)->T("Desktop shortcut created"), 2.0f);
462
}
463
});
464
}
465
466
// Don't want to be able to delete the game while it's running.
467
if (!inGame_) {
468
Choice *deleteChoice = parent->Add(new Choice(ga->T("Delete Game"), ImageID("I_WARNING")));
469
deleteChoice->OnClick.Handle(this, &GameScreen::OnDeleteGame);
470
}
471
}
472
473
void GameScreen::OnCreateConfig(UI::EventParams &e) {
474
if (!info_->Ready(GameInfoFlags::PARAM_SFO)) {
475
return;
476
}
477
g_Config.CreateGameConfig(info_->id);
478
g_Config.SaveGameConfig(info_->id, info_->GetTitle());
479
info_->hasConfig = true;
480
481
screenManager()->topScreen()->RecreateViews();
482
}
483
484
std::string_view GameScreen::GetTitle() const {
485
if (knownFlags_ & GameInfoFlags::PARAM_SFO) {
486
titleCache_ = info_->GetDBTitle();
487
}
488
489
return titleCache_;
490
}
491
492
void GameScreen::OnDeleteConfig(UI::EventParams &e) {
493
auto di = GetI18NCategory(I18NCat::DIALOG);
494
const bool trashAvailable = System_GetPropertyBool(SYSPROP_HAS_TRASH_BIN);
495
screenManager()->push(
496
new UI::MessagePopupScreen(di->T("Delete"), di->T("DeleteConfirmGameConfig", "Do you really want to delete the settings for this game?"),
497
trashAvailable ? di->T("Move to trash") : di->T("Delete"), di->T("Cancel"), [this](bool result) {
498
if (!result) {
499
return;
500
}
501
std::shared_ptr<GameInfo> info = g_gameInfoCache->GetInfo(nullptr, gamePath_, GameInfoFlags::PARAM_SFO);
502
if (!info->Ready(GameInfoFlags::PARAM_SFO)) {
503
return;
504
}
505
g_Config.DeleteGameConfig(info->id);
506
info->hasConfig = false;
507
RecreateViews();
508
}));
509
}
510
511
void GameScreen::OnCwCheat(UI::EventParams &e) {
512
screenManager()->push(new CwCheatScreen(gamePath_));
513
}
514
515
void GameScreen::OnSwitchBack(UI::EventParams &e) {
516
TriggerFinish(DR_OK);
517
}
518
519
void GameScreen::OnPlay(UI::EventParams &e) {
520
screenManager()->switchScreen(new EmuScreen(gamePath_));
521
}
522
523
void GameScreen::OnGameSettings(UI::EventParams &e) {
524
std::shared_ptr<GameInfo> info_ = g_gameInfoCache->GetInfo(NULL, gamePath_, GameInfoFlags::PARAM_SFO);
525
if (info_ && info_->Ready(GameInfoFlags::PARAM_SFO)) {
526
std::string discID = info_->GetParamSFO().GetValueString("DISC_ID");
527
if ((discID.empty() || !info_->disc_total) && gamePath_.FilePathContainsNoCase("PSP/GAME/"))
528
discID = g_paramSFO.GenerateFakeID(gamePath_);
529
screenManager()->push(new GameSettingsScreen(gamePath_, discID, true));
530
}
531
}
532
533
void GameScreen::OnDeleteSaveData(UI::EventParams &e) {
534
std::shared_ptr<GameInfo> info_ = g_gameInfoCache->GetInfo(NULL, gamePath_, GameInfoFlags::PARAM_SFO | GameInfoFlags::SIZE);
535
if (info_) {
536
// Check that there's any savedata to delete
537
if (info_->saveDataSize) {
538
const bool trashAvailable = System_GetPropertyBool(SYSPROP_HAS_TRASH_BIN);
539
auto di = GetI18NCategory(I18NCat::DIALOG);
540
Path gamePath = gamePath_;
541
screenManager()->push(
542
new UI::MessagePopupScreen(di->T("Delete"), di->T("DeleteConfirmAll", "Do you really want to delete all\nyour save data for this game?"), trashAvailable ? di->T("Move to trash") : di->T("Delete"), di->T("Cancel"),
543
[gamePath](bool yes) {
544
if (yes) {
545
std::shared_ptr<GameInfo> info_ = g_gameInfoCache->GetInfo(NULL, gamePath, GameInfoFlags::PARAM_SFO);
546
info_->DeleteAllSaveData();
547
info_->saveDataSize = 0;
548
info_->installDataSize = 0;
549
}
550
}));
551
}
552
}
553
RecreateViews();
554
}
555
556
void GameScreen::OnDeleteGame(UI::EventParams &e) {
557
std::shared_ptr<GameInfo> info_ = g_gameInfoCache->GetInfo(NULL, gamePath_, GameInfoFlags::PARAM_SFO);
558
if (info_->Ready(GameInfoFlags::PARAM_SFO)) {
559
auto di = GetI18NCategory(I18NCat::DIALOG);
560
auto ga = GetI18NCategory(I18NCat::GAME);
561
std::string prompt;
562
prompt = di->T("DeleteConfirmGame", "Do you really want to delete this game\nfrom your device? You can't undo this.");
563
prompt += "\n\n" + gamePath_.ToVisualString(g_Config.memStickDirectory.c_str());
564
const bool trashAvailable = System_GetPropertyBool(SYSPROP_HAS_TRASH_BIN);
565
Path gamePath = gamePath_;
566
ScreenManager *sm = screenManager();
567
screenManager()->push(
568
new UI::MessagePopupScreen(ga->T("Delete Game"), prompt, trashAvailable ? di->T("Move to trash") : di->T("Delete"), di->T("Cancel"),
569
[sm, gamePath](bool yes) {
570
if (yes) {
571
std::shared_ptr<GameInfo> info_ = g_gameInfoCache->GetInfo(NULL, gamePath, GameInfoFlags::PARAM_SFO);
572
info_->Delete();
573
g_gameInfoCache->Clear();
574
g_recentFiles.Remove(gamePath.c_str());
575
sm->switchScreen(new MainScreen());
576
}
577
}));
578
}
579
}
580
581
void GameScreen::OnRemoveFromRecent(UI::EventParams &e) {
582
g_recentFiles.Remove(gamePath_.ToString());
583
screenManager()->switchScreen(new MainScreen());
584
}
585
586
void GameScreen::OnSetBackground(UI::EventParams &e) {
587
auto ga = GetI18NCategory(I18NCat::GAME);
588
std::shared_ptr<GameInfo> info = g_gameInfoCache->GetInfo(nullptr, gamePath_, GameInfoFlags::PIC1);
589
if (!info->Ready(GameInfoFlags::PIC1)) {
590
return;
591
}
592
593
GameInfoTex *pic = nullptr;
594
if (info->pic1.dataLoaded && info->pic1.data.size()) {
595
pic = &info->pic1;
596
}
597
598
if (pic) {
599
const Path bgPng = GetSysDirectory(DIRECTORY_SYSTEM) / "background.png";
600
File::WriteStringToFile(false, pic->data, bgPng);
601
}
602
603
// Reinitializes the UI background.
604
UIBackgroundShutdown();
605
}
606
607