1
0
forked from liza/Questionable

Don't handle dialogue/UI interactions for quests if no quest is running

This commit is contained in:
Liza 2024-08-13 23:25:14 +02:00
parent d8cf9616c0
commit f9368ae809
Signed by: liza
GPG Key ID: 7199F8D727D55F67

View File

@ -42,6 +42,8 @@ internal sealed class GameUiController : IDisposable
private readonly ILogger<GameUiController> _logger; private readonly ILogger<GameUiController> _logger;
private readonly Regex _returnRegex; private readonly Regex _returnRegex;
private bool _isInitialCheck;
public GameUiController( public GameUiController(
IAddonLifecycle addonLifecycle, IAddonLifecycle addonLifecycle,
IDataManager dataManager, IDataManager dataManager,
@ -88,8 +90,13 @@ internal sealed class GameUiController : IDisposable
_addonLifecycle.RegisterListener(AddonEvent.PostSetup, "GuildLeve", GuildLevePostSetup); _addonLifecycle.RegisterListener(AddonEvent.PostSetup, "GuildLeve", GuildLevePostSetup);
} }
private bool ShouldHandleUiInteractions => _isInitialCheck || _questController.IsRunning;
internal unsafe void HandleCurrentDialogueChoices() internal unsafe void HandleCurrentDialogueChoices()
{ {
try
{
_isInitialCheck = true;
if (_gameGui.TryGetAddonByName("SelectString", out AddonSelectString* addonSelectString)) if (_gameGui.TryGetAddonByName("SelectString", out AddonSelectString* addonSelectString))
{ {
_logger.LogInformation("SelectString window is open"); _logger.LogInformation("SelectString window is open");
@ -121,6 +128,11 @@ internal sealed class GameUiController : IDisposable
PointMenuPostSetup(addonPointMenu); PointMenuPostSetup(addonPointMenu);
} }
} }
finally
{
_isInitialCheck = false;
}
}
private unsafe void SelectStringPostSetup(AddonEvent type, AddonArgs args) private unsafe void SelectStringPostSetup(AddonEvent type, AddonArgs args)
{ {
@ -130,6 +142,9 @@ internal sealed class GameUiController : IDisposable
private unsafe void SelectStringPostSetup(AddonSelectString* addonSelectString, bool checkAllSteps) private unsafe void SelectStringPostSetup(AddonSelectString* addonSelectString, bool checkAllSteps)
{ {
if (!ShouldHandleUiInteractions)
return;
string? actualPrompt = addonSelectString->AtkUnitBase.AtkValues[2].ReadAtkString(); string? actualPrompt = addonSelectString->AtkUnitBase.AtkValues[2].ReadAtkString();
if (actualPrompt == null) if (actualPrompt == null)
return; return;
@ -155,6 +170,9 @@ internal sealed class GameUiController : IDisposable
private unsafe void CutsceneSelectStringPostSetup(AddonCutSceneSelectString* addonCutSceneSelectString, private unsafe void CutsceneSelectStringPostSetup(AddonCutSceneSelectString* addonCutSceneSelectString,
bool checkAllSteps) bool checkAllSteps)
{ {
if (!ShouldHandleUiInteractions)
return;
string? actualPrompt = addonCutSceneSelectString->AtkUnitBase.AtkValues[2].ReadAtkString(); string? actualPrompt = addonCutSceneSelectString->AtkUnitBase.AtkValues[2].ReadAtkString();
if (actualPrompt == null) if (actualPrompt == null)
return; return;
@ -177,6 +195,9 @@ internal sealed class GameUiController : IDisposable
[SuppressMessage("ReSharper", "RedundantJumpStatement")] [SuppressMessage("ReSharper", "RedundantJumpStatement")]
private unsafe void SelectIconStringPostSetup(AddonSelectIconString* addonSelectIconString, bool checkAllSteps) private unsafe void SelectIconStringPostSetup(AddonSelectIconString* addonSelectIconString, bool checkAllSteps)
{ {
if (!ShouldHandleUiInteractions)
return;
string? actualPrompt = addonSelectIconString->AtkUnitBase.AtkValues[3].ReadAtkString(); string? actualPrompt = addonSelectIconString->AtkUnitBase.AtkValues[3].ReadAtkString();
if (string.IsNullOrEmpty(actualPrompt)) if (string.IsNullOrEmpty(actualPrompt))
actualPrompt = null; actualPrompt = null;
@ -442,9 +463,6 @@ internal sealed class GameUiController : IDisposable
private int? HandleInstanceListChoice(string? actualPrompt) private int? HandleInstanceListChoice(string? actualPrompt)
{ {
if (!_questController.IsRunning)
return null;
string? expectedPrompt = _excelFunctions.GetDialogueTextByRowId("Addon", 2090, false).GetString(); string? expectedPrompt = _excelFunctions.GetDialogueTextByRowId("Addon", 2090, false).GetString();
if (GameFunctions.GameStringEquals(actualPrompt, expectedPrompt)) if (GameFunctions.GameStringEquals(actualPrompt, expectedPrompt))
{ {
@ -464,6 +482,9 @@ internal sealed class GameUiController : IDisposable
[SuppressMessage("ReSharper", "RedundantJumpStatement")] [SuppressMessage("ReSharper", "RedundantJumpStatement")]
private unsafe void SelectYesnoPostSetup(AddonSelectYesno* addonSelectYesno, bool checkAllSteps) private unsafe void SelectYesnoPostSetup(AddonSelectYesno* addonSelectYesno, bool checkAllSteps)
{ {
if (!ShouldHandleUiInteractions)
return;
string? actualPrompt = addonSelectYesno->AtkUnitBase.AtkValues[0].ReadAtkString(); string? actualPrompt = addonSelectYesno->AtkUnitBase.AtkValues[0].ReadAtkString();
if (actualPrompt == null) if (actualPrompt == null)
return; return;
@ -671,6 +692,9 @@ internal sealed class GameUiController : IDisposable
private unsafe void PointMenuPostSetup(AtkUnitBase* addonPointMenu) private unsafe void PointMenuPostSetup(AtkUnitBase* addonPointMenu)
{ {
if (!ShouldHandleUiInteractions)
return;
var currentQuest = _questController.StartedQuest; var currentQuest = _questController.StartedQuest;
if (currentQuest == null) if (currentQuest == null)
{ {
@ -717,6 +741,9 @@ internal sealed class GameUiController : IDisposable
/// </summary> /// </summary>
private unsafe void CreditScrollPostSetup(AddonEvent type, AddonArgs args) private unsafe void CreditScrollPostSetup(AddonEvent type, AddonArgs args)
{ {
if (!ShouldHandleUiInteractions)
return;
_logger.LogInformation("Closing Credits sequence"); _logger.LogInformation("Closing Credits sequence");
AtkUnitBase* addon = (AtkUnitBase*)args.Addon; AtkUnitBase* addon = (AtkUnitBase*)args.Addon;
addon->FireCallbackInt(-2); addon->FireCallbackInt(-2);
@ -727,6 +754,9 @@ internal sealed class GameUiController : IDisposable
/// </summary> /// </summary>
private unsafe void CreditPostSetup(AddonEvent type, AddonArgs args) private unsafe void CreditPostSetup(AddonEvent type, AddonArgs args)
{ {
if (!ShouldHandleUiInteractions)
return;
_logger.LogInformation("Closing Credits sequence"); _logger.LogInformation("Closing Credits sequence");
AtkUnitBase* addon = (AtkUnitBase*)args.Addon; AtkUnitBase* addon = (AtkUnitBase*)args.Addon;
addon->FireCallbackInt(-2); addon->FireCallbackInt(-2);
@ -734,6 +764,9 @@ internal sealed class GameUiController : IDisposable
private unsafe void CreditPlayerPostSetup(AddonEvent type, AddonArgs args) private unsafe void CreditPlayerPostSetup(AddonEvent type, AddonArgs args)
{ {
if (!ShouldHandleUiInteractions)
return;
_logger.LogInformation("Closing CreditPlayer"); _logger.LogInformation("Closing CreditPlayer");
AtkUnitBase* addon = (AtkUnitBase*)args.Addon; AtkUnitBase* addon = (AtkUnitBase*)args.Addon;
addon->Close(true); addon->Close(true);
@ -741,6 +774,9 @@ internal sealed class GameUiController : IDisposable
private unsafe void UnendingCodexPostSetup(AddonEvent type, AddonArgs args) private unsafe void UnendingCodexPostSetup(AddonEvent type, AddonArgs args)
{ {
if (!ShouldHandleUiInteractions)
return;
if (_questController.StartedQuest?.Quest.Id.Value == 4526) if (_questController.StartedQuest?.Quest.Id.Value == 4526)
{ {
_logger.LogInformation("Closing Unending Codex"); _logger.LogInformation("Closing Unending Codex");
@ -751,6 +787,9 @@ internal sealed class GameUiController : IDisposable
private unsafe void ContentsTutorialPostSetup(AddonEvent type, AddonArgs args) private unsafe void ContentsTutorialPostSetup(AddonEvent type, AddonArgs args)
{ {
if (!ShouldHandleUiInteractions)
return;
if (_questController.StartedQuest?.Quest.Id.Value == 245) if (_questController.StartedQuest?.Quest.Id.Value == 245)
{ {
_logger.LogInformation("Closing ContentsTutorial"); _logger.LogInformation("Closing ContentsTutorial");
@ -764,6 +803,9 @@ internal sealed class GameUiController : IDisposable
/// </summary> /// </summary>
private unsafe void MultipleHelpWindowPostSetup(AddonEvent type, AddonArgs args) private unsafe void MultipleHelpWindowPostSetup(AddonEvent type, AddonArgs args)
{ {
if (!ShouldHandleUiInteractions)
return;
if (_questController.StartedQuest?.Quest.Id.Value == 245) if (_questController.StartedQuest?.Quest.Id.Value == 245)
{ {
_logger.LogInformation("Closing MultipleHelpWindow"); _logger.LogInformation("Closing MultipleHelpWindow");
@ -775,18 +817,19 @@ internal sealed class GameUiController : IDisposable
private unsafe void HousingSelectBlockPostSetup(AddonEvent type, AddonArgs args) private unsafe void HousingSelectBlockPostSetup(AddonEvent type, AddonArgs args)
{ {
if (_questController.IsRunning) if (!ShouldHandleUiInteractions)
{ return;
_logger.LogInformation("Confirming selected housing ward"); _logger.LogInformation("Confirming selected housing ward");
AtkUnitBase* addon = (AtkUnitBase*)args.Addon; AtkUnitBase* addon = (AtkUnitBase*)args.Addon;
addon->FireCallbackInt(0); addon->FireCallbackInt(0);
} }
}
private unsafe void JournalResultPostSetup(AddonEvent type, AddonArgs args) private unsafe void JournalResultPostSetup(AddonEvent type, AddonArgs args)
{ {
if (_questController.IsRunning) if (!ShouldHandleUiInteractions)
{ return;
_logger.LogInformation("Checking for quest name of journal result"); _logger.LogInformation("Checking for quest name of journal result");
AddonJournalResult* addon = (AddonJournalResult*)args.Addon; AddonJournalResult* addon = (AddonJournalResult*)args.Addon;
@ -811,7 +854,6 @@ internal sealed class GameUiController : IDisposable
} }
} }
} }
}
private unsafe void GuildLevePostSetup(AddonEvent type, AddonArgs args) private unsafe void GuildLevePostSetup(AddonEvent type, AddonArgs args)
{ {