-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMapPanelHandler.cs
More file actions
469 lines (401 loc) · 16 KB
/
Copy pathMapPanelHandler.cs
File metadata and controls
469 lines (401 loc) · 16 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
using Il2Cpp;
using UnityEngine;
namespace DigimonNOAccess
{
/// <summary>
/// Handles accessibility for the map panel (world/area/minimap navigation)
/// and the town jump panel (fast travel when in the city).
/// Both open with the same key but are different UI systems.
/// </summary>
public class MapPanelHandler : HandlerBase<uDigiviceMapPanel>
{
protected override string LogTag => "[MapPanel]";
public override int Priority => 65;
// Field map state
private uDigiviceMapPanel.State _lastState = uDigiviceMapPanel.State.NONE;
private string _lastLocationName = "";
// Town jump state
private uTownJumpPanel _townJumpPanel;
private uTownJumpPanelCommand _townJumpCommand;
private bool _townJumpActive;
private int _lastTownJumpCursor = -1;
public override bool IsOpen()
{
// Check town jump first (asset-loaded via MainGameManager)
// Skip if construction panel is active (town jump UI briefly appears during confirmations)
try
{
var mgm = MainGameManager.m_instance;
if (mgm != null)
{
var constructionPanel = Object.FindObjectOfType<uConstructionPanel>();
if (constructionPanel != null && constructionPanel.m_state != uConstructionPanel.State.None)
{
// Construction is open, don't detect town jump
}
else
{
var tjPanel = mgm.townJumpUI;
if (tjPanel != null && tjPanel.m_state == uTownJumpPanel.State.CommandMain)
{
_townJumpPanel = tjPanel;
_townJumpActive = true;
return true;
}
}
}
}
catch { }
_townJumpActive = false;
_townJumpPanel = null;
// Then check field map (scene object)
if (_panel == null)
_panel = Object.FindObjectOfType<uDigiviceMapPanel>();
if (_panel == null)
return false;
var state = _panel.m_state;
return state != uDigiviceMapPanel.State.NONE && state != uDigiviceMapPanel.State.CLOSE;
}
protected override void OnOpen()
{
if (_townJumpActive)
{
OnTownJumpOpen();
return;
}
_lastState = uDigiviceMapPanel.State.NONE;
_lastLocationName = "";
if (_panel == null)
return;
var state = _panel.m_state;
_lastState = state;
string mapLevel = GetMapLevelName(state);
string locationName = GetCurrentLocationName();
_lastLocationName = locationName;
string announcement = !string.IsNullOrEmpty(locationName)
? $"Map, {mapLevel}. {locationName}"
: $"Map, {mapLevel}";
ScreenReader.Say(announcement);
DebugLogger.Log($"{LogTag} Opened, state={state}, location={locationName}");
}
protected override void OnClose()
{
if (_townJumpActive || _townJumpPanel != null)
OnTownJumpClose();
_lastState = uDigiviceMapPanel.State.NONE;
_lastLocationName = "";
base.OnClose();
}
protected override void OnUpdate()
{
if (_townJumpActive)
{
UpdateTownJump();
return;
}
CheckStateChange();
CheckLocationChange();
}
// ── Town Jump (Fast Travel) ──
private void OnTownJumpOpen()
{
_lastTownJumpCursor = -1;
try { _townJumpCommand = _townJumpPanel?.m_townJumpPanelCommand; }
catch { _townJumpCommand = null; }
int cursor = GetTownJumpCursor();
string destination = GetTownJumpDestinationName(cursor);
int total = GetTownJumpItemCount();
string announcement = $"{GetTownJumpCaptionText()}. {destination}. {cursor + 1} of {total}";
ScreenReader.Say(announcement);
DebugLogger.Log($"{LogTag} Town Jump opened, cursor={cursor}, items={total}");
_lastTownJumpCursor = cursor;
}
private void OnTownJumpClose()
{
_townJumpPanel = null;
_townJumpCommand = null;
_townJumpActive = false;
_lastTownJumpCursor = -1;
}
private void UpdateTownJump()
{
if (_townJumpCommand == null) return;
int cursor = GetTownJumpCursor();
if (cursor == _lastTownJumpCursor || cursor < 0) return;
string destination = GetTownJumpDestinationName(cursor);
int total = GetTownJumpItemCount();
ScreenReader.Say($"{destination}. {cursor + 1} of {total}");
DebugLogger.Log($"{LogTag} Town Jump cursor: {destination} ({cursor + 1}/{total})");
_lastTownJumpCursor = cursor;
}
private int GetTownJumpCursor()
{
try
{
if (_townJumpCommand != null)
return _townJumpCommand.m_selectNo;
}
catch { }
return 0;
}
private int GetTownJumpItemCount()
{
try
{
var datas = _townJumpPanel?.GetParameterTownJumpDatas();
if (datas != null && datas.Length > 0)
return datas.Length;
}
catch { }
try
{
if (_townJumpCommand != null)
return _townJumpCommand.m_itemMaxNum;
}
catch { }
return 1;
}
private string GetTownJumpDestinationName(int index)
{
try
{
if (_townJumpCommand == null)
{
DebugLogger.Log($"{LogTag} Destination {index}: town jump command is null");
}
else if (_townJumpPanel == null)
{
DebugLogger.Log($"{LogTag} Destination {index}: town jump panel is null");
}
else
{
uint pointId = _townJumpCommand.selectPointId;
if (pointId == 0)
{
DebugLogger.Log($"{LogTag} Destination {index}: selectPointId is zero");
}
else
{
var jumpData = _townJumpPanel.GetParameterTownJumpData(pointId);
if (jumpData == null)
{
DebugLogger.Log($"{LogTag} Destination {index}: GetParameterTownJumpData({pointId}) returned null");
}
else
{
string dataName = jumpData.GetName();
string cleaned = TextUtilities.StripRichTextTags(ButtonHintCache.Filter(dataName))?.Trim();
if (!string.IsNullOrWhiteSpace(cleaned))
return cleaned;
DebugLogger.Log($"{LogTag} Destination {index}: ParameterTownJumpData.GetName() is empty");
}
}
}
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} Destination {index}: parameter name read failed: {ex.Message}");
}
try
{
if (_townJumpCommand == null)
{
DebugLogger.Log($"{LogTag} Destination {index}: command unavailable for rendered row");
}
else
{
var parts = _townJumpCommand.GetSelectItemParts(index);
if (parts == null)
{
DebugLogger.Log($"{LogTag} Destination {index}: selected row parts are null");
}
else
{
var nameText = parts.m_name;
if (nameText == null)
{
DebugLogger.Log($"{LogTag} Destination {index}: selected row m_name is null");
}
else
{
string cleaned = TextUtilities.StripRichTextTags(ButtonHintCache.Filter(nameText.text))?.Trim();
if (!string.IsNullOrWhiteSpace(cleaned))
return cleaned;
DebugLogger.Log($"{LogTag} Destination {index}: selected row m_name.text is empty");
}
}
}
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} Destination {index}: rendered row read failed: {ex.Message}");
}
DebugLogger.Log($"{LogTag} Destination {index}: localized name unavailable; using English fallback");
return AnnouncementBuilder.FallbackItem("Destination", index);
}
private string GetTownJumpCaptionText()
{
const string fallback = "Fast Travel";
try
{
if (_townJumpPanel == null)
{
DebugLogger.Log($"{LogTag} Town jump caption: panel is null");
return fallback;
}
var caption = _townJumpPanel.m_caption;
if (caption == null)
{
DebugLogger.Log($"{LogTag} Town jump caption: m_caption is null");
return fallback;
}
var text = caption.m_text;
if (text == null)
{
DebugLogger.Log($"{LogTag} Town jump caption: m_caption.m_text is null");
return fallback;
}
string cleaned = TextUtilities.StripRichTextTags(ButtonHintCache.Filter(text.text))?.Trim();
if (string.IsNullOrWhiteSpace(cleaned) || TextUtilities.IsPlaceholderText(cleaned))
{
DebugLogger.Log($"{LogTag} Town jump caption: m_caption.m_text.text is empty");
return fallback;
}
return cleaned;
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} Town jump caption read failed: {ex.Message}");
return fallback;
}
}
// ── Field Map ──
private void CheckStateChange()
{
if (_panel == null)
return;
var currentState = _panel.m_state;
if (currentState != _lastState && currentState != uDigiviceMapPanel.State.CLOSE)
{
_lastLocationName = "";
string mapLevel = GetMapLevelName(currentState);
string locationName = GetCurrentLocationName();
_lastLocationName = locationName;
string announcement = !string.IsNullOrEmpty(locationName)
? $"{mapLevel}. {locationName}"
: mapLevel;
ScreenReader.Say(announcement);
DebugLogger.Log($"{LogTag} State changed to {mapLevel}");
_lastState = currentState;
}
}
private void CheckLocationChange()
{
if (_panel == null)
return;
string currentLocation = GetCurrentLocationName();
if (!string.IsNullOrEmpty(currentLocation) && currentLocation != _lastLocationName)
{
ScreenReader.Say(currentLocation);
DebugLogger.Log($"{LogTag} Location changed: {currentLocation}");
_lastLocationName = currentLocation;
}
}
private string GetMapLevelName(uDigiviceMapPanel.State state)
{
string fallback = state switch
{
uDigiviceMapPanel.State.WORLD => "World Map",
uDigiviceMapPanel.State.AREA => "Area Map",
uDigiviceMapPanel.State.MINI_AREA => "Local Map",
_ => "Map"
};
if (state != uDigiviceMapPanel.State.WORLD &&
state != uDigiviceMapPanel.State.AREA &&
state != uDigiviceMapPanel.State.MINI_AREA)
return fallback;
try
{
if (_panel == null)
{
DebugLogger.Log($"{LogTag} {state} caption: map panel is null");
return fallback;
}
var caption = _panel.m_uDigiviceMapPanelCaption;
if (caption == null)
{
DebugLogger.Log($"{LogTag} {state} caption: m_uDigiviceMapPanelCaption is null");
return fallback;
}
var text = caption.m_caption;
if (text == null)
{
DebugLogger.Log($"{LogTag} {state} caption: m_caption is null");
return fallback;
}
string cleaned = TextUtilities.StripRichTextTags(ButtonHintCache.Filter(text.text))?.Trim();
if (string.IsNullOrWhiteSpace(cleaned) || TextUtilities.IsPlaceholderText(cleaned))
{
DebugLogger.Log($"{LogTag} {state} caption: m_caption.text is empty");
return fallback;
}
return cleaned;
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} {state} caption read failed: {ex.Message}");
return fallback;
}
}
private string GetCurrentLocationName()
{
try
{
var headline = _panel?.m_uDigiviceMapPanelHeadLine;
if (headline != null)
{
var currentLookingText = headline.m_CurrentLookingName;
if (currentLookingText != null)
{
string text = currentLookingText.text;
if (!string.IsNullOrEmpty(text))
return text;
}
var mapNameText = headline.m_MapName;
if (mapNameText != null)
{
string text = mapNameText.text;
if (!string.IsNullOrEmpty(text))
return text;
}
}
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} Error getting location name: {ex.Message}");
}
return "";
}
// ── Status ──
public override void AnnounceStatus()
{
if (!IsOpen())
return;
if (_townJumpActive)
{
int cursor = GetTownJumpCursor();
string destination = GetTownJumpDestinationName(cursor);
int total = GetTownJumpItemCount();
ScreenReader.Say($"{GetTownJumpCaptionText()}. {destination}. {cursor + 1} of {total}");
return;
}
var state = _panel.m_state;
string mapLevel = GetMapLevelName(state);
string locationName = GetCurrentLocationName();
string announcement = !string.IsNullOrEmpty(locationName)
? $"Map, {mapLevel}. {locationName}"
: $"Map, {mapLevel}";
ScreenReader.Say(announcement);
}
}
}