-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDialogHandler.cs
More file actions
137 lines (115 loc) · 4.04 KB
/
Copy pathDialogHandler.cs
File metadata and controls
137 lines (115 loc) · 4.04 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
using Il2Cpp;
using UnityEngine;
using UnityEngine.UI;
namespace DigimonNOAccess
{
/// <summary>
/// Handles accessibility for yes/no dialogs.
/// </summary>
public class DialogHandler : HandlerBase<uDialogBase>
{
protected override string LogTag => "[Dialog]";
public override int Priority => 30;
private uDialogBase.CursorIndex _lastDialogCursor = uDialogBase.CursorIndex.Yes;
public override bool IsOpen()
{
_panel = Object.FindObjectOfType<uDialogBase>();
return _panel != null && _panel.m_isOpend;
}
protected override void OnOpen()
{
_lastDialogCursor = uDialogBase.CursorIndex.Yes;
if (_panel == null)
return;
// Try to get dialog text from child Text components
string dialogText = GetDialogText();
string currentChoice = GetCursorText(_panel.m_cursorIndex);
string announcement = "Dialog";
if (!string.IsNullOrEmpty(dialogText))
announcement += $". {dialogText}";
announcement += $". {currentChoice} selected";
ScreenReader.Say(announcement);
DebugLogger.Log($"{LogTag} Opened: {dialogText}, cursor={_panel.m_cursorIndex}");
_lastDialogCursor = _panel.m_cursorIndex;
}
protected override void OnClose()
{
_lastDialogCursor = uDialogBase.CursorIndex.Yes;
base.OnClose();
}
protected override void OnUpdate()
{
CheckCursorChange();
}
private void CheckCursorChange()
{
if (_panel == null)
return;
var cursor = _panel.m_cursorIndex;
if (cursor != _lastDialogCursor)
{
string choice = GetCursorText(cursor);
ScreenReader.Say(choice);
DebugLogger.Log($"{LogTag} Cursor changed: {choice}");
_lastDialogCursor = cursor;
}
}
private string GetDialogText()
{
if (_panel == null)
return "";
try
{
// Try to find Text components in the dialog's children
var textComponents = _panel.GetComponentsInChildren<Text>();
if (textComponents != null)
{
foreach (var text in textComponents)
{
if (text != null && !string.IsNullOrEmpty(text.text))
{
string txt = text.text.Trim();
// Skip button labels like "Yes" "No"
if (txt.Length > 5 && txt != "Yes" && txt != "No")
{
return txt;
}
}
}
}
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} Error getting text: {ex.Message}");
}
return "";
}
private string GetCursorText(uDialogBase.CursorIndex cursor)
{
switch (cursor)
{
case uDialogBase.CursorIndex.Yes:
return "Yes";
case uDialogBase.CursorIndex.No:
return "No";
default:
return $"Option {(int)cursor}";
}
}
/// <summary>
/// Announce current status.
/// </summary>
public override void AnnounceStatus()
{
if (!IsOpen())
return;
string dialogText = GetDialogText();
string currentChoice = GetCursorText(_panel.m_cursorIndex);
string announcement = "Dialog";
if (!string.IsNullOrEmpty(dialogText))
announcement += $". {dialogText}";
announcement += $". {currentChoice} selected";
ScreenReader.Say(announcement);
}
}
}