-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCommonSelectWindowHandler.cs
More file actions
489 lines (418 loc) · 17.5 KB
/
Copy pathCommonSelectWindowHandler.cs
File metadata and controls
489 lines (418 loc) · 17.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
using Il2Cpp;
using UnityEngine;
namespace DigimonNOAccess
{
/// <summary>
/// Handles accessibility for the common selection window.
/// Used by Birdramon transport, shops, museum, treasure hunting, and many other NPC menus.
/// Announces item names with costs (Bits/Points/Coins) when applicable.
/// </summary>
public class CommonSelectWindowHandler : HandlerBase<uCommonSelectWindowPanel>
{
protected override string LogTag => "[CommonSelectWindow]";
public override int Priority => 35;
private ParameterCommonSelectWindowMode.OutMode _currentOutMode;
private ParameterCommonSelectWindowMode.WindowType _windowType;
public override bool IsOpen()
{
if (_panel == null)
{
_panel = Object.FindObjectOfType<uCommonSelectWindowPanel>();
}
if (_panel == null)
return false;
try
{
return _panel.isEnabelPanel();
}
catch
{
return _panel.gameObject != null && _panel.gameObject.activeInHierarchy;
}
}
protected override void OnOpen()
{
_lastCursor = -1;
_currentOutMode = ParameterCommonSelectWindowMode.OutMode.None;
_windowType = ParameterCommonSelectWindowMode.WindowType.None;
if (_panel == null)
return;
try { _currentOutMode = _panel.m_outMode; } catch { }
try { _windowType = _panel.m_windowType; } catch { }
int cursor = GetCursorPosition();
string itemText = GetItemAnnouncement(cursor);
int total = GetMenuItemCount();
string title = GetWindowTitle();
string announcement = AnnouncementBuilder.MenuOpen(title, itemText, cursor, total);
string desc = GetItemDescription(cursor);
if (!string.IsNullOrEmpty(desc))
announcement += $". {desc}";
// On open, also announce player's current balance if this menu has costs
string balance = GetPlayerBalance();
if (!string.IsNullOrEmpty(balance))
announcement += $". {balance}";
ScreenReader.Say(announcement);
DebugLogger.Log($"{LogTag} Menu opened: type={_windowType}, outMode={_currentOutMode}, cursor={cursor}, total={total}");
_lastCursor = cursor;
}
protected override void OnClose()
{
base.OnClose();
}
protected override void OnUpdate()
{
if (ModInputManager.IsActionTriggered("ShopCheckBits"))
{
string balance = GetPlayerBalance();
ScreenReader.Say(!string.IsNullOrEmpty(balance) ? balance : "Bits unknown");
return;
}
CheckCursorChange();
}
private void CheckCursorChange()
{
if (_panel == null)
return;
int cursor = GetCursorPosition();
if (cursor != _lastCursor && cursor >= 0)
{
string itemText = GetItemAnnouncement(cursor);
int total = GetMenuItemCount();
string announcement = AnnouncementBuilder.CursorPosition(itemText, cursor, total);
string desc = GetItemDescription(cursor);
if (!string.IsNullOrEmpty(desc))
announcement += $". {desc}";
ScreenReader.Say(announcement);
DebugLogger.Log($"{LogTag} Cursor changed: {itemText}");
_lastCursor = cursor;
}
}
/// <summary>
/// Builds the full announcement for an item: name + cost + description if applicable.
/// </summary>
private string GetItemAnnouncement(int index)
{
string name = GetMenuItemText(index);
string cost = GetItemCost(index);
string announcement = name;
if (!string.IsNullOrEmpty(cost))
announcement += $", {cost}";
return announcement;
}
/// <summary>
/// Gets the best available name for a menu item.
/// Reads directly from the UI's uItemParts.m_name text (what sighted players see).
/// Falls back to ParameterCommonSelectWindow.GetLanguageString() if UI text unavailable.
/// </summary>
private string GetMenuItemText(int index)
{
string fallback = AnnouncementBuilder.FallbackItem("Option", index);
if (_panel == null)
{
DebugLogger.Log($"{LogTag} Item name: m_panel was null");
return fallback;
}
// Primary: read the actual rendered UI text from uItemParts
try
{
var itemPanel = _panel.m_itemPanel;
if (itemPanel == null)
{
DebugLogger.Log($"{LogTag} Item name: m_itemPanel was null");
}
else
{
var parts = itemPanel.GetSelectItemParts(index);
if (parts == null)
{
DebugLogger.Log($"{LogTag} Item name: GetSelectItemParts({index}) returned null");
}
else
{
var nameText = parts.m_name;
if (nameText == null)
{
DebugLogger.Log($"{LogTag} Item name: selected uItemParts.m_name was null");
}
else
{
string cleaned = TextUtilities.StripRichTextTags(ButtonHintCache.Filter(nameText.text))?.Trim();
if (!string.IsNullOrWhiteSpace(cleaned))
return cleaned;
DebugLogger.Log($"{LogTag} Item name: selected uItemParts.m_name.text was empty");
}
}
}
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} Error reading UI item text: {ex.Message}");
}
// Fallback: param language string
try
{
var paramList = _panel.m_paramCommonSelectWindowList;
if (paramList == null)
{
DebugLogger.Log($"{LogTag} Item name: m_paramCommonSelectWindowList was null");
return fallback;
}
if (index < 0 || index >= paramList.Count)
{
DebugLogger.Log($"{LogTag} Item name: index {index} was outside m_paramCommonSelectWindowList count {paramList.Count}");
return fallback;
}
var param = paramList[index];
if (param == null)
{
DebugLogger.Log($"{LogTag} Item name: m_paramCommonSelectWindowList[{index}] was null");
return fallback;
}
string text = TextUtilities.StripRichTextTags(ButtonHintCache.Filter(param.GetLanguageString()))?.Trim();
if (!string.IsNullOrWhiteSpace(text))
return text;
DebugLogger.Log($"{LogTag} Item name: ParameterCommonSelectWindow.GetLanguageString() was empty for index {index}");
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} Error reading param text: {ex.Message}");
}
return fallback;
}
/// <summary>
/// Gets the cost string for an item, e.g. "100 Bits".
/// Returns null if this menu doesn't show costs.
/// </summary>
private string GetItemCost(int index)
{
if (_currentOutMode == ParameterCommonSelectWindowMode.OutMode.None)
return null;
try
{
var paramList = _panel?.m_paramCommonSelectWindowList;
if (paramList != null && index >= 0 && index < paramList.Count)
{
var param = paramList[index];
if (param != null)
{
int cost = param.m_value;
if (cost > 0)
{
string currency = GetCurrencyName();
return $"{cost} {currency}";
}
}
}
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} Error reading cost: {ex.Message}");
}
return null;
}
/// <summary>
/// Gets the item description via ParameterItemData looked up from uItemParts.itemID.
/// </summary>
private string GetItemDescription(int index)
{
try
{
var paramList = _panel?.m_paramCommonSelectWindowList;
if (paramList == null || index < 0 || index >= paramList.Count)
return null;
var param = paramList[index];
if (param == null) return null;
// scriptCommandParam1 contains the item string ID (e.g. "item_other_003")
string itemStringId = param.m_scriptCommandParam1;
if (string.IsNullOrEmpty(itemStringId))
return null;
uint itemHash = Language.makeHash(itemStringId);
var paramItemData = ParameterItemData.GetParam(itemHash);
if (paramItemData == null) return null;
string desc = paramItemData.GetDescription();
if (!string.IsNullOrEmpty(desc))
return TextUtilities.CleanText(desc);
}
catch { }
return null;
}
/// <summary>
/// Gets the player's current balance from the mode panel's value text.
/// </summary>
private string GetPlayerBalance()
{
if (_currentOutMode == ParameterCommonSelectWindowMode.OutMode.None)
return null;
try
{
var modePanel = GetCurrentModePanel("balance");
if (modePanel == null)
return null;
var valueText = modePanel.m_valueText;
if (valueText == null)
{
DebugLogger.Log($"{LogTag} Balance: m_valueText was null");
return null;
}
string text = TextUtilities.StripRichTextTags(ButtonHintCache.Filter(valueText.text))?.Trim();
if (string.IsNullOrWhiteSpace(text) || TextUtilities.IsPlaceholderText(text))
{
DebugLogger.Log($"{LogTag} Balance: m_valueText.text unusable: {TextUtilities.DescribeUnusable(text)}");
return null;
}
string currency = GetCurrencyName();
return $"Your {currency}: {text}";
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} Error reading balance: {ex.Message}");
}
return null;
}
private string GetCurrencyName()
{
string fallback = _currentOutMode switch
{
ParameterCommonSelectWindowMode.OutMode.Bit => "Bits",
ParameterCommonSelectWindowMode.OutMode.DailyQuestPoint => "Daily Quest Points",
ParameterCommonSelectWindowMode.OutMode.Coin => "Coins",
_ => "currency"
};
var modePanel = GetCurrentModePanel("currency title");
if (modePanel == null)
return fallback;
try
{
var titleText = modePanel.m_titleText;
if (titleText == null)
{
DebugLogger.Log($"{LogTag} Currency title: m_titleText was null");
return fallback;
}
string cleaned = TextUtilities.StripRichTextTags(ButtonHintCache.Filter(titleText.text))?.Trim();
if (string.IsNullOrWhiteSpace(cleaned) || TextUtilities.IsPlaceholderText(cleaned))
{
DebugLogger.Log($"{LogTag} Currency title: m_titleText.text unusable: {TextUtilities.DescribeUnusable(cleaned)}");
return fallback;
}
return cleaned;
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} Currency title read failed: {ex.Message}");
return fallback;
}
}
private uCommonSelectWindowPanelMode GetCurrentModePanel(string purpose)
{
try
{
if (_panel == null)
{
DebugLogger.Log($"{LogTag} {purpose}: m_panel was null");
return null;
}
var modeTable = _panel.m_uCommonSelectWindowModeTbl;
if (modeTable == null)
{
DebugLogger.Log($"{LogTag} {purpose}: m_uCommonSelectWindowModeTbl was null");
return null;
}
int modeIndex = (int)_currentOutMode;
if (modeIndex < 0 || modeIndex >= modeTable.Length)
{
DebugLogger.Log($"{LogTag} {purpose}: mode index {modeIndex} was outside m_uCommonSelectWindowModeTbl length {modeTable.Length}");
return null;
}
var modePanel = modeTable[modeIndex];
if (modePanel == null)
{
DebugLogger.Log($"{LogTag} {purpose}: m_uCommonSelectWindowModeTbl[{modeIndex}] was null");
return null;
}
return modePanel;
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} {purpose} chain read failed: {ex.Message}");
return null;
}
}
/// <summary>
/// Gets the window title. Uses descriptive name from window type since
/// the caption panel text often contains button labels rather than titles.
/// </summary>
private string GetWindowTitle()
{
return GetWindowTypeName();
}
private string GetWindowTypeName()
{
return _windowType switch
{
ParameterCommonSelectWindowMode.WindowType.Transmission => "Transport",
ParameterCommonSelectWindowMode.WindowType.TreasureHunting => "Treasure Hunting",
ParameterCommonSelectWindowMode.WindowType.Museum => "Museum",
ParameterCommonSelectWindowMode.WindowType.MovieTheater => "Movie Theater",
ParameterCommonSelectWindowMode.WindowType.TamerInfo => "Tamer Info",
ParameterCommonSelectWindowMode.WindowType.AdventureInfo => "Adventure Info",
ParameterCommonSelectWindowMode.WindowType.ExDungeonEntrance => "Ex Dungeon",
ParameterCommonSelectWindowMode.WindowType.ExDungeonSupport => "Ex Dungeon Support",
ParameterCommonSelectWindowMode.WindowType.LaboratorySkillLearn => "Skill Learn",
ParameterCommonSelectWindowMode.WindowType.TrainingMachineGradeUp => "Training Machine Upgrade",
ParameterCommonSelectWindowMode.WindowType.TrainingTutorial => "Training Tutorial",
ParameterCommonSelectWindowMode.WindowType.EntertainmentZonePrizeChange => "Prize Exchange",
ParameterCommonSelectWindowMode.WindowType.TreasureFoodShop01 => "Food Shop",
ParameterCommonSelectWindowMode.WindowType.TreasureFoodShop02 => "Food Shop",
ParameterCommonSelectWindowMode.WindowType.TreasureMaterial => "Material Exchange",
_ => "Selection Menu"
};
}
private int GetCursorPosition()
{
try
{
var itemPanel = _panel?.m_itemPanel;
if (itemPanel != null)
{
return itemPanel.m_selectNo;
}
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} Error getting cursor: {ex.Message}");
}
return 0;
}
private int GetMenuItemCount()
{
try
{
var paramList = _panel?.m_paramCommonSelectWindowList;
if (paramList != null)
{
return paramList.Count;
}
}
catch { }
return 1;
}
public override void AnnounceStatus()
{
if (!IsOpen())
return;
int cursor = GetCursorPosition();
string itemText = GetItemAnnouncement(cursor);
int total = GetMenuItemCount();
string title = GetWindowTitle();
string announcement = AnnouncementBuilder.MenuOpen(title, itemText, cursor, total);
string desc = GetItemDescription(cursor);
if (!string.IsNullOrEmpty(desc))
announcement += $". {desc}";
string balance = GetPlayerBalance();
if (!string.IsNullOrEmpty(balance))
announcement += $". {balance}";
ScreenReader.Say(announcement);
}
}
}