From c245d07ae5474f21e55eb06a22e38e29c5f8d772 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Sat, 26 Oct 2019 00:16:40 +1100 Subject: [PATCH] pause: touch panel support --- .../source/plugins/TLAC/Components/Pause.cpp | 43 ++++++++++++++++--- .../source/plugins/TLAC/Components/Pause.h | 7 ++- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index c4c6d51..466cf4e 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -1,6 +1,7 @@ #include "Pause.h" #include "../Constants.h" #include "GameState.h" +#include "ComponentsManager.h" #include "../Utilities/Drawing.h" #include "GL/glut.h" #include "detours.h" @@ -36,7 +37,10 @@ namespace TLAC::Components PlayerData* Pause::playerData; InputState* Pause::inputState; TouchSliderState* Pause::sliderState; + TouchPanelState* Pause::panelState; + ComponentsManager* Pause::componentsManager; JvsButtons Pause::filteredButtons; + int Pause::lastTouchType = 0; std::vector Pause::menu = { { "PAUSED", @@ -79,11 +83,13 @@ namespace TLAC::Components memcpy(origFramespeedOp.data(), framespeedPatchAddress, 4); } - void Pause::Initialize(ComponentsManager*) + void Pause::Initialize(ComponentsManager* manager) { inputState = (InputState*)(*(uint64_t*)INPUT_STATE_PTR_ADDRESS); playerData = (PlayerData*)PLAYER_DATA_ADDRESS; sliderState = (TouchSliderState*)SLIDER_CTRL_TASK_ADDRESS; + panelState = (TouchPanelState*)TASK_TOUCH_ADDRESS; + componentsManager = manager; saveOldPatchOps(); @@ -187,6 +193,31 @@ namespace TLAC::Components if (inputState->Tapped.Buttons & JVS_CIRCLE) menu[curMenuSet].items[curMenuPos].callback(); + if (!componentsManager->IsDwGuiActive()) // not sure if this check is necessary, but it doesn't hurt + { + if (panelState->ContactType == 2 && lastTouchType != 2) // down and was not down before + { + for (int i = 0; i < menu[curMenuSet].items.size(); i++) + { + Drawing::Point itemCoords = getMenuItemCoords(curMenuSet, i); + + Drawing::Point touchCoords = { panelState->XPosition, panelState->YPosition }; + touchCoords.x *= 1280.0f / *(int*)RESOLUTION_WIDTH_ADDRESS; // convert to 720p coords + touchCoords.y *= 720.0f / *(int*)RESOLUTION_HEIGHT_ADDRESS; + + if (touchCoords.x >= itemCoords.x - menuItemWidth / 2 && + touchCoords.x <= itemCoords.x + menuItemWidth / 2 && + touchCoords.y >= itemCoords.y - menuItemHeight / 2 && + touchCoords.y <= itemCoords.y + menuItemHeight / 2) + { + setMenuPos(curMenuSet, i); + menu[curMenuSet].items[i].callback(); + break; + } + } + } + } + if (curMenuSet == MENUSET_SEVOL) { const char volformat[] = "%d"; @@ -257,10 +288,12 @@ namespace TLAC::Components inputState->Down.Buttons = (JvsButtons)(inputState->Down.Buttons & ~filteredButtons); inputState->Released.Buttons = (JvsButtons)(inputState->Released.Buttons & ~filteredButtons); inputState->IntervalTapped.Buttons = (JvsButtons)(inputState->IntervalTapped.Buttons & ~filteredButtons); + + lastTouchType = panelState->ContactType; } // returns the midpoint of a menu button - Drawing::Point Pause::getMenuItemCoord(menusets set, int pos) + Drawing::Point Pause::getMenuItemCoords(menusets set, int pos) { const float slant = 35.0f / 199.0f; @@ -394,9 +427,9 @@ namespace TLAC::Components }); - Drawing::Point menuCoords = getMenuItemCoord(curMenuSet, curMenuPos); + Drawing::Point menuCoords = getMenuItemCoords(curMenuSet, curMenuPos); // selection cursor - const float selectBoxWidth = 150; + const float selectBoxWidth = menuItemWidth; const float selectBoxHeight = menuItemHeight; const float selectBoxThickness = 2; @@ -442,7 +475,7 @@ namespace TLAC::Components for (int i = 0; i < menu[curMenuSet].items.size(); i++) { - menuCoords = getMenuItemCoord(curMenuSet, i); + menuCoords = getMenuItemCoords(curMenuSet, i); dtParams.textCurrentLoc = { menuCoords.x, menuCoords.y - menuTextSize / 2 }; dtParams.lineOriginLoc = dtParams.textCurrentLoc; if (i == curMenuPos) diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index 98287b7..66afc4f 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -6,6 +6,7 @@ #include "../Utilities/Drawing.h" #include "Input/InputState.h" #include "Input/TouchSliderState.h" +#include "Input/TouchPanelState.h" #include #include #include @@ -52,12 +53,16 @@ namespace TLAC::Components static PlayerData* playerData; static InputState* inputState; static TouchSliderState* sliderState; + static TouchPanelState* panelState; + static ComponentsManager* componentsManager; static const JvsButtons allButtons = (JvsButtons)(JVS_START | JVS_TRIANGLE | JVS_SQUARE | JVS_CROSS | JVS_CIRCLE | JVS_L | JVS_R); // deliberately only has control panel buttons static JvsButtons filteredButtons; + static int lastTouchType; static const int menuX = 640; static const int menuY = 360; + static const int menuItemWidth = 150; static const int menuItemHeight = 36; static const int menuItemPadding = 12; static const int menuItemTotalHeight = menuItemHeight + menuItemPadding; @@ -125,6 +130,6 @@ namespace TLAC::Components static float getMenuAnimPos(); - static TLAC::Utilities::Drawing::Point getMenuItemCoord(menusets set, int pos); + static TLAC::Utilities::Drawing::Point getMenuItemCoords(menusets set, int pos); }; }