From 12a70386cc44207dc06c59d16c647f53da13f7a9 Mon Sep 17 00:00:00 2001 From: MelonSpeedruns Date: Tue, 17 May 2022 19:16:39 -0400 Subject: [PATCH] touch --- libultraship/libultraship/Controller.cpp | 5 ++ libultraship/libultraship/Controller.h | 3 ++ .../Lib/Fast3D/U64/PR/ultra64/controller.h | 5 +- libultraship/libultraship/SDLController.cpp | 15 ++++++ libultraship/libultraship/UltraController.h | 5 +- soh/src/code/padmgr.c | 6 +++ soh/src/code/title_setup.c | 2 +- soh/src/overlays/actors/ovl_En_Mag/z_en_mag.c | 5 +- .../ovl_file_choose/z_file_choose.c | 49 +++++++++++++++++++ .../ovl_file_choose/z_file_nameset_PAL.c | 19 +++++++ 10 files changed, 109 insertions(+), 5 deletions(-) diff --git a/libultraship/libultraship/Controller.cpp b/libultraship/libultraship/Controller.cpp index e400f6e18..5af18fdb9 100644 --- a/libultraship/libultraship/Controller.cpp +++ b/libultraship/libultraship/Controller.cpp @@ -44,6 +44,11 @@ namespace Ship { pad->gyro_x = wGyroX; pad->gyro_y = wGyroY; + + pad->touch_x = wTouchX; + pad->touch_y = wTouchY; + + pad->touch = wTouching; } void Controller::SetButtonMapping(const std::string& szButtonName, int32_t dwScancode) { diff --git a/libultraship/libultraship/Controller.h b/libultraship/libultraship/Controller.h index 256b31fee..5009d432c 100644 --- a/libultraship/libultraship/Controller.h +++ b/libultraship/libultraship/Controller.h @@ -38,6 +38,9 @@ namespace Ship { int8_t wStickY; float wGyroX; float wGyroY; + bool wTouching; + float wTouchX; + float wTouchY; virtual std::string GetControllerType() = 0; virtual std::string GetConfSection() = 0; diff --git a/libultraship/libultraship/Lib/Fast3D/U64/PR/ultra64/controller.h b/libultraship/libultraship/Lib/Fast3D/U64/PR/ultra64/controller.h index c2aafa919..b2b7ca380 100644 --- a/libultraship/libultraship/Lib/Fast3D/U64/PR/ultra64/controller.h +++ b/libultraship/libultraship/Lib/Fast3D/U64/PR/ultra64/controller.h @@ -114,7 +114,10 @@ typedef struct { /* 0x04 */ u8 err_no; /* 0x05 */ f32 gyro_x; /* 0x09 */ f32 gyro_y; -} OSContPad; // size = 0x0D + /* 0x0A */ u8 touch; + /* 0x0B */ f32 touch_x; + /* 0x0F */ f32 touch_y; +} OSContPad; // size = 0x13 typedef struct { /* 0x00 */ u8 rumble; diff --git a/libultraship/libultraship/SDLController.cpp b/libultraship/libultraship/SDLController.cpp index ab2c48b30..7d36de8eb 100644 --- a/libultraship/libultraship/SDLController.cpp +++ b/libultraship/libultraship/SDLController.cpp @@ -227,6 +227,21 @@ namespace Ship { wGyroX *= gyro_sensitivity; wGyroY *= gyro_sensitivity; + + int x, y; + Uint32 buttons; + SDL_PumpEvents(); + buttons = SDL_GetMouseState(&x, &y); + + wTouchX = x; + wTouchY = y; + + if ((buttons & SDL_BUTTON_LMASK) != 0) { + wTouching = 1; + } + else { + wTouching = 0; + } } for (int32_t i = SDL_CONTROLLER_BUTTON_A; i < SDL_CONTROLLER_BUTTON_MAX; i++) { diff --git a/libultraship/libultraship/UltraController.h b/libultraship/libultraship/UltraController.h index 1c18dcd9b..535cdeb6e 100644 --- a/libultraship/libultraship/UltraController.h +++ b/libultraship/libultraship/UltraController.h @@ -120,7 +120,10 @@ typedef struct { /* 0x04 */ uint8_t err_no; /* 0x05 */ float gyro_x; /* 0x09 */ float gyro_y; -} OSContPad; // size = 0x0D + /* 0x0A */ uint8_t touch; + /* 0x0B */ float touch_x; + /* 0x0F */ float touch_y; +} OSContPad; // size = 0x13 typedef struct { /* 0x00 */ uint8_t rumble; diff --git a/soh/src/code/padmgr.c b/soh/src/code/padmgr.c index b467f5ee6..27f5ee7a6 100644 --- a/soh/src/code/padmgr.c +++ b/soh/src/code/padmgr.c @@ -247,6 +247,7 @@ void PadMgr_ProcessInputs(PadMgr* padMgr) { input->cur.button = 0; input->cur.stick_x = 0; input->cur.stick_y = 0; + input->cur.touch = 0; input->cur.err_no = padnow1->err_no; if (padMgr->ctrlrIsConnected[i]) { padMgr->ctrlrIsConnected[i] = false; @@ -269,6 +270,11 @@ void PadMgr_ProcessInputs(PadMgr* padMgr) { PadUtils_UpdateRelXY(input); input->press.stick_x += (s8)(input->cur.stick_x - input->prev.stick_x); input->press.stick_y += (s8)(input->cur.stick_y - input->prev.stick_y); + + u8 buttonDiff2; + buttonDiff2 = input->prev.touch != input->cur.touch; + input->press.touch = (u8)(input->cur.touch && buttonDiff2); + input->rel.touch = (u8)(!input->cur.touch && buttonDiff2); } controllerCallback.rumble = CVar_GetS32("gRumbleEnabled", 0) && (padMgr->rumbleEnable[0] > 0); diff --git a/soh/src/code/title_setup.c b/soh/src/code/title_setup.c index 1e709dc12..131c97627 100644 --- a/soh/src/code/title_setup.c +++ b/soh/src/code/title_setup.c @@ -4,7 +4,7 @@ void TitleSetup_InitImpl(GameState* gameState) { osSyncPrintf("ゼルダ共通データ初期化\n"); // "Zelda common data initalization" SaveContext_Init(); gameState->running = false; - SET_NEXT_GAMESTATE(gameState, Title_Init, TitleContext); + SET_NEXT_GAMESTATE(gameState, FileChoose_Init, TitleContext); } void TitleSetup_Destroy(GameState* gameState) { diff --git a/soh/src/overlays/actors/ovl_En_Mag/z_en_mag.c b/soh/src/overlays/actors/ovl_En_Mag/z_en_mag.c index a7392e14c..54d1c8997 100644 --- a/soh/src/overlays/actors/ovl_En_Mag/z_en_mag.c +++ b/soh/src/overlays/actors/ovl_En_Mag/z_en_mag.c @@ -341,7 +341,7 @@ void EnMag_Update(Actor* thisx, GlobalContext* globalCtx) { if (this->globalState < MAG_STATE_DISPLAY) { if (CHECK_BTN_ALL(globalCtx->state.input[0].press.button, BTN_START) || CHECK_BTN_ALL(globalCtx->state.input[0].press.button, BTN_A) || - CHECK_BTN_ALL(globalCtx->state.input[0].press.button, BTN_B)) { + CHECK_BTN_ALL(globalCtx->state.input[0].press.button, BTN_B) || globalCtx->state.input[0].press.touch) { Audio_PlaySoundGeneral(NA_SE_SY_PIECE_OF_HEART, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); @@ -367,7 +367,8 @@ void EnMag_Update(Actor* thisx, GlobalContext* globalCtx) { if (sDelayTimer == 0) { if (CHECK_BTN_ALL(globalCtx->state.input[0].press.button, BTN_START) || CHECK_BTN_ALL(globalCtx->state.input[0].press.button, BTN_A) || - CHECK_BTN_ALL(globalCtx->state.input[0].press.button, BTN_B)) { + CHECK_BTN_ALL(globalCtx->state.input[0].press.button, BTN_B) || + globalCtx->state.input[0].press.touch) { if (globalCtx->sceneLoadFlag != 20) { Audio_SetCutsceneFlag(0); diff --git a/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index 570eedd1f..c028ee187 100644 --- a/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -163,6 +163,30 @@ void FileChoose_FinishFadeIn(GameState* thisx) { } } +void HandleMouseInput(Input* input) { + if (input->press.touch) { + input->press.button = BTN_A; + } +} + +u8 HandleMouseCursor(FileChooseContext* this, Input* input, int minx, int miny, int maxx, int maxy) { + float ogratio = 320.0f / 240.0f; + float ratio = (float)OTRGetCurrentWidth() / (float)OTRGetCurrentHeight(); + + float newX = ((240.0f * ratio) - (240.0f * ogratio)) / 2.0f; + + float pos_x = ((input->cur.touch_x / OTRGetCurrentWidth()) * (240.0f * ratio) - newX); + float pos_y = (input->cur.touch_y / OTRGetCurrentHeight()) * 240.0f; + + if (pos_x >= minx && pos_x <= minx + maxx) { + if (pos_y >= miny && pos_y <= miny + maxy) { + return 1; + } + } + + return 0; +} + /** * Update the cursor and wait for the player to select a button to change menus accordingly. * If an empty file is selected, enter the name entry config mode. @@ -178,6 +202,31 @@ void FileChoose_UpdateMainMenu(GameState* thisx) { Input* input = &this->state.input[0]; bool dpad = CVar_GetS32("gDpadPauseName", 0); + if (HandleMouseCursor(this, input, 57, 74, 66, 17)) { + if (this->buttonIndex != FS_BTN_MAIN_FILE_1) { + this->buttonIndex = FS_BTN_MAIN_FILE_1; + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + + HandleMouseInput(input); + } + else if (HandleMouseCursor(this, input, 57, 91, 66, 17)) { + if (this->buttonIndex != FS_BTN_MAIN_FILE_2) { + this->buttonIndex = FS_BTN_MAIN_FILE_2; + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + + HandleMouseInput(input); + } + else if (HandleMouseCursor(this, input, 57, 107, 66, 17)) { + if (this->buttonIndex != FS_BTN_MAIN_FILE_3) { + this->buttonIndex = FS_BTN_MAIN_FILE_3; + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + + HandleMouseInput(input); + } + if (CHECK_BTN_ALL(input->press.button, BTN_START) || CHECK_BTN_ALL(input->press.button, BTN_A)) { if (this->buttonIndex <= FS_BTN_MAIN_FILE_3) { osSyncPrintf("REGCK_ALL[%x]=%x,%x,%x,%x,%x,%x\n", this->buttonIndex, diff --git a/soh/src/overlays/gamestates/ovl_file_choose/z_file_nameset_PAL.c b/soh/src/overlays/gamestates/ovl_file_choose/z_file_nameset_PAL.c index 501986d2b..86b21a3ec 100644 --- a/soh/src/overlays/gamestates/ovl_file_choose/z_file_nameset_PAL.c +++ b/soh/src/overlays/gamestates/ovl_file_choose/z_file_nameset_PAL.c @@ -347,6 +347,25 @@ void FileChoose_DrawNameEntry(GameState* thisx) { PRIMITIVE, 0); gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 255, 255); + if (HandleMouseCursor(this, input, 193, 169, 28, 17)) { + if (this->kbdButton != FS_KBD_BTN_BACKSPACE) { + this->kbdButton = FS_KBD_BTN_BACKSPACE; + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + + HandleMouseInput(input); + } + + if (HandleMouseCursor(this, input, 226, 169, 44, 17)) { + if (this->kbdY != 5 && this->kbdX != 4) { + this->kbdY = 5; + this->kbdX = 4; + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + + HandleMouseInput(input); + } + if (this->configMode == CM_NAME_ENTRY) { if (CHECK_BTN_ALL(input->press.button, BTN_START)) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);