2013-10-28 15:45:25 +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/.
2013-10-27 17:58:47 +00:00
# include "Core/Config.h"
# include "Core/System.h"
2023-02-01 14:35:57 +00:00
# include "Core/TiltEventProcessor.h"
2023-02-01 23:59:29 +00:00
# include "Core/ConfigValues.h"
2023-02-01 14:35:57 +00:00
# include "Common/Math/math_util.h"
2023-02-01 15:07:01 +00:00
# include "Common/Log.h"
2020-10-01 11:05:04 +00:00
# include "Common/Data/Text/I18n.h"
2013-10-27 17:58:47 +00:00
2023-02-01 14:35:57 +00:00
# include "UI/JoystickHistoryView.h"
2023-02-01 23:59:29 +00:00
# include "UI/GamepadEmu.h"
2023-02-01 14:35:57 +00:00
# include "UI/TiltAnalogSettingsScreen.h"
2013-10-28 11:28:46 +00:00
void TiltAnalogSettingsScreen : : CreateViews ( ) {
2013-10-27 17:58:47 +00:00
using namespace UI ;
2020-01-26 18:43:18 +00:00
auto co = GetI18NCategory ( " Controls " ) ;
auto di = GetI18NCategory ( " Dialog " ) ;
2013-10-27 17:58:47 +00:00
2023-02-02 10:59:56 +00:00
bool vertical = UseVerticalLayout ( ) ;
root_ = new LinearLayout ( vertical ? ORIENT_VERTICAL : ORIENT_HORIZONTAL ) ;
2016-01-23 06:52:13 +00:00
root_ - > SetTag ( " TiltAnalogSettings " ) ;
2013-10-27 17:58:47 +00:00
2023-02-02 10:59:56 +00:00
LinearLayout * settings = new LinearLayoutList ( ORIENT_VERTICAL ) ;
if ( vertical ) {
// Don't need a scrollview, probably..
root_ - > Add ( settings ) ;
} else {
ViewGroup * menuRoot = new ScrollView ( ORIENT_VERTICAL , new LinearLayoutParams ( 600 , FILL_PARENT ) ) ;
root_ - > Add ( menuRoot ) ;
menuRoot - > Add ( settings ) ;
}
2023-02-01 14:35:57 +00:00
2023-02-01 23:59:29 +00:00
if ( g_Config . iTiltInputType = = TILT_ANALOG ) {
tilt_ = new JoystickHistoryView ( StickHistoryViewType : : OTHER , " " , new LinearLayoutParams ( 1.0f ) ) ;
root_ - > Add ( tilt_ ) ;
} else {
AnchorLayout * rightSide = new AnchorLayout ( new LinearLayoutParams ( 1.0 ) ) ;
root_ - > Add ( rightSide ) ;
switch ( g_Config . iTiltInputType ) {
case TILT_DPAD :
{
PSPDpad * pad = rightSide - > Add ( new PSPDpad ( ImageID ( " I_DIR_LINE " ) , " D-pad " , ImageID ( " I_DIR_LINE " ) , ImageID ( " I_ARROW " ) , 1.5f , 1.3f , new AnchorLayoutParams ( NONE , NONE , NONE , NONE , true ) ) ) ;
pad - > SetForceVisible ( true ) ;
break ;
}
case TILT_ACTION_BUTTON :
{
PSPButton * circle = new PSPButton ( CTRL_CIRCLE , " Circle button " , ImageID ( " I_ROUND_LINE " ) , ImageID ( " I_ROUND " ) , ImageID ( " I_CIRCLE " ) , 1.5f , new AnchorLayoutParams ( NONE , NONE , 100.0f , NONE , true ) ) ;
PSPButton * cross = new PSPButton ( CTRL_CROSS , " Cross button " , ImageID ( " I_ROUND_LINE " ) , ImageID ( " I_ROUND " ) , ImageID ( " I_CROSS " ) , 1.5f , new AnchorLayoutParams ( NONE , NONE , NONE , 100.0f , true ) ) ;
PSPButton * triangle = new PSPButton ( CTRL_TRIANGLE , " Triangle button " , ImageID ( " I_ROUND_LINE " ) , ImageID ( " I_ROUND " ) , ImageID ( " I_TRIANGLE " ) , 1.5f , new AnchorLayoutParams ( NONE , 100.0f , NONE , NONE , true ) ) ;
PSPButton * square = new PSPButton ( CTRL_SQUARE , " Square button " , ImageID ( " I_ROUND_LINE " ) , ImageID ( " I_ROUND " ) , ImageID ( " I_SQUARE " ) , 1.5f , new AnchorLayoutParams ( 100.0f , NONE , NONE , NONE , true ) ) ;
circle - > SetForceVisible ( true ) ;
cross - > SetForceVisible ( true ) ;
triangle - > SetForceVisible ( true ) ;
square - > SetForceVisible ( true ) ;
rightSide - > Add ( circle ) ;
rightSide - > Add ( cross ) ;
rightSide - > Add ( triangle ) ;
rightSide - > Add ( square ) ;
break ;
}
case TILT_TRIGGER_BUTTONS :
{
PSPButton * lTrigger = new PSPButton ( CTRL_LTRIGGER , " Left shoulder button " , ImageID ( " I_SHOULDER_LINE " ) , ImageID ( " I_SHOULDER " ) , ImageID ( " I_L " ) , 1.5f , new AnchorLayoutParams ( 100.0f , NONE , NONE , NONE , true ) ) ;
PSPButton * rTrigger = new PSPButton ( CTRL_RTRIGGER , " Right shoulder button " , ImageID ( " I_SHOULDER_LINE " ) , ImageID ( " I_SHOULDER " ) , ImageID ( " I_R " ) , 1.5f , new AnchorLayoutParams ( NONE , NONE , 100.0f , NONE , true ) ) ;
rTrigger - > FlipImageH ( true ) ;
lTrigger - > SetForceVisible ( true ) ;
rTrigger - > SetForceVisible ( true ) ;
rightSide - > Add ( lTrigger ) ;
rightSide - > Add ( rTrigger ) ;
break ;
}
}
}
2023-02-01 14:35:57 +00:00
2023-02-02 09:29:16 +00:00
auto enabledFunc = [ = ] ( ) - > bool {
return g_Config . iTiltInputType ! = 0 ;
} ;
2013-10-28 15:04:53 +00:00
settings - > SetSpacing ( 0 ) ;
2023-02-01 13:17:01 +00:00
2023-02-02 09:53:42 +00:00
2023-02-02 09:29:16 +00:00
static const char * tiltTypes [ ] = { " None (Disabled) " , " Analog Stick " , " D-PAD " , " PSP Action Buttons " , " L/R Trigger Buttons " } ;
2023-02-02 09:53:42 +00:00
settings - > Add ( new ItemHeader ( co - > T ( " Tilt control setup " ) ) ) ;
2023-02-02 09:29:16 +00:00
settings - > Add ( new PopupMultiChoice ( & g_Config . iTiltInputType , co - > T ( " Tilt Input Type " ) , tiltTypes , 0 , ARRAY_SIZE ( tiltTypes ) , co - > GetName ( ) , screenManager ( ) ) ) - > OnChoice . Add (
[ = ] ( UI : : EventParams & p ) {
//when the tilt event type is modified, we need to reset all tilt settings.
//refer to the ResetTiltEvents() function for a detailed explanation.
TiltEventProcessor : : ResetTiltEvents ( ) ;
RecreateViews ( ) ;
return UI : : EVENT_DONE ;
} ) ;
2023-02-01 13:17:01 +00:00
settings - > Add ( new ItemHeader ( co - > T ( " Calibration " ) ) ) ;
2023-02-01 23:59:29 +00:00
TextView * calibrationInfo = new TextView ( co - > T ( " To Calibrate " , " Hold device at your preferred angle and press Calibrate. " ) ) ;
calibrationInfo - > SetSmall ( true ) ;
calibrationInfo - > SetPadding ( 5 ) ;
2023-02-01 13:17:01 +00:00
settings - > Add ( calibrationInfo ) ;
Choice * calibrate = new Choice ( co - > T ( " Calibrate " ) ) ;
calibrate - > OnClick . Handle ( this , & TiltAnalogSettingsScreen : : OnCalibrate ) ;
2023-02-02 09:29:16 +00:00
calibrate - > SetEnabledFunc ( enabledFunc ) ;
2023-02-01 13:17:01 +00:00
settings - > Add ( calibrate ) ;
2015-07-01 20:31:04 +00:00
settings - > Add ( new ItemHeader ( co - > T ( " Sensitivity " ) ) ) ;
2023-02-16 10:07:57 +00:00
if ( g_Config . iTiltInputType = = 1 ) {
2023-04-05 08:16:21 +00:00
settings - > Add ( new PopupSliderChoiceFloat ( & g_Config . fTiltAnalogDeadzoneRadius , 0.0f , 0.8f , 0.0f , co - > T ( " Deadzone radius " ) , 0.01f , screenManager ( ) , " / 1.0 " ) ) - > SetEnabledFunc ( enabledFunc ) ;
2023-02-11 22:42:55 +00:00
}
2023-04-05 08:35:41 +00:00
settings - > Add ( new PopupSliderChoice ( & g_Config . iTiltSensitivityX , 0 , 100 , 60 , co - > T ( " Tilt Sensitivity along X axis " ) , screenManager ( ) , " % " ) ) - > SetEnabledFunc ( enabledFunc ) ;
settings - > Add ( new PopupSliderChoice ( & g_Config . iTiltSensitivityY , 0 , 100 , 60 , co - > T ( " Tilt Sensitivity along Y axis " ) , screenManager ( ) , " % " ) ) - > SetEnabledFunc ( enabledFunc ) ;
2023-02-11 22:42:55 +00:00
settings - > Add ( new ItemHeader ( co - > T ( " Invert Axes " ) ) ) ;
settings - > Add ( new CheckBox ( & g_Config . bInvertTiltX , co - > T ( " Invert Tilt along X axis " ) ) ) - > SetEnabledFunc ( enabledFunc ) ;
settings - > Add ( new CheckBox ( & g_Config . bInvertTiltY , co - > T ( " Invert Tilt along Y axis " ) ) ) - > SetEnabledFunc ( enabledFunc ) ;
2013-10-27 17:58:47 +00:00
2021-09-28 00:47:15 +00:00
settings - > Add ( new BorderView ( BORDER_BOTTOM , BorderStyle : : HEADER_FG , 2.0f , new LayoutParams ( FILL_PARENT , 40.0f ) ) ) ;
2015-07-01 21:26:55 +00:00
settings - > Add ( new Choice ( di - > T ( " Back " ) ) ) - > OnClick . Handle < UIScreen > ( this , & UIScreen : : OnBack ) ;
2013-10-28 15:45:25 +00:00
}
2013-10-27 17:58:47 +00:00
2022-12-31 20:44:52 +00:00
void TiltAnalogSettingsScreen : : axis ( const AxisInput & axis ) {
2023-02-01 15:07:01 +00:00
UIDialogScreenWithGameBackground : : axis ( axis ) ;
2023-02-01 14:35:57 +00:00
2017-03-15 03:52:30 +00:00
if ( axis . deviceId = = DEVICE_ID_ACCELEROMETER ) {
2023-02-01 15:07:01 +00:00
switch ( axis . axisId ) {
case JOYSTICK_AXIS_ACCELEROMETER_X : down_ . x = axis . value ; break ;
case JOYSTICK_AXIS_ACCELEROMETER_Y : down_ . y = axis . value ; break ;
case JOYSTICK_AXIS_ACCELEROMETER_Z : down_ . z = axis . value ; break ;
2017-03-15 03:52:30 +00:00
}
}
2013-10-28 15:45:25 +00:00
}
2013-10-27 17:58:47 +00:00
2013-10-28 11:28:46 +00:00
UI : : EventReturn TiltAnalogSettingsScreen : : OnCalibrate ( UI : : EventParams & e ) {
2023-02-01 15:07:01 +00:00
Lin : : Vec3 down = down_ . normalized ( ) ;
g_Config . fTiltBaseAngleY = atan2 ( down . z , down . x ) ;
2013-10-27 17:58:47 +00:00
return UI : : EVENT_DONE ;
2013-10-28 15:45:25 +00:00
}
2013-10-27 17:58:47 +00:00
2023-02-01 14:35:57 +00:00
void TiltAnalogSettingsScreen : : update ( ) {
UIDialogScreenWithGameBackground : : update ( ) ;
2023-02-01 23:59:29 +00:00
if ( tilt_ ) {
tilt_ - > SetXY (
Clamp ( TiltEventProcessor : : rawTiltAnalogX , - 1.0f , 1.0f ) ,
Clamp ( TiltEventProcessor : : rawTiltAnalogY , - 1.0f , 1.0f ) ) ;
}
2023-02-01 14:35:57 +00:00
}