-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStoragePanelHandler.cs
More file actions
432 lines (369 loc) · 14.3 KB
/
Copy pathStoragePanelHandler.cs
File metadata and controls
432 lines (369 loc) · 14.3 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
using Il2Cpp;
using UnityEngine;
namespace DigimonNOAccess
{
/// <summary>
/// Handles accessibility for the storage panel (item storage management)
/// </summary>
public class StoragePanelHandler : IAccessibilityHandler
{
public int Priority => 65;
private uStoragePanel _panel;
private bool _wasActive = false;
private int _lastCursorL = -1;
private int _lastCursorR = -1;
private uStoragePanelInfo.Type _lastArrowType = uStoragePanelInfo.Type.MAX;
public bool IsOpen()
{
if (_panel == null)
{
_panel = Object.FindObjectOfType<uStoragePanel>();
}
if (_panel == null)
return false;
return _panel.m_enabelPanel;
}
public void Update()
{
bool isActive = IsOpen();
if (isActive && !_wasActive)
{
OnOpen();
}
else if (!isActive && _wasActive)
{
OnClose();
}
else if (isActive)
{
CheckCursorChange();
}
_wasActive = isActive;
}
private void OnOpen()
{
_lastCursorL = -1;
_lastCursorR = -1;
_lastArrowType = uStoragePanelInfo.Type.MAX;
if (_panel == null)
return;
ScreenReader.Say(GetStorageCaption());
// Determine which side is initially focused and announce it
try
{
var infoPanel = _panel.m_infoPanel;
if (infoPanel != null)
_lastArrowType = infoPanel.m_arrowType;
}
catch { }
bool leftFocused = _lastArrowType == uStoragePanelInfo.Type.RIGHT;
var focusedPanel = leftFocused ? _panel.m_itemPanelL : _panel.m_itemPanelR;
if (focusedPanel != null)
{
var focusedSide = leftFocused ? uStoragePanelInfo.Type.LEFT : uStoragePanelInfo.Type.RIGHT;
string sectionName = GetStorageTypeName(focusedPanel, focusedSide);
string itemInfo = GetItemInfo(focusedPanel);
int cursor = focusedPanel.m_selectNo;
int total = GetItemCount(focusedPanel);
string itemAnnouncement = total > 0
? $"{sectionName}, {AnnouncementBuilder.CursorPosition(itemInfo, cursor, total)}"
: $"{sectionName}, empty";
ScreenReader.SayQueued(itemAnnouncement);
}
UpdateLastCursors();
DebugLogger.Log($"[StoragePanel] Opened");
}
private void OnClose()
{
_panel = null;
_lastCursorL = -1;
_lastCursorR = -1;
_lastArrowType = uStoragePanelInfo.Type.MAX;
DebugLogger.Log("[StoragePanel] Closed");
}
private void CheckCursorChange()
{
if (_panel == null)
return;
var leftPanel = _panel.m_itemPanelL;
var rightPanel = _panel.m_itemPanelR;
// Detect side switch via info panel arrow direction
bool sideSwitched = false;
try
{
var infoPanel = _panel.m_infoPanel;
if (infoPanel != null)
{
var arrowType = infoPanel.m_arrowType;
if (arrowType != _lastArrowType)
{
sideSwitched = true;
_lastArrowType = arrowType;
}
}
}
catch { }
// Check left panel
if (leftPanel != null)
{
int cursorL = leftPanel.m_selectNo;
bool leftChanged = cursorL != _lastCursorL;
bool leftJustFocused = sideSwitched && _lastArrowType == uStoragePanelInfo.Type.RIGHT;
if (leftChanged || leftJustFocused)
{
AnnounceItemChange(leftPanel, uStoragePanelInfo.Type.LEFT, "Left", leftJustFocused);
_lastCursorL = cursorL;
}
}
// Check right panel
if (rightPanel != null)
{
int cursorR = rightPanel.m_selectNo;
bool rightChanged = cursorR != _lastCursorR;
bool rightJustFocused = sideSwitched && _lastArrowType == uStoragePanelInfo.Type.LEFT;
if (rightChanged || rightJustFocused)
{
AnnounceItemChange(rightPanel, uStoragePanelInfo.Type.RIGHT, "Right", rightJustFocused);
_lastCursorR = cursorR;
}
}
}
private void AnnounceItemChange(
uStoragePanelItem panel,
uStoragePanelInfo.Type panelSide,
string side,
bool includeSectionName)
{
if (panel == null)
return;
try
{
int cursor = panel.m_selectNo;
int total = GetItemCount(panel);
string sectionName = GetStorageTypeName(panel, panelSide);
string itemInfo = GetItemInfo(panel);
string announcement;
if (total == 0)
{
announcement = $"{sectionName}, empty";
}
else if (includeSectionName)
{
announcement = $"{sectionName}, {AnnouncementBuilder.CursorPosition(itemInfo, cursor, total)}";
}
else
{
announcement = AnnouncementBuilder.CursorPosition(itemInfo, cursor, total);
}
ScreenReader.Say(announcement);
DebugLogger.Log($"[StoragePanel] {side} cursor changed: {itemInfo}");
}
catch (System.Exception ex)
{
DebugLogger.Log($"[StoragePanel] Error announcing item change: {ex.Message}");
}
}
private string BuildFullAnnouncement()
{
var leftPanel = _panel?.m_itemPanelL;
var rightPanel = _panel?.m_itemPanelR;
string leftInfo = GetPanelSummary(leftPanel, uStoragePanelInfo.Type.LEFT, "Left");
string rightInfo = GetPanelSummary(rightPanel, uStoragePanelInfo.Type.RIGHT, "Right");
return $"{GetStorageCaption()}. {leftInfo}. {rightInfo}";
}
private string GetPanelSummary(
uStoragePanelItem panel,
uStoragePanelInfo.Type panelSide,
string side)
{
if (panel == null)
return $"{side} panel unavailable";
try
{
string storageType = GetStorageTypeName(panel, panelSide);
int total = GetItemCount(panel);
if (total == 0)
{
return $"{side}: {storageType}, empty";
}
int cursor = panel.m_selectNo;
string itemInfo = GetItemInfo(panel);
return $"{side}: {storageType}, {AnnouncementBuilder.CursorPosition(itemInfo, cursor, total)}";
}
catch (System.Exception ex)
{
DebugLogger.Log($"[StoragePanel] Error getting panel summary: {ex.Message}");
return $"{side} panel";
}
}
private string GetStorageTypeName(uStoragePanelItem itemPanel, uStoragePanelInfo.Type panelSide)
{
string fallback = "Items";
try
{
if (itemPanel == null)
{
DebugLogger.Log("[StoragePanel] Section title: item panel was null");
return fallback;
}
fallback = GetStorageTypeFallback(itemPanel.m_storageType);
if (_panel == null)
{
DebugLogger.Log("[StoragePanel] Section title: _panel was null");
return fallback;
}
var infoPanel = _panel.m_infoPanel;
if (infoPanel == null)
{
DebugLogger.Log("[StoragePanel] Section title: m_infoPanel was null");
return fallback;
}
var titleTexts = infoPanel.m_titleText;
if (titleTexts == null)
{
DebugLogger.Log("[StoragePanel] Section title: m_infoPanel.m_titleText was null");
return fallback;
}
int index = (int)panelSide;
if (index < 0 || index >= titleTexts.Length)
{
DebugLogger.Log($"[StoragePanel] Section title: m_titleText index {index} was out of range");
return fallback;
}
var titleText = titleTexts[index];
if (titleText == null)
{
DebugLogger.Log($"[StoragePanel] Section title: m_titleText[{index}] was null");
return fallback;
}
string title = (TextUtilities.StripRichTextTags(titleText.text) ?? "").Trim();
if (!string.IsNullOrWhiteSpace(title))
return title;
DebugLogger.Log($"[StoragePanel] Section title: m_titleText[{index}].text was empty");
}
catch (System.Exception ex)
{
DebugLogger.Log($"[StoragePanel] Error reading m_infoPanel.m_titleText: {ex.Message}");
}
return fallback;
}
private static string GetStorageTypeFallback(ItemStorageData.StorageType type)
{
return type switch
{
ItemStorageData.StorageType.PLAYER => "Inventory",
ItemStorageData.StorageType.SHOP => "Storage",
ItemStorageData.StorageType.MATERIAL => "Materials",
ItemStorageData.StorageType.KEY_ITEM => "Key Items",
_ => "Items"
};
}
private int GetItemCount(uStoragePanelItem panel)
{
try
{
var itemList = panel?.m_itemList;
if (itemList != null)
{
return itemList.Count;
}
}
catch (System.Exception ex)
{
DebugLogger.Log($"[StoragePanel] Error in GetItemCount: {ex.Message}");
}
return 0;
}
private string GetItemInfo(uStoragePanelItem panel)
{
try
{
if (panel == null)
{
DebugLogger.Log("[StoragePanel] Item name: item panel was null");
return "Unknown Item";
}
var paramData = panel.GetSelectItemParam();
if (paramData != null)
{
string name = (TextUtilities.StripRichTextTags(paramData.GetName()) ?? "").Trim();
if (!string.IsNullOrWhiteSpace(name))
return name;
DebugLogger.Log("[StoragePanel] Item name: ParameterItemData.GetName() was empty");
}
else
{
DebugLogger.Log("[StoragePanel] Item name: GetSelectItemParam() returned null");
}
int logicalIndex = panel.selectNo;
var itemParts = panel.GetSelectItemParts(logicalIndex);
if (itemParts == null)
{
DebugLogger.Log($"[StoragePanel] Item name: GetSelectItemParts({logicalIndex}) returned null");
return "Unknown Item";
}
var nameText = itemParts.m_name;
if (nameText == null)
{
DebugLogger.Log("[StoragePanel] Item name: selected uItemParts.m_name was null");
return "Unknown Item";
}
string renderedName = (TextUtilities.StripRichTextTags(nameText.text) ?? "").Trim();
if (!string.IsNullOrWhiteSpace(renderedName))
return renderedName;
DebugLogger.Log("[StoragePanel] Item name: selected uItemParts.m_name.text was empty");
}
catch (System.Exception ex)
{
DebugLogger.Log($"[StoragePanel] Error getting item info: {ex.Message}");
}
return "Unknown Item";
}
private string GetStorageCaption()
{
try
{
if (_panel == null)
{
DebugLogger.Log("[StoragePanel] Caption: _panel was null");
return "Storage";
}
var captionPanel = _panel.m_captionPanel;
if (captionPanel == null)
{
DebugLogger.Log("[StoragePanel] Caption: m_captionPanel was null");
return "Storage";
}
var text = captionPanel.m_text;
if (text == null)
{
DebugLogger.Log("[StoragePanel] Caption: m_captionPanel.m_text was null");
return "Storage";
}
string caption = (TextUtilities.StripRichTextTags(text.text) ?? "").Trim();
if (!string.IsNullOrWhiteSpace(caption))
return caption;
DebugLogger.Log("[StoragePanel] Caption: m_captionPanel.m_text.text was empty");
}
catch (System.Exception ex)
{
DebugLogger.Log($"[StoragePanel] Error reading m_captionPanel.m_text.text: {ex.Message}");
}
return "Storage";
}
private void UpdateLastCursors()
{
if (_panel?.m_itemPanelL != null)
_lastCursorL = _panel.m_itemPanelL.m_selectNo;
if (_panel?.m_itemPanelR != null)
_lastCursorR = _panel.m_itemPanelR.m_selectNo;
}
public void AnnounceStatus()
{
if (!IsOpen())
return;
string announcement = BuildFullAnnouncement();
ScreenReader.Say(announcement);
}
}
}