Skip to content

Commit

Permalink
DPad Analog
Browse files Browse the repository at this point in the history
Better multiple analog handling

More customizzable analog

RightAnalog mode fix

Remove now unused branch

Fix bad undefinite behavious

Update

try to fix submodule
  • Loading branch information
iota97 committed Nov 17, 2019
1 parent a8d2e51 commit e909853
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ static ConfigSetting generalSettings[] = {
ConfigSetting("GridView2", &g_Config.bGridView2, true),
ConfigSetting("GridView3", &g_Config.bGridView3, false),
ConfigSetting("ComboMode", &g_Config.iComboMode, 0),
ConfigSetting("RightAnalogMode", &g_Config.iRightAnalogMode, 0),
ConfigSetting("RightAnalogPress", &g_Config.iRightAnalogPress, 0),

// "default" means let emulator decide, "" means disable.
ConfigSetting("ReportingHost", &g_Config.sReportHost, "default"),
Expand Down
4 changes: 4 additions & 0 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ struct Config {
//Combo key screen flag
int iComboMode;

// Right analog mode
int iRightAnalogMode;
int iRightAnalogPress;

// Disable diagonals
bool bDisableDpadDiagonals;
bool bGamepadOnlyFocused;
Expand Down
42 changes: 40 additions & 2 deletions UI/GamepadEmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ void PSPStick::Touch(const TouchInput &input) {
}

void PSPStick::ProcessTouch(float x, float y, bool down) {
static const int analogButton[2][4] = {{CTRL_RIGHT, CTRL_DOWN, CTRL_LEFT, CTRL_UP},{CTRL_CIRCLE, CTRL_CROSS, CTRL_SQUARE, CTRL_TRIANGLE}};
static const int button[16] = {CTRL_LTRIGGER, CTRL_RTRIGGER, CTRL_SQUARE, CTRL_TRIANGLE, CTRL_CIRCLE, CTRL_CROSS, CTRL_UP, CTRL_DOWN, CTRL_LEFT, CTRL_RIGHT, CTRL_START, CTRL_SELECT};

if (down && centerX_ >= 0.0f) {
float inv_stick_size = 1.0f / (stick_size_ * scale_);

Expand All @@ -431,9 +434,40 @@ void PSPStick::ProcessTouch(float x, float y, bool down) {
dx = std::min(1.0f, std::max(-1.0f, dx));
dy = std::min(1.0f, std::max(-1.0f, dy));

if(stick_ == 2) { // Custom right analog
int rightAnalogMode = g_Config.iRightAnalogMode - 1; // 0 is the right analog mode
if(dx > 0.5f)
__CtrlButtonDown(analogButton[rightAnalogMode][0]);
else
__CtrlButtonUp(analogButton[rightAnalogMode][0]);
if (dx < -0.5f)
__CtrlButtonDown(analogButton[rightAnalogMode][2]);
else
__CtrlButtonUp(analogButton[rightAnalogMode][2]);
if(dy > 0.5f)
__CtrlButtonDown(analogButton[rightAnalogMode][1]);
else
__CtrlButtonUp(analogButton[rightAnalogMode][1]);
if (dy < -0.5f)
__CtrlButtonDown(analogButton[rightAnalogMode][3]);
else
__CtrlButtonUp(analogButton[rightAnalogMode][3]);

if (g_Config.iRightAnalogPress != 0) // 0 is disabled
__CtrlButtonDown(button[g_Config.iRightAnalogPress-1]);
}
__CtrlSetAnalogX(dx, stick_);
__CtrlSetAnalogY(-dy, stick_);
} else {
if(stick_ == 2) { // Custom right analog
int rightAnalogMode = g_Config.iRightAnalogMode - 1; // 0 is the right analog mode
__CtrlButtonUp(analogButton[rightAnalogMode][0]);
__CtrlButtonUp(analogButton[rightAnalogMode][1]);
__CtrlButtonUp(analogButton[rightAnalogMode][2]);
__CtrlButtonUp(analogButton[rightAnalogMode][3]);
if (g_Config.iRightAnalogPress != 0) // 0 is disabled
__CtrlButtonUp(button[g_Config.iRightAnalogPress-1]);
}
__CtrlSetAnalogX(0.0f, stick_);
__CtrlSetAnalogY(0.0f, stick_);
}
Expand Down Expand Up @@ -651,8 +685,12 @@ UI::ViewGroup *CreatePadLayout(float xres, float yres, bool *pause) {
if (g_Config.touchAnalogStick.show)
root->Add(new PSPStick(stickBg, stickImage, I_STICK, 0, g_Config.touchAnalogStick.scale, buttonLayoutParams(g_Config.touchAnalogStick)));

if (g_Config.touchRightAnalogStick.show)
root->Add(new PSPStick(stickBg, stickImage, I_STICK, 1, g_Config.touchRightAnalogStick.scale, buttonLayoutParams(g_Config.touchRightAnalogStick)));
if (g_Config.touchRightAnalogStick.show) {
if (g_Config.iRightAnalogMode == 0)
root->Add(new PSPStick(stickBg, stickImage, I_STICK, 1, g_Config.touchRightAnalogStick.scale, buttonLayoutParams(g_Config.touchRightAnalogStick)));
else
root->Add(new PSPStick(stickBg, stickImage, I_STICK, 2, g_Config.touchRightAnalogStick.scale, buttonLayoutParams(g_Config.touchRightAnalogStick)));
}

addComboKey(g_Config.iCombokey0, roundImage, I_ROUND, comboKeyImages[0], g_Config.touchCombo0);
addComboKey(g_Config.iCombokey1, roundImage, I_ROUND, comboKeyImages[1], g_Config.touchCombo1);
Expand Down
9 changes: 8 additions & 1 deletion UI/TouchControlVisibilityScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ void TouchControlVisibilityScreen::CreateViews() {
toggles_.push_back({ "Select", &g_Config.touchSelectKey.show, I_SELECT });
toggles_.push_back({ "Dpad", &g_Config.touchDpad.show, -1 });
toggles_.push_back({ "Analog Stick", &g_Config.touchAnalogStick.show, -1 });
toggles_.push_back({ "Right Analog Stick\n(not used by most games)", &g_Config.touchRightAnalogStick.show, -1 });
toggles_.push_back({ "Unthrottle", &g_Config.touchUnthrottleKey.show, -1 });
toggles_.push_back({ "Combo0", &g_Config.touchCombo0.show, I_1 });
toggles_.push_back({ "Combo1", &g_Config.touchCombo1.show, I_2 });
Expand All @@ -89,6 +88,7 @@ void TouchControlVisibilityScreen::CreateViews() {
toggles_.push_back({ "Combo4", &g_Config.touchCombo4.show, I_5 });
toggles_.push_back({ "Alt speed 1", &g_Config.touchSpeed1Key.show, -1 });
toggles_.push_back({ "Alt speed 2", &g_Config.touchSpeed2Key.show, -1 });
toggles_.push_back({ "Right Analog Stick", &g_Config.touchRightAnalogStick.show, -1 });

I18NCategory *mc = GetI18NCategory("MappableControls");

Expand All @@ -111,6 +111,13 @@ void TouchControlVisibilityScreen::CreateViews() {
row->Add(choice);
grid->Add(row);
}

static const char *rightAnalogModes[] = {"Right analog", "D-Pad", "Face button"};
View *rightAnalog = vert->Add(new PopupMultiChoice(&g_Config.iRightAnalogMode, co->T("Right analog mode"), rightAnalogModes, 0, ARRAY_SIZE(rightAnalogModes), co->GetName(), screenManager()));
rightAnalog->SetEnabledPtr(&g_Config.touchRightAnalogStick.show);
static const char *rightAnalogButton[] = {"Disabled", "Left trigger", "Right trigger", "Square", "Triangle", "Circle", "Cross", "Up", "Down", "Left", "Right", "Start", "Select"};
View *rightAnalogPress = vert->Add(new PopupMultiChoice(&g_Config.iRightAnalogPress, co->T("Right analog button on press"), rightAnalogButton, 0, ARRAY_SIZE(rightAnalogButton), co->GetName(), screenManager()));
rightAnalogPress->SetEnabledPtr(&g_Config.touchRightAnalogStick.show);
}

void TouchControlVisibilityScreen::onFinish(DialogResult result) {
Expand Down

0 comments on commit e909853

Please sign in to comment.