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

Auto rotating analog #12749

Merged
merged 2 commits into from
Mar 23, 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 Common/KeyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,8 @@ const KeyMap_IntStrPair psp_button_names[] = {
{VIRTKEY_TEXTURE_REPLACE, "Texture Replacement"},
{VIRTKEY_SCREENSHOT, "Screenshot"},
{VIRTKEY_MUTE_TOGGLE, "Mute toggle"},
{VIRTKEY_ANALOG_ROTATE_CW, "Rotate Analog (CW)"},
{VIRTKEY_ANALOG_ROTATE_CCW, "Rotate Analog (CCW)"},

{CTRL_HOME, "Home"},
{CTRL_HOLD, "Hold"},
Expand Down
2 changes: 2 additions & 0 deletions Common/KeyMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ enum {
VIRTKEY_SCREENSHOT = 0x4000001B,
VIRTKEY_MUTE_TOGGLE = 0x4000001C,
VIRTKEY_OPENCHAT = 0x4000001D,
VIRTKEY_ANALOG_ROTATE_CW = 0x4000001E,
VIRTKEY_ANALOG_ROTATE_CCW = 0x4000001F,
VIRTKEY_LAST,
VIRTKEY_COUNT = VIRTKEY_LAST - VIRTKEY_FIRST
};
Expand Down
5 changes: 5 additions & 0 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ static ConfigSetting controlSettings[] = {
ConfigSetting("TouchButtonOpacity", &g_Config.iTouchButtonOpacity, 65, true, true),
ConfigSetting("TouchButtonHideSeconds", &g_Config.iTouchButtonHideSeconds, 20, true, true),
ConfigSetting("AutoCenterTouchAnalog", &g_Config.bAutoCenterTouchAnalog, false, true, true),
ConfigSetting("AnalogAutoRotSpeed", &g_Config.fAnalogAutoRotSpeed, 15.0f, true, true),

// Snap touch control position
ConfigSetting("TouchSnapToGrid", &g_Config.bTouchSnapToGrid, false, true, true),
Expand Down Expand Up @@ -894,6 +895,8 @@ static ConfigSetting controlSettings[] = {
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),
ConfigSetting("AnalogRotationCWKeyX", "AnalogRotationKeyCWY", "AnalogRotationKeyCWScale", "ShowAnalogRotationCWKey", &g_Config.touchAnalogRotationCWKey, defaultTouchPosHide, true, true),
ConfigSetting("AnalogRotationCCWKeyX", "AnalogRotationKeyCCWY", "AnalogRotationKeyCCWScale", "ShowAnalogRotationCCWKey", &g_Config.touchAnalogRotationCCWKey, defaultTouchPosHide, true, true),

#ifdef _WIN32
ConfigSetting("DInputAnalogDeadzone", &g_Config.fDInputAnalogDeadzone, 0.1f, true, true),
Expand Down Expand Up @@ -1629,6 +1632,8 @@ void Config::ResetControlLayout() {
reset(g_Config.touchSpeed1Key);
reset(g_Config.touchSpeed2Key);
reset(g_Config.touchRapidFireKey);
reset(g_Config.touchAnalogRotationCWKey);
reset(g_Config.touchAnalogRotationCCWKey);
}

void Config::GetReportingInfo(UrlEncoder &data) {
Expand Down
4 changes: 4 additions & 0 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ struct Config {
int iTouchButtonStyle;
int iTouchButtonOpacity;
int iTouchButtonHideSeconds;
// Auto rotation speed
float fAnalogAutoRotSpeed;

// Snap touch control position
bool bTouchSnapToGrid;
Expand Down Expand Up @@ -325,6 +327,8 @@ struct Config {
ConfigTouchPos touchSpeed1Key;
ConfigTouchPos touchSpeed2Key;
ConfigTouchPos touchRapidFireKey;
ConfigTouchPos touchAnalogRotationCWKey;
ConfigTouchPos touchAnalogRotationCCWKey;

// Controls Visibility
bool bShowTouchControls;
Expand Down
30 changes: 30 additions & 0 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,14 @@ void EmuScreen::onVKeyDown(int virtualKeyCode) {
case VIRTKEY_MUTE_TOGGLE:
g_Config.bEnableSound = !g_Config.bEnableSound;
break;
case VIRTKEY_ANALOG_ROTATE_CW:
autoRotatingAnalogCW_ = true;
autoRotatingAnalogCCW_ = false;
break;
case VIRTKEY_ANALOG_ROTATE_CCW:
autoRotatingAnalogCW_ = false;
autoRotatingAnalogCCW_ = true;
break;
}
}

Expand Down Expand Up @@ -718,6 +726,18 @@ void EmuScreen::onVKeyUp(int virtualKeyCode) {
__CtrlSetRapidFire(false);
break;

case VIRTKEY_ANALOG_ROTATE_CW:
autoRotatingAnalogCW_ = false;
__CtrlSetAnalogX(0.0f, 0);
__CtrlSetAnalogY(0.0f, 0);
break;

case VIRTKEY_ANALOG_ROTATE_CCW:
autoRotatingAnalogCCW_ = false;
__CtrlSetAnalogX(0.0f, 0);
__CtrlSetAnalogY(0.0f, 0);
break;

default:
break;
}
Expand Down Expand Up @@ -1163,6 +1183,16 @@ void EmuScreen::update() {
if (invalid_)
return;

if (autoRotatingAnalogCW_) {
const float now = time_now_d();
__CtrlSetAnalogX(cos(now*-g_Config.fAnalogAutoRotSpeed), 0);
__CtrlSetAnalogY(sin(now*-g_Config.fAnalogAutoRotSpeed), 0);
} else if (autoRotatingAnalogCCW_) {
const float now = time_now_d();
__CtrlSetAnalogX(cos(now*g_Config.fAnalogAutoRotSpeed), 0);
__CtrlSetAnalogY(sin(now*g_Config.fAnalogAutoRotSpeed), 0);
}

// This is here to support the iOS on screen back button.
if (pauseTrigger_) {
pauseTrigger_ = false;
Expand Down
2 changes: 2 additions & 0 deletions UI/EmuScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,6 @@ class EmuScreen : public UIScreen {
UI::TextView *loadingTextView_ = nullptr;

UI::Button *cardboardDisableButton_ = nullptr;
bool autoRotatingAnalogCW_ = false;
bool autoRotatingAnalogCCW_ = false;
};
1 change: 1 addition & 0 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ void GameSettingsScreen::CreateViews() {
#else
controlsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fXInputAnalogSensitivity, 0.0f, 10.0f, co->T("Analog Axis Sensitivity", "Analog Axis Sensitivity"), 0.01f, screenManager(), "x"));
#endif
controlsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fAnalogAutoRotSpeed, 0.0f, 25.0f, co->T("Analog auto-rotation speed"), 1.0f, screenManager()));

controlsSettings->Add(new ItemHeader(co->T("Keyboard", "Keyboard Control Settings")));
#if defined(USING_WIN_UI)
Expand Down
44 changes: 42 additions & 2 deletions UI/GamepadEmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ void FPSLimitButton::Touch(const TouchInput &input) {
}
}

bool FPSLimitButton::IsDown() {
return PSP_CoreParameter().fpsLimit == limit_;
}

void RapidFireButton::Touch(const TouchInput &input) {
bool lastDown = pointerDownMask_ != 0;
MultiTouchButton::Touch(input);
Expand All @@ -175,8 +179,32 @@ bool RapidFireButton::IsDown() {
return __CtrlGetRapidFire();
}

bool FPSLimitButton::IsDown() {
return PSP_CoreParameter().fpsLimit == limit_;
void AnalogRotationButton::Touch(const TouchInput &input) {
bool lastDown = pointerDownMask_ != 0;
MultiTouchButton::Touch(input);
bool down = pointerDownMask_ != 0;
if (down && !lastDown) {
autoRotating_ = true;
} else if (lastDown && !down) {
autoRotating_ = false;
__CtrlSetAnalogX(0.0f, 0);
__CtrlSetAnalogY(0.0f, 0);
}
}

void AnalogRotationButton::Update() {
const float now = time_now();
float delta = now - lastFrameTime_;
if (delta > 0) {
secondsWithoutTouch_ += delta;
}
lastFrameTime_ = now;

if (autoRotating_) {
float speed = clockWise_ ? -g_Config.fAnalogAutoRotSpeed : g_Config.fAnalogAutoRotSpeed;
__CtrlSetAnalogX(cos(now*speed), 0);
__CtrlSetAnalogY(sin(now*speed), 0);
}
}

void PSPButton::Touch(const TouchInput &input) {
Expand Down Expand Up @@ -533,6 +561,8 @@ 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);
initTouchPos(g_Config.touchAnalogRotationCCWKey, unthrottle_key_X, unthrottle_key_Y - 120 * scale);
initTouchPos(g_Config.touchAnalogRotationCWKey, unthrottle_key_X + bottom_key_spacing * scale, unthrottle_key_Y - 120 * scale);

// L and R------------------------------------------------------------
// Put them above the analog stick / above the buttons to the right.
Expand Down Expand Up @@ -661,6 +691,16 @@ UI::ViewGroup *CreatePadLayout(float xres, float yres, bool *pause) {
rapidFire->SetAngle(90.0f, 180.0f);
}

if (g_Config.touchAnalogRotationCWKey.show) {
auto analogRotationCC = root->Add(new AnalogRotationButton(true, rectImage, ImageID("I_RECT"), ImageID("I_ARROW"), g_Config.touchAnalogRotationCWKey.scale, buttonLayoutParams(g_Config.touchAnalogRotationCWKey)));
analogRotationCC->SetAngle(190.0f, 180.0f);
}

if (g_Config.touchAnalogRotationCCWKey.show) {
auto analogRotationCCW = root->Add(new AnalogRotationButton(false, rectImage, ImageID("I_RECT"), ImageID("I_ARROW"), g_Config.touchAnalogRotationCCWKey.scale, buttonLayoutParams(g_Config.touchAnalogRotationCCWKey)));
analogRotationCCW->SetAngle(350.0f, 180.0f);
}

FPSLimitButton *speed1 = addFPSLimitButton(FPSLimit::CUSTOM1, rectImage, ImageID("I_RECT"), ImageID("I_ARROW"), g_Config.touchSpeed1Key);
if (speed1)
speed1->SetAngle(170.0f, 180.0f);
Expand Down
13 changes: 13 additions & 0 deletions UI/GamepadEmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ class RapidFireButton : public MultiTouchButton {
bool IsDown() override;
};

class AnalogRotationButton : public MultiTouchButton {
public:
AnalogRotationButton(bool clockWise, ImageID bgImg, ImageID bgDownImg, ImageID img, float scale, UI::LayoutParams *layoutParams)
: MultiTouchButton(bgImg, bgDownImg, img, scale, layoutParams), clockWise_(clockWise) {
}
void Touch(const TouchInput &input) override;
void Update() override;

private:
bool autoRotating_ = false;
bool clockWise_;
};

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

if (g_Config.touchAnalogRotationCWKey.show) {
DragDropButton *analogRotationCW = new DragDropButton(g_Config.touchAnalogRotationCWKey, rectImage, ImageID("I_ARROW"));
analogRotationCW->SetAngle(190.0f, 180.0f);
controls_.push_back(analogRotationCW);
}

if (g_Config.touchAnalogRotationCCWKey.show) {
DragDropButton *analogRotationCCW = new DragDropButton(g_Config.touchAnalogRotationCCWKey, rectImage, ImageID("I_ARROW"));
analogRotationCCW->SetAngle(350.0f, 180.0f);
controls_.push_back(analogRotationCCW);
}

if (g_Config.touchLKey.show) {
controls_.push_back(new DragDropButton(g_Config.touchLKey, shoulderImage, ImageID("I_L")));
}
Expand Down
2 changes: 2 additions & 0 deletions UI/TouchControlVisibilityScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ void TouchControlVisibilityScreen::CreateViews() {
toggles_.push_back({ "Alt speed 1", &g_Config.touchSpeed1Key.show, ImageID::invalid() });
toggles_.push_back({ "Alt speed 2", &g_Config.touchSpeed2Key.show, ImageID::invalid() });
toggles_.push_back({ "RapidFire", &g_Config.touchRapidFireKey.show, ImageID::invalid() });
toggles_.push_back({ "Auto Analog Rotation (CW)", &g_Config.touchAnalogRotationCWKey.show, ImageID::invalid() });
toggles_.push_back({ "Auto Analog Rotation (CCW)", &g_Config.touchAnalogRotationCCWKey.show, ImageID::invalid() });

auto mc = GetI18NCategory("MappableControls");

Expand Down