-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.js
166 lines (143 loc) · 7.15 KB
/
menu.js
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
"use strict";
function createMenu(onSelect, assets) {
let menuItems = ["Start Game", "Options", "About", "Quit"];
let selectedItemShape = null;
let selectedItemIndex = 0;
let mainContainer = new createjs.Container();
let backgroundContainer = createBackground();
//backgroundContainer.cache(0,0,SCREEN_WIDTH, SCREEN_WIDTH);
let menuContainer = createMainMenu();
mainContainer.addChild(backgroundContainer, menuContainer);
// The Pixel dance test..
/*
let testShape = new createjs.Shape();
line(testShape.graphics, MenuColors.WHITE, 11, 11, 11, 21);
line(testShape.graphics, MenuColors.WHITE, 21, 11, 26, 11);
line(testShape.graphics, MenuColors.WHITE, 31, 11, 41, 21);
putPixel(testShape.graphics, MenuColors.WHITE, 51, 11);
putPixel(testShape.graphics, MenuColors.WHITE, 51, 15);
putPixel(testShape.graphics, MenuColors.WHITE, 51, 15);
bar(testShape.graphics, MenuColors.WHITE, 61, 11, 71, 21);
line(testShape.graphics, MenuColors.WHITE, 0, 110, SCREEN_WIDTH, 110);
putPixel(testShape.graphics, MenuColors.RED, 0, 0);
bar(testShape.graphics, MenuColors.WHITE, 0, 120, SCREEN_WIDTH, 120);
showPCX(assets, mainContainer, "bar.pcx", 40, 80, 10, 10);
mainContainer.addChild(testShape);
*/
return {
container: mainContainer,
onKeyDown: onKeyDown,
};
function createBackground() {
let backgroundContainer = new createjs.Container();
//Show_PCX('Gfx\menutop.pcx',GetMaxX div 2 - 319,GetMaxY div 2 - 240,639,239);
//Show_PCX('Gfx\menubot.pcx',GetMaxX div 2 - 319,GetMaxY div 2 ,639,239);
showPCX(assets, backgroundContainer, "menutop.pcx", SCREEN_WIDTH_CENTER - 319, SCREEN_HEIGHT_CENTER - 240, 639, 239);
showPCX(assets, backgroundContainer, "menubot.pcx", SCREEN_WIDTH_CENTER - 319, SCREEN_HEIGHT_CENTER, 639, 239);
// SetColor(DarkGray);
// Line(GetMaxX div 2 - 319,GetMaxY div 2 + 240,GetMaxX div 2 + 320,GetMaxY div 2 + 240);
// Line(GetMaxX div 2 + 320,GetMaxY div 2 - 239,GetMaxX div 2 + 320,GetMaxY div 2 + 239);
// SetColor(Gray);
// Line(GetMaxX div 2 - 319,GetMaxY div 2 - 239,GetMaxX div 2 + 320,GetMaxY div 2 - 239);
// Line(GetMaxX div 2 - 319,GetMaxY div 2 - 239,GetMaxX div 2 - 319,GetMaxY div 2 + 240);
let shape = new createjs.Shape();
line(shape.graphics, MenuColors.DARKGRAY, SCREEN_WIDTH_CENTER - 319, SCREEN_HEIGHT_CENTER + 240, SCREEN_WIDTH_CENTER + 320, SCREEN_HEIGHT_CENTER + 240);
line(shape.graphics, MenuColors.DARKGRAY, SCREEN_WIDTH_CENTER + 320, SCREEN_HEIGHT_CENTER - 239, SCREEN_WIDTH_CENTER + 320, SCREEN_HEIGHT_CENTER + 239);
line(shape.graphics, MenuColors.GRAY, SCREEN_WIDTH_CENTER - 319, SCREEN_HEIGHT_CENTER - 239, SCREEN_WIDTH_CENTER + 320, SCREEN_HEIGHT_CENTER - 239);
line(shape.graphics, MenuColors.GRAY, SCREEN_WIDTH_CENTER - 319, SCREEN_HEIGHT_CENTER - 239, SCREEN_WIDTH_CENTER - 319, SCREEN_HEIGHT_CENTER + 240);
backgroundContainer.addChild(shape);
// SetColor(DarkGray);
// OutTextXY(GetMaxX div 2 + 286,GetMaxY div 2 + 230,'v'+FloatToStr(Version,0,1));
outTextXY(backgroundContainer, MenuColors.DARKGRAY, "v1.0", SCREEN_WIDTH_CENTER + 286, SCREEN_HEIGHT_CENTER + 230);
return backgroundContainer;
}
function createMainMenu() {
let menuContainer = new createjs.Container();
// x[1] := GetMaxX div 2 - 80;
// y[1] := GetMaxY div 2 - 70;
// x[2] := x[1] + 159;
// y[2] := y[1] + 193;
// SetFillStyle(SolidFill,DarkGray);
// bar(x[1]+2,y[1]+2,x[2]+2,y[2]+2);
let x1 = SCREEN_WIDTH_CENTER - 80;
let y1 = SCREEN_HEIGHT_CENTER - 70;
let x2 = x1 + 159;
let y2 = y1 + 193;
let menubackContainer = new createjs.Container();
showPCX(assets, menubackContainer, "menuback.pcx", x1, y1, x2 - x1, y2 - y1);
// add shadow
menubackContainer.shadow = new createjs.Shadow(MenuColors.DARKGRAY, 2, 2, 0);
menuContainer.addChild(menubackContainer);
/* SetColor(BrightGray);
Line(x[1],y[1],x[2],y[1]);
Line(x[1],y[1],x[1],y[2]);
SetColor(Gray);
Line(x[1],y[2],x[2],y[2]);
Line(x[2],y[1],x[2],y[2]);
*/
let shape = new createjs.Shape();
line(shape.graphics, MenuColors.BRIGHTGRAY, x1, y1, x2, y1);
line(shape.graphics, MenuColors.BRIGHTGRAY, x1, y1, x1, y2);
line(shape.graphics, MenuColors.GRAY, x1, y2, x2, y2);
line(shape.graphics, MenuColors.GRAY, x2, y1, x2, y2);
menuContainer.addChild(shape);
// SetColor(DarkGray);
// OutTextXY(GetMaxX div 2 - 68,y[1]+10,'M A I N M E N U');
outTextXY(menuContainer, MenuColors.DARKGRAY, "M A I N M E N U", SCREEN_WIDTH_CENTER - 68, y1 + 10);
// DrawFrame(x[1]+16,y[1]+32,x[2]-16,y[2]-16);
let frame = drawFrame(menuContainer, MenuColors, x1 + 16, y1 + 32, x2 - 16, y2 - 16);
// bar(x[1]+19,y[1]+23+i*30,x[2]-20,y[1]+35+i*30);
let yPos = getItemBarPosition(selectedItemIndex);
selectedItemShape = barAsShape(MenuColors.DARKESTGREEN, x1 + 19, yPos, x2 - 20, yPos + 12);
menuContainer.addChild(selectedItemShape);
let menuItemsContainer = createMenuItems();
menuContainer.addChild(menuItemsContainer);
return menuContainer;
}
function createMenuItems() {
let container = new createjs.Container();
for (let i = 0; i < menuItems.length; ++i) {
/*
if i = C then SetFillStyle(SolidFill,DarkestGreen) else SetFillStyle(SolidFill,Black);
bar(x[1]+19,y[1]+23+i*30,x[2]-20,y[1]+35+i*30);
SetColor(Black);
OutTextXY(GetMaxX div 2 - (TextWidth(MenuItems[i]) div 2)+2,y[1]+27+i*30,MenuItems[i]);
SetColor(White);
OutTextXY(GetMaxX div 2 - (TextWidth(MenuItems[i]) div 2),y[1]+25+i*30,MenuItems[i]);
*/
outTextXY(container, MenuColors.WHITE, menuItems[i], SCREEN_WIDTH_CENTER, getItemBarPosition(i) + 2, "center", MenuColors.BLACK);
}
return container;
}
function getItemBarPosition(itemIndex) {
return (SCREEN_HEIGHT_CENTER - 70) + 23 + (itemIndex + 1) * 30;
}
function onKeyDown(stage, key) {
switch (key) {
case Keys.DOWN_ARROW:
if (selectedItemIndex < menuItems.length - 1) {
selectedItemIndex++;
}
else {
selectedItemIndex = 0;
}
selectedItemShape.y = getItemBarPosition(selectedItemIndex);
break;
case Keys.UP_ARROW:
if (selectedItemIndex > 0) {
selectedItemIndex--;
}
else {
selectedItemIndex = menuItems.length - 1;
}
selectedItemShape.y = getItemBarPosition(selectedItemIndex);
break;
case Keys.ENTER:
onSelect(selectedItemIndex);
break;
case Keys.ESCAPE:
// TODO: Implement quit.
break;
}
}
}