-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCommonSelectWindowHandler.cs
More file actions
391 lines (339 loc) · 13.9 KB
/
Copy pathCommonSelectWindowHandler.cs
File metadata and controls
391 lines (339 loc) · 13.9 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
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)
{
// Primary: read the actual rendered UI text from uItemParts
try
{
var itemPanel = _panel?.m_itemPanel;
if (itemPanel != null)
{
var parts = itemPanel.GetSelectItemParts(index);
if (parts != null)
{
var nameText = parts.m_name;
if (nameText != null)
{
string uiText = nameText.text;
if (!string.IsNullOrEmpty(uiText))
{
string cleaned = TextUtilities.StripRichTextTags(uiText);
if (!string.IsNullOrEmpty(cleaned))
return cleaned;
}
}
}
}
}
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 && index >= 0 && index < paramList.Count)
{
var param = paramList[index];
if (param != null)
{
string text = param.GetLanguageString();
if (!string.IsNullOrEmpty(text))
return text;
}
}
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} Error reading param text: {ex.Message}");
}
return AnnouncementBuilder.FallbackItem("Option", index);
}
/// <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 modeTbl = _panel?.m_uCommonSelectWindowModeTbl;
if (modeTbl != null)
{
int modeIndex = (int)_currentOutMode;
if (modeIndex >= 0 && modeIndex < modeTbl.Length)
{
var modePanel = modeTbl[modeIndex];
if (modePanel != null)
{
var valueText = modePanel.m_valueText;
if (valueText != null)
{
string text = valueText.text;
if (!string.IsNullOrEmpty(text))
{
string currency = GetCurrencyName();
return $"Your {currency}: {TextUtilities.StripRichTextTags(text)}";
}
}
}
}
}
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} Error reading balance: {ex.Message}");
}
return null;
}
private string GetCurrencyName()
{
return _currentOutMode switch
{
ParameterCommonSelectWindowMode.OutMode.Bit => "Bits",
ParameterCommonSelectWindowMode.OutMode.DailyQuestPoint => "Daily Quest Points",
ParameterCommonSelectWindowMode.OutMode.Coin => "Coins",
_ => "currency"
};
}
/// <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);
}
}
}