From 3f28fdb92c47af0d537c9a15759931ec189101d3 Mon Sep 17 00:00:00 2001
From: Cameron Taylor <cameron.taylor.ninja@gmail.com>
Date: Fri, 2 Dec 2022 21:37:07 -0500
Subject: [PATCH] song name on result screen stuff WIP

---
 hmm.json                                     |   6 +-
 source/funkin/TitleState.hx                  |   2 +
 source/funkin/play/ResultState.hx            | 103 ++++++++++++++++++-
 source/funkin/shaderslmfao/LeftMaskShader.hx |  55 ++++++++++
 4 files changed, 159 insertions(+), 7 deletions(-)
 create mode 100644 source/funkin/shaderslmfao/LeftMaskShader.hx

diff --git a/hmm.json b/hmm.json
index 07816ff2d..ce015c5ad 100644
--- a/hmm.json
+++ b/hmm.json
@@ -86,10 +86,8 @@
     },
     {
       "name": "lime",
-      "type": "git",
-      "dir": null,
-      "ref": "develop",
-      "url": "https://github.com/openfl/lime"
+      "type": "haxelib",
+      "version": null
     },
     {
       "name": "openfl",
diff --git a/source/funkin/TitleState.hx b/source/funkin/TitleState.hx
index b4b521052..ef3984f80 100644
--- a/source/funkin/TitleState.hx
+++ b/source/funkin/TitleState.hx
@@ -166,6 +166,8 @@ class TitleState extends MusicBeatState
 
 		add(gfDance);
 
+		// gfDance.shader = maskShader;
+
 		// gfDance.shader = swagShader.shader;
 
 		// gfDance.shader = new TitleOutline();
diff --git a/source/funkin/play/ResultState.hx b/source/funkin/play/ResultState.hx
index 132f1cbad..359b64f5a 100644
--- a/source/funkin/play/ResultState.hx
+++ b/source/funkin/play/ResultState.hx
@@ -3,18 +3,27 @@ package funkin.play;
 import flixel.FlxBasic;
 import flixel.FlxSprite;
 import flixel.graphics.frames.FlxAtlasFrames;
+import flixel.graphics.frames.FlxBitmapFont;
 import flixel.group.FlxGroup.FlxTypedGroup;
+import flixel.math.FlxPoint;
+import flixel.text.FlxBitmapText;
 import flixel.text.FlxText;
 import flixel.tweens.FlxEase;
 import flixel.tweens.FlxTween;
 import flixel.util.FlxColor;
 import flixel.util.FlxGradient;
 import flixel.util.FlxTimer;
+import funkin.shaderslmfao.LeftMaskShader;
 import funkin.ui.TallyCounter;
 
 class ResultState extends MusicBeatSubstate
 {
 	var resultsVariation:ResultVariations;
+	var songName:FlxBitmapText;
+	var difficulty:FlxSprite;
+
+	var maskShaderSongName = new LeftMaskShader();
+	var maskShaderDifficulty = new LeftMaskShader();
 
 	override function create()
 	{
@@ -71,7 +80,7 @@ class ResultState extends MusicBeatSubstate
 		soundSystem.antialiasing = true;
 		add(soundSystem);
 
-		var difficulty:FlxSprite = new FlxSprite(680);
+		difficulty = new FlxSprite(555);
 
 		var diffSpr:String = switch (CoolUtil.difficultyString())
 		{
@@ -86,11 +95,35 @@ class ResultState extends MusicBeatSubstate
 		}
 
 		difficulty.loadGraphic(Paths.image("resultScreen/" + diffSpr));
-		difficulty.y = -difficulty.height;
-		FlxTween.tween(difficulty, {y: 110}, 0.5, {ease: FlxEase.quartOut, startDelay: 0.8});
 		difficulty.antialiasing = true;
 		add(difficulty);
 
+		var fontLetters:String = "AaBbCcDdEeFfGgHhiIJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz:1234567890";
+		songName = new FlxBitmapText(FlxBitmapFont.fromMonospace(Paths.image("resultScreen/tardlingSpritesheet"), fontLetters, FlxPoint.get(49, 62)));
+
+		// stole this from PauseSubState, I think eric wrote it!!
+		if (PlayState.instance.currentChart != null)
+		{
+			songName.text += '${PlayState.instance.currentChart.songName}:${PlayState.instance.currentChart.songArtist}';
+		}
+		else
+		{
+			songName.text += PlayState.currentSong.song;
+		}
+
+		songName.antialiasing = true;
+		songName.letterSpacing = -15;
+		songName.angle = -4.1;
+		add(songName);
+
+		timerThenSongName();
+
+		songName.shader = maskShaderSongName;
+		difficulty.shader = maskShaderDifficulty;
+
+		maskShaderSongName.swagMaskX = difficulty.x - 15;
+		maskShaderDifficulty.swagMaskX = difficulty.x - 15;
+
 		var blackTopBar:FlxSprite = new FlxSprite().loadGraphic(Paths.image("resultScreen/topBarBlack"));
 		blackTopBar.y = -blackTopBar.height;
 		FlxTween.tween(blackTopBar, {y: 0}, 0.4, {ease: FlxEase.quartOut, startDelay: 0.5});
@@ -196,8 +229,72 @@ class ResultState extends MusicBeatSubstate
 		super.create();
 	}
 
+	function timerThenSongName()
+	{
+		movingSongStuff = false;
+
+		difficulty.x = 555;
+
+		var diffYTween = 122;
+
+		difficulty.y = -difficulty.height;
+		FlxTween.tween(difficulty, {y: diffYTween}, 0.5, {ease: FlxEase.quartOut, startDelay: 0.8});
+
+		songName.y = diffYTween - 30;
+		songName.x = (difficulty.x + difficulty.width) + 20;
+
+		new FlxTimer().start(3, _ ->
+		{
+			movingSongStuff = true;
+		});
+	}
+
+	var movingSongStuff:Bool = false;
+	var speedOfTween:FlxPoint = FlxPoint.get(-1, 0.1);
+
 	override function update(elapsed:Float)
 	{
+		maskShaderSongName.swagSprX = songName.x;
+		maskShaderDifficulty.swagSprX = difficulty.x;
+
+		if (movingSongStuff)
+		{
+			songName.x += speedOfTween.x;
+			difficulty.x += speedOfTween.x;
+			songName.y += speedOfTween.y;
+			difficulty.y += speedOfTween.y;
+
+			if (songName.x + songName.width < 100)
+			{
+				timerThenSongName();
+			}
+		}
+
+		if (FlxG.keys.justPressed.RIGHT)
+			speedOfTween.x += 0.1;
+
+		if (FlxG.keys.justPressed.LEFT)
+		{
+			speedOfTween.x -= 0.1;
+		}
+
+		if (FlxG.keys.justPressed.UP)
+			speedOfTween.y -= 0.1;
+
+		if (FlxG.keys.justPressed.DOWN)
+			speedOfTween.y += 0.1;
+
+		if (FlxG.keys.pressed.V)
+		{
+			trace(speedOfTween);
+		}
+
+		if (FlxG.keys.justPressed.PERIOD)
+			songName.angle += 0.1;
+
+		if (FlxG.keys.justPressed.COMMA)
+			songName.angle -= 0.1;
+
 		if (controls.PAUSE)
 			FlxG.switchState(new FreeplayState());
 
diff --git a/source/funkin/shaderslmfao/LeftMaskShader.hx b/source/funkin/shaderslmfao/LeftMaskShader.hx
new file mode 100644
index 000000000..0e0b7bcc7
--- /dev/null
+++ b/source/funkin/shaderslmfao/LeftMaskShader.hx
@@ -0,0 +1,55 @@
+package funkin.shaderslmfao;
+
+import flixel.system.FlxAssets.FlxShader;
+
+class LeftMaskShader extends FlxShader
+{
+	public var swagMaskX(default, set):Float = 0;
+	public var swagSprX(default, set):Float = 0;
+
+	function set_swagSprX(x:Float):Float
+	{
+		sprX.value[0] = x;
+
+		return x;
+	}
+
+	function set_swagMaskX(x:Float):Float
+	{
+		maskX.value[0] = x;
+
+		return x;
+	}
+
+	@:glFragmentSource('
+        #pragma header
+
+        uniform float sprX;
+        uniform float maskX;
+
+        void main()
+        {
+
+            float cutOff = maskX - sprX;
+            float sprPos = cutOff / openfl_TextureSize.x;
+
+            vec2 uv = openfl_TextureCoordv.xy;
+
+            vec4 color = flixel_texture2D(bitmap, uv);
+
+            if (uv.x < sprPos)
+            {
+                color = vec4(0.0, 0.0, 0.0, 0.0);
+            }
+
+            gl_FragColor = color;
+        }
+    ')
+	public function new()
+	{
+		super();
+
+		sprX.value = [0];
+		maskX.value = [0];
+	}
+}