-
-
Notifications
You must be signed in to change notification settings - Fork 318
Expand file tree
/
Copy pathMainMenuState.hx
More file actions
241 lines (198 loc) · 6.52 KB
/
MainMenuState.hx
File metadata and controls
241 lines (198 loc) · 6.52 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
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
package funkin.menus;
import flixel.FlxState;
import flixel.effects.FlxFlicker;
import flixel.tweens.FlxTween;
import funkin.backend.FunkinText;
import funkin.backend.scripting.events.menu.MenuChangeEvent;
import funkin.backend.scripting.events.NameEvent;
import funkin.menus.credits.CreditsMain;
import funkin.options.OptionsMenu;
import lime.app.Application;
using StringTools;
class MainMenuState extends MusicBeatState
{
var curSelected:Int = 0;
var menuItems:FlxTypedGroup<FlxSprite>;
var optionShit:Array<String> = CoolUtil.coolTextFile(Paths.txt("config/menuItems"));
var bg:FlxSprite;
var magenta:FlxSprite;
var camFollow:FlxObject;
var versionText:FunkinText;
var devModeWarning:FunkinText;
public var canAccessDebugMenus:Bool = !Flags.DISABLE_EDITORS;
override function create()
{
super.create();
DiscordUtil.call("onMenuLoaded", ["Main Menu"]);
CoolUtil.playMenuSong();
bg = new FlxSprite(-80).loadAnimatedGraphic(Paths.image('menus/menuBG'));
add(bg);
camFollow = new FlxObject(0, 0, 1, 1);
add(camFollow);
magenta = new FlxSprite(-80).loadAnimatedGraphic(Paths.image('menus/menuDesat'));
magenta.visible = false;
magenta.color = 0xFFfd719b;
add(magenta);
for(bg in [bg, magenta]) {
bg.scrollFactor.set(0, 0.18);
bg.scale.set(1.15, 1.15);
bg.updateHitbox();
bg.screenCenter();
bg.antialiasing = true;
}
menuItems = new FlxTypedGroup<FlxSprite>();
add(menuItems);
for (i=>option in optionShit)
{
var menuItem:FlxSprite = new FlxSprite(0, 60 + (i * 160));
menuItem.frames = Paths.getFrames('menus/mainmenu/${option}');
menuItem.animation.addByPrefix('idle', option + " basic", 24);
menuItem.animation.addByPrefix('selected', option + " white", 24);
menuItem.animation.play('idle');
menuItem.ID = i;
menuItem.screenCenter(X);
menuItems.add(menuItem);
menuItem.scrollFactor.set();
menuItem.antialiasing = true;
}
FlxG.camera.follow(camFollow, null, 0.06);
versionText = new FunkinText(5, FlxG.height - 2, 0, [
Flags.VERSION_MESSAGE,
TU.translate("mainMenu.commit", [Flags.COMMIT_NUMBER, Flags.COMMIT_HASH]),
TU.translate("mainMenu.openMods", [controls.getKeyName(SWITCHMOD)]),
''
].join('\n'));
versionText.y -= versionText.height;
versionText.scrollFactor.set();
add(versionText);
changeItem();
devModeWarning = new FunkinText(0, FlxG.height - 50, 1280, "You have to enable DEVELOPER MODE in the miscellaneous settings!", 24);
devModeWarning.alignment = CENTER;
add(devModeWarning);
devModeWarning.scrollFactor.set();
devModeWarning.alpha = 0;
}
var selectedSomethin:Bool = false;
var forceCenterX:Bool = true;
var devModeCount:Int = 0;
override function update(elapsed:Float)
{
if (FlxG.sound.music.volume < 0.8)
FlxG.sound.music.volume += 0.5 * elapsed;
if (!selectedSomethin)
{
if (canAccessDebugMenus) {
if (controls.DEV_ACCESS) {
persistentUpdate = false;
persistentDraw = true;
openSubState(new funkin.editors.EditorPicker());
}
/*
if (FlxG.keys.justPressed.SEVEN)
FlxG.switchState(new funkin.desktop.DesktopMain());
if (FlxG.keys.justPressed.EIGHT) {
CoolUtil.safeSaveFile("chart.json", Json.stringify(funkin.backend.chart.Chart.parse("dadbattle", "hard")));
}
*/
}
if (!Options.devMode && FlxG.keys.justPressed.SEVEN) {
FlxG.sound.play(Paths.sound(Flags.DEFAULT_EDITOR_DELETE_SOUND));
if (devModeCount++ == 2) {
FlxTween.tween(devModeWarning, {alpha: 1}, 0.4);
}
FlxTween.completeTweensOf(devModeWarning);
FlxTween.color(devModeWarning, 0.2, 0xFFFF0000, 0xFFFFFFFF);
FlxTween.shake(devModeWarning, 0.005, 0.3);
devModeWarning.y = FlxG.height - 75;
FlxTween.tween(devModeWarning, {y: FlxG.height - 50}, 0.4);
}
var upP = controls.UP_P;
var downP = controls.DOWN_P;
var scroll = FlxG.mouse.wheel;
if (upP || downP || scroll != 0) // like this we wont break mods that expect a 0 change event when calling sometimes - Nex
changeItem((upP ? -1 : 0) + (downP ? 1 : 0) - scroll);
if (controls.BACK)
FlxG.switchState(new TitleState());
if (FlxG.mouse.justPressed){
for(index => sprite in menuItems.members){
if(FlxG.mouse.overlaps(sprite)){
if(curSelected != index)
changeItem(index-curSelected);
else
selectItem();
break;
}
}
#if MOD_SUPPORT
if(FlxG.mouse.overlaps(versionText)){
openSubState(new ModSwitchMenu());
persistentUpdate = false;
persistentDraw = true;
}
#end
}
#if MOD_SUPPORT
if (controls.SWITCHMOD) {
openSubState(new ModSwitchMenu());
persistentUpdate = false;
persistentDraw = true;
}
#end
if (controls.ACCEPT)
selectItem();
}
super.update(elapsed);
if (forceCenterX)
menuItems.forEach(function(spr:FlxSprite)
{
spr.screenCenter(X);
});
}
public override function switchTo(nextState:FlxState):Bool {
try {
menuItems.forEach(function(spr:FlxSprite) {
FlxTween.tween(spr, {alpha: 0}, 0.5, {ease: FlxEase.quintOut});
});
}
return super.switchTo(nextState);
}
function selectItem() {
selectedSomethin = true;
CoolUtil.playMenuSFX(CONFIRM);
if (Options.flashingMenu) FlxFlicker.flicker(magenta, 1.1, 0.15, false);
FlxFlicker.flicker(menuItems.members[curSelected], 1, Options.flashingMenu ? 0.06 : 0.15, false, false, function(flick:FlxFlicker)
{
var daChoice:String = optionShit[curSelected];
var event = event("onSelectItem", EventManager.get(NameEvent).recycle(daChoice));
if (event.cancelled) return;
switch (event.name)
{
case 'story mode': FlxG.switchState(new StoryMenuState());
case 'freeplay': FlxG.switchState(new FreeplayState());
case 'donate', 'credits': FlxG.switchState(new CreditsMain()); // kept donate for not breaking scripts, if you don't want donate to bring you to the credits menu, thats easy softcodable - Nex
case 'options': FlxG.switchState(new OptionsMenu());
}
});
}
function changeItem(huh:Int = 0)
{
var event = event("onChangeItem", EventManager.get(MenuChangeEvent).recycle(curSelected, FlxMath.wrap(curSelected + huh, 0, menuItems.length-1), huh, huh != 0));
if (event.cancelled) return;
curSelected = event.value;
if (event.playMenuSFX)
CoolUtil.playMenuSFX(SCROLL, 0.7);
menuItems.forEach(function(spr:FlxSprite)
{
spr.animation.play('idle');
if (spr.ID == curSelected)
{
spr.animation.play('selected');
var mid = spr.getGraphicMidpoint();
camFollow.setPosition(mid.x, mid.y);
mid.put();
}
spr.updateHitbox();
spr.centerOffsets();
});
}
}