Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/Menu/MenuControl.txt
1319 views
1
//----------------Sonic CD Menu Control Script----------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Aliases
6
#alias Object.Value0 : Object.Fade
7
#alias Object.Value1 : Object.ButtonYOffset
8
#alias Object.Value2 : Object.DragCurrentSelection
9
#alias Object.Value3 : Object.CurrentSelection
10
#alias Object.Value4 : Object.ButtonScroll
11
#alias Object.Value5 : Object.DragEnabled
12
#alias Object.Value6 : Object.DragYOffset
13
#alias Object.Value7 : Object.DragSmooth
14
#alias Object.Direction : Object.YOffsetCorrection
15
16
// Object[1] is a blank object only used to share values across the menu objects
17
#alias Object[1].Value0 : Object.DragPos
18
#alias Object[1].Value1 : Object.RecenterValue
19
#alias Object[1].Value2 : Object.MaxButtonCount
20
#alias Object[1].Value3 : Object.DragLimit
21
#alias Object[1].Value4 : Object.YOffSet1 //in other scripts this is used to check inputs
22
#alias Object[1].Value5 : Object.YOffSet2
23
#alias Object[1].Value6 : Object.YOffSet3
24
25
// Menu Button Aliases
26
#alias Object[34].State : MenuButton.State
27
28
// States
29
#alias 0 : MENUCONTROL_SETUP
30
#alias 1 : MENUCONTROL_BUTTONS_MOVEIN
31
#alias 2 : MENUCONTROL_CONTROLS
32
#alias 3 : MENUCONTROL_BLANK
33
#alias 4 : MENUCONTROL_ENTER_TIMEATTACK
34
#alias 5 : MENUCONTROL_ENTER_DEMO
35
#alias 6 : MENUCONTROL_MENUBUTTON_CHECK
36
#alias 7 : MENUCONTROL_ENTER_TROPHIES
37
#alias 8 : MENUCONTROL_ENTER_LEADERBOARDS
38
39
// MenuButton States
40
#alias 2 : MENUBUTTON_CONFIRM_SELECTION
41
42
// Presentation Stages
43
#alias 2 : STAGE_P_TATTACK
44
#alias 9 : STAGE_P_THROPIES
45
#alias 10 : STAGE_P_LEADERBOARDS
46
47
// Regular Stages
48
#alias 0 : STAGE_R_PPZ1A
49
50
// Global SFX
51
#alias 23 : SFX_G_MENUBUTTON
52
#alias 27 : SFX_G_SELECT
53
54
// Soundtrack
55
#alias 0 : OST_JP
56
57
// Engine & CallBacks
58
#alias 2 : MESSAGE_LOSTFOCUS
59
60
// Device Type
61
#alias 0 : RETRO_STANDARD
62
63
64
sub ObjectMain
65
66
switch Object.State
67
case MENUCONTROL_SETUP
68
Object.State = MENUCONTROL_BUTTONS_MOVEIN
69
Object.Fade = 384
70
SetScreenFade(0, 0, 0, 255)
71
PlayMusic(Options.Soundtrack)
72
if Engine.FrameSkipTimer > -1
73
Engine.FrameSkipTimer = -1
74
end if
75
break
76
77
case MENUCONTROL_BUTTONS_MOVEIN
78
if Object.Fade > 0
79
Object.Fade -= 8
80
else
81
Object.State = MENUCONTROL_MENUBUTTON_CHECK
82
end if
83
SetScreenFade(0, 0, 0, Object.Fade)
84
break
85
86
case MENUCONTROL_CONTROLS
87
88
#platform: Standard
89
CheckResult = true
90
#endplatform
91
92
#platform: Mobile
93
CheckEqual(Options.PhysicalControls, true)
94
#endplatform
95
96
#platform: Use_Origins
97
CheckEqual(Options.PhysicalControls, true)
98
#endplatform
99
100
101
// 2011 Steam lacks Options.PhysicalControls, so we force it here first and the other platforms can override it
102
if CheckResult == true
103
#platform: Use_Origins
104
Menu.ExitFlag = true
105
#endplatform
106
if KeyPress.Up == true
107
Object.CurrentSelection--
108
if Object.CurrentSelection < 1
109
Object.CurrentSelection = 1
110
else
111
PlaySfx(SFX_G_MENUBUTTON, false)
112
end if
113
end if
114
115
if KeyPress.Down == true
116
Object.CurrentSelection++
117
if Object.CurrentSelection > Object.MaxButtonCount
118
Object.CurrentSelection = Object.MaxButtonCount
119
else
120
PlaySfx(SFX_G_MENUBUTTON, false)
121
end if
122
end if
123
124
TempValue0 = Object.CurrentSelection
125
TempValue0 -= Object.ButtonScroll
126
if TempValue0 < 1
127
Object.ButtonScroll--
128
Object.YOffsetCorrection = 3
129
end if
130
131
if TempValue0 > 4
132
Object.ButtonScroll++
133
Object.YOffsetCorrection = 0
134
end if
135
136
//Button Movement across the screen
137
TempValue0 = Object.ButtonYOffset
138
TempValue0 -= 32
139
140
TempValue1 = Object.ButtonScroll
141
TempValue1 *= -60
142
TempValue1 -= TempValue0
143
TempValue1 += Object.YOffsetCorrection
144
TempValue1 >>= 2
145
Object.ButtonYOffset += TempValue1
146
147
#platform: Use_Origins
148
CheckTouchRect(0, 0, Screen.XSize, Screen.YSize)
149
if CheckResult > -1
150
Options.PhysicalControls = false
151
Object.CurrentSelection = 0
152
Object.DragCurrentSelection = 0
153
end if
154
#endplatform
155
156
#platform: Mobile
157
CheckTouchRect(0, 0, Screen.XSize, Screen.YSize)
158
if CheckResult > -1
159
Options.PhysicalControls = false
160
Object.CurrentSelection = 0
161
Object.DragCurrentSelection = 0
162
end if
163
#endplatform
164
165
else
166
if Engine.Message == MESSAGE_LOSTFOCUS
167
Object.CurrentSelection = 0
168
Object.DragCurrentSelection = 0
169
end if
170
171
if Object.DragCurrentSelection > 0
172
Object.CurrentSelection = Object.DragCurrentSelection
173
else
174
Object.CurrentSelection = 0
175
end if
176
177
if Object.MaxButtonCount > 4
178
CheckTouchRect(0, 0, Screen.XSize, Screen.YSize)
179
if CheckResult > -1
180
ArrayPos0 = CheckResult
181
if Object.DragEnabled == false
182
Object.DragEnabled = true
183
Object.DragPos = Object.ButtonYOffset
184
Object.DragYOffset = TouchScreen[ArrayPos0].YPos
185
else
186
//Dragging of buttons based on input
187
TempValue0 = TouchScreen[ArrayPos0].YPos
188
TempValue0 -= Object.DragYOffset
189
TempValue0 += Object.DragPos
190
191
Object.YOffSet3 = Object.YOffSet2
192
Object.YOffSet2 = Object.YOffSet1
193
Object.YOffSet1 = Object.DragSmooth
194
195
Object.DragSmooth = TempValue0
196
Object.DragSmooth -= Object.ButtonYOffset
197
Object.ButtonYOffset = TempValue0
198
end if
199
200
TempValue0 = Object.DragSmooth
201
TempValue0 >>= 2
202
if TempValue0 != 0
203
Object.CurrentSelection = 0
204
Object.DragCurrentSelection = 0
205
end if
206
else
207
if Object.DragEnabled == true
208
//Sets the position to where the buttons will go post-drag
209
Object.DragEnabled = false
210
Object.DragYOffset = Object.ButtonYOffset
211
Object.DragYOffset <<= 8
212
213
Object.DragSmooth += Object.YOffSet1
214
Object.DragSmooth += Object.YOffSet2
215
Object.DragSmooth += Object.YOffSet3
216
Object.DragSmooth >>= 2
217
Object.DragSmooth <<= 7
218
219
if Object.DragSmooth == 0
220
if Object.CurrentSelection == 0
221
Object.DragSmooth = 1 //Forces movement
222
end if
223
end if
224
end if
225
226
if Object.DragSmooth != 0
227
//Centers to whatever button is closer to the center + offset up or down depending of to where did you drag
228
Object.DragYOffset += Object.DragSmooth
229
if Object.DragYOffset < Object.DragLimit
230
Object.DragYOffset = Object.DragLimit
231
Object.DragSmooth = 0
232
end if
233
if Object.DragYOffset > 0x5A00
234
Object.DragYOffset = 0x5A00
235
Object.DragSmooth = 0
236
end if
237
238
if Object.DragSmooth > 0
239
Object.DragSmooth -= 32
240
if Object.DragSmooth < 0
241
Object.DragSmooth = 0
242
end if
243
else
244
Object.DragSmooth += 32
245
if Object.DragSmooth > 0
246
Object.DragSmooth = 0
247
end if
248
end if
249
250
Object.ButtonYOffset = Object.DragYOffset
251
Object.ButtonYOffset >>= 8
252
if Object.DragSmooth == 0
253
Object.ButtonScroll = Object.ButtonYOffset
254
Object.ButtonScroll -= 32
255
Object.ButtonScroll /= -60
256
if Object.ButtonScroll < 0
257
Object.ButtonScroll = 0
258
end if
259
260
TempValue0 = Object.MaxButtonCount
261
TempValue0 -= 4
262
if Object.ButtonScroll > TempValue0
263
Object.ButtonScroll = TempValue0
264
end if
265
end if
266
else
267
//Drag screen re-centering
268
TempValue0 = Object.ButtonYOffset
269
TempValue0 -= 32
270
Object.RecenterValue = Object.ButtonScroll
271
Object.RecenterValue *= -60
272
Object.RecenterValue -= TempValue0
273
Object.RecenterValue >>= 2
274
if Object.RecenterValue < -4
275
Object.RecenterValue = -4
276
end if
277
if Object.RecenterValue > 4
278
Object.RecenterValue = 4
279
end if
280
Object.ButtonYOffset += Object.RecenterValue
281
end if
282
end if
283
end if
284
285
#platform: Use_Origins
286
if KeyPress[0].Up == true
287
Object.CurrentSelection = Object.MaxButtonCount
288
Options.PhysicalControls = true
289
end if
290
291
if KeyPress[0].Down == true
292
Object.CurrentSelection = 1
293
Options.PhysicalControls = true
294
end if
295
#endplatform
296
297
#platform: Mobile
298
if KeyPress[0].Up == true
299
Object.CurrentSelection = Object.MaxButtonCount
300
Options.PhysicalControls = true
301
end if
302
303
if KeyPress[0].Down == true
304
Object.CurrentSelection = 1
305
Options.PhysicalControls = true
306
end if
307
#endplatform
308
end if
309
310
break
311
312
case MENUCONTROL_BLANK //Used to stop the controls temporarily
313
break
314
315
case MENUCONTROL_ENTER_TIMEATTACK
316
if Object.Fade < 320
317
Object.Fade += 8
318
else
319
Stage.ListPos = STAGE_P_TATTACK
320
LoadStage()
321
end if
322
SetScreenFade(0, 0, 0, Object.Fade)
323
break
324
325
case MENUCONTROL_ENTER_DEMO //Only used in Demo versions of the game
326
if Object.Fade < 320
327
Object.Fade += 8
328
else
329
LoadVideo("Opening")
330
331
332
// if Engine.PlatformID != RETRO_WP7
333
// if Options.Soundtrack == OST_JP
334
// LoadVideo("Opening")
335
// else
336
// LoadVideo("OpeningUS")
337
// end if
338
// end if
339
340
Stage.ActiveList = REGULAR_STAGE
341
Stage.ListPos = STAGE_R_PPZ1A
342
LoadStage()
343
end if
344
SetScreenFade(0, 0, 0, Object.Fade)
345
break
346
347
case MENUCONTROL_MENUBUTTON_CHECK
348
if MenuButton.State == MENUBUTTON_CONFIRM_SELECTION
349
Object.State = MENUCONTROL_CONTROLS
350
end if
351
break
352
353
case MENUCONTROL_ENTER_TROPHIES //Mobile Only
354
if Object.Fade < 320
355
Object.Fade += 8
356
else
357
Stage.ListPos = STAGE_P_THROPIES
358
LoadStage()
359
end if
360
SetScreenFade(0, 0, 0, Object.Fade)
361
362
break
363
364
case MENUCONTROL_ENTER_LEADERBOARDS //Mobile Only
365
if Object.Fade < 320
366
Object.Fade += 8
367
else
368
Stage.ListPos = STAGE_P_LEADERBOARDS
369
LoadStage()
370
end if
371
SetScreenFade(0, 0, 0, Object.Fade)
372
373
break
374
375
end switch
376
end sub
377
378
379
sub ObjectStartup
380
SetMusicTrack("JP/SpecialStage.ogg", 0, 1)
381
SetMusicTrack("US/SpecialStage.ogg", 1, 270972)
382
Object[0].Type = TypeName[Menu Control]
383
Object[0].ButtonYOffset = 32
384
385
#platform: Use_Origins // they have in mind a mobile release or this is for Switch?
386
if Engine.DeviceType == RETRO_STANDARD
387
Object[0].CurrentSelection = 1
388
Options.PhysicalControls = true
389
else
390
Options.PhysicalControls = false
391
endif
392
#endplatform
393
394
#platform: Use_Standalone
395
#platform: Standard
396
Object[0].CurrentSelection = 1
397
#endplatform
398
#endplatform
399
#platform: Use_Standalone
400
#platform: Mobile
401
Options.PhysicalControls = false
402
#endplatform
403
#endplatform
404
405
Object[0].DragCurrentSelection = 0
406
end sub
407
408
409
// ========================
410
// Editor Subs
411
// ========================
412
413
sub RSDKDraw
414
DrawSprite(0)
415
end sub
416
417
418
sub RSDKLoad
419
LoadSpriteSheet("Global/Display.gif")
420
SpriteFrame(-16, -16, 32, 32, 1, 143) // #0 - "Script" Icon
421
422
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
423
end sub
424
425