Repository navigation
Expand file tree
/
Copy pathCardGalleryHandler.cs
More file actions
239 lines (201 loc) · 6.85 KB
/
Copy pathCardGalleryHandler.cs
File metadata and controls
239 lines (201 loc) · 6.85 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
using Il2Cpp;
using UnityEngine;
namespace DigimonNOAccess
{
public class CardGalleryHandler : IAccessibilityHandler
{
private const string LogTag = "[CardGallery]";
private uCardGalleryPanel _panel;
private bool _wasOpen;
private string _lastName = "";
public int Priority => 55;
public bool IsOpen()
{
if (_panel == null)
_panel = Object.FindObjectOfType<uCardGalleryPanel>();
if (_panel == null)
return false;
try
{
return _panel.gameObject != null && _panel.gameObject.activeInHierarchy;
}
catch
{
return false;
}
}
public void Update()
{
bool isOpen = IsOpen();
if (isOpen && !_wasOpen)
{
OnOpen();
}
else if (!isOpen && _wasOpen)
{
OnClose();
}
else if (isOpen)
{
CheckCursorChange();
}
_wasOpen = isOpen;
}
private void OnOpen()
{
_lastName = "";
string collected = GetCollectionProgress();
string cardText = GetCardText();
string currentName = GetCurrentName();
string header = string.IsNullOrEmpty(collected)
? "Card Gallery"
: $"Card Gallery, {collected}";
ScreenReader.Say(header);
if (!string.IsNullOrEmpty(currentName))
{
ScreenReader.SayQueued(cardText);
_lastName = currentName;
}
DebugLogger.Log($"{LogTag} Opened, {collected}");
}
private void OnClose()
{
_lastName = "";
DebugLogger.Log($"{LogTag} Closed");
}
private void CheckCursorChange()
{
string currentName = GetCurrentName();
if (!string.IsNullOrEmpty(currentName) && currentName != _lastName)
{
_lastName = currentName;
string cardText = GetCardText();
ScreenReader.Say(cardText);
DebugLogger.Log($"{LogTag} Cursor: {cardText}");
}
}
private string GetCurrentName()
{
try
{
var nameText = _panel?.m_CardNameName;
if (nameText != null)
return nameText.text ?? "";
}
catch { }
return "";
}
private string GetCardText()
{
string cardName = GetRenderedCardName();
try
{
var parts = new System.Collections.Generic.List<string>();
if (!string.IsNullOrEmpty(cardName))
parts.Add(cardName);
var numberText = _panel?.m_CardNameNumber;
string numStr = numberText?.text;
int total = GetTotalCards();
int cardNum = -1;
if (!string.IsNullOrEmpty(numStr) && int.TryParse(numStr, out cardNum))
{
if (total > 0)
parts.Add($"{cardNum} of {total}");
else
parts.Add($"Number {cardNum}");
}
if (cardNum > 0)
{
try
{
var cardData = ParameterDigimonCardData.GetParam(cardNum);
if (cardData != null)
{
string rarity = ((ParameterDigimonCardData.RarityIndex)cardData.m_rarity).ToString();
parts.Add($"Rarity {rarity}");
}
}
catch { }
}
if (parts.Count > 0)
return string.Join(", ", parts);
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} Error: {ex.Message}");
}
if (string.IsNullOrWhiteSpace(cardName))
return "Card";
return cardName;
}
private string GetRenderedCardName()
{
try
{
if (_panel == null)
{
DebugLogger.Log($"{LogTag} Card name: m_panel was null");
return "";
}
var nameText = _panel.m_CardNameName;
if (nameText == null)
{
DebugLogger.Log($"{LogTag} Card name: m_CardNameName was null");
return "";
}
string cleaned = TextUtilities.StripRichTextTags(ButtonHintCache.Filter(nameText.text))?.Trim();
if (string.IsNullOrWhiteSpace(cleaned) || TextUtilities.IsPlaceholderText(cleaned))
{
DebugLogger.Log($"{LogTag} Card name: m_CardNameName.text unusable: {TextUtilities.DescribeUnusable(cleaned)}");
return "";
}
return cleaned;
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} Card name read failed: {ex.Message}");
return "";
}
}
private int GetTotalCards()
{
try
{
var max = _panel?.m_PossessionMax;
if (max != null && !string.IsNullOrEmpty(max.text) &&
int.TryParse(max.text, out int total))
return total;
}
catch { }
return 0;
}
private string GetCollectionProgress()
{
try
{
var current = _panel?.m_PossessionCurrent;
var max = _panel?.m_PossessionMax;
if (current != null && max != null &&
!string.IsNullOrEmpty(current.text) && !string.IsNullOrEmpty(max.text))
{
string curStr = int.TryParse(current.text, out int curNum) ? curNum.ToString() : current.text;
string maxStr = int.TryParse(max.text, out int maxNum) ? maxNum.ToString() : max.text;
return $"Collected {curStr} of {maxStr}";
}
}
catch { }
return "";
}
public void AnnounceStatus()
{
if (!IsOpen())
return;
string cardText = GetCardText();
string collected = GetCollectionProgress();
string announcement = string.IsNullOrEmpty(collected)
? $"Card Gallery, {cardText}"
: $"Card Gallery, {collected}, {cardText}";
ScreenReader.Say(announcement);
}
}
}