This repository has been archived by the owner on Aug 1, 2018. It is now read-only.
forked from Mardoxx/skyrimui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CenteredScrollingList.as
305 lines (253 loc) · 8.25 KB
/
CenteredScrollingList.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
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
import Shared.ListFilterer;
class Shared.CenteredScrollingList extends Shared.BSScrollingList
{
var EntriesA: Array;
var _filterer: ListFilterer;
var bDisableInput: Boolean;
var bMouseDrivenNav: Boolean;
var bRecenterSelection: Boolean;
var border: MovieClip;
var dispatchEvent: Function;
var fListHeight: Number;
var iDividerIndex: Number;
var iListItemsShown: Number;
var iMaxItemsShown: Number;
var iMaxScrollPosition: Number;
var iMaxTextLength: Number;
var iNumTopHalfEntries: Number;
var iNumUnfilteredItems: Number;
var iPlatform: Number;
var iScrollPosition: Number;
var iSelectedIndex: Number;
function CenteredScrollingList()
{
super();
_filterer = new ListFilterer();
_filterer.addEventListener("filterChange", this, "onFilterChange");
bRecenterSelection = false;
iMaxTextLength = 256;
iDividerIndex = -1;
iNumUnfilteredItems = 0;
}
function get filterer(): ListFilterer
{
return _filterer;
}
function set maxTextLength(aLength: Number): Void
{
if (aLength > 3)
iMaxTextLength = aLength;
}
function get numUnfilteredItems(): Number
{
return iNumUnfilteredItems;
}
function get maxTextLength(): Number
{
return iMaxTextLength;
}
function get numTopHalfEntries(): Number
{
return iNumTopHalfEntries;
}
function set numTopHalfEntries(aiNum: Number): Void
{
iNumTopHalfEntries = aiNum;
}
function get centeredEntry(): Object
{
return EntriesA[GetClipByIndex(iNumTopHalfEntries).itemIndex];
}
function IsDivider(aEntry: Object): Boolean
{
return aEntry.divider == true || aEntry.flag == 0;
}
// No longer needed? 20120615
/* function IsSelectionAboveDivider(): Boolean
{
return iDividerIndex == -1 || selectedIndex < iDividerIndex;
} */
function get dividerIndex(): Number
{
return iDividerIndex;
}
function RestoreScrollPosition(aiNewPosition: Number, abRecenterSelection: Boolean): Void
{
iScrollPosition = aiNewPosition;
if (iScrollPosition < 0)
iScrollPosition = 0;
if (iScrollPosition > iMaxScrollPosition)
iScrollPosition = iMaxScrollPosition;
bRecenterSelection = abRecenterSelection;
}
function UpdateList(): Void
{
var iItemHeight: Number = GetClipByIndex(0)._y;
var iHeightSum: Number = 0;
var iEntryIndex: Number = filterer.ClampIndex(0);
iDividerIndex = -1;
for (var i: Number = 0; i < EntriesA.length; i++)
if (IsDivider(EntriesA[i]))
iDividerIndex = i;
if (bRecenterSelection || iPlatform != 0)
iSelectedIndex = -1;
else
iSelectedIndex = filterer.ClampIndex(iSelectedIndex);
for (var i: Number = 0; i < iScrollPosition - iNumTopHalfEntries; i++) {
EntriesA[iEntryIndex].clipIndex = undefined;
iEntryIndex = filterer.GetNextFilterMatch(iEntryIndex);
}
iListItemsShown = 0;
iNumUnfilteredItems = 0;
for (var i: Number = 0; i < iNumTopHalfEntries; i++) {
var item: MovieClip = GetClipByIndex(i);
if (iScrollPosition - iNumTopHalfEntries + i >= 0) {
SetEntry(item, EntriesA[iEntryIndex]);
item._visible = true;
item.itemIndex = IsDivider(EntriesA[iEntryIndex]) == true ? undefined : iEntryIndex;
EntriesA[iEntryIndex].clipIndex = i;
iEntryIndex = filterer.GetNextFilterMatch(iEntryIndex);
++iNumUnfilteredItems;
} else {
item._visible = false;
item.itemIndex = undefined;
}
item._y = iItemHeight + iHeightSum;
iHeightSum = iHeightSum + item._height;
++iListItemsShown;
}
if (iEntryIndex != undefined && (bRecenterSelection || iPlatform != 0))
iSelectedIndex = iEntryIndex;
for (iEntryIndex; iEntryIndex != undefined && iEntryIndex != -1 && iEntryIndex < EntriesA.length && iListItemsShown < iMaxItemsShown && iHeightSum <= fListHeight; iEntryIndex = filterer.GetNextFilterMatch(iEntryIndex)) {
var item: MovieClip = GetClipByIndex(iListItemsShown);
SetEntry(item, EntriesA[iEntryIndex]);
EntriesA[iEntryIndex].clipIndex = iListItemsShown;
item.itemIndex = IsDivider(EntriesA[iEntryIndex]) == true ? undefined : iEntryIndex;
item._y = iItemHeight + iHeightSum;
item._visible = true;
iHeightSum = iHeightSum + item._height;
if (iHeightSum <= fListHeight && iListItemsShown < iMaxItemsShown) {
++iListItemsShown;
++iNumUnfilteredItems;
}
}
for (var i: Number = iListItemsShown; i < iMaxItemsShown; i++) {
GetClipByIndex(i)._visible = false;
GetClipByIndex(i).itemIndex = undefined;
}
if (bMouseDrivenNav && !bRecenterSelection)
for (var target: Object = Mouse.getTopMostEntity(); target != undefined; target = target._parent)
if (target._parent == this && target._visible && target.itemIndex != undefined)
doSetSelectedIndex(target.itemIndex, 0);
bRecenterSelection = false;
}
function InvalidateData(): Void
{
filterer.filterArray = EntriesA;
fListHeight = border._height;
CalculateMaxScrollPosition();
if (iScrollPosition > iMaxScrollPosition)
iScrollPosition = iMaxScrollPosition;
UpdateList();
}
function onFilterChange(): Void
{
iSelectedIndex = filterer.ClampIndex(iSelectedIndex);
CalculateMaxScrollPosition();
}
function moveSelectionUp(): Void
{
var itemIndex: Number = filterer.GetPrevFilterMatch(iSelectedIndex);
var iInitialScrollPos: Number = iScrollPosition;
if (itemIndex != undefined && IsDivider(EntriesA[itemIndex]) == true) {
--iScrollPosition;
itemIndex = filterer.GetPrevFilterMatch(itemIndex);
}
if (itemIndex != undefined) {
iSelectedIndex = itemIndex;
iHighlightedIndex = itemIndex; //faB++
bRecenterSelection = true; //fab
if (iScrollPosition > 0)
--iScrollPosition;
bMouseDrivenNav = false;
UpdateList();
dispatchEvent({type: "listMovedUp", index: iSelectedIndex, scrollChanged: iInitialScrollPos != iScrollPosition});
}
}
function moveSelectionDown(): Void
{
var itemIndex: Number = filterer.GetNextFilterMatch(iSelectedIndex);
var iInitialScrollPos: Number = iScrollPosition;
if (itemIndex != undefined && IsDivider(EntriesA[itemIndex]) == true) {
++iScrollPosition;
itemIndex = filterer.GetNextFilterMatch(itemIndex);
}
if (itemIndex != undefined) {
iSelectedIndex = itemIndex;
iHighlightedIndex = itemIndex; //faB++
bRecenterSelection = true; //fab
if (iScrollPosition < iMaxScrollPosition)
++iScrollPosition;
bMouseDrivenNav = false;
UpdateList();
dispatchEvent({type: "listMovedDown", index: iSelectedIndex, scrollChanged: iInitialScrollPos != iScrollPosition});
}
}
function onMouseWheel(delta: Number): Void
{
if (bDisableInput)
return;
for (var item: Object = Mouse.getTopMostEntity(); item && item != undefined; item = item._parent) {
if (item == this) {
if (delta < 0) {
var newItem: MovieClip = GetClipByIndex(iNumTopHalfEntries + 1);
if (newItem._visible == true) {
if (newItem.itemIndex == undefined)
scrollPosition = scrollPosition + 2;
else
scrollPosition = scrollPosition + 1;
}
} else if (delta > 0) {
var newItem = GetClipByIndex(iNumTopHalfEntries - 1);
if (newItem._visible == true) {
if (newItem.itemIndex == undefined)
scrollPosition = scrollPosition - 2;
else
scrollPosition = scrollPosition - 1;
}
}
}
}
bMouseDrivenNav = true;
}
function CalculateMaxScrollPosition(): Void
{
iMaxScrollPosition = -1;
for (var itemIndex: Number = filterer.ClampIndex(0); itemIndex != undefined; itemIndex = filterer.GetNextFilterMatch(itemIndex))
++iMaxScrollPosition;
if (iMaxScrollPosition == undefined || iMaxScrollPosition < 0)
iMaxScrollPosition = 0;
}
function SetEntry(aEntryClip: MovieClip, aEntryObject: Object): Void
{
var aSelectedEntry: Object = EntriesA[iHighlightedIndex];
if (aEntryClip != undefined) {
if (IsDivider(aEntryObject) == true)
aEntryClip.gotoAndStop("Divider");
else
aEntryClip.gotoAndStop("Normal");
if (iPlatform == 0) {
aEntryClip._alpha = aEntryObject == aSelectedEntry ? 100 : 60;
} else {
var iAlphaMulti: Number = 4;
if (aEntryClip.clipIndex < iNumTopHalfEntries)
aEntryClip._alpha = 60 - iAlphaMulti * (iNumTopHalfEntries - aEntryClip.clipIndex);
else if (aEntryClip.clipIndex > iNumTopHalfEntries)
aEntryClip._alpha = 60 - iAlphaMulti * (aEntryClip.clipIndex - iNumTopHalfEntries);
else
aEntryClip._alpha = 100;
}
SetEntryText(aEntryClip, aEntryObject);
}
}
}