UI: Show custom speed toggle buttons.

This allows more flexibility if unthrottle is too fast or too uneven.
This commit is contained in:
Unknown W. Brackets 2018-06-16 23:00:21 -07:00
parent 69dd59d9b9
commit f2956a1c1a
6 changed files with 79 additions and 7 deletions

View File

@ -723,6 +723,8 @@ static ConfigSetting controlSettings[] = {
ConfigSetting("fcombo2X", "fcombo2Y", "comboKeyScale2", "ShowComboKey2", &g_Config.touchCombo2, defaultTouchPosHide, true, true),
ConfigSetting("fcombo3X", "fcombo3Y", "comboKeyScale3", "ShowComboKey3", &g_Config.touchCombo3, defaultTouchPosHide, true, true),
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),
#ifdef _WIN32
ConfigSetting("DInputAnalogDeadzone", &g_Config.fDInputAnalogDeadzone, 0.1f, true, true),
@ -1428,6 +1430,8 @@ void Config::ResetControlLayout() {
reset(g_Config.touchCombo2);
reset(g_Config.touchCombo3);
reset(g_Config.touchCombo4);
reset(g_Config.touchSpeed1Key);
reset(g_Config.touchSpeed2Key);
}
void Config::GetReportingInfo(UrlEncoder &data) {

View File

@ -294,6 +294,8 @@ public:
ConfigTouchPos touchCombo2;
ConfigTouchPos touchCombo3;
ConfigTouchPos touchCombo4;
ConfigTouchPos touchSpeed1Key;
ConfigTouchPos touchSpeed2Key;
// Controls Visibility
bool bShowTouchControls;

View File

@ -107,7 +107,7 @@ void MultiTouchButton::Draw(UIContext &dc) {
uint32_t colorBg = colorAlpha(GetButtonColor(), opacity);
uint32_t color = colorAlpha(0xFFFFFF, opacity);
dc.Draw()->DrawImageRotated(bgImg_, bounds_.centerX(), bounds_.centerY(), scale, angle_ * (M_PI * 2 / 360.0f), colorBg, flipImageH_);
dc.Draw()->DrawImageRotated(bgImg_, bounds_.centerX(), bounds_.centerY(), scale, bgAngle_ * (M_PI * 2 / 360.0f), colorBg, flipImageH_);
int y = bounds_.centerY();
// Hack round the fact that the center of the rectangular picture the triangle is contained in
@ -127,6 +127,26 @@ void BoolButton::Touch(const TouchInput &input) {
}
}
void FPSLimitButton::Touch(const TouchInput &input) {
bool lastDown = pointerDownMask_ != 0;
MultiTouchButton::Touch(input);
bool down = pointerDownMask_ != 0;
if (!down && lastDown && IsDown()) {
PSP_CoreParameter().fpsLimit = FPSLimit::NORMAL;
} else if (down && !lastDown && PSP_CoreParameter().fpsLimit == FPSLimit::NORMAL) {
int limit = limit_ == FPSLimit::CUSTOM1 ? g_Config.iFpsLimit1 : g_Config.iFpsLimit2;
// Validate it actually has a setting (may this should override visible?)
if (limit >= 0) {
PSP_CoreParameter().fpsLimit = limit_;
}
}
}
bool FPSLimitButton::IsDown() {
return PSP_CoreParameter().fpsLimit == limit_;
}
void PSPButton::Touch(const TouchInput &input) {
bool lastDown = pointerDownMask_ != 0;
MultiTouchButton::Touch(input);
@ -445,6 +465,9 @@ void InitPadLayout(float xres, float yres, float globalScale) {
int unthrottle_key_Y = yres - 60 * scale;
initTouchPos(g_Config.touchUnthrottleKey, unthrottle_key_X, unthrottle_key_Y);
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);
// L and R------------------------------------------------------------
// Put them above the analog stick / above the buttons to the right.
// The corners were very hard to reach..
@ -532,6 +555,12 @@ UI::ViewGroup *CreatePadLayout(float xres, float yres, bool *pause) {
}
return nullptr;
};
auto addFPSLimitButton = [=](FPSLimit value, int bgImg, int img, const ConfigTouchPos &touch) -> FPSLimitButton * {
if (touch.show) {
return root->Add(new FPSLimitButton(value, bgImg, img, touch.scale, buttonLayoutParams(touch)));
}
return nullptr;
};
if (!System_GetPropertyBool(SYSPROP_HAS_BACK_BUTTON) || g_Config.bShowTouchPause) {
root->Add(new BoolButton(pause, roundImage, I_ARROW, 1.0f, new AnchorLayoutParams(halfW, 20, NONE, NONE, true)))->SetAngle(90);
@ -552,7 +581,14 @@ UI::ViewGroup *CreatePadLayout(float xres, float yres, bool *pause) {
BoolButton *unthrottle = addBoolButton(&PSP_CoreParameter().unthrottle, rectImage, I_ARROW, g_Config.touchUnthrottleKey);
if (unthrottle)
unthrottle->SetAngle(180);
unthrottle->SetAngle(180.0f);
FPSLimitButton *speed1 = addFPSLimitButton(FPSLimit::CUSTOM1, rectImage, I_ARROW, g_Config.touchSpeed1Key);
if (speed1)
speed1->SetAngle(170.0f, 180.0f);
FPSLimitButton *speed2 = addFPSLimitButton(FPSLimit::CUSTOM2, rectImage, I_ARROW, g_Config.touchSpeed2Key);
if (speed2)
speed2->SetAngle(190.0f, 180.0f);
addPSPButton(CTRL_LTRIGGER, shoulderImage, I_L, g_Config.touchLKey);
PSPButton *rTrigger = addPSPButton(CTRL_RTRIGGER, shoulderImage, I_R, g_Config.touchRKey);

View File

@ -22,6 +22,7 @@
#include "ui/view.h"
#include "ui/viewgroup.h"
#include "Core/CoreParameter.h"
class GamepadView : public UI::View {
public:
@ -43,7 +44,7 @@ protected:
class MultiTouchButton : public GamepadView {
public:
MultiTouchButton(int bgImg, int img, float scale, UI::LayoutParams *layoutParams)
: GamepadView(layoutParams), pointerDownMask_(0), scale_(scale), bgImg_(bgImg), img_(img), angle_(0.0f), flipImageH_(false) {
: GamepadView(layoutParams), scale_(scale), bgImg_(bgImg), img_(img) {
}
void Touch(const TouchInput &input) override;
@ -52,17 +53,19 @@ public:
virtual bool IsDown() { return pointerDownMask_ != 0; }
// chainable
MultiTouchButton *FlipImageH(bool flip) { flipImageH_ = flip; return this; }
MultiTouchButton *SetAngle(float angle) { angle_ = angle; return this; }
MultiTouchButton *SetAngle(float angle) { angle_ = angle; bgAngle_ = angle; return this; }
MultiTouchButton *SetAngle(float angle, float bgAngle) { angle_ = angle; bgAngle_ = bgAngle; return this; }
protected:
uint32_t pointerDownMask_;
uint32_t pointerDownMask_ = 0;
float scale_;
private:
int bgImg_;
int img_;
float angle_;
bool flipImageH_;
float bgAngle_ = 0.0f;
float angle_ = 0.0f;
bool flipImageH_ = false;
};
class BoolButton : public MultiTouchButton {
@ -78,6 +81,19 @@ private:
bool *value_;
};
class FPSLimitButton : public MultiTouchButton {
public:
FPSLimitButton(FPSLimit limit, int bgImg, int img, float scale, UI::LayoutParams *layoutParams)
: MultiTouchButton(bgImg, img, scale, layoutParams), limit_(limit) {
}
void Touch(const TouchInput &input) override;
bool IsDown() override;
private:
FPSLimit limit_;
};
class PSPButton : public MultiTouchButton {
public:
PSPButton(int pspButtonBit, int bgImg, int img, float scale, UI::LayoutParams *layoutParams)

View File

@ -396,6 +396,18 @@ void TouchControlLayoutScreen::CreateViews() {
controls_.push_back(unthrottle);
}
if (g_Config.touchSpeed1Key.show) {
DragDropButton *speed1 = new DragDropButton(g_Config.touchSpeed1Key, rectImage, I_ARROW);
speed1->SetAngle(170.0f, 180.0f);
controls_.push_back(speed1);
}
if (g_Config.touchSpeed2Key.show) {
DragDropButton *speed2 = new DragDropButton(g_Config.touchSpeed2Key, rectImage, I_ARROW);
speed2->SetAngle(190.0f, 180.0f);
controls_.push_back(speed2);
}
if (g_Config.touchLKey.show) {
controls_.push_back(new DragDropButton(g_Config.touchLKey, shoulderImage, I_L));
}

View File

@ -74,6 +74,8 @@ void TouchControlVisibilityScreen::CreateViews() {
keyToggles["Combo2"] = &g_Config.touchCombo2.show;
keyToggles["Combo3"] = &g_Config.touchCombo3.show;
keyToggles["Combo4"] = &g_Config.touchCombo4.show;
keyToggles["Alt speed 1"] = &g_Config.touchSpeed1Key.show;
keyToggles["Alt speed 2"] = &g_Config.touchSpeed2Key.show;
std::map<std::string, int>::iterator imageFinder;