From a88a30fb1dd4b484d13dc56503435e670824b1c6 Mon Sep 17 00:00:00 2001 From: The Dax Date: Sat, 19 Oct 2013 22:40:52 -0400 Subject: [PATCH] Add a touch control visibility screen. All touch controls can now be toggled on or off, except for the Pause button on platforms that have it, as a safety precaution. --- Core/Config.cpp | 26 ++++++- Core/Config.h | 12 +++- UI/GameSettingsScreen.cpp | 10 ++- UI/GameSettingsScreen.h | 1 + UI/GamepadEmu.cpp | 42 ++++++++---- UI/TouchControlVisibilityScreen.cpp | 102 ++++++++++++++++++++++++++++ UI/TouchControlVisibilityScreen.h | 39 +++++++++++ 7 files changed, 215 insertions(+), 17 deletions(-) create mode 100644 UI/TouchControlVisibilityScreen.cpp create mode 100644 UI/TouchControlVisibilityScreen.h diff --git a/Core/Config.cpp b/Core/Config.cpp index 164be39d3d..b2d3551f7b 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -191,7 +191,18 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) IniFile::Section *control = iniFile.GetOrCreateSection("Control"); control->Get("HapticFeedback", &bHapticFeedback, true); - control->Get("ShowAnalogStick", &bShowAnalogStick, true); + control->Get("ShowAnalogStick", &bShowTouchAnalogStick, true); + control->Get("ShowTouchCross", bShowTouchCross); + control->Get("ShowTouchCircle", bShowTouchCircle); + control->Get("ShowTouchSquare", bShowTouchSquare); + control->Get("ShowTouchTriangle", bShowTouchTriangle); + control->Get("ShowTouchStart", bShowTouchStart); + control->Get("ShowTouchSelect", bShowTouchSelect); + control->Get("ShowTouchLTrigger", bShowTouchLTrigger); + control->Get("ShowTouchRTrigger", bShowTouchRTrigger); + control->Get("ShowAnalogStick", bShowTouchAnalogStick); + control->Get("ShowTouchUnthrottle", bShowTouchUnthrottle); + #if defined(USING_GLES2) std::string name = System_GetProperty(SYSPROP_NAME); if (KeyMap::HasBuiltinController(name)) { @@ -380,8 +391,19 @@ void Config::Save() { IniFile::Section *control = iniFile.GetOrCreateSection("Control"); control->Set("HapticFeedback", bHapticFeedback); - control->Set("ShowAnalogStick", bShowAnalogStick); + control->Set("ShowTouchControls", bShowTouchControls); + control->Set("ShowTouchCross", bShowTouchCross); + control->Set("ShowTouchCircle", bShowTouchCircle); + control->Set("ShowTouchSquare", bShowTouchSquare); + control->Set("ShowTouchTriangle", bShowTouchTriangle); + control->Set("ShowTouchStart", bShowTouchStart); + control->Set("ShowTouchSelect", bShowTouchSelect); + control->Set("ShowTouchLTrigger", bShowTouchLTrigger); + control->Set("ShowTouchRTrigger", bShowTouchRTrigger); + control->Set("ShowAnalogStick", bShowTouchAnalogStick); + control->Set("ShowTouchUnthrottle", bShowTouchUnthrottle); + // control->Set("KeyMapping",iMappingMap); #ifdef USING_GLES2 control->Set("AccelerometerToAnalogHoriz", bAccelerometerToAnalogHoriz); diff --git a/Core/Config.h b/Core/Config.h index 840fa954d8..ad61c7f1b5 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -105,7 +105,17 @@ public: // Controls bool bShowTouchControls; - bool bShowAnalogStick; + bool bShowTouchCross; + bool bShowTouchCircle; + bool bShowTouchSquare; + bool bShowTouchTriangle; + bool bShowTouchStart; + bool bShowTouchSelect; + bool bShowTouchLTrigger; + bool bShowTouchRTrigger; + bool bShowTouchAnalogStick; + bool bShowTouchUnthrottle; + bool bShowTouchDpad; bool bHapticFeedback; // UI diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 3673265419..a826d507aa 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -29,8 +29,8 @@ #include "UI/MiscScreens.h" #include "UI/ControlMappingScreen.h" #include "UI/DevScreens.h" -//yuck. need a better name #include "UI/TouchControlLayoutScreen.h" +#include "UI/TouchControlVisibilityScreen.h" #include "Core/Config.h" #include "Core/Host.h" @@ -214,9 +214,10 @@ void GameSettingsScreen::CreateViews() { controlsSettings->Add(new ItemHeader(c->T("OnScreen", "On-Screen Touch Controls"))); controlsSettings->Add(new CheckBox(&g_Config.bShowTouchControls, c->T("OnScreen", "On-Screen Touch Controls"))); controlsSettings->Add(new Choice(c->T("Custom layout...")))->OnClick.Handle(this, &GameSettingsScreen::OnTouchControlLayout); + controlsSettings->Add(new Choice("Control Visibility..."))->OnClick.Handle(this, &GameSettingsScreen::OnTouchControlVisibility); controlsSettings->Add(new PopupSliderChoice(&g_Config.iTouchButtonOpacity, 0, 100, c->T("Button Opacity"), screenManager())); controlsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fButtonScale, 0.80, 2.0, c->T("Button Scaling"), screenManager())); - controlsSettings->Add(new CheckBox(&g_Config.bShowAnalogStick, c->T("Show Left Analog Stick"))); + controlsSettings->Add(new Choice("Control Visibility..."))->OnClick.Handle(this, &GameSettingsScreen::OnTouchControlVisibility); // System ViewGroup *systemSettingsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); @@ -461,6 +462,11 @@ UI::EventReturn GameSettingsScreen::OnTouchControlLayout(UI::EventParams &e){ return UI::EVENT_DONE; }; +UI::EventReturn GameSettingsScreen::OnTouchControlVisibility(UI::EventParams &e){ + screenManager()->push(new TouchControlVisibilityScreen()); + return UI::EVENT_DONE; +}; + void DeveloperToolsScreen::CreateViews() { using namespace UI; root_ = new ScrollView(ORIENT_VERTICAL); diff --git a/UI/GameSettingsScreen.h b/UI/GameSettingsScreen.h index 77aa17931e..893a99ce96 100644 --- a/UI/GameSettingsScreen.h +++ b/UI/GameSettingsScreen.h @@ -49,6 +49,7 @@ private: // Event handlers UI::EventReturn OnControlMapping(UI::EventParams &e); UI::EventReturn OnTouchControlLayout(UI::EventParams &e); + UI::EventReturn OnTouchControlVisibility(UI::EventParams &e); UI::EventReturn OnDumpNextFrameToLog(UI::EventParams &e); UI::EventReturn OnBack(UI::EventParams &e); UI::EventReturn OnReloadCheats(UI::EventParams &e); diff --git a/UI/GamepadEmu.cpp b/UI/GamepadEmu.cpp index 7b7f768fc4..942eefd83a 100644 --- a/UI/GamepadEmu.cpp +++ b/UI/GamepadEmu.cpp @@ -303,7 +303,7 @@ void InitPadLayout() { int D_pad_X = 2.5 * D_pad_Radius; int D_pad_Y = dp_yres - D_pad_Radius; - if(g_Config.bShowAnalogStick){ + if (g_Config.bShowTouchAnalogStick){ D_pad_Y -= 200 * scale; } @@ -432,28 +432,46 @@ UI::ViewGroup *CreatePadLayout(bool *pause) { if (g_Config.bShowTouchControls) { float scale = g_Config.fButtonScale; +<<<<<<< HEAD #if USE_PAUSE_BUTTON root->Add(new BoolButton(pause, I_ROUND, I_ARROW, scale, new AnchorLayoutParams(halfW, 20, NONE, NONE, true)))->SetAngle(90); #endif +======= + if (g_Config.bShowTouchCircle) +>>>>>>> 86338a5... Add a touch control visibility screen. All touch controls can now be toggled on or off, except for the Pause button on platforms that have it, as a safety precaution. root->Add(new PSPButton(CTRL_CIRCLE, I_ROUND, I_CIRCLE, scale, new AnchorLayoutParams(Action_circle_button_X, Action_circle_button_Y, NONE, NONE, true))); - root->Add(new PSPButton(CTRL_CROSS, I_ROUND, I_CROSS, scale, new AnchorLayoutParams(Action_cross_button_X, Action_cross_button_Y, NONE, NONE, true))); - root->Add(new PSPButton(CTRL_TRIANGLE, I_ROUND, I_TRIANGLE, scale, new AnchorLayoutParams(Action_triangle_button_X, Action_triangle_button_Y, NONE, NONE, true))); - root->Add(new PSPButton(CTRL_SQUARE, I_ROUND, I_SQUARE, scale, new AnchorLayoutParams(Action_square_button_X, Action_square_button_Y, NONE, NONE, true))); - root->Add(new PSPButton(CTRL_START, I_RECT, I_START, scale, new AnchorLayoutParams(start_key_X, start_key_Y, NONE, NONE, true))); - root->Add(new PSPButton(CTRL_SELECT, I_RECT, I_SELECT, scale, new AnchorLayoutParams(select_key_X, select_key_Y, NONE, NONE, true))); - root->Add(new BoolButton(&PSP_CoreParameter().unthrottle, I_RECT, I_ARROW, scale, new AnchorLayoutParams(unthrottle_key_X, unthrottle_key_Y, NONE, NONE, true)))->SetAngle(180); + if (g_Config.bShowTouchCross) + root->Add(new PSPButton(CTRL_CROSS, I_ROUND, I_CROSS, scale, new AnchorLayoutParams(Action_cross_button_X, Action_cross_button_Y, NONE, NONE, true))); - root->Add(new PSPButton(CTRL_LTRIGGER, I_SHOULDER, I_L, scale, new AnchorLayoutParams(l_key_X, l_key_Y, NONE, NONE, true))); - root->Add(new PSPButton(CTRL_RTRIGGER, I_SHOULDER, I_R, scale, new AnchorLayoutParams(r_key_X,r_key_Y, NONE, NONE, true)))->FlipImageH(true); + if (g_Config.bShowTouchTriangle) + root->Add(new PSPButton(CTRL_TRIANGLE, I_ROUND, I_TRIANGLE, scale, new AnchorLayoutParams(Action_triangle_button_X, Action_triangle_button_Y, NONE, NONE, true))); - root->Add(new PSPCross(I_DIR, I_ARROW, scale, D_pad_Radius, new AnchorLayoutParams(D_pad_X, D_pad_Y, NONE, NONE, true))); + if (g_Config.bShowTouchSquare) + root->Add(new PSPButton(CTRL_SQUARE, I_ROUND, I_SQUARE, scale, new AnchorLayoutParams(Action_square_button_X, Action_square_button_Y, NONE, NONE, true))); - if (g_Config.bShowAnalogStick) { + if (g_Config.bShowTouchStart) + root->Add(new PSPButton(CTRL_START, I_RECT, I_START, scale, new AnchorLayoutParams(start_key_X, start_key_Y, NONE, NONE, true))); + + if (g_Config.bShowTouchSelect) + root->Add(new PSPButton(CTRL_SELECT, I_RECT, I_SELECT, scale, new AnchorLayoutParams(select_key_X, select_key_Y, NONE, NONE, true))); + + if (g_Config.bShowTouchUnthrottle) + root->Add(new BoolButton(&PSP_CoreParameter().unthrottle, I_RECT, I_ARROW, scale, new AnchorLayoutParams(unthrottle_key_X, unthrottle_key_Y, NONE, NONE, true)))->SetAngle(180); + + if (g_Config.bShowTouchLTrigger) + root->Add(new PSPButton(CTRL_LTRIGGER, I_SHOULDER, I_L, scale, new AnchorLayoutParams(l_key_X, l_key_Y, NONE, NONE, true))); + + if (g_Config.bShowTouchRTrigger) + root->Add(new PSPButton(CTRL_RTRIGGER, I_SHOULDER, I_R, scale, new AnchorLayoutParams(r_key_X,r_key_Y, NONE, NONE, true)))->FlipImageH(true); + + if (g_Config.bShowTouchDpad) + root->Add(new PSPCross(I_DIR, I_ARROW, scale, D_pad_Radius, new AnchorLayoutParams(D_pad_X, D_pad_Y, NONE, NONE, true))); + + if (g_Config.bShowTouchAnalogStick) root->Add(new PSPStick(I_STICKBG, I_STICK, 0, scale, new AnchorLayoutParams(analog_stick_X, analog_stick_Y, NONE, NONE, true))); - } } return root; diff --git a/UI/TouchControlVisibilityScreen.cpp b/UI/TouchControlVisibilityScreen.cpp new file mode 100644 index 0000000000..e8fe19cfb8 --- /dev/null +++ b/UI/TouchControlVisibilityScreen.cpp @@ -0,0 +1,102 @@ +// Copyright (c) 2013- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. + +#include "TouchControlVisibilityScreen.h" +#include "Common/KeyMap.h" +#include "Core/Config.h" +#include "ui/ui_atlas.h" + +#include +#include + +TouchControlVisibilityScreen::TouchControlVisibilityScreen() { + +} + +void TouchControlVisibilityScreen::CreateViews() { + using namespace UI; + + root_ = new ScrollView(ORIENT_VERTICAL); + LinearLayout *vert = root_->Add(new LinearLayout(ORIENT_VERTICAL, new LayoutParams(FILL_PARENT, FILL_PARENT))); + vert->SetSpacing(0); + + LinearLayout *topBar = new LinearLayout(ORIENT_HORIZONTAL); + topBar->Add(new Choice("Back"))->OnClick.Handle(this, &TouchControlVisibilityScreen::OnBack); + topBar->Add(new Choice("Toggle All"))->OnClick.Handle(this, &TouchControlVisibilityScreen::OnToggleAll); + + vert->Add(topBar); + + vert->Add(new ItemHeader("Touch Control Visibility")); + + const int cellSize = 400; + + UI::GridLayoutSettings gridsettings(cellSize, 64, 5); + gridsettings.fillCells = true; + GridLayout *grid = vert->Add(new GridLayout(gridsettings, new LayoutParams(FILL_PARENT, WRAP_CONTENT))); + + std::map keyImages; + keyImages["Circle"] = I_CIRCLE; + keyImages["Cross"] = I_CROSS; + keyImages["Square"] = I_SQUARE; + keyImages["Triangle"] = I_TRIANGLE; + keyImages["Start"] = I_START; + keyImages["Select"] = I_SELECT; + keyImages["L"] = I_L; + keyImages["R"] = I_R; + + std::map keyToggles; + keyToggles["Circle"] = &g_Config.bShowTouchCircle; + keyToggles["Cross"] = &g_Config.bShowTouchCross; + keyToggles["Square"] = &g_Config.bShowTouchSquare; + keyToggles["Triangle"] = &g_Config.bShowTouchTriangle; + keyToggles["L"] = &g_Config.bShowTouchLTrigger; + keyToggles["R"] = &g_Config.bShowTouchRTrigger; + keyToggles["Start"] = &g_Config.bShowTouchStart; + keyToggles["Select"] = &g_Config.bShowTouchSelect; + keyToggles["Dpad"] = &g_Config.bShowTouchDpad; + keyToggles["Analog Stick"] = &g_Config.bShowTouchAnalogStick; + keyToggles["Unthrottle"] = &g_Config.bShowTouchUnthrottle; + + std::map::iterator imageFinder; + + for (auto i = keyToggles.begin(); i != keyToggles.end(); ++i) { + LinearLayout *row = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); + row->SetSpacing(0); + + imageFinder = keyImages.find(i->first); + row->Add(new CheckBox(i->second, "", "", new LinearLayoutParams(50, WRAP_CONTENT))); + + if (imageFinder != keyImages.end()) { + row->Add(new Choice(keyImages[imageFinder->first], new LinearLayoutParams(1.0f))); + } else { + row->Add(new Choice(i->first, new LinearLayoutParams(1.0f))); + } + grid->Add(row); + } +} + +UI::EventReturn TouchControlVisibilityScreen::OnBack(UI::EventParams &e) { + screenManager()->finishDialog(this, DR_OK); + + g_Config.Save(); + + return UI::EVENT_DONE; +} + +UI::EventReturn TouchControlVisibilityScreen::OnToggleAll(UI::EventParams &e) { + return UI::EVENT_DONE; +} diff --git a/UI/TouchControlVisibilityScreen.h b/UI/TouchControlVisibilityScreen.h new file mode 100644 index 0000000000..50abef490b --- /dev/null +++ b/UI/TouchControlVisibilityScreen.h @@ -0,0 +1,39 @@ +// Copyright (c) 2013- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. + +#pragma once + +#include "base/functional.h" +#include "ui/view.h" +#include "MiscScreens.h" +#include + +class TouchControlVisibilityScreen : public UIScreenWithBackground { +public: + TouchControlVisibilityScreen(); + + virtual void CreateViews(); + +protected: + virtual UI::EventReturn OnBack(UI::EventParams &e); + virtual UI::EventReturn OnToggleAll(UI::EventParams &e); + +private: + //DragDropButton *pickedControl_; + //std::vector controls_; + //DragDropButton *getPickedControl(const int x, const int y); +}; \ No newline at end of file