From cb0f3d0023d61e27cb7763140520e6d69846e312 Mon Sep 17 00:00:00 2001 From: Demur Rumed Date: Fri, 18 Apr 2025 00:56:26 +0000 Subject: [PATCH] a11y: read out changes in action button --- .../GameInteractor_HookTable.h | 1 + .../game-interactor/GameInteractor_Hooks.cpp | 4 ++ .../game-interactor/GameInteractor_Hooks.h | 1 + soh/soh/Enhancements/tts/tts.cpp | 44 ++++++++++++++++++- soh/src/code/z_parameter.c | 1 + 5 files changed, 49 insertions(+), 2 deletions(-) diff --git a/soh/soh/Enhancements/game-interactor/GameInteractor_HookTable.h b/soh/soh/Enhancements/game-interactor/GameInteractor_HookTable.h index ecd970b31..e70c0d33e 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor_HookTable.h +++ b/soh/soh/Enhancements/game-interactor/GameInteractor_HookTable.h @@ -22,6 +22,7 @@ DEFINE_HOOK(OnFlagSet, (int16_t flagType, int16_t flag)); DEFINE_HOOK(OnFlagUnset, (int16_t flagType, int16_t flag)); DEFINE_HOOK(OnSceneSpawnActors, ()); DEFINE_HOOK(OnPlayerUpdate, ()); +DEFINE_HOOK(OnSetDoAction, (uint16_t action)); DEFINE_HOOK(OnOcarinaSongAction, ()); DEFINE_HOOK(OnCuccoOrChickenHatch, ()); DEFINE_HOOK(OnShopSlotChange, (uint8_t cursorIndex, int16_t price)); diff --git a/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp b/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp index 5e52bed71..08f2660dd 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp +++ b/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp @@ -85,6 +85,10 @@ void GameInteractor_ExecuteOnPlayerUpdate() { GameInteractor::Instance->ExecuteHooks(); } +void GameInteractor_ExecuteOnSetDoAction(uint16_t action) { + GameInteractor::Instance->ExecuteHooks(action); +} + void GameInteractor_ExecuteOnOcarinaSongAction() { GameInteractor::Instance->ExecuteHooks(); } diff --git a/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.h b/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.h index b1f9195b4..cd8e7962e 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.h +++ b/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.h @@ -25,6 +25,7 @@ void GameInteractor_ExecuteOnFlagSet(int16_t flagType, int16_t flag); void GameInteractor_ExecuteOnFlagUnset(int16_t flagType, int16_t flag); void GameInteractor_ExecuteOnSceneSpawnActors(); void GameInteractor_ExecuteOnPlayerUpdate(); +void GameInteractor_ExecuteOnSetDoAction(uint16_t action); void GameInteractor_ExecuteOnOcarinaSongAction(); void GameInteractor_ExecuteOnCuccoOrChickenHatch(); void GameInteractor_ExecuteOnActorInit(void* actor); diff --git a/soh/soh/Enhancements/tts/tts.cpp b/soh/soh/Enhancements/tts/tts.cpp index 77df9983d..b1c3bd377 100644 --- a/soh/soh/Enhancements/tts/tts.cpp +++ b/soh/soh/Enhancements/tts/tts.cpp @@ -95,10 +95,8 @@ const char* GetLanguageCode() { switch (CVarGetInteger(CVAR_SETTING("Languages"), 0)) { case LANGUAGE_FRA: return "fr-FR"; - break; case LANGUAGE_GER: return "de-DE"; - break; } return "en-US"; @@ -1148,6 +1146,47 @@ void RegisterOnSetGameLanguageHook() { GameInteractor::Instance->RegisterGameHook([]() { InitTTSBank(); }); } +void RegisterOnSetDoAction() { + GameInteractor::Instance->RegisterGameHook([](uint16_t action) { + if (CVarGetInteger(CVAR_SETTING("A11yTTS"), 0)) { + uint8_t language = CVarGetInteger(CVAR_SETTING("Languages"), 0); + const char* text; + switch (action) { + case DO_ACTION_CHECK: + text = language == LANGUAGE_FRA ? "voir" : language == LANGUAGE_GER ? "lesen" : "check"; + break; + case DO_ACTION_ENTER: + text = language == LANGUAGE_FRA ? "enter" : language == LANGUAGE_GER ? "kriechen" : "ranger"; + break; + case DO_ACTION_OPEN: + text = language == LANGUAGE_FRA ? "ouvrir" : language == LANGUAGE_GER ? "öffnen" : "open"; + break; + case DO_ACTION_THROW: + text = language == LANGUAGE_FRA ? "jeter" : language == LANGUAGE_GER ? "werfen" : "throw"; + break; + case DO_ACTION_CLIMB: + text = language == LANGUAGE_FRA ? "monter" : language == LANGUAGE_GER ? "hinauf" : "climb"; + break; + case DO_ACTION_DROP: + text = language == LANGUAGE_FRA ? "poser" : language == LANGUAGE_GER ? "ablegen" : "drop"; + break; + case DO_ACTION_SPEAK: + text = language == LANGUAGE_FRA ? "parler" : language == LANGUAGE_GER ? "reden" : "speak"; + break; + case DO_ACTION_GRAB: + text = language == LANGUAGE_FRA ? "action" : language == LANGUAGE_GER ? "aktion" : "grab"; + break; + case DO_ACTION_PUTAWAY: + text = language == LANGUAGE_FRA ? "ranger" : language == LANGUAGE_GER ? "zurück" : "putaway"; + break; + default: + return; + } + SpeechSynthesizer::Instance->Speak(text, GetLanguageCode()); + } + }); +} + void RegisterTTSModHooks() { RegisterOnSetGameLanguageHook(); RegisterOnDialogMessageHook(); @@ -1156,6 +1195,7 @@ void RegisterTTSModHooks() { RegisterOnInterfaceUpdateHook(); RegisterOnKaleidoscopeUpdateHook(); RegisterOnUpdateMainMenuSelection(); + RegisterOnSetDoAction(); } void RegisterTTS() { diff --git a/soh/src/code/z_parameter.c b/soh/src/code/z_parameter.c index 4ead0d268..3423855b6 100644 --- a/soh/src/code/z_parameter.c +++ b/soh/src/code/z_parameter.c @@ -2791,6 +2791,7 @@ void Interface_SetDoAction(PlayState* play, u16 action) { PauseContext* pauseCtx = &play->pauseCtx; if (interfaceCtx->unk_1F0 != action) { + GameInteractor_ExecuteOnSetDoAction(action); interfaceCtx->unk_1F0 = action; interfaceCtx->unk_1EC = 1; interfaceCtx->unk_1F4 = 0.0f;