Repository navigation
Expand file tree
/
Copy pathEvolutionDojoHandler.cs
More file actions
661 lines (569 loc) · 22.5 KB
/
Copy pathEvolutionDojoHandler.cs
File metadata and controls
661 lines (569 loc) · 22.5 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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
using Il2Cpp;
using UnityEngine;
namespace DigimonNOAccess
{
public class EvolutionDojoHandler : IAccessibilityHandler
{
private const string LogTag = "[EvoDojo]";
public int Priority => 70;
private uEvolutionDojoPanel _panel;
private bool _wasOpen;
private int _lastCursorX = -1;
private int _lastCursorY = -1;
private int _lastSelectPartner = -1;
private uGenelogyUI.Type _lastType = uGenelogyUI.Type.None;
private bool _lastEvoAfter = false;
private string _lastAnnouncedName = "";
private static readonly string[] GrowthNames =
{ "Baby 1", "Baby 2", "Rookie", "Champion", "Ultimate", "Mega", "Ultra" };
public bool IsOpen()
{
try
{
_panel = uEvolutionDojoPanel.Ref;
if (_panel == null) return false;
return _panel.m_State == uEvolutionDojoPanel.State.Normal;
}
catch
{
_panel = null;
return false;
}
}
public void Update()
{
bool isOpen = IsOpen();
if (isOpen && !_wasOpen)
OnOpen();
else if (!isOpen && _wasOpen)
OnClose();
else if (isOpen)
OnUpdate();
_wasOpen = isOpen;
}
private void OnOpen()
{
_lastCursorX = -1;
_lastCursorY = -1;
_lastSelectPartner = -1;
_lastType = uGenelogyUI.Type.None;
_lastEvoAfter = false;
_lastAnnouncedName = "";
var genelogy = GetGenelogy();
if (genelogy == null)
{
ScreenReader.Say(GetPanelTitle());
return;
}
_lastSelectPartner = _panel.m_SelectPartner;
_lastType = genelogy.m_Type;
string generation = GetGenerationText();
string announcement = GetPanelTitle();
if (!string.IsNullOrEmpty(generation))
announcement += ", " + generation;
ScreenReader.Say(announcement);
DebugLogger.Log($"{LogTag} Opened: {announcement}");
// Announce cursor position (name, stage, probability, index, description)
_lastCursorX = genelogy.m_CursorX;
_lastCursorY = genelogy.m_CursorY;
AnnounceCursorItem(genelogy, queued: true);
}
private void OnClose()
{
_panel = null;
_lastCursorX = -1;
_lastCursorY = -1;
_lastSelectPartner = -1;
_lastAnnouncedName = "";
DebugLogger.Log($"{LogTag} Closed");
}
private void OnUpdate()
{
if (_panel == null) return;
var genelogy = GetGenelogy();
if (genelogy == null) return;
try
{
// Check partner switch
int currentPartner = _panel.m_SelectPartner;
if (currentPartner != _lastSelectPartner && _lastSelectPartner >= 0)
{
_lastSelectPartner = currentPartner;
_lastAnnouncedName = "";
_lastCursorX = genelogy.m_CursorX;
_lastCursorY = genelogy.m_CursorY;
AnnounceCursorItem(genelogy);
return;
}
_lastSelectPartner = currentPartner;
// Check type change (Dojo vs History)
var currentType = genelogy.m_Type;
if (currentType != _lastType)
{
DebugLogger.Log($"{LogTag} Type changed: {_lastType} -> {currentType}");
_lastType = currentType;
}
// Check evo after state change (entering/exiting future evolution view)
bool evoAfter = genelogy.m_SelectEvoAfter;
if (evoAfter != _lastEvoAfter)
{
_lastEvoAfter = evoAfter;
_lastAnnouncedName = "";
}
// Check cursor movement
int cx = genelogy.m_CursorX;
int cy = genelogy.m_CursorY;
if (cx != _lastCursorX || cy != _lastCursorY)
{
_lastCursorX = cx;
_lastCursorY = cy;
AnnounceCursorItem(genelogy);
}
}
catch (System.Exception ex)
{
DebugLogger.Error($"{LogTag} Update error: {ex.Message}");
}
}
private void AnnounceCursorItem(uGenelogyUI genelogy, bool queued = false)
{
bool evoAfter = genelogy.m_SelectEvoAfter;
// When viewing future evolutions, read evo name; otherwise read current name
string name;
if (evoAfter)
{
name = GetInfoPanelEvoName();
if (string.IsNullOrEmpty(name))
name = GetInfoPanelName();
}
else
{
name = GetInfoPanelName();
if (string.IsNullOrEmpty(name))
name = GetInfoPanelEvoName();
}
// Avoid repeating the exact same announcement
if (name == _lastAnnouncedName && !string.IsNullOrEmpty(name))
return;
_lastAnnouncedName = name ?? "";
if (string.IsNullOrEmpty(name))
{
DebugLogger.Log($"{LogTag} Cursor ({_lastCursorX},{_lastCursorY}): empty cell");
return;
}
string announcement = name;
// Add growth stage
string stage = GetGrowthStageForName(name);
if (!string.IsNullOrEmpty(stage))
announcement += ", " + stage;
// Add probability
string probability = GetProbability(genelogy);
if (!string.IsNullOrEmpty(probability))
announcement += ", " + probability;
// Add locked status
if (IsCurrentLocked(genelogy))
announcement += ", Locked";
// Add grid position context
int maxX = genelogy.m_CursorX_Max;
int maxY = genelogy.m_CursorY_Max;
if (maxX > 0 || maxY > 0)
announcement += $", {_lastCursorX + 1} of {maxX + 1}";
// Add description after index (only for past/current forms - not for future evos)
if (!evoAfter)
{
string description = GetInfoPanelText("m_Description");
if (!string.IsNullOrEmpty(description))
announcement += ", " + description;
}
// For future evolutions, add nature/attribute and conditions
if (evoAfter)
{
string nature = GetInfoPanelText("m_Nature_Evo");
if (!string.IsNullOrEmpty(nature))
announcement += $", {GetInfoLabel(true, true)}: {nature}";
string property = GetInfoPanelText("m_Property_Evo");
if (!string.IsNullOrEmpty(property))
announcement += $", {GetInfoLabel(false, true)}: {property}";
string conditions = GetConditionsText();
if (!string.IsNullOrEmpty(conditions))
announcement += ", Conditions: " + conditions;
}
if (queued)
ScreenReader.SayQueued(announcement);
else
ScreenReader.Say(announcement);
DebugLogger.Log($"{LogTag} Cursor ({_lastCursorX},{_lastCursorY}): {announcement}");
}
public void AnnounceStatus()
{
if (!IsOpen()) return;
var genelogy = GetGenelogy();
if (genelogy == null)
{
ScreenReader.Say(GetPanelTitle());
return;
}
string announcement = GetPanelTitle();
// Partner
string partnerName = GetCurrentPartnerName();
if (!string.IsNullOrEmpty(partnerName))
announcement += ", " + partnerName;
// Current digimon name
string name = GetInfoPanelName();
if (!string.IsNullOrEmpty(name))
announcement += ", " + name;
// Nature and property
string nature = GetInfoPanelText("m_Nature");
if (!string.IsNullOrEmpty(nature))
announcement += $", {GetInfoLabel(true, false)}: {nature}";
string property = GetInfoPanelText("m_Property");
if (!string.IsNullOrEmpty(property))
announcement += $", {GetInfoLabel(false, false)}: {property}";
// Description
string description = GetInfoPanelText("m_Description");
if (!string.IsNullOrEmpty(description))
announcement += ", " + description;
// Growth stage
string stage = GetGrowthStageForName(name);
if (!string.IsNullOrEmpty(stage))
announcement += ", Stage: " + stage;
// Probability
string probability = GetProbability(genelogy);
if (!string.IsNullOrEmpty(probability))
announcement += ", " + probability;
// Locked
if (IsCurrentLocked(genelogy))
announcement += ", Locked";
// Evolution conditions
string conditions = GetConditionsText();
if (!string.IsNullOrEmpty(conditions))
announcement += ", Conditions: " + conditions;
// Evolution target
string evoName = GetInfoPanelEvoName();
if (!string.IsNullOrEmpty(evoName) && evoName != name)
announcement += ", Evolves to: " + evoName;
// Generation
string generation = GetGenerationText();
if (!string.IsNullOrEmpty(generation))
announcement += ", " + generation;
// Grid position
announcement += $", Position {_lastCursorX + 1} of {genelogy.m_CursorX_Max + 1}";
ScreenReader.Say(announcement);
DebugLogger.Log($"{LogTag} Status: {announcement}");
}
// --- Helpers ---
private string GetPanelTitle()
{
const string fallback = "Evolution Dojo";
try
{
if (_panel == null)
{
DebugLogger.Log($"{LogTag} Title: m_panel was null");
return fallback;
}
var headLine = _panel.m_HeadLine;
if (headLine == null)
{
DebugLogger.Log($"{LogTag} Title: m_HeadLine was null");
return fallback;
}
return GetRenderedText(headLine.m_ScreenNameText, "m_HeadLine.m_ScreenNameText", fallback);
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} Title read failed: {ex.Message}");
return fallback;
}
}
private string GetInfoLabel(bool nature, bool evo)
{
string fallback = nature ? "Nature" : "Attribute";
try
{
if (_panel == null)
{
DebugLogger.Log($"{LogTag} {fallback} label: m_panel was null");
return fallback;
}
var genelogy = _panel.m_Genelogy;
if (genelogy == null)
{
DebugLogger.Log($"{LogTag} {fallback} label: m_Genelogy was null");
return fallback;
}
var info = genelogy.m_GenelogyInfo;
if (info == null)
{
DebugLogger.Log($"{LogTag} {fallback} label: m_GenelogyInfo was null");
return fallback;
}
UnityEngine.UI.Text label;
string fieldName;
if (nature)
{
label = evo ? info.m_NatureTitle_Evo : info.m_NatureTitle;
fieldName = evo ? "m_NatureTitle_Evo" : "m_NatureTitle";
}
else
{
label = evo ? info.m_PropertyTitle_Evo : info.m_PropertyTitle;
fieldName = evo ? "m_PropertyTitle_Evo" : "m_PropertyTitle";
}
return GetRenderedText(label, $"m_GenelogyInfo.{fieldName}", fallback)
.TrimEnd(':', ':')
.Trim();
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} {fallback} label read failed: {ex.Message}");
return fallback;
}
}
private string GetRenderedText(UnityEngine.UI.Text textComponent, string fieldName, string fallback)
{
if (textComponent == null)
{
DebugLogger.Log($"{LogTag} {fieldName} was null");
return fallback;
}
try
{
string cleaned = TextUtilities.StripRichTextTags(ButtonHintCache.Filter(textComponent.text))?.Trim();
if (string.IsNullOrWhiteSpace(cleaned) || TextUtilities.IsPlaceholderText(cleaned))
{
DebugLogger.Log($"{LogTag} {fieldName}.text unusable: {TextUtilities.DescribeUnusable(cleaned)}");
return fallback;
}
return cleaned;
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} {fieldName} read failed: {ex.Message}");
return fallback;
}
}
private uGenelogyUI GetGenelogy()
{
try
{
return _panel?.m_Genelogy;
}
catch { return null; }
}
private uGenelogyInformationUI GetInfoPanel()
{
try
{
return GetGenelogy()?.m_GenelogyInfo;
}
catch { return null; }
}
private string GetInfoPanelName()
{
try
{
var info = GetInfoPanel();
if (info == null) return null;
var nameText = info.m_DigimonName;
if (nameText == null) return null;
string text = nameText.text;
if (string.IsNullOrEmpty(text)) return null;
return TextUtilities.StripRichTextTags(text);
}
catch { return null; }
}
private string GetInfoPanelEvoName()
{
try
{
var info = GetInfoPanel();
if (info == null) return null;
var nameText = info.m_DigimonName_Evo;
if (nameText == null) return null;
string text = nameText.text;
if (string.IsNullOrEmpty(text)) return null;
return TextUtilities.StripRichTextTags(text);
}
catch { return null; }
}
private string GetInfoPanelText(string fieldName)
{
try
{
var info = GetInfoPanel();
if (info == null) return null;
UnityEngine.UI.Text textComp = fieldName switch
{
"m_Nature" => info.m_Nature,
"m_Property" => info.m_Property,
"m_Description" => info.m_Description,
"m_Nature_Evo" => info.m_Nature_Evo,
"m_Property_Evo" => info.m_Property_Evo,
_ => null
};
if (textComp == null) return null;
string text = textComp.text;
if (string.IsNullOrEmpty(text)) return null;
return TextUtilities.StripRichTextTags(text);
}
catch { return null; }
}
private string GetProbability(uGenelogyUI genelogy)
{
try
{
// The game shows one of these GameObjects depending on probability
if (genelogy.m_Fix != null && genelogy.m_Fix.activeSelf)
return "Guaranteed";
if (genelogy.m_High != null && genelogy.m_High.activeSelf)
return "High chance";
if (genelogy.m_Mid != null && genelogy.m_Mid.activeSelf)
return "Medium chance";
if (genelogy.m_Low != null && genelogy.m_Low.activeSelf)
return "Low chance";
// Check the Possibility parent - if not active, no probability shown
if (genelogy.m_Possibility != null && !genelogy.m_Possibility.activeSelf)
return null;
return null;
}
catch { return null; }
}
private bool IsCurrentLocked(uGenelogyUI genelogy)
{
try
{
if (genelogy.m_Rock != null && genelogy.m_Rock.activeSelf)
return true;
return false;
}
catch { return false; }
}
private string GetGrowthStageForName(string digimonName)
{
if (string.IsNullOrEmpty(digimonName)) return null;
try
{
var paramManager = AppMainScript.parameterManager;
if (paramManager == null) return null;
var digimonData = paramManager.digimonData;
if (digimonData == null) return null;
int count = digimonData.GetRecordMax();
for (int i = 0; i < count; i++)
{
try
{
var param = digimonData.GetParams(i);
if (param == null) continue;
string name = param.GetDefaultName();
if (name == digimonName)
{
int growth = param.m_growth;
if (growth >= 0 && growth < GrowthNames.Length)
return GrowthNames[growth];
return null;
}
}
catch { }
}
return null;
}
catch { return null; }
}
private string GetConditionsText()
{
try
{
var info = GetInfoPanel();
if (info == null) return null;
var titles = info.m_ConditionsTitleText;
var values = info.m_ConditionsValueText;
if (titles == null || values == null) return null;
var parts = new System.Collections.Generic.List<string>();
int count = System.Math.Min(titles.Length, values.Length);
for (int i = 0; i < count; i++)
{
try
{
if (titles[i] == null || values[i] == null) continue;
string title = titles[i].text;
string value = values[i].text;
if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(value)) continue;
title = TextUtilities.StripRichTextTags(title);
value = TextUtilities.StripRichTextTags(value);
// Replace universal visual symbols with speech-friendly text
if (value == "???" || value == "???")
value = "not met";
else if (value == "—" || value == "-" || value == "-" || value == "―")
value = "met";
parts.Add($"{title} {value}");
}
catch { }
}
return parts.Count > 0 ? string.Join(", ", parts) : null;
}
catch { return null; }
}
private string GetGenerationText()
{
try
{
if (_panel == null)
{
DebugLogger.Log($"{LogTag} Generation: m_panel was null");
return null;
}
var genelogy = _panel.m_Genelogy;
if (genelogy == null)
{
DebugLogger.Log($"{LogTag} Generation: m_Genelogy was null");
return null;
}
var text = genelogy.m_GenerationText;
if (text == null)
{
DebugLogger.Log($"{LogTag} Generation: m_GenerationText was null");
return null;
}
string value = TextUtilities.StripRichTextTags(ButtonHintCache.Filter(text.text))?.Trim();
if (string.IsNullOrWhiteSpace(value) || TextUtilities.IsPlaceholderText(value))
{
DebugLogger.Log($"{LogTag} Generation: m_GenerationText.text unusable: {TextUtilities.DescribeUnusable(value)}");
return null;
}
string unit = GetRenderedText(genelogy.m_GenerationUnit, "m_GenerationUnit", "Generation");
return $"{unit} {value}";
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} Generation read failed: {ex.Message}");
return null;
}
}
private string GetCurrentPartnerName()
{
try
{
if (_panel == null) return null;
int partner = _panel.m_SelectPartner;
// Dojo panel uses m_SelectPartner directly (not inverted like uPartnerPanel)
var partnerCtrl = MainGameManager.GetPartnerCtrl(partner);
if (partnerCtrl != null)
{
var commonData = partnerCtrl.gameData?.m_commonData;
if (commonData != null)
{
string name = commonData.m_name;
if (!string.IsNullOrEmpty(name) && !name.Contains("ランゲージ"))
return name;
}
}
return PartnerUtilities.GetPartnerLabel(partner);
}
catch
{
return _panel != null ? PartnerUtilities.GetPartnerLabel(_panel.m_SelectPartner) : "Partner";
}
}
}
}