-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLevelSelector.angelscript
More file actions
81 lines (71 loc) · 1.98 KB
/
Copy pathLevelSelector.angelscript
File metadata and controls
81 lines (71 loc) · 1.98 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
class LevelSelector : ItemSelector
{
private bool m_startOnFirstPage;
LevelSelector(const string &in sceneName, PageProperties@ props, const bool startOnFirstPage = true)
{
m_startOnFirstPage = startOnFirstPage;
super(sceneName, @props);
}
int findFirstUnlockedLevel(PageProperties@ props)
{
for (uint t = 0; t < props.numItems; t++)
{
if (!props.itemChooser.validateItem(t))
return t;
}
return props.numItems - 1;
}
int findLastUnlockedLevel(PageProperties@ props)
{
int r = int(props.numItems) - 1;
for (uint t = 0; t < props.numItems; t++)
{
if (!props.itemChooser.validateItem(t))
{
r = int(t) - 1;
break;
}
}
r = max(r, 0);
return r;
}
void preLoop()
{
ItemSelector::preLoop();
if (!m_startOnFirstPage)
m_pageManager.setCurrentPage(m_pageManager.pageOf(findLastUnlockedLevel(@m_props)));
enableActivatedButtonBounceEffect();
}
void enableActivatedButtonBounceEffect()
{
const int lastUnlockedLevel = findLastUnlockedLevel(@m_props);
const int pageCount = int(m_pageManager.getPageCount());
const int buttonsPerPage = int(m_pageManager.getNumButtonsPerPage());
if (lastUnlockedLevel >= 0 && lastUnlockedLevel < pageCount * buttonsPerPage)
{
const uint currentPage = lastUnlockedLevel / uint(buttonsPerPage);
const uint relativeButtonIdx = uint(int((lastUnlockedLevel % buttonsPerPage)));
Button@ lastUnlockedLevelButton = m_pageManager.getButton(currentPage, relativeButtonIdx);
//print(currentPage + ", " + relativeButtonIdx + ", " + m_pageManager.getNumButtonsPerPage());
if (lastUnlockedLevelButton !is null)
{
lastUnlockedLevelButton.setBounce(
m_props.highlightButtonBounceMin,
m_props.highlightButtonBounceMax,
m_props.highlightButtonBounceTimeStride);
}
}
}
void loop()
{
ItemSelector::loop();
if (GetInputHandle().GetKeyState(K_BACK) == KS_HIT)
{
g_stateManager.setState(g_gameStateFactory.createMenuState());
}
}
string getName()
{
return "LevelSelector";
}
}