-
Notifications
You must be signed in to change notification settings - Fork 22
/
DialogueMenu.as
265 lines (224 loc) · 7.32 KB
/
DialogueMenu.as
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
import gfx.io.GameDelegate;
import Components.CrossPlatformButtons;
import Shared.GlobalFunc;
import gfx.managers.FocusHandler;
import gfx.ui.InputDetails;
import gfx.ui.NavigationCode;
class DialogueMenu extends MovieClip
{
static var ALLOW_PROGRESS_DELAY: Number = 750;
static var iMouseDownExecutionCount: Number = 0;
static var SHOW_GREETING: Number = 0;
static var TOPIC_LIST_SHOWN: Number = 1;
static var TOPIC_CLICKED: Number = 2;
static var TRANSITIONING: Number = 3;
var ExitButton: CrossPlatformButtons;
var SpeakerName: TextField;
var SubtitleText: TextField;
var TopicList: MovieClip;
var TopicListHolder: Object;
var bAllowProgress: Boolean;
var bFadedIn: Boolean;
var eMenuState: Number;
var iAllowProgressTimerID: Number;
function DialogueMenu()
{
super();
TopicList = TopicListHolder.List_mc;
eMenuState = DialogueMenu.SHOW_GREETING;
bFadedIn = true;
bAllowProgress = false;
}
function InitExtensions()
{
Mouse.addListener(this);
GameDelegate.addCallBack("Cancel", this, "onCancelPress");
GameDelegate.addCallBack("ShowDialogueText", this, "ShowDialogueText");
GameDelegate.addCallBack("HideDialogueText", this, "HideDialogueText");
GameDelegate.addCallBack("PopulateDialogueList", this, "PopulateDialogueLists");
GameDelegate.addCallBack("ShowDialogueList", this, "DoShowDialogueList");
GameDelegate.addCallBack("StartHideMenu", this, "StartHideMenu");
GameDelegate.addCallBack("SetSpeakerName", this, "SetSpeakerName");
GameDelegate.addCallBack("NotifyVoiceReady", this, "OnVoiceReady");
GameDelegate.addCallBack("AdjustForPALSD", this, "AdjustForPALSD");
TopicList.addEventListener("listMovedUp", this, "playListUpAnim");
TopicList.addEventListener("listMovedDown", this, "playListDownAnim");
TopicList.addEventListener("itemPress", this, "onItemSelect");
GlobalFunc.SetLockFunction();
ExitButton.Lock("BR");
ExitButton._x = ExitButton._x - 50;
ExitButton._y = ExitButton._y - 30;
ExitButton.addEventListener("click", this, "onCancelPress");
TopicListHolder._visible = false;
TopicListHolder.TextCopy_mc._visible = false;
TopicListHolder.TextCopy_mc.textField.textColor = 0x606060;
TopicListHolder.TextCopy_mc.textField.verticalAutoSize = "top";
TopicListHolder.PanelCopy_mc._visible = false;
FocusHandler.instance.setFocus(TopicList, 0);
SubtitleText.verticalAutoSize = "top";
SubtitleText.SetText(" ");
SpeakerName.verticalAutoSize = "top";
SpeakerName.SetText(" ");
}
function AdjustForPALSD(): Void
{
_root.DialogueMenu_mc._x = _root.DialogueMenu_mc._x - 35;
}
function SetPlatform(aiPlatform: Number, abPS3Switch: Boolean): Void
{
ExitButton.SetPlatform(aiPlatform, abPS3Switch);
TopicList.SetPlatform(aiPlatform, abPS3Switch);
}
function SetSpeakerName(strName: String): Void
{
SpeakerName.SetText(strName);
}
function handleInput(details: InputDetails, pathToFocus: Array): Boolean
{
if (bFadedIn && GlobalFunc.IsKeyPressed(details)) {
if (details.navEquivalent == NavigationCode.TAB) {
onCancelPress();
} else if ((details.navEquivalent != NavigationCode.UP && details.navEquivalent != NavigationCode.DOWN) || eMenuState == DialogueMenu.TOPIC_LIST_SHOWN) {
pathToFocus[0].handleInput(details, pathToFocus.slice(1));
}
}
return true;
}
function get menuState(): Number
{
return eMenuState;
}
function set menuState(aNewState: Number): Void
{
eMenuState = aNewState;
}
function ShowDialogueText(astrText: String): Void
{
SubtitleText.SetText(astrText);
}
function OnVoiceReady(): Void
{
StartProgressTimer();
}
function StartProgressTimer(): Void
{
bAllowProgress = false;
clearInterval(iAllowProgressTimerID);
iAllowProgressTimerID = setInterval(this, "SetAllowProgress", DialogueMenu.ALLOW_PROGRESS_DELAY);
}
function HideDialogueText(): Void
{
SubtitleText.SetText(" ");
}
function SetAllowProgress(): Void
{
clearInterval(iAllowProgressTimerID);
bAllowProgress = true;
}
function PopulateDialogueLists(): Void
{
var TOPIC_TEXT: Number = 0;
var TOPIC_ISNEW: Number = 1;
var TOPIC_INDEX: Number = 2;
var TOPIC_STRIDE: Number = 3;
TopicList.ClearList();
for (var i: Number = 0; i < arguments.length - 1; i += TOPIC_STRIDE) {
var topicData: Object = {text: arguments[i + TOPIC_TEXT], topicIsNew: arguments[i + TOPIC_ISNEW], topicIndex: arguments[i + TOPIC_INDEX]};
TopicList.entryList.push(topicData);
}
if (arguments[arguments.length - 1] != -1) {
// Select last topic entry if valid
TopicList.SetSelectedTopic(arguments[arguments.length - 1]);
}
TopicList.InvalidateData();
}
function DoShowDialogueList(abNewList: Boolean, abHideExitButton: Boolean): Void
{
if (eMenuState == DialogueMenu.TOPIC_CLICKED || (eMenuState == DialogueMenu.SHOW_GREETING && TopicList.entryList.length > 0)) {
ShowDialogueList(abNewList, abNewList && eMenuState == DialogueMenu.TOPIC_CLICKED);
}
ExitButton._visible = !abHideExitButton;
}
function ShowDialogueList(abSlideAnim: Boolean, abCopyVisible: Boolean): Void
{
TopicListHolder._visible = true;
TopicListHolder.gotoAndPlay(abSlideAnim ? "slideListIn" : "fadeListIn");
eMenuState = DialogueMenu.TRANSITIONING;
TopicListHolder.TextCopy_mc._visible = abCopyVisible;
TopicListHolder.PanelCopy_mc._visible = abCopyVisible;
}
function onItemSelect(event: Object): Void
{
if (bAllowProgress && event.keyboardOrMouse != 0) {
if (eMenuState == DialogueMenu.TOPIC_LIST_SHOWN) {
onSelectionClick();
} else if (eMenuState == DialogueMenu.TOPIC_CLICKED || eMenuState == DialogueMenu.SHOW_GREETING) {
SkipText();
}
bAllowProgress = false;
}
}
function SkipText(): Void
{
if (bAllowProgress) {
GameDelegate.call("SkipText", []);
bAllowProgress = false;
}
}
function onMouseDown(): Void
{
++DialogueMenu.iMouseDownExecutionCount;
if (DialogueMenu.iMouseDownExecutionCount % 2 != 0) {
onItemSelect();
}
}
function onCancelPress(): Void
{
if (eMenuState == DialogueMenu.SHOW_GREETING) {
SkipText();
return;
}
StartHideMenu();
}
function StartHideMenu(): Void
{
SubtitleText._visible = false;
bFadedIn = false;
SpeakerName.SetText(" ");
ExitButton._visible = false;
_parent.gotoAndPlay("startFadeOut");
GameDelegate.call("CloseMenu", []);
}
function playListUpAnim(aEvent: Object): Void
{
if (aEvent.scrollChanged == true) {
aEvent.target._parent.gotoAndPlay("moveUp");
}
}
function playListDownAnim(aEvent: Object): Void
{
if (aEvent.scrollChanged == true) {
aEvent.target._parent.gotoAndPlay("moveDown");
}
}
function onSelectionClick(): Void
{
if (eMenuState == DialogueMenu.TOPIC_LIST_SHOWN) {
eMenuState = DialogueMenu.TOPIC_CLICKED;
}
if (TopicList.scrollPosition != TopicList.selectedIndex) {
TopicList.RestoreScrollPosition(TopicList.selectedIndex, true);
TopicList.UpdateList();
}
TopicListHolder.gotoAndPlay("topicClicked");
TopicListHolder.TextCopy_mc._visible = true;
TopicListHolder.TextCopy_mc.textField.SetText(TopicListHolder.List_mc.selectedEntry.text);
var textFieldyOffset: Number = TopicListHolder.TextCopy_mc._y - TopicListHolder.List_mc._y - TopicListHolder.List_mc.Entry4._y;
TopicListHolder.TextCopy_mc.textField._y = 6.25 - textFieldyOffset;
GameDelegate.call("TopicClicked", [TopicList.selectedEntry.topicIndex]);
}
function onFadeOutCompletion(): Void
{
GameDelegate.call("FadeDone", []);
}
}