Mirror for Friday Night Funkin
1package funkin.ui.debug;
2
3import flixel.math.FlxPoint;
4import flixel.FlxObject;
5import flixel.FlxSprite;
6import funkin.ui.MusicBeatSubState;
7import funkin.audio.FunkinSound;
8import funkin.ui.TextMenuList;
9import funkin.ui.debug.charting.ChartEditorState;
10import funkin.util.logging.CrashHandler;
11import flixel.addons.transition.FlxTransitionableState;
12import funkin.util.FileUtil;
13
14class DebugMenuSubState extends MusicBeatSubState
15{
16 var items:TextMenuList;
17
18 /**
19 * Camera focus point
20 */
21 var camFocusPoint:FlxObject;
22
23 override function create():Void
24 {
25 FlxTransitionableState.skipNextTransIn = true;
26 super.create();
27
28 bgColor = 0x00000000;
29
30 // Create an object for the camera to track.
31 camFocusPoint = new FlxObject(0, 0);
32 add(camFocusPoint);
33
34 // Follow the camera focus as we scroll.
35 FlxG.camera.follow(camFocusPoint, null, 0.06);
36
37 // Create the green background.
38 var menuBG = new FlxSprite().loadGraphic(Paths.image('menuDesat'));
39 menuBG.color = 0xFF4CAF50;
40 menuBG.setGraphicSize(Std.int(menuBG.width * 1.1));
41 menuBG.updateHitbox();
42 menuBG.screenCenter();
43 menuBG.scrollFactor.set(0, 0);
44 add(menuBG);
45
46 // Create the list for menu items.
47 items = new TextMenuList();
48 // Move the camera when the menu is scrolled.
49 items.onChange.add(onMenuChange);
50 add(items);
51
52 FlxTransitionableState.skipNextTransIn = true;
53
54 // Create each menu item.
55 // Call onMenuChange when the first item is created to move the camera .
56 #if FEATURE_CHART_EDITOR
57 createItem("CHART EDITOR", openChartEditor);
58 #end
59 createItem("ANIMATION EDITOR", openAnimationEditor);
60 #if FEATURE_STAGE_EDITOR
61 createItem("STAGE EDITOR", openStageEditor);
62 #end
63 #if FEATURE_RESULTS_DEBUG
64 createItem("RESULTS SCREEN DEBUG", openTestResultsScreen);
65 #end
66 // createItem("Input Offset Testing", openInputOffsetTesting);
67 // createItem("CHARACTER SELECT", openCharSelect, true);
68 // createItem("TEST STICKERS", testStickers);
69 #if sys
70 createItem("OPEN CRASH LOG FOLDER", openLogFolder);
71 #end
72 onMenuChange(items.members[0]);
73 FlxG.camera.focusOn(new FlxPoint(camFocusPoint.x, camFocusPoint.y + 500));
74 }
75
76 function onMenuChange(selected:TextMenuItem)
77 {
78 camFocusPoint.setPosition(selected.x + selected.width / 2, selected.y + selected.height / 2);
79 }
80
81 override function update(elapsed:Float):Void
82 {
83 super.update(elapsed);
84
85 if (controls.BACK)
86 {
87 FunkinSound.playOnce(Paths.sound('cancelMenu'));
88 exitDebugMenu();
89 }
90 }
91
92 function createItem(name:String, callback:Void->Void, fireInstantly = false):TextMenuItem
93 {
94 var item = items.createItem(0, 100 + items.length * 100, name, BOLD, callback);
95 item.fireInstantly = fireInstantly;
96 item.screenCenter(X);
97 return item;
98 }
99
100 function openChartEditor()
101 {
102 FlxTransitionableState.skipNextTransIn = true;
103
104 FlxG.switchState(() -> new ChartEditorState());
105 }
106
107 function openInputOffsetTesting()
108 {
109 openSubState(new funkin.ui.debug.latency.LatencyState());
110 trace('Input Offset Testing');
111 }
112
113 function openCharSelect()
114 {
115 FlxG.switchState(new funkin.ui.charSelect.CharSelectSubState());
116 }
117
118 function openAnimationEditor()
119 {
120 FlxG.switchState(() -> new funkin.ui.debug.anim.DebugBoundingState());
121 trace('Animation Editor');
122 }
123
124 function testStickers()
125 {
126 openSubState(new funkin.ui.transition.stickers.StickerSubState({}));
127 trace('opened stickers');
128 }
129
130 function openStageEditor()
131 {
132 trace('Stage Editor');
133 FlxG.switchState(() -> new funkin.ui.debug.stageeditor.StageEditorState());
134 }
135
136 function openTestResultsScreen():Void
137 {
138 FlxG.switchState(() -> new funkin.ui.debug.results.ResultsDebugSubState());
139 }
140
141 #if sys
142 function openLogFolder()
143 {
144 FileUtil.openFolder(CrashHandler.LOG_FOLDER);
145 }
146 #end
147
148 function exitDebugMenu()
149 {
150 // TODO: Add a transition?
151 this.close();
152 }
153}