Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rapid fire to touch control #12601

Merged
merged 1 commit into from
Feb 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ static ConfigSetting controlSettings[] = {
ConfigSetting("fcombo4X", "fcombo4Y", "comboKeyScale4", "ShowComboKey4", &g_Config.touchCombo4, defaultTouchPosHide, true, true),
ConfigSetting("Speed1KeyX", "Speed1KeyY", "Speed1KeyScale", "ShowSpeed1Key", &g_Config.touchSpeed1Key, defaultTouchPosHide, true, true),
ConfigSetting("Speed2KeyX", "Speed2KeyY", "Speed2KeyScale", "ShowSpeed2Key", &g_Config.touchSpeed2Key, defaultTouchPosHide, true, true),
ConfigSetting("RapidFireKeyX", "RapidFireKeyY", "RapidFireKeyScale", "ShowRapidFireKey", &g_Config.touchRapidFireKey, defaultTouchPosHide, true, true),

#ifdef _WIN32
ConfigSetting("DInputAnalogDeadzone", &g_Config.fDInputAnalogDeadzone, 0.1f, true, true),
Expand Down Expand Up @@ -1599,6 +1600,7 @@ void Config::ResetControlLayout() {
reset(g_Config.touchCombo4);
reset(g_Config.touchSpeed1Key);
reset(g_Config.touchSpeed2Key);
reset(g_Config.touchRapidFireKey);
}

void Config::GetReportingInfo(UrlEncoder &data) {
Expand Down
1 change: 1 addition & 0 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ struct Config {
ConfigTouchPos touchCombo4;
ConfigTouchPos touchSpeed1Key;
ConfigTouchPos touchSpeed2Key;
ConfigTouchPos touchRapidFireKey;

// Controls Visibility
bool bShowTouchControls;
Expand Down
5 changes: 5 additions & 0 deletions Core/HLE/sceCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ void __CtrlSetRapidFire(bool state)
emuRapidFire = state;
}

bool __CtrlGetRapidFire()
{
return emuRapidFire;
}

static int __CtrlReadSingleBuffer(PSPPointer<CtrlData> data, bool negative)
{
if (data.IsValid())
Expand Down
1 change: 1 addition & 0 deletions Core/HLE/sceCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void __CtrlSetAnalogY(float value, int stick = CTRL_STICK_LEFT);

// Call this to enable rapid-fire. This will cause buttons other than arrows to alternate.
void __CtrlSetRapidFire(bool state);
bool __CtrlGetRapidFire();

// For use by internal UI like MsgDialog
u32 __CtrlPeekButtons();
Expand Down
10 changes: 7 additions & 3 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,9 @@ void EmuScreen::onVKeyDown(int virtualKeyCode) {
osm.Show(sc->T("replaceTextures_false", "Textures no longer are being replaced"), 2.0);
NativeMessageReceived("gpu_clearCache", "");
break;
case VIRTKEY_RAPID_FIRE:
__CtrlSetRapidFire(true);
break;
}
}

Expand Down Expand Up @@ -677,6 +680,10 @@ void EmuScreen::onVKeyUp(int virtualKeyCode) {
setVKeyAnalogY(CTRL_STICK_RIGHT, VIRTKEY_AXIS_RIGHT_Y_MIN, VIRTKEY_AXIS_RIGHT_Y_MAX);
break;

case VIRTKEY_RAPID_FIRE:
__CtrlSetRapidFire(false);
break;

default:
break;
}
Expand Down Expand Up @@ -1080,9 +1087,6 @@ void EmuScreen::update() {
if (invalid_)
return;

// Virtual keys.
__CtrlSetRapidFire(virtKeys[VIRTKEY_RAPID_FIRE - VIRTKEY_FIRST]);

// This is here to support the iOS on screen back button.
if (pauseTrigger_) {
pauseTrigger_ = false;
Expand Down
19 changes: 19 additions & 0 deletions UI/GamepadEmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,19 @@ void FPSLimitButton::Touch(const TouchInput &input) {
}
}

void RapidFireButton::Touch(const TouchInput &input) {
bool lastDown = pointerDownMask_ != 0;
MultiTouchButton::Touch(input);
bool down = pointerDownMask_ != 0;
if (down && !lastDown) {
__CtrlSetRapidFire(!__CtrlGetRapidFire());
}
}

bool RapidFireButton::IsDown() {
return __CtrlGetRapidFire();
}

bool FPSLimitButton::IsDown() {
return PSP_CoreParameter().fpsLimit == limit_;
}
Expand Down Expand Up @@ -510,6 +523,7 @@ void InitPadLayout(float xres, float yres, float globalScale) {

initTouchPos(g_Config.touchSpeed1Key, unthrottle_key_X, unthrottle_key_Y - 60 * scale);
initTouchPos(g_Config.touchSpeed2Key, unthrottle_key_X + bottom_key_spacing * scale, unthrottle_key_Y - 60 * scale);
initTouchPos(g_Config.touchRapidFireKey, unthrottle_key_X + 2*bottom_key_spacing * scale, unthrottle_key_Y - 60 * scale);

// L and R------------------------------------------------------------
// Put them above the analog stick / above the buttons to the right.
Expand Down Expand Up @@ -633,6 +647,11 @@ UI::ViewGroup *CreatePadLayout(float xres, float yres, bool *pause) {
});
}

if (g_Config.touchRapidFireKey.show) {
auto rapidFire = root->Add(new RapidFireButton(rectImage, I_RECT, I_ARROW, g_Config.touchRapidFireKey.scale, buttonLayoutParams(g_Config.touchRapidFireKey)));
rapidFire->SetAngle(90.0f, 180.0f);
}

FPSLimitButton *speed1 = addFPSLimitButton(FPSLimit::CUSTOM1, rectImage, I_RECT, I_ARROW, g_Config.touchSpeed1Key);
if (speed1)
speed1->SetAngle(170.0f, 180.0f);
Expand Down
9 changes: 9 additions & 0 deletions UI/GamepadEmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ class FPSLimitButton : public MultiTouchButton {
FPSLimit limit_;
};

class RapidFireButton : public MultiTouchButton {
public:
RapidFireButton(int bgImg, int bgDownImg, int img, float scale, UI::LayoutParams *layoutParams)
: MultiTouchButton(bgImg, bgDownImg, img, scale, layoutParams) {
}
void Touch(const TouchInput &input) override;
bool IsDown() override;
};

class PSPButton : public MultiTouchButton {
public:
PSPButton(int pspButtonBit, int bgImg, int bgDownImg, int img, float scale, UI::LayoutParams *layoutParams)
Expand Down
6 changes: 6 additions & 0 deletions UI/TouchControlLayoutScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@ void TouchControlLayoutScreen::CreateViews() {
controls_.push_back(speed2);
}

if (g_Config.touchRapidFireKey.show) {
DragDropButton *rapidFire = new DragDropButton(g_Config.touchRapidFireKey, rectImage, I_ARROW);
rapidFire->SetAngle(90.0f, 180.0f);
controls_.push_back(rapidFire);
}

if (g_Config.touchLKey.show) {
controls_.push_back(new DragDropButton(g_Config.touchLKey, shoulderImage, I_L));
}
Expand Down
1 change: 1 addition & 0 deletions UI/TouchControlVisibilityScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,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({ "Rapid Fire", &g_Config.touchRapidFireKey.show, -1 });

I18NCategory *mc = GetI18NCategory("MappableControls");

Expand Down