Permalink
Browse files

UI: Show custom speed toggle buttons.

This allows more flexibility if unthrottle is too fast or too uneven.
  • Loading branch information...
unknownbrackets committed Jun 17, 2018
1 parent 69dd59d commit f2956a1c1a2de5507e05a33f5c3a89a4f7d3f72b
Showing with 79 additions and 7 deletions.
  1. +4 −0 Core/Config.cpp
  2. +2 −0 Core/Config.h
  3. +38 −2 UI/GamepadEmu.cpp
  4. +21 −5 UI/GamepadEmu.h
  5. +12 −0 UI/TouchControlLayoutScreen.cpp
  6. +2 −0 UI/TouchControlVisibilityScreen.cpp
@@ -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) {
@@ -294,6 +294,8 @@ struct Config {
ConfigTouchPos touchCombo2;
ConfigTouchPos touchCombo3;
ConfigTouchPos touchCombo4;
ConfigTouchPos touchSpeed1Key;
ConfigTouchPos touchSpeed2Key;
// Controls Visibility
bool bShowTouchControls;
@@ -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);
@@ -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 @@ class GamepadView : public UI::View {
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 @@ class MultiTouchButton : public GamepadView {
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 @@ class BoolButton : public MultiTouchButton {
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)
@@ -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));
}
@@ -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;

0 comments on commit f2956a1

Please sign in to comment.