-
-
Notifications
You must be signed in to change notification settings - Fork 320
Expand file tree
/
Copy pathTitleState.hx
More file actions
353 lines (294 loc) · 8.92 KB
/
TitleState.hx
File metadata and controls
353 lines (294 loc) · 8.92 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
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
package funkin.menus;
import flixel.group.FlxGroup;
import flixel.input.gamepad.FlxGamepad;
import flixel.util.FlxColor;
import flixel.util.FlxTimer;
import flixel.util.typeLimit.OneOfTwo;
import funkin.backend.MusicBeatGroup;
import funkin.backend.utils.XMLUtil;
import haxe.xml.Access;
import openfl.Assets;
using StringTools;
@:allow(funkin.backend.assets.ModsFolder)
@:allow(funkin.backend.system.MainState)
class TitleState extends MusicBeatState
{
static var initialized:Bool = false;
static var hasCheckedUpdates:Bool = false;
public var curWacky:Array<String> = [];
public var blackScreen:FlxSprite;
public var textGroup:FlxGroup;
override public function create():Void
{
curWacky = FlxG.random.getObject(getIntroTextShit());
MusicBeatState.skipTransIn = true;
startIntro();
super.create();
DiscordUtil.call("onMenuLoaded", ["Title Screen"]);
}
var titleText:FlxSprite;
var titleScreenSprites:MusicBeatGroup;
function startIntro()
{
if (!initialized)
CoolUtil.playMenuSong(true);
persistentUpdate = true;
var bg:FlxSprite = new FlxSprite().makeSolid(FlxG.width, FlxG.height, FlxColor.BLACK);
add(bg);
titleScreenSprites = new MusicBeatGroup();
add(titleScreenSprites);
loadXML();
if (titleText == null) {
titleText = new FlxSprite(0, FlxG.height * 0.8);
titleText.frames = Paths.getFrames('menus/titlescreen/titleEnter');
titleText.animation.addByPrefix('idle', "Press Enter to Begin", 24);
titleText.animation.addByPrefix('press', "ENTER PRESSED", 24);
titleText.antialiasing = true;
titleText.animation.play('idle');
titleText.updateHitbox();
titleText.screenCenter(X);
}
add(titleText);
textGroup = new FlxGroup();
blackScreen = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, FlxColor.BLACK);
add(blackScreen);
FlxG.mouse.visible = false;
if (initialized)
skipIntro();
else
initialized = true;
add(textGroup);
}
public function getIntroTextShit():Array<Array<String>>
{
var fullText:String = Assets.getText(Paths.txt('titlescreen/introText'));
var firstArray:Array<String> = fullText.split('\n');
var swagGoodArray:Array<Array<String>> = [];
for (i in firstArray)
{
swagGoodArray.push(i.split('--'));
}
return swagGoodArray;
}
var transitioning:Bool = false;
override function update(elapsed:Float)
{
var pressedEnter:Bool = FlxG.keys.justPressed.ENTER;
#if mobile
for (touch in FlxG.touches.list)
{
if (touch.justPressed)
{
pressedEnter = true;
}
}
#end
var gamepad:FlxGamepad = FlxG.gamepads.lastActive;
if (gamepad != null)
{
if (gamepad.justPressed.START)
pressedEnter = true;
#if switch
if (gamepad.justPressed.B)
pressedEnter = true;
#end
}
if (pressedEnter && transitioning && skippedIntro) {
FlxG.camera.stopFX();// FlxG.camera.visible = false;
goToMainMenu(false);
}
if (pressedEnter && !transitioning && skippedIntro)
{
pressEnter();
}
if (pressedEnter && !skippedIntro)
skipIntro();
super.update(elapsed);
}
public function pressEnter() {
titleText.animation.play('press');
FlxG.camera.flash(FlxColor.WHITE, 1);
CoolUtil.playMenuSFX(CONFIRM, 0.7);
transitioning = true;
// FlxG.sound.music.stop();
new FlxTimer().start(2, (_) -> goToMainMenu(false));
}
function goToMainMenu(force = true) {
#if UPDATE_CHECKING
if (!force && !Flags.DISABLE_AUTOUPDATER) {
funkin.backend.system.updating.UpdateUtil.waitForUpdates(false, (report) -> {
hasCheckedUpdates = true;
if (FlxG.state != this) return;
if (!report.newUpdate) goToMainMenu(true);
else FlxG.switchState(new funkin.backend.system.updating.UpdateAvailableScreen(report));
}, true);
}
else
#end {
FlxG.switchState(new MainMenuState());
}
}
public function createCoolText(textArray:Array<String>)
{
for (i=>text in textArray)
{
if (text == "" || text == null) continue;
var money:Alphabet = new Alphabet(0, (i * 60) + 200, text, "bold");
money.screenCenter(X);
textGroup.add(money);
}
}
public function addMoreText(text:String)
{
var coolText:Alphabet = new Alphabet(0, (textGroup.length * 60) + 200, text, "bold");
coolText.screenCenter(X);
textGroup.add(coolText);
}
public function deleteCoolText()
{
while (textGroup.members.length > 0) {
textGroup.members[0].destroy();
textGroup.remove(textGroup.members[0], true);
}
}
override function beatHit(curBeat:Int)
{
super.beatHit(curBeat);
if (curBeat >= titleLength || skippedIntro) {
if (!skippedIntro) skipIntro();
return;
}
var introText = titleLines[curBeat];
if (introText != null)
introText.show();
}
public var xml:Access;
public var titleLength:Int = 16;
public var titleLines:Map<Int, IntroText> = [
1 => new IntroText(['ninjamuffin99', 'phantomArcade', 'kawaisprite', 'evilsk8er']),
3 => new IntroText(['ninjamuffin99', 'phantomArcade', 'kawaisprite', 'evilsk8er', 'present']),
4 => new IntroText(),
5 => new IntroText(['In association', 'with']),
7 => new IntroText(['In association', 'with', 'newgrounds', {
name: "newgroundsLogo",
path: "menus/titlescreen/newgrounds_logo",
scale: 0.8
}]),
8 => new IntroText(),
9 => new IntroText(["{introText1}"]),
11 => new IntroText(["{introText1}", "{introText2}"]),
12 => new IntroText(),
13 => new IntroText(['Friday']),
14 => new IntroText(['Friday', 'Night']),
15 => new IntroText(['Friday', 'Night', "Funkin'"]),
];
public var titleSprites:Map<String, FlxSprite> = [];
public function loadXML() {
try {
xml = new Access(Xml.parse(Assets.getText(Paths.xml('titlescreen/titlescreen'))).firstElement());
if (xml.hasNode.intro) {
titleLines = [];
if (xml.node.intro.has.length) titleLength = Std.parseInt(xml.node.intro.att.length).getDefault(16);
for(node in xml.nodes.sprites) {
var parentFolder:String = node.getAtt("folder").getDefault("");
if (parentFolder != "" && !parentFolder.endsWith("/")) parentFolder += "/";
for(sprNode in node.elements) {
var spr = XMLUtil.createSpriteFromXML(sprNode, parentFolder);
switch(sprNode.name) {
case "press-enter":
titleText = spr;
default:
titleScreenSprites.add(spr);
}
if(node.has.name) titleSprites[node.att.name] = spr;
}
}
for(text in xml.node.intro.nodes.text) {
var beat:Int = text.has.beat ? Std.parseInt(text.att.beat).getDefault(0) : 0;
var texts:Array<OneOfTwo<String, TitleStateImage>> = [];
for(node in text.elements) {
switch(node.name) {
case "line":
if (!node.has.text) continue;
texts.push(node.att.text);
case "introtext":
if (!node.has.line) continue;
texts.push('{introText${node.att.line}}');
case "sprite":
if (!node.has.path) continue;
var name:String = node.has.name ? node.att.name : null;
var path:String = node.att.path;
var flipX:Bool = node.has.flipX ? node.att.flipX == "true" : false;
var flipY:Bool = node.has.flipY ? node.att.flipY == "true" : false;
var scale:Float = node.has.scale ? Std.parseFloat(node.att.scale).getDefault(1) : 1;
texts.push({
name: name,
path: path,
flipX: flipX,
flipY: flipY,
scale: scale
});
}
}
titleLines[beat] = new IntroText(texts);
}
}
} catch(e) {
Logs.error('Failed to load titlescreen XML: $e');
}
}
var skippedIntro:Bool = false;
public function skipIntro():Void
{
if (!skippedIntro)
{
FlxG.camera.flash(FlxColor.WHITE, 4);
remove(blackScreen);
blackScreen.destroy();
remove(textGroup);
skippedIntro = true;
}
}
}
class IntroText {
public var lines:Array<OneOfTwo<String, TitleStateImage>> = [];
public function new(?lines:Array<OneOfTwo<String, TitleStateImage>>) {
this.lines = lines;
}
public function show() {
var state = cast(FlxG.state, TitleState);
state.deleteCoolText();
if (lines == null) return;
for(e in lines) {
if (e is String) {
var text = cast(e, String);
for(k=>e in state.curWacky) text = text.replace('{introText${k+1}}', e);
state.addMoreText(text);
} else if (e is Dynamic) {
var image:TitleStateImage = e;
if (image.path == null) continue;
var scale:Float = image.scale.getDefault(1);
var yPos:Float = 200;
if(state.textGroup.members.length > 0) {
var lastLine:FlxSprite = cast state.textGroup.members[state.textGroup.members.length-1];
yPos = lastLine.y + lastLine.height + 10;
}
var sprite = new FlxSprite(0, yPos).loadAnimatedGraphic(Paths.image(image.path));
sprite.flipX = image.flipX.getDefault(false);
sprite.flipY = image.flipY.getDefault(false);
sprite.scale.set(scale, scale);
sprite.updateHitbox();
sprite.screenCenter(X);
sprite.antialiasing = true;
state.textGroup.add(sprite);
}
}
}
}
typedef TitleStateImage = {
var name:String;
var path:String;
@:optional var scale:Null<Float>;
@:optional var flipX:Null<Bool>;
@:optional var flipY:Null<Bool>;
}