2016-08-07 17:59:35 -07:00
// Copyright (c) 2012- PPSSPP Project.
2013-10-13 10:26:51 +08:00
// 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/.
2020-08-09 21:20:42 -07:00
# include "i18n/i18n.h"
2020-08-10 00:12:51 -07:00
# include "Common/Serialize/Serializer.h"
# include "Common/Serialize/SerializeFuncs.h"
2014-03-15 10:38:46 -07:00
# include "Core/Config.h"
2020-08-09 21:20:42 -07:00
# include "Core/Dialog/PSPNetconfDialog.h"
2015-04-05 18:03:50 -07:00
# include "Core/MemMapHelpers.h"
2013-12-29 23:44:35 +01:00
# include "Core/HLE/sceNetAdhoc.h"
2014-01-31 19:08:52 -05:00
# include "Core/Util/PPGeDraw.h"
# include "Core/HLE/sceCtrl.h"
# include "Core/HLE/sceUtility.h"
2013-10-26 23:08:21 +01:00
2014-01-31 19:08:52 -05:00
# define NETCONF_CONNECT_APNET 0
# define NETCONF_STATUS_APNET 1
2013-10-26 23:08:21 +01:00
# define NETCONF_CONNECT_ADHOC 2
2020-03-15 12:22:21 -07:00
# define NETCONF_CONNECT_APNET_LAST 3
2013-10-26 23:08:21 +01:00
# define NETCONF_CREATE_ADHOC 4
# define NETCONF_JOIN_ADHOC 5
2013-10-13 10:26:51 +08:00
2020-03-15 12:22:21 -07:00
// Needs testing.
const static int NET_INIT_DELAY_US = 300000 ;
const static int NET_SHUTDOWN_DELAY_US = 26000 ;
2013-10-13 10:26:51 +08:00
PSPNetconfDialog : : PSPNetconfDialog ( ) {
}
PSPNetconfDialog : : ~ PSPNetconfDialog ( ) {
}
int PSPNetconfDialog : : Init ( u32 paramAddr ) {
// Already running
2020-03-15 12:22:21 -07:00
if ( status ! = SCE_UTILITY_STATUS_NONE )
2013-10-13 10:26:51 +08:00
return SCE_ERROR_UTILITY_INVALID_STATUS ;
int size = Memory : : Read_U32 ( paramAddr ) ;
memset ( & request , 0 , sizeof ( request ) ) ;
// Only copy the right size to support different request format
Memory : : Memcpy ( & request , paramAddr , size ) ;
2020-03-15 12:22:21 -07:00
ChangeStatusInit ( NET_INIT_DELAY_US ) ;
2014-01-31 23:16:39 -05:00
// Eat any keys pressed before the dialog inited.
2014-02-02 15:47:25 -08:00
UpdateButtons ( ) ;
2014-01-31 23:16:39 -05:00
2014-01-31 19:08:52 -05:00
StartFade ( true ) ;
2013-10-13 10:26:51 +08:00
return 0 ;
}
2014-01-31 19:08:52 -05:00
void PSPNetconfDialog : : DrawBanner ( ) {
PPGeDrawRect ( 0 , 0 , 480 , 23 , CalcFadedColor ( 0x65636358 ) ) ;
2014-01-31 23:16:39 -05:00
2020-05-23 21:21:16 -07:00
PPGeStyle textStyle = FadedStyle ( PPGeAlign : : BOX_VCENTER , 0.6f ) ;
textStyle . hasShadow = false ;
2014-01-31 23:16:39 -05:00
// TODO: Draw a hexagon icon
2020-05-23 21:21:16 -07:00
PPGeDrawImage ( 10 , 6 , 12.0f , 12.0f , 1 , 10 , 1 , 10 , 10 , 10 , textStyle . color ) ;
2020-01-26 10:43:18 -08:00
auto di = GetI18NCategory ( " Dialog " ) ;
2020-05-23 21:21:16 -07:00
PPGeDrawText ( di - > T ( " Network Connection " ) , 30 , 11 , textStyle ) ;
2014-01-31 19:08:52 -05:00
}
2013-10-16 18:54:17 +02:00
int PSPNetconfDialog : : Update ( int animSpeed ) {
2020-03-15 12:22:21 -07:00
if ( GetStatus ( ) ! = SCE_UTILITY_STATUS_RUNNING ) {
return SCE_ERROR_UTILITY_INVALID_STATUS ;
}
2014-02-02 15:47:25 -08:00
UpdateButtons ( ) ;
2020-01-26 10:43:18 -08:00
auto di = GetI18NCategory ( " Dialog " ) ;
auto err = GetI18NCategory ( " Error " ) ;
2014-01-31 19:08:52 -05:00
const float WRAP_WIDTH = 254.0f ;
2020-02-29 21:51:14 +01:00
const ImageID confirmBtnImage = g_Config . iButtonPreference = = PSP_SYSTEMPARAM_BUTTON_CROSS ? ImageID ( " I_CROSS " ) : ImageID ( " I_CIRCLE " ) ;
2014-01-31 19:08:52 -05:00
const int confirmBtn = g_Config . iButtonPreference = = PSP_SYSTEMPARAM_BUTTON_CROSS ? CTRL_CROSS : CTRL_CIRCLE ;
2020-05-23 21:21:16 -07:00
PPGeStyle textStyle = FadedStyle ( PPGeAlign : : BOX_CENTER , 0.5f ) ;
PPGeStyle buttonStyle = FadedStyle ( PPGeAlign : : BOX_LEFT , 0.5f ) ;
2020-03-15 12:22:21 -07:00
if ( request . netAction = = NETCONF_CONNECT_APNET | | request . netAction = = NETCONF_STATUS_APNET | | request . netAction = = NETCONF_CONNECT_APNET_LAST ) {
2014-01-31 19:08:52 -05:00
UpdateFade ( animSpeed ) ;
StartDraw ( ) ;
DrawBanner ( ) ;
PPGeDrawRect ( 0 , 0 , 480 , 272 , CalcFadedColor ( 0x63636363 ) ) ;
2020-05-23 21:21:16 -07:00
PPGeDrawTextWrapped ( err - > T ( " PPSSPPDoesNotSupportInternet " , " PPSSPP currently does not support connecting to the Internet for DLC, PSN, or game updates. " ) , 241 , 132 , WRAP_WIDTH , 0 , textStyle ) ;
PPGeDrawImage ( confirmBtnImage , 195 , 250 , 20 , 20 , buttonStyle ) ;
PPGeDrawText ( di - > T ( " OK " ) , 225 , 252 , buttonStyle ) ;
2014-01-31 19:08:52 -05:00
if ( IsButtonPressed ( confirmBtn ) ) {
StartFade ( false ) ;
2020-03-15 12:22:21 -07:00
ChangeStatus ( SCE_UTILITY_STATUS_FINISHED , 0 ) ;
2014-01-31 23:16:39 -05:00
// TODO: When the dialog is aborted, does it really set the result to this?
// It seems to make Phantasy Star Portable 2 happy, so it should be okay for now.
2014-01-31 19:08:52 -05:00
request . common . result = SCE_UTILITY_DIALOG_RESULT_ABORT ;
}
2020-03-15 12:22:21 -07:00
EndDraw ( ) ;
} else if ( request . netAction = = NETCONF_CONNECT_ADHOC | | request . netAction = = NETCONF_CREATE_ADHOC | | request . netAction = = NETCONF_JOIN_ADHOC ) {
if ( request . NetconfData . IsValid ( ) ) {
2014-01-31 19:08:52 -05:00
Shutdown ( true ) ;
2014-04-25 21:41:56 -04:00
if ( sceNetAdhocctlCreate ( request . NetconfData - > groupName ) = = 0 ) {
2020-03-15 12:22:21 -07:00
ChangeStatus ( SCE_UTILITY_STATUS_FINISHED , 0 ) ;
2014-01-31 19:08:52 -05:00
return 0 ;
}
return - 1 ;
}
}
2013-10-13 10:26:51 +08:00
return 0 ;
}
int PSPNetconfDialog : : Shutdown ( bool force ) {
if ( status ! = SCE_UTILITY_STATUS_FINISHED & & ! force )
return SCE_ERROR_UTILITY_INVALID_STATUS ;
2020-03-15 12:22:21 -07:00
PSPDialog : : Shutdown ( force ) ;
if ( ! force ) {
ChangeStatusShutdown ( NET_SHUTDOWN_DELAY_US ) ;
}
return 0 ;
2013-10-13 10:26:51 +08:00
}
2013-10-13 11:56:47 +08:00
void PSPNetconfDialog : : DoState ( PointerWrap & p ) {
PSPDialog : : DoState ( p ) ;
2013-10-13 10:26:51 +08:00
auto s = p . Section ( " PSPNetconfigDialog " , 0 , 1 ) ;
if ( ! s )
return ;
2020-08-09 21:20:42 -07:00
Do ( p , request ) ;
2013-10-26 23:08:21 +01:00
}