2013-06-02 11:43:15 +00:00
// Copyright (c) 2013- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
2014-06-21 21:03:50 +00:00
# include <algorithm>
2017-02-24 19:50:27 +00:00
# include "ppsspp_config.h"
2013-06-09 10:41:12 +00:00
# include "base/colorutil.h"
# include "base/timeutil.h"
2013-08-18 18:25:33 +00:00
# include "gfx_es2/draw_buffer.h"
2013-07-15 22:29:00 +00:00
# include "i18n/i18n.h"
2013-06-09 10:41:12 +00:00
# include "math/curves.h"
2013-12-11 19:19:30 +00:00
# include "util/text/utf8.h"
2013-06-09 10:41:12 +00:00
# include "ui/ui_context.h"
2013-06-08 20:42:31 +00:00
# include "ui/view.h"
# include "ui/viewgroup.h"
2017-03-26 17:02:34 +00:00
# include "Common/FileUtil.h"
# include "Core/Host.h"
# include "Core/Config.h"
# include "Core/System.h"
2016-06-19 22:18:35 +00:00
# include "UI/CwCheatScreen.h"
2013-06-08 20:42:31 +00:00
# include "UI/EmuScreen.h"
# include "UI/GameScreen.h"
# include "UI/GameSettingsScreen.h"
# include "UI/GameInfoCache.h"
2013-07-15 15:41:24 +00:00
# include "UI/MiscScreens.h"
2013-06-10 20:06:51 +00:00
# include "UI/MainScreen.h"
2014-06-22 15:02:04 +00:00
# include "UI/BackgroundAudio.h"
GameScreen : : GameScreen ( const std : : string & gamePath ) : UIDialogScreenWithGameBackground ( gamePath ) {
SetBackgroundAudioGame ( gamePath ) ;
}
GameScreen : : ~ GameScreen ( ) {
}
2013-06-08 20:42:31 +00:00
void GameScreen : : CreateViews ( ) {
2017-05-18 10:52:03 +00:00
std : : shared_ptr < GameInfo > info = g_gameInfoCache - > GetInfo ( NULL , gamePath_ , GAMEINFO_WANTBG | GAMEINFO_WANTSIZE ) ;
2013-06-08 20:42:31 +00:00
2017-03-25 05:02:22 +00:00
if ( info & & ! info - > id . empty ( ) )
2017-01-31 23:39:59 +00:00
saveDirs = info - > GetSaveDataDirectories ( ) ; // Get's very heavy, let's not do it in update()
2015-07-01 21:26:55 +00:00
I18NCategory * di = GetI18NCategory ( " Dialog " ) ;
2013-07-15 22:29:00 +00:00
I18NCategory * ga = GetI18NCategory ( " Game " ) ;
2016-06-19 22:18:35 +00:00
I18NCategory * pa = GetI18NCategory ( " Pause " ) ;
2013-07-15 22:29:00 +00:00
2013-06-08 20:42:31 +00:00
// Information in the top left.
// Back button to the bottom left.
// Scrolling action menu to the right.
using namespace UI ;
Margins actionMenuMargins ( 0 , 100 , 15 , 0 ) ;
root_ = new LinearLayout ( ORIENT_HORIZONTAL ) ;
ViewGroup * leftColumn = new AnchorLayout ( new LinearLayoutParams ( 1.0f ) ) ;
root_ - > Add ( leftColumn ) ;
2015-07-01 21:26:55 +00:00
leftColumn - > Add ( new Choice ( di - > T ( " Back " ) , " " , false , new AnchorLayoutParams ( 150 , WRAP_CONTENT , 10 , NONE , NONE , 10 ) ) ) - > OnClick . Handle ( this , & GameScreen : : OnSwitchBack ) ;
2013-06-08 20:42:31 +00:00
if ( info ) {
2017-01-30 13:33:38 +00:00
texvGameIcon_ = leftColumn - > Add ( new TextureView ( 0 , IS_DEFAULT , new AnchorLayoutParams ( 144 * 2 , 80 * 2 , 10 , 10 , NONE , NONE ) ) ) ;
2016-08-07 21:31:54 +00:00
LinearLayout * infoLayout = new LinearLayout ( ORIENT_VERTICAL , new AnchorLayoutParams ( 10 , 200 , NONE , NONE ) ) ;
leftColumn - > Add ( infoLayout ) ;
tvTitle_ = infoLayout - > Add ( new TextView ( info - > GetTitle ( ) , ALIGN_LEFT | FLAG_WRAP_TEXT , false , new LinearLayoutParams ( FILL_PARENT , WRAP_CONTENT ) ) ) ;
2015-02-15 10:21:17 +00:00
tvTitle_ - > SetShadow ( true ) ;
2016-08-07 21:31:54 +00:00
infoLayout - > Add ( new Spacer ( 12 ) ) ;
2013-12-08 06:48:12 +00:00
// This one doesn't need to be updated.
2016-08-07 21:31:54 +00:00
infoLayout - > Add ( new TextView ( gamePath_ , ALIGN_LEFT | FLAG_WRAP_TEXT , true , new LinearLayoutParams ( FILL_PARENT , WRAP_CONTENT ) ) ) - > SetShadow ( true ) ;
tvGameSize_ = infoLayout - > Add ( new TextView ( " ... " , ALIGN_LEFT , true , new LinearLayoutParams ( FILL_PARENT , WRAP_CONTENT ) ) ) ;
2015-02-15 10:21:17 +00:00
tvGameSize_ - > SetShadow ( true ) ;
2016-08-07 21:31:54 +00:00
tvSaveDataSize_ = infoLayout - > Add ( new TextView ( " ... " , ALIGN_LEFT , true , new LinearLayoutParams ( FILL_PARENT , WRAP_CONTENT ) ) ) ;
2015-02-15 10:21:17 +00:00
tvSaveDataSize_ - > SetShadow ( true ) ;
2016-08-07 21:31:54 +00:00
tvInstallDataSize_ = infoLayout - > Add ( new TextView ( " " , ALIGN_LEFT , true , new LinearLayoutParams ( FILL_PARENT , WRAP_CONTENT ) ) ) ;
2015-02-15 10:21:17 +00:00
tvInstallDataSize_ - > SetShadow ( true ) ;
2016-08-07 21:31:54 +00:00
tvInstallDataSize_ - > SetVisibility ( V_GONE ) ;
tvRegion_ = infoLayout - > Add ( new TextView ( " " , ALIGN_LEFT , true , new LinearLayoutParams ( FILL_PARENT , WRAP_CONTENT ) ) ) ;
2015-02-15 10:21:17 +00:00
tvRegion_ - > SetShadow ( true ) ;
2016-08-07 20:58:56 +00:00
} else {
texvGameIcon_ = nullptr ;
tvTitle_ = nullptr ;
tvGameSize_ = nullptr ;
tvSaveDataSize_ = nullptr ;
tvInstallDataSize_ = nullptr ;
tvRegion_ = nullptr ;
2013-06-08 20:42:31 +00:00
}
ViewGroup * rightColumn = new ScrollView ( ORIENT_VERTICAL , new LinearLayoutParams ( 300 , FILL_PARENT , actionMenuMargins ) ) ;
root_ - > Add ( rightColumn ) ;
2013-10-16 17:02:51 +00:00
LinearLayout * rightColumnItems = new LinearLayout ( ORIENT_VERTICAL ) ;
rightColumnItems - > SetSpacing ( 0.0f ) ;
2013-06-08 20:42:31 +00:00
rightColumn - > Add ( rightColumnItems ) ;
2016-08-07 20:58:56 +00:00
rightColumnItems - > Add ( new Choice ( ga - > T ( " Play " ) ) ) - > OnClick . Handle ( this , & GameScreen : : OnPlay ) ;
2017-03-26 17:02:34 +00:00
btnGameSettings_ = rightColumnItems - > Add ( new Choice ( ga - > T ( " Game Settings " ) ) ) ;
btnGameSettings_ - > OnClick . Handle ( this , & GameScreen : : OnGameSettings ) ;
btnDeleteGameConfig_ = rightColumnItems - > Add ( new Choice ( ga - > T ( " Delete Game Config " ) ) ) ;
btnDeleteGameConfig_ - > OnClick . Handle ( this , & GameScreen : : OnDeleteConfig ) ;
btnCreateGameConfig_ = rightColumnItems - > Add ( new Choice ( ga - > T ( " Create Game Config " ) ) ) ;
btnCreateGameConfig_ - > OnClick . Handle ( this , & GameScreen : : OnCreateConfig ) ;
btnGameSettings_ - > SetVisibility ( V_GONE ) ;
btnDeleteGameConfig_ - > SetVisibility ( V_GONE ) ;
btnCreateGameConfig_ - > SetVisibility ( V_GONE ) ;
btnDeleteSaveData_ = new Choice ( ga - > T ( " Delete Save Data " ) ) ;
rightColumnItems - > Add ( btnDeleteSaveData_ ) - > OnClick . Handle ( this , & GameScreen : : OnDeleteSaveData ) ;
btnDeleteSaveData_ - > SetVisibility ( V_GONE ) ;
2016-08-07 20:58:56 +00:00
2017-12-29 16:55:49 +00:00
if ( info & & ! info - > pending ) {
2017-01-31 23:39:59 +00:00
otherChoices_ . clear ( ) ;
}
2016-08-07 20:58:56 +00:00
rightColumnItems - > Add ( AddOtherChoice ( new Choice ( ga - > T ( " Delete Game " ) ) ) ) - > OnClick . Handle ( this , & GameScreen : : OnDeleteGame ) ;
2013-08-26 17:00:16 +00:00
if ( host - > CanCreateShortcut ( ) ) {
2016-08-07 20:58:56 +00:00
rightColumnItems - > Add ( AddOtherChoice ( new Choice ( ga - > T ( " Create Shortcut " ) ) ) ) - > OnClick . Handle ( this , & GameScreen : : OnCreateShortcut ) ;
2013-08-26 17:00:16 +00:00
}
2013-09-19 08:10:31 +00:00
if ( isRecentGame ( gamePath_ ) ) {
2016-08-07 20:58:56 +00:00
rightColumnItems - > Add ( AddOtherChoice ( new Choice ( ga - > T ( " Remove From Recent " ) ) ) ) - > OnClick . Handle ( this , & GameScreen : : OnRemoveFromRecent ) ;
2013-09-19 08:10:31 +00:00
}
2013-12-11 19:19:30 +00:00
# ifdef _WIN32
2016-08-07 20:58:56 +00:00
rightColumnItems - > Add ( AddOtherChoice ( new Choice ( ga - > T ( " Show In Folder " ) ) ) ) - > OnClick . Handle ( this , & GameScreen : : OnShowInFolder ) ;
2013-12-11 19:19:30 +00:00
# endif
2016-06-19 22:18:35 +00:00
if ( g_Config . bEnableCheats ) {
2016-08-07 20:58:56 +00:00
rightColumnItems - > Add ( AddOtherChoice ( new Choice ( pa - > T ( " Cheats " ) ) ) ) - > OnClick . Handle ( this , & GameScreen : : OnCwCheat ) ;
2016-06-19 22:18:35 +00:00
}
2017-03-26 17:02:34 +00:00
btnSetBackground_ = rightColumnItems - > Add ( new Choice ( ga - > T ( " Use UI background " ) ) ) ;
btnSetBackground_ - > OnClick . Handle ( this , & GameScreen : : OnSetBackground ) ;
btnSetBackground_ - > SetVisibility ( V_GONE ) ;
2013-06-08 20:42:31 +00:00
}
2016-08-07 20:58:56 +00:00
UI : : Choice * GameScreen : : AddOtherChoice ( UI : : Choice * choice ) {
otherChoices_ . push_back ( choice ) ;
// While loading.
choice - > SetVisibility ( UI : : V_GONE ) ;
return choice ;
}
2017-03-25 05:02:22 +00:00
UI : : EventReturn GameScreen : : OnCreateConfig ( UI : : EventParams & e ) {
2017-05-18 10:52:03 +00:00
std : : shared_ptr < GameInfo > info = g_gameInfoCache - > GetInfo ( nullptr , gamePath_ , 0 ) ;
2017-03-25 05:02:22 +00:00
if ( ! info ) {
return UI : : EVENT_SKIPPED ;
}
2014-12-14 19:33:20 +00:00
g_Config . createGameConfig ( info - > id ) ;
2014-12-19 13:52:44 +00:00
g_Config . saveGameConfig ( info - > id ) ;
2015-09-10 15:17:26 +00:00
info - > hasConfig = true ;
2014-12-19 13:52:44 +00:00
2014-12-14 19:33:20 +00:00
screenManager ( ) - > topScreen ( ) - > RecreateViews ( ) ;
return UI : : EVENT_DONE ;
}
2017-03-25 05:02:22 +00:00
void GameScreen : : CallbackDeleteConfig ( bool yes ) {
if ( yes ) {
2017-05-18 10:52:03 +00:00
std : : shared_ptr < GameInfo > info = g_gameInfoCache - > GetInfo ( nullptr , gamePath_ , 0 ) ;
2017-03-25 05:02:22 +00:00
if ( ! info ) {
return ;
}
2014-12-14 19:33:20 +00:00
g_Config . deleteGameConfig ( info - > id ) ;
2015-10-03 20:56:18 +00:00
info - > hasConfig = false ;
2014-12-14 19:33:20 +00:00
screenManager ( ) - > RecreateAllViews ( ) ;
}
}
UI : : EventReturn GameScreen : : OnDeleteConfig ( UI : : EventParams & e )
{
2015-07-01 21:26:55 +00:00
I18NCategory * di = GetI18NCategory ( " Dialog " ) ;
2014-12-14 19:33:20 +00:00
I18NCategory * ga = GetI18NCategory ( " Game " ) ;
screenManager ( ) - > push (
2015-07-01 21:26:55 +00:00
new PromptScreen ( di - > T ( " DeleteConfirmGameConfig " , " Do you really want to delete the settings for this game? " ) , ga - > T ( " ConfirmDelete " ) , di - > T ( " Cancel " ) ,
2016-10-12 09:32:24 +00:00
std : : bind ( & GameScreen : : CallbackDeleteConfig , this , std : : placeholders : : _1 ) ) ) ;
2014-12-14 19:33:20 +00:00
return UI : : EVENT_DONE ;
}
2017-03-15 05:01:18 +00:00
void GameScreen : : update ( ) {
UIScreen : : update ( ) ;
2013-06-08 20:42:31 +00:00
2013-08-30 17:00:25 +00:00
I18NCategory * ga = GetI18NCategory ( " Game " ) ;
2014-08-17 19:29:36 +00:00
2017-01-30 13:33:38 +00:00
Draw : : DrawContext * thin3d = screenManager ( ) - > getDrawContext ( ) ;
2014-08-17 19:29:36 +00:00
2017-05-18 10:52:03 +00:00
std : : shared_ptr < GameInfo > info = g_gameInfoCache - > GetInfo ( thin3d , gamePath_ , GAMEINFO_WANTBG | GAMEINFO_WANTSIZE ) ;
2013-06-09 11:41:15 +00:00
2013-06-08 20:42:31 +00:00
if ( tvTitle_ )
2015-12-24 21:18:46 +00:00
tvTitle_ - > SetText ( info - > GetTitle ( ) + " ( " + info - > id + " ) " ) ;
2017-03-26 07:00:57 +00:00
if ( info - > icon . texture & & texvGameIcon_ ) {
texvGameIcon_ - > SetTexture ( info - > icon . texture - > GetTexture ( ) ) ;
2014-06-21 21:03:50 +00:00
// Fade the icon with the background.
2017-03-26 07:00:57 +00:00
double loadTime = info - > icon . timeLoaded ;
if ( info - > pic1 . texture ) {
loadTime = std : : max ( loadTime , info - > pic1 . timeLoaded ) ;
2014-06-21 21:03:50 +00:00
}
2017-03-26 07:00:57 +00:00
if ( info - > pic0 . texture ) {
loadTime = std : : max ( loadTime , info - > pic0 . timeLoaded ) ;
2014-06-21 21:03:50 +00:00
}
uint32_t color = whiteAlpha ( ease ( ( time_now_d ( ) - loadTime ) * 3 ) ) ;
2013-06-09 11:41:15 +00:00
texvGameIcon_ - > SetColor ( color ) ;
}
2013-06-09 10:41:12 +00:00
if ( info - > gameSize ) {
char temp [ 256 ] ;
2013-08-30 17:00:25 +00:00
sprintf ( temp , " %s: %1.1f %s " , ga - > T ( " Game " ) , ( float ) ( info - > gameSize ) / 1024.f / 1024.f , ga - > T ( " MB " ) ) ;
2013-06-09 10:41:12 +00:00
tvGameSize_ - > SetText ( temp ) ;
2013-08-30 17:00:25 +00:00
sprintf ( temp , " %s: %1.2f %s " , ga - > T ( " SaveData " ) , ( float ) ( info - > saveDataSize ) / 1024.f / 1024.f , ga - > T ( " MB " ) ) ;
2013-06-09 10:41:12 +00:00
tvSaveDataSize_ - > SetText ( temp ) ;
2013-10-03 12:44:16 +00:00
if ( info - > installDataSize > 0 ) {
sprintf ( temp , " %s: %1.2f %s " , ga - > T ( " InstallData " ) , ( float ) ( info - > installDataSize ) / 1024.f / 1024.f , ga - > T ( " MB " ) ) ;
tvInstallDataSize_ - > SetText ( temp ) ;
2016-08-07 21:31:54 +00:00
tvInstallDataSize_ - > SetVisibility ( UI : : V_VISIBLE ) ;
2013-10-03 12:44:16 +00:00
}
2013-06-09 10:41:12 +00:00
}
2013-12-10 16:23:03 +00:00
if ( info - > region > = 0 & & info - > region < GAMEREGION_MAX & & info - > region ! = GAMEREGION_OTHER ) {
static const char * regionNames [ GAMEREGION_MAX ] = {
" Japan " ,
" USA " ,
" Europe " ,
" Hong Kong " ,
" Asia "
} ;
tvRegion_ - > SetText ( ga - > T ( regionNames [ info - > region ] ) ) ;
2017-05-26 21:15:04 +00:00
} else if ( info - > region > GAMEREGION_MAX ) {
tvRegion_ - > SetText ( ga - > T ( " Homebrew " ) ) ;
2013-12-10 16:23:03 +00:00
}
2016-08-07 20:58:56 +00:00
if ( ! info - > id . empty ( ) ) {
btnGameSettings_ - > SetVisibility ( info - > hasConfig ? UI : : V_VISIBLE : UI : : V_GONE ) ;
btnDeleteGameConfig_ - > SetVisibility ( info - > hasConfig ? UI : : V_VISIBLE : UI : : V_GONE ) ;
btnCreateGameConfig_ - > SetVisibility ( info - > hasConfig ? UI : : V_GONE : UI : : V_VISIBLE ) ;
if ( saveDirs . size ( ) ) {
btnDeleteSaveData_ - > SetVisibility ( UI : : V_VISIBLE ) ;
}
2017-03-26 17:02:34 +00:00
if ( info - > pic0 . texture | | info - > pic1 . texture ) {
btnSetBackground_ - > SetVisibility ( UI : : V_VISIBLE ) ;
}
2016-08-07 20:58:56 +00:00
}
2017-12-29 16:55:49 +00:00
if ( ! info - > pending ) {
2016-08-07 20:58:56 +00:00
// At this point, the above buttons won't become visible. We can show these now.
for ( UI : : Choice * choice : otherChoices_ ) {
choice - > SetVisibility ( UI : : V_VISIBLE ) ;
}
}
2013-06-09 10:41:12 +00:00
}
2013-12-11 19:19:30 +00:00
UI : : EventReturn GameScreen : : OnShowInFolder ( UI : : EventParams & e ) {
2017-02-24 19:50:27 +00:00
# if defined(_WIN32) && !PPSSPP_PLATFORM(UWP)
2013-12-11 19:19:30 +00:00
std : : string str = std : : string ( " explorer.exe /select, \" " ) + ReplaceAll ( gamePath_ , " / " , " \\ " ) + " \" " ;
_wsystem ( ConvertUTF8ToWString ( str ) . c_str ( ) ) ;
# endif
return UI : : EVENT_DONE ;
}
2016-06-19 22:18:35 +00:00
UI : : EventReturn GameScreen : : OnCwCheat ( UI : : EventParams & e ) {
screenManager ( ) - > push ( new CwCheatScreen ( gamePath_ ) ) ;
return UI : : EVENT_DONE ;
}
2013-06-09 10:41:12 +00:00
UI : : EventReturn GameScreen : : OnSwitchBack ( UI : : EventParams & e ) {
2017-03-20 00:43:03 +00:00
TriggerFinish ( DR_OK ) ;
2013-06-09 10:41:12 +00:00
return UI : : EVENT_DONE ;
2013-06-08 20:42:31 +00:00
}
UI : : EventReturn GameScreen : : OnPlay ( UI : : EventParams & e ) {
screenManager ( ) - > switchScreen ( new EmuScreen ( gamePath_ ) ) ;
return UI : : EVENT_DONE ;
}
UI : : EventReturn GameScreen : : OnGameSettings ( UI : : EventParams & e ) {
2017-05-18 10:52:03 +00:00
std : : shared_ptr < GameInfo > info = g_gameInfoCache - > GetInfo ( NULL , gamePath_ , GAMEINFO_WANTBG | GAMEINFO_WANTSIZE ) ;
2013-06-08 20:42:31 +00:00
if ( info & & info - > paramSFOLoaded ) {
std : : string discID = info - > paramSFO . GetValueString ( " DISC_ID " ) ;
2017-05-30 01:37:06 +00:00
if ( ( discID . empty ( ) | | ! info - > disc_total ) & & gamePath_ . find ( " /PSP/GAME/ " ) ! = std : : string : : npos )
discID = g_paramSFO . GenerateFakeID ( gamePath_ ) ;
2014-12-14 19:33:20 +00:00
screenManager ( ) - > push ( new GameSettingsScreen ( gamePath_ , discID , true ) ) ;
2013-06-08 20:42:31 +00:00
}
return UI : : EVENT_DONE ;
}
UI : : EventReturn GameScreen : : OnDeleteSaveData ( UI : : EventParams & e ) {
2015-07-01 21:26:55 +00:00
I18NCategory * di = GetI18NCategory ( " Dialog " ) ;
2013-08-30 17:00:25 +00:00
I18NCategory * ga = GetI18NCategory ( " Game " ) ;
2017-05-18 10:52:03 +00:00
std : : shared_ptr < GameInfo > info = g_gameInfoCache - > GetInfo ( NULL , gamePath_ , GAMEINFO_WANTBG | GAMEINFO_WANTSIZE ) ;
2013-06-08 20:42:31 +00:00
if ( info ) {
2014-07-21 18:59:03 +00:00
// Check that there's any savedata to delete
if ( saveDirs . size ( ) ) {
screenManager ( ) - > push (
2015-07-01 21:26:55 +00:00
new PromptScreen ( di - > T ( " DeleteConfirmAll " , " Do you really want to delete all \n your save data for this game? " ) , ga - > T ( " ConfirmDelete " ) , di - > T ( " Cancel " ) ,
2016-10-12 09:32:24 +00:00
std : : bind ( & GameScreen : : CallbackDeleteSaveData , this , std : : placeholders : : _1 ) ) ) ;
2014-07-21 18:59:03 +00:00
}
2013-06-08 20:42:31 +00:00
}
RecreateViews ( ) ;
return UI : : EVENT_DONE ;
}
2013-06-09 10:41:12 +00:00
void GameScreen : : CallbackDeleteSaveData ( bool yes ) {
2017-05-18 10:52:03 +00:00
std : : shared_ptr < GameInfo > info = g_gameInfoCache - > GetInfo ( NULL , gamePath_ , 0 ) ;
2013-06-09 10:41:12 +00:00
if ( yes ) {
info - > DeleteAllSaveData ( ) ;
2013-10-09 11:34:36 +00:00
info - > saveDataSize = 0 ;
info - > installDataSize = 0 ;
2013-06-09 10:41:12 +00:00
}
}
2013-06-08 20:42:31 +00:00
UI : : EventReturn GameScreen : : OnDeleteGame ( UI : : EventParams & e ) {
2015-07-01 21:26:55 +00:00
I18NCategory * di = GetI18NCategory ( " Dialog " ) ;
2013-08-30 17:00:25 +00:00
I18NCategory * ga = GetI18NCategory ( " Game " ) ;
2017-05-18 10:52:03 +00:00
std : : shared_ptr < GameInfo > info = g_gameInfoCache - > GetInfo ( NULL , gamePath_ , GAMEINFO_WANTBG | GAMEINFO_WANTSIZE ) ;
2013-06-08 20:42:31 +00:00
if ( info ) {
2013-06-09 10:41:12 +00:00
screenManager ( ) - > push (
2015-07-01 21:26:55 +00:00
new PromptScreen ( di - > T ( " DeleteConfirmGame " , " Do you really want to delete this game \n from your device? You can't undo this. " ) , ga - > T ( " ConfirmDelete " ) , di - > T ( " Cancel " ) ,
2016-10-12 09:32:24 +00:00
std : : bind ( & GameScreen : : CallbackDeleteGame , this , std : : placeholders : : _1 ) ) ) ;
2013-06-08 20:42:31 +00:00
}
2013-06-09 10:41:12 +00:00
return UI : : EVENT_DONE ;
}
void GameScreen : : CallbackDeleteGame ( bool yes ) {
2017-05-18 10:52:03 +00:00
std : : shared_ptr < GameInfo > info = g_gameInfoCache - > GetInfo ( NULL , gamePath_ , 0 ) ;
2013-06-09 10:41:12 +00:00
if ( yes ) {
2015-06-11 18:22:16 +00:00
info - > Delete ( ) ;
2016-02-14 21:07:10 +00:00
g_gameInfoCache - > Clear ( ) ;
2013-06-10 20:06:51 +00:00
screenManager ( ) - > switchScreen ( new MainScreen ( ) ) ;
2013-06-09 10:41:12 +00:00
}
}
2013-08-26 17:00:16 +00:00
UI : : EventReturn GameScreen : : OnCreateShortcut ( UI : : EventParams & e ) {
2017-05-18 10:52:03 +00:00
std : : shared_ptr < GameInfo > info = g_gameInfoCache - > GetInfo ( NULL , gamePath_ , 0 ) ;
2013-08-26 17:00:16 +00:00
if ( info ) {
2015-12-24 21:18:46 +00:00
host - > CreateDesktopShortcut ( gamePath_ , info - > GetTitle ( ) ) ;
2013-08-26 17:00:16 +00:00
}
return UI : : EVENT_DONE ;
}
2013-09-19 08:10:31 +00:00
2014-02-09 21:15:53 +00:00
bool GameScreen : : isRecentGame ( const std : : string & gamePath ) {
2014-06-29 03:44:24 +00:00
if ( g_Config . iMaxRecent < = 0 )
return false ;
2013-09-19 08:10:31 +00:00
for ( auto it = g_Config . recentIsos . begin ( ) ; it ! = g_Config . recentIsos . end ( ) ; + + it ) {
2013-11-19 12:46:33 +00:00
# ifdef _WIN32
2013-11-23 17:11:33 +00:00
if ( ! strcmpIgnore ( ( * it ) . c_str ( ) , gamePath . c_str ( ) , " \\ " , " / " ) )
2013-11-19 12:46:33 +00:00
# else
2013-11-23 17:11:33 +00:00
if ( ! strcmp ( ( * it ) . c_str ( ) , gamePath . c_str ( ) ) )
2013-11-19 12:46:33 +00:00
# endif
2013-09-19 08:10:31 +00:00
return true ;
}
return false ;
}
UI : : EventReturn GameScreen : : OnRemoveFromRecent ( UI : : EventParams & e ) {
2014-06-29 03:44:24 +00:00
if ( g_Config . iMaxRecent < = 0 )
return UI : : EVENT_DONE ;
2013-09-19 08:10:31 +00:00
for ( auto it = g_Config . recentIsos . begin ( ) ; it ! = g_Config . recentIsos . end ( ) ; + + it ) {
2013-11-19 12:46:33 +00:00
# ifdef _WIN32
2013-11-18 15:42:38 +00:00
if ( ! strcmpIgnore ( ( * it ) . c_str ( ) , gamePath_ . c_str ( ) , " \\ " , " / " ) ) {
2013-11-19 12:46:33 +00:00
# else
2013-11-23 17:11:33 +00:00
if ( ! strcmp ( ( * it ) . c_str ( ) , gamePath_ . c_str ( ) ) ) {
2013-11-19 12:46:33 +00:00
# endif
2013-09-19 08:10:31 +00:00
g_Config . recentIsos . erase ( it ) ;
screenManager ( ) - > switchScreen ( new MainScreen ( ) ) ;
return UI : : EVENT_DONE ;
}
}
return UI : : EVENT_DONE ;
2013-09-21 16:56:34 +00:00
}
2017-03-26 17:02:34 +00:00
class SetBackgroundPopupScreen : public PopupScreen {
public :
SetBackgroundPopupScreen ( const std : : string & title , const std : : string & gamePath ) ;
protected :
bool FillVertical ( ) const override { return false ; }
bool ShowButtons ( ) const override { return false ; }
void CreatePopupContents ( UI : : ViewGroup * parent ) override ;
void update ( ) override ;
private :
std : : string gamePath_ ;
double timeStart_ ;
double timeDone_ = 0.0 ;
enum class Status {
PENDING ,
DELAY ,
DONE ,
} ;
Status status_ = Status : : PENDING ;
} ;
SetBackgroundPopupScreen : : SetBackgroundPopupScreen ( const std : : string & title , const std : : string & gamePath )
: PopupScreen ( title ) , gamePath_ ( gamePath ) {
timeStart_ = time_now_d ( ) ;
}
void SetBackgroundPopupScreen : : CreatePopupContents ( UI : : ViewGroup * parent ) {
I18NCategory * ga = GetI18NCategory ( " Game " ) ;
parent - > Add ( new UI : : TextView ( ga - > T ( " One moment please... " ) , ALIGN_LEFT | ALIGN_VCENTER , false , new UI : : LinearLayoutParams ( UI : : Margins ( 10 , 0 , 10 , 10 ) ) ) ) ;
}
void SetBackgroundPopupScreen : : update ( ) {
PopupScreen : : update ( ) ;
2017-05-18 10:52:03 +00:00
std : : shared_ptr < GameInfo > info = g_gameInfoCache - > GetInfo ( nullptr , gamePath_ , GAMEINFO_WANTBG | GAMEINFO_WANTBGDATA ) ;
2017-12-29 16:55:49 +00:00
if ( status_ = = Status : : PENDING & & info & & ! info - > pending ) {
2017-03-26 17:02:34 +00:00
GameInfoTex * pic = nullptr ;
if ( info - > pic1 . dataLoaded & & info - > pic1 . data . size ( ) ) {
pic = & info - > pic1 ;
} else if ( info - > pic0 . dataLoaded & & info - > pic0 . data . size ( ) ) {
pic = & info - > pic0 ;
}
if ( pic ) {
const std : : string bgPng = GetSysDirectory ( DIRECTORY_SYSTEM ) + " background.png " ;
writeStringToFile ( false , pic - > data , bgPng . c_str ( ) ) ;
}
NativeMessageReceived ( " bgImage_updated " , " " ) ;
// It's worse if it flickers, stay open for at least 1s.
timeDone_ = timeStart_ + 1.0 ;
status_ = Status : : DELAY ;
}
if ( status_ = = Status : : DELAY & & timeDone_ < = time_now_d ( ) ) {
TriggerFinish ( DR_OK ) ;
status_ = Status : : DONE ;
}
}
UI : : EventReturn GameScreen : : OnSetBackground ( UI : : EventParams & e ) {
I18NCategory * ga = GetI18NCategory ( " Game " ) ;
2017-04-02 17:56:41 +00:00
// This popup is used to prevent any race condition:
// g_gameInfoCache may take time to load the data, and a crash could happen if they exit before then.
2017-03-26 17:02:34 +00:00
SetBackgroundPopupScreen * pop = new SetBackgroundPopupScreen ( ga - > T ( " Setting Background " ) , gamePath_ ) ;
if ( e . v )
pop - > SetPopupOrigin ( e . v ) ;
screenManager ( ) - > push ( pop ) ;
return UI : : EVENT_DONE ;
}