-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaperture-science-logo.script
172 lines (130 loc) · 3.23 KB
/
aperture-science-logo.script
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
# Customizable variables
rotation_allow = 1;
rotation_speed_normal = 0.005;
font_name = "Sans";
font_size = "12";
msgs["spacing"] = 0;
# Runtime Variables
msgs["size"] = 0;
status = "normal";
font = font_name + " " + font_size;
time = 0;
rotation = 0;
rotation_speed = rotation_speed_normal;
imgname_main = "bg";
imgname_main_glow = "bg_glow";
if (Window.GetBitsPerPixel() == 4) {
imgname_main = "" + imgname_main + "";
imgname_main_glow = "" + imgname_main_glow + "";
}
imgname_main += ".png";
imgname_main_glow += ".png";
img_main = Image(imgname_main);
img_main_glow = Image(imgname_main_glow);
window_width = Window.GetWidth();
window_height = Window.GetHeight();
# Helper functions
fun pos_pct_x(width, pct)
{
return window_width * pct - width / 2;
}
fun pos_pct_y(height, pct)
{
return window_height * pct - height / 2;
}
fun spr_pct_x(spr, pct)
{
spr.SetX(pos_pct_x(spr.GetImage().GetWidth(), pct));
}
fun spr_pct_y(spr, pct)
{
spr.SetY(pos_pct_y(spr.GetImage().GetHeight(), pct));
}
# Callbacks
fun tick()
{
time += 0.05;
spr_main_glow.SetOpacity(Math.Clamp(Math.Sin(time), 0, 1));
if (rotation_allow == 1) {
rotation += rotation_speed;
spr_main.SetImage(img_main.Rotate(rotation));
spr_main_glow.SetImage(img_main_glow.Rotate(rotation));
}
}
fun normal()
{
if (status == "password") {
# "Reset" msgs (remove first element)
for (i = 0; i < msgs["size"]; i++)
msgs[i] = msgs[i + 1];
msgs["size"]--;
}
status = "normal";
}
fun display_msg(text)
{
base_y = spr_main.GetY() + spr_main.GetImage().GetHeight() + 1;
spr = Sprite();
spr.SetImage(Image.Text(text, 1, 1, 1, 1, font, "center"));
spr_pct_x(spr, 0.5);
spr.SetY(base_y);
height_used = spr.GetImage().GetHeight() + msgs["spacing"];
# Push entries one down
i = msgs["size"];
while (i--) {
if (i <= 10)
msgs[i + 1] = msgs[i];
else
msg[i + 1] = NULL;
}
# Reposition sprites
msgs_size = msgs["size"];
for (i = 1; i <= msgs_size; i++) {
sprmsg = msgs[i];
sprmsg.SetOpacity(sprmsg.GetOpacity() - 0.10);
sprmsg.SetY(base_y + height_used);
height_used += sprmsg.GetImage().GetHeight() + msgs["spacing"];
}
msgs["size"]++;
msgs[0] = spr;
}
fun display_choice(text, choice)
{
display_msg(text + "\n" + choice)
}
fun password(prompt, chars)
{
prompt += ": ";
while (chars--)
prompt += "*";
spr = Sprite();
spr.SetImage(Image.Text(prompt, 1, 1, 0, font, "center"));
if (status != "password") {
status = "password";
display_msg(prompt);
}
spr_pct_x(spr, 0.5);
spr.SetY(msgs[0].GetY());
msgs[0] = spr;
}
# Main Setup
spr_main = Sprite();
spr_main.SetImage(img_main);
spr_main.SetZ(1);
spr_pct_x(spr_main, 0.5);
spr_pct_y(spr_main, 0.5);
spr_main_glow = Sprite();
spr_main_glow.SetImage(img_main_glow);
spr_main_glow.SetZ(0);
# We're assuming that the images are the same size
spr_main_glow.SetX(spr_main.GetX());
spr_main_glow.SetY(spr_main.GetY());
Window.SetBackgroundTopColor(0.0, 0.0, 0.0);
Window.SetBackgroundBottomColor(0.0, 0.0, 0.0);
# Register Callbacks
Plymouth.SetRefreshFunction(tick);
Plymouth.SetDisplayNormalFunction(normal);
Plymouth.SetUpdateStatusFunction(display_msg);
Plymouth.SetMessageFunction(dispay_msg);
Plymouth.SetDisplayQuestionFunction(display_choice);
Plymouth.SetDisplayPasswordFunction(password);