-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathItemPickPanelHandler.cs
More file actions
157 lines (132 loc) · 4.44 KB
/
Copy pathItemPickPanelHandler.cs
File metadata and controls
157 lines (132 loc) · 4.44 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
using Il2Cpp;
using UnityEngine;
namespace DigimonNOAccess
{
/// <summary>
/// Handles accessibility for item pickup panel (collecting items/materials in the field)
/// </summary>
public class ItemPickPanelHandler : HandlerBase<uItemPickPanel>
{
protected override string LogTag => "[ItemPickPanel]";
public override int Priority => 90;
private uItemPickPanel.State _lastState = uItemPickPanel.State.None;
public override bool IsOpen()
{
if (_panel == null)
{
_panel = Object.FindObjectOfType<uItemPickPanel>();
}
if (_panel == null)
return false;
try
{
return _panel.isOpen;
}
catch
{
return false;
}
}
protected override void OnOpen()
{
_lastState = uItemPickPanel.State.None;
if (_panel == null)
return;
var state = _panel.m_state;
_lastState = state;
string stateName = GetStateName(state);
ScreenReader.Say($"Item pickup, {stateName}");
DebugLogger.Log($"{LogTag} Opened, state={state}");
}
protected override void OnClose()
{
_lastState = uItemPickPanel.State.None;
base.OnClose();
}
protected override void OnUpdate()
{
CheckStateChange();
}
private void CheckStateChange()
{
if (_panel == null)
return;
var currentState = _panel.m_state;
if (currentState != _lastState)
{
string announcement = GetStateAnnouncement(currentState);
if (!string.IsNullOrEmpty(announcement))
{
ScreenReader.Say(announcement);
DebugLogger.Log($"{LogTag} State changed to {currentState}");
}
_lastState = currentState;
}
}
private string GetStateName(uItemPickPanel.State state)
{
return state switch
{
uItemPickPanel.State.CommandMain => "Menu",
uItemPickPanel.State.ItemPick => "Picking item",
uItemPickPanel.State.MaterialPick => "Picking material",
uItemPickPanel.State.Result => "Result",
uItemPickPanel.State.Close => "Closing",
uItemPickPanel.State.Wait => "Please wait",
_ => "Ready"
};
}
private string GetStateAnnouncement(uItemPickPanel.State state)
{
switch (state)
{
case uItemPickPanel.State.CommandMain:
return "Choose action";
case uItemPickPanel.State.ItemPick:
return "Picking up item";
case uItemPickPanel.State.MaterialPick:
return "Picking up material";
case uItemPickPanel.State.Result:
return GetResultAnnouncement();
case uItemPickPanel.State.Close:
case uItemPickPanel.State.None:
case uItemPickPanel.State.Wait:
return null;
default:
return GetStateName(state);
}
}
private string GetResultAnnouncement()
{
try
{
var resultPanel = _panel?.m_itemPickPanelResult;
if (resultPanel != null)
{
var itemIds = _panel.m_itemIds;
if (itemIds != null)
{
string message = resultPanel.GetResultMessage(itemIds);
if (!string.IsNullOrEmpty(message))
{
return message;
}
}
}
}
catch (System.Exception ex)
{
DebugLogger.Log($"{LogTag} Error getting result: {ex.Message}");
}
return "Item obtained";
}
public override void AnnounceStatus()
{
if (!IsOpen())
return;
var state = _panel.m_state;
string stateName = GetStateName(state);
ScreenReader.Say($"Item pickup, {stateName}");
}
}
}