Repository navigation
Expand file tree
/
Copy pathBattleDialogHandler.cs
More file actions
151 lines (128 loc) · 4.44 KB
/
Copy pathBattleDialogHandler.cs
File metadata and controls
151 lines (128 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using Il2Cpp;
using UnityEngine;
namespace DigimonNOAccess
{
/// <summary>
/// Handles battle dialog accessibility (escape confirmation, etc.).
/// Announces dialog messages and Yes/No selection.
/// </summary>
public class BattleDialogHandler : IAccessibilityHandler
{
public int Priority => 80;
/// <summary>
/// IAccessibilityHandler.IsOpen() - delegates to IsActive().
/// </summary>
public bool IsOpen() => IsActive();
public void AnnounceStatus()
{
ScreenReader.Say("Battle dialog");
}
private uBattlePanelDialog _cachedDialog;
private int _lastCursor = -1;
private bool _wasActive = false;
private string _lastMessage = "";
public void Update()
{
// Check if battle is active first
var battlePanel = uBattlePanel.m_instance;
if (battlePanel == null || !battlePanel.m_enabled)
{
ResetState();
return;
}
// Find the dialog
var dialog = Object.FindObjectOfType<uBattlePanelDialog>();
if (dialog == null || !dialog.m_isOpend)
{
if (_wasActive)
{
ResetState();
}
return;
}
_cachedDialog = dialog;
// Dialog just opened
if (!_wasActive)
{
_wasActive = true;
_lastCursor = dialog.m_cursorIndex;
_lastMessage = dialog.m_messageText?.text ?? "";
AnnounceDialog();
return;
}
// Check for cursor change
if (dialog.m_cursorIndex != _lastCursor)
{
_lastCursor = dialog.m_cursorIndex;
AnnounceSelection();
}
// Check for message change (shouldn't happen but just in case)
string currentMessage = dialog.m_messageText?.text ?? "";
if (currentMessage != _lastMessage && !string.IsNullOrEmpty(currentMessage))
{
_lastMessage = currentMessage;
AnnounceDialog();
}
}
private void ResetState()
{
_cachedDialog = null;
_lastCursor = -1;
_wasActive = false;
_lastMessage = "";
}
private void AnnounceDialog()
{
if (_cachedDialog == null)
return;
string message = GetMessageText();
string selection = GetSelectionName(_cachedDialog.m_cursorIndex);
ScreenReader.Say($"{message} {selection}");
}
private void AnnounceSelection()
{
if (_cachedDialog == null)
return;
string selection = GetSelectionName(_cachedDialog.m_cursorIndex);
ScreenReader.Say(selection);
}
private string GetSelectionName(int cursorIndex)
{
return cursorIndex == 0 ? "Yes" : "No";
}
private string GetMessageText()
{
const string fallback = "Confirm?";
try
{
if (_cachedDialog == null)
{
DebugLogger.Log("[BattleDialogHandler] Message: cached dialog was null");
return fallback;
}
var messageText = _cachedDialog.m_messageText;
if (messageText == null)
{
DebugLogger.Log("[BattleDialogHandler] Message: m_messageText was null");
return fallback;
}
string message = TextUtilities.StripRichTextTags(ButtonHintCache.Filter(messageText.text))?.Trim();
if (string.IsNullOrWhiteSpace(message) || TextUtilities.IsPlaceholderText(message))
{
DebugLogger.Log($"[BattleDialogHandler] Message: m_messageText.text unusable: {TextUtilities.DescribeUnusable(message)}");
return fallback;
}
return message;
}
catch (System.Exception ex)
{
DebugLogger.Log($"[BattleDialogHandler] Message read failed: {ex.Message}");
return fallback;
}
}
public bool IsActive()
{
return _wasActive && _cachedDialog != null;
}
}
}