Repository navigation
Expand file tree
/
Copy pathAgreeWindowHandler.cs
More file actions
256 lines (222 loc) · 8.9 KB
/
Copy pathAgreeWindowHandler.cs
File metadata and controls
256 lines (222 loc) · 8.9 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
using Il2Cpp;
using UnityEngine;
namespace DigimonNOAccess
{
/// <summary>
/// Handles accessibility for the agreement windows (EULA, Privacy Policy, KPI/Data Analysis consent).
/// These appear when starting a new game for the first time.
/// </summary>
public class AgreeWindowHandler : IAccessibilityHandler
{
public int Priority => 15;
private uAgreeWindow _window;
private bool _wasActive = false;
private int _lastCursor = -1;
private uAgreeWindow.AgreeWindowType _lastWindowType;
public bool IsOpen()
{
try
{
_window = Object.FindObjectOfType<uAgreeWindow>();
return _window != null &&
_window.gameObject != null &&
_window.gameObject.activeInHierarchy &&
_window.IsOpen;
}
catch
{
return false;
}
}
public void Update()
{
bool isActive = IsOpen();
if (isActive && !_wasActive)
{
OnOpen();
}
else if (!isActive && _wasActive)
{
OnClose();
}
else if (isActive)
{
CheckChanges();
}
_wasActive = isActive;
}
private void OnOpen()
{
_lastCursor = -1;
if (_window == null)
return;
var windowType = _window.m_currentWindowType;
_lastWindowType = windowType;
int cursor = (int)_window.m_cursorIndex;
string windowName = GetWindowTypeName(windowType);
string selection = GetSelectionName(cursor);
string announcement = AnnouncementBuilder.MenuOpen(windowName, selection, cursor, 2);
ScreenReader.Say(announcement);
DebugLogger.Log($"[AgreeWindow] Opened: type={windowType}, cursor={cursor}");
_lastCursor = cursor;
}
private void OnClose()
{
_window = null;
_lastCursor = -1;
DebugLogger.Log("[AgreeWindow] Closed");
}
private void CheckChanges()
{
if (_window == null)
return;
// Check if window type changed (shouldn't happen often, but handle it)
var windowType = _window.m_currentWindowType;
if (windowType != _lastWindowType)
{
_lastWindowType = windowType;
_lastCursor = -1;
string windowName = GetWindowTypeName(windowType);
int cursor = (int)_window.m_cursorIndex;
string selection = GetSelectionName(cursor);
string announcement = AnnouncementBuilder.MenuOpen(windowName, selection, cursor, 2);
ScreenReader.Say(announcement);
DebugLogger.Log($"[AgreeWindow] Type changed: {windowType}");
_lastCursor = cursor;
return;
}
// Check cursor change
int currentCursor = (int)_window.m_cursorIndex;
if (currentCursor != _lastCursor)
{
string selection = GetSelectionName(currentCursor);
string announcement = AnnouncementBuilder.CursorPosition(selection, currentCursor, 2);
ScreenReader.Say(announcement);
DebugLogger.Log($"[AgreeWindow] Cursor changed: {currentCursor} = {selection}");
_lastCursor = currentCursor;
}
}
/// <summary>
/// The title of the agreement being shown.
///
/// Read from the window's own header, so it matches what is on screen in
/// whatever language the player is running. The English names are a fallback
/// for the frame before the header is populated - these screens appear before
/// the player has chosen a language, so getting them right matters.
/// </summary>
private string GetWindowTypeName(uAgreeWindow.AgreeWindowType type)
{
string header = GetHeaderText();
if (!string.IsNullOrWhiteSpace(header))
return header;
switch (type)
{
case uAgreeWindow.AgreeWindowType.Eula:
return "End User License Agreement";
case uAgreeWindow.AgreeWindowType.PP:
return "Privacy Policy";
case uAgreeWindow.AgreeWindowType.KPI:
return "Data Analysis Consent";
default:
return "Agreement";
}
}
/// <summary>
/// The rendered header text, or null if it is not reachable yet. Each hop logs
/// its own reason so a chain broken by a game update is visible in the log
/// rather than silently reverting everyone to English.
/// </summary>
private string GetHeaderText()
{
try
{
if (_window == null)
{
DebugLogger.Log("[AgreeWindow] Header: window is unavailable");
return null;
}
var header = _window.m_Header;
if (header == null)
{
DebugLogger.Log("[AgreeWindow] Header: window has no header component");
return null;
}
var text = header.m_headerText;
if (text == null)
{
DebugLogger.Log("[AgreeWindow] Header: header component has no Text");
return null;
}
string rendered = TextUtilities.StripRichTextTags(ButtonHintCache.Filter(text.text))?.Trim();
if (string.IsNullOrWhiteSpace(rendered) || TextUtilities.IsPlaceholderText(rendered))
{
DebugLogger.Log($"[AgreeWindow] Header: m_Header.m_headerText.text unusable: {TextUtilities.DescribeUnusable(rendered)}");
return null;
}
return rendered;
}
catch (System.Exception ex)
{
DebugLogger.Log($"[AgreeWindow] Header read failed: {ex.Message}");
return null;
}
}
private string GetSelectionName(int cursor)
{
if (_window == null)
{
DebugLogger.Log("[AgreeWindow] Selection: window is unavailable");
return cursor == 0 ? "Yes" : "No";
}
try
{
if (cursor == (int)uAgreeWindow.CursorIndex.Yes)
{
var yesText = _window.m_yes;
if (yesText == null)
{
DebugLogger.Log("[AgreeWindow] Selection: m_yes was null");
return "Yes";
}
string rendered = TextUtilities.StripRichTextTags(ButtonHintCache.Filter(yesText.text))?.Trim();
if (string.IsNullOrWhiteSpace(rendered) || TextUtilities.IsPlaceholderText(rendered))
{
DebugLogger.Log($"[AgreeWindow] Selection: m_yes.text unusable: {TextUtilities.DescribeUnusable(rendered)}");
return "Yes";
}
return rendered;
}
var noText = _window.m_no;
if (noText == null)
{
DebugLogger.Log("[AgreeWindow] Selection: m_no was null");
return "No";
}
string noRendered = TextUtilities.StripRichTextTags(ButtonHintCache.Filter(noText.text))?.Trim();
if (string.IsNullOrWhiteSpace(noRendered) || TextUtilities.IsPlaceholderText(noRendered))
{
DebugLogger.Log($"[AgreeWindow] Selection: m_no.text unusable: {TextUtilities.DescribeUnusable(noRendered)}");
return "No";
}
return noRendered;
}
catch (System.Exception ex)
{
DebugLogger.Log($"[AgreeWindow] Selection text read failed for cursor {cursor}: {ex.Message}");
}
// Fallback to Yes/No based on CursorIndex enum
return cursor == (int)uAgreeWindow.CursorIndex.Yes ? "Yes" : "No";
}
public void AnnounceStatus()
{
if (!IsOpen())
return;
var windowType = _window.m_currentWindowType;
int cursor = (int)_window.m_cursorIndex;
string windowName = GetWindowTypeName(windowType);
string selection = GetSelectionName(cursor);
string announcement = AnnouncementBuilder.MenuOpen(windowName, selection, cursor, 2);
ScreenReader.Say(announcement);
}
}
}