forked from FUCKGITHUBSHIT/Psych-Engine-0.5-Android-Port
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainMenuState.hx
319 lines (274 loc) · 8.89 KB
/
MainMenuState.hx
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
package;
#if desktop
import Discord.DiscordClient;
#end
import flixel.FlxG;
import flixel.FlxObject;
import flixel.FlxSprite;
import flixel.FlxCamera;
import flixel.addons.transition.FlxTransitionableState;
import flixel.effects.FlxFlicker;
import flixel.graphics.frames.FlxAtlasFrames;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.text.FlxText;
import flixel.math.FlxMath;
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
import flixel.util.FlxColor;
import lime.app.Application;
import Achievements;
import editors.MasterEditorMenu;
import flixel.input.keyboard.FlxKey;
using StringTools;
class MainMenuState extends MusicBeatState
{
public static var psychEngineVersion:String = '0.5'; //This is also used for Discord RPC
public static var curSelected:Int = 0;
var menuItems:FlxTypedGroup<FlxSprite>;
private var camGame:FlxCamera;
private var camAchievement:FlxCamera;
var optionShit:Array<String> = [
'story_mode',
'freeplay',
#if MODS_ALLOWED 'mods', #end
#if ACHIEVEMENTS_ALLOWED 'awards', #end
'credits',
#if !switch 'donate', #end
'options'
];
var magenta:FlxSprite;
var camFollow:FlxObject;
var camFollowPos:FlxObject;
var debugKeys:Array<FlxKey>;
private var char1 Character = null;
override function create()
{
#if desktop
// Updating Discord Rich Presence
DiscordClient.changePresence("In the Menus", null);
#end
WeekData.setDirectoryFromWeek();
debugKeys = ClientPrefs.copyKey(ClientPrefs.keyBinds.get('debug_1'));
camGame = new FlxCamera();
camAchievement = new FlxCamera();
camAchievement.bgColor.alpha = 0;
FlxG.cameras.reset(camGame);
FlxG.cameras.add(camAchievement);
FlxCamera.defaultCameras = [camGame];
transIn = FlxTransitionableState.defaultTransIn;
transOut = FlxTransitionableState.defaultTransOut;
persistentUpdate = persistentDraw = true;
var yScroll:Float = Math.max(0.25 - (0.05 * (optionShit.length - 4)), 0.1);
var bg:FlxSprite = new FlxSprite(-80).loadGraphic(Paths.image('menuBG'));
bg.scrollFactor.set(0, yScroll);
bg.setGraphicSize(Std.int(bg.width * 1.175));
bg.updateHitbox();
bg.screenCenter();
bg.antialiasing = ClientPrefs.globalAntialiasing;
add(bg);
camFollow = new FlxObject(0, 0, 1, 1);
camFollowPos = new FlxObject(0, 0, 1, 1);
add(camFollow);
add(camFollowPos);
magenta = new FlxSprite(-80).loadGraphic(Paths.image('menuDesat'));
magenta.scrollFactor.set(0, yScroll);
magenta.setGraphicSize(Std.int(magenta.width * 1.175));
magenta.updateHitbox();
magenta.screenCenter();
magenta.visible = false;
magenta.antialiasing = ClientPrefs.globalAntialiasing;
magenta.color = 0xFFfd719b;
add(magenta);
// magenta.scrollFactor.set();
menuItems = new FlxTypedGroup<FlxSprite>();
add(menuItems);
var scale:Float = 1;
/*if(optionShit.length > 6) {
scale = 6 / optionShit.length;
}*/
for (i in 0...optionShit.length)
{
var offset:Float = 108 - (Math.max(optionShit.length, 4) - 4) * 80;
var menuItem:FlxSprite = new FlxSprite(0, (i * 140) + offset);
menuItem.scale.x = scale;
menuItem.scale.y = scale;
menuItem.frames = Paths.getSparrowAtlas('mainmenu/menu_' + optionShit[i]);
menuItem.animation.addByPrefix('idle', optionShit[i] + " basic", 24);
menuItem.animation.addByPrefix('selected', optionShit[i] + " white", 24);
menuItem.animation.play('idle');
menuItem.ID = i;
//menuItem.screenCenter(X);
menuItem.x += 250;
menuItems.add(menuItem);
var scr:Float = (optionShit.length - 4) * 0.135;
if(optionShit.length < 6) scr = 0;
menuItem.scrollFactor.set(0, scr);
menuItem.antialiasing = ClientPrefs.globalAntialiasing;
//menuItem.setGraphicSize(Std.int(menuItem.width * 0.58));
menuItem.updateHitbox();
}
FlxG.camera.follow(camFollowPos, null, 1);
char1 = new Character(800, -130, 'dad' true);
char1.setGraphicSize(Std.int(char1.width = 0.8));
add(char1);
char1.visible = false;
var versionShit:FlxText = new FlxText(12, FlxG.height - 44, 0, "Psych Engine v" + psychEngineVersion, 12);
versionShit.scrollFactor.set();
versionShit.setFormat("VCR OSD Mono", 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
add(versionShit);
var versionShit:FlxText = new FlxText(12, FlxG.height - 24, 0, "Friday Night Funkin' v" + Application.current.meta.get('version'), 12);
versionShit.scrollFactor.set();
versionShit.setFormat("VCR OSD Mono", 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
add(versionShit);
// NG.core.calls.event.logEvent('swag').send();
changeItem();
#if ACHIEVEMENTS_ALLOWED
Achievements.loadAchievements();
var leDate = Date.now();
if (leDate.getDay() == 5 && leDate.getHours() >= 18) {
var achieveID:Int = Achievements.getAchievementIndex('friday_night_play');
if(!Achievements.isAchievementUnlocked(Achievements.achievementsStuff[achieveID][2])) { //It's a friday night. WEEEEEEEEEEEEEEEEEE
Achievements.achievementsMap.set(Achievements.achievementsStuff[achieveID][2], true);
giveAchievement();
ClientPrefs.saveSettings();
}
}
#end
#if mobileC
addVirtualPad(UP_DOWN, A_B_7);
#end
super.create();
}
#if ACHIEVEMENTS_ALLOWED
// Unlocks "Freaky on a Friday Night" achievement
function giveAchievement() {
add(new AchievementObject('friday_night_play', camAchievement));
FlxG.sound.play(Paths.sound('confirmMenu'), 0.7);
trace('Giving achievement "friday_night_play"');
}
#end
var selectedSomethin:Bool = false;
override function update(elapsed:Float)
{
if (FlxG.sound.music.volume < 0.8)
{
FlxG.sound.music.volume += 0.5 * FlxG.elapsed;
}
var lerpVal:Float = CoolUtil.boundTo(elapsed * 7.5, 0, 1);
camFollowPos.setPosition(FlxMath.lerp(camFollowPos.x, camFollow.x, lerpVal), FlxMath.lerp(camFollowPos.y, camFollow.y, lerpVal));
if (optionShit[curSelected] == 'story_mode')
{
changeItem(-1);
changeItem(1);
char1.dance();
char1.updateHitbox();
char1.visible = true;
}
else
{
char1.visible = false;
}
if (!selectedSomethin)
{
if (controls.UI_UP_P)
{
FlxG.sound.play(Paths.sound('scrollMenu'));
changeItem(-1);
}
if (controls.UI_DOWN_P)
{
FlxG.sound.play(Paths.sound('scrollMenu'));
changeItem(1);
}
if (controls.BACK)
{
selectedSomethin = true;
FlxG.sound.play(Paths.sound('cancelMenu'));
MusicBeatState.switchState(new TitleState());
}
if (controls.ACCEPT)
{
if (optionShit[curSelected] == 'donate')
{
CoolUtil.browserLoad('https://ninja-muffin24.itch.io/funkin');
}
else
{
selectedSomethin = true;
FlxG.sound.play(Paths.sound('confirmMenu'));
if(ClientPrefs.flashing) FlxFlicker.flicker(magenta, 1.1, 0.15, false);
menuItems.forEach(function(spr:FlxSprite)
{
if (curSelected != spr.ID)
{
FlxTween.tween(spr, {alpha: 0}, 0.4, {
ease: FlxEase.quadOut,
onComplete: function(twn:FlxTween)
{
spr.kill();
}
});
}
else
{
FlxFlicker.flicker(spr, 1, 0.06, false, false, function(flick:FlxFlicker)
{
var daChoice:String = optionShit[curSelected];
switch (daChoice)
{
case 'story_mode':
MusicBeatState.switchState(new StoryMenuState());
case 'freeplay':
MusicBeatState.switchState(new FreeplayState());
#if MODS_ALLOWED
case 'mods':
MusicBeatState.switchState(new ModsMenuState());
#end
case 'awards':
MusicBeatState.switchState(new AchievementsMenuState());
case 'credits':
MusicBeatState.switchState(new CreditsState());
case 'options':
MusicBeatState.switchState(new options.OptionsState());
}
});
}
});
}
}
else if (FlxG.keys.anyJustPressed(debugKeys) #if mobileC || _virtualpad.button7.justPressed #end)
{
selectedSomethin = true;
MusicBeatState.switchState(new MasterEditorMenu());
}
}
super.update(elapsed);
menuItems.forEach(function(spr:FlxSprite)
{
//spr.screenCenter(X);
});
}
function changeItem(huh:Int = 0)
{
curSelected += huh;
if (curSelected >= menuItems.length)
curSelected = 0;
if (curSelected < 0)
curSelected = menuItems.length - 1;
menuItems.forEach(function(spr:FlxSprite)
{
spr.animation.play('idle');
spr.updateHitbox();
if (spr.ID == curSelected)
{
spr.animation.play('selected');
var add:Float = 0;
if(menuItems.length > 4) {
add = menuItems.length * 8;
}
camFollow.setPosition(spr.getGraphicMidpoint().x, spr.getGraphicMidpoint().y - add);
spr.centerOffsets();
}
});
}
}