2023-11-07 09:04:22 +00:00
|
|
|
package funkin.ui.freeplay;
|
2023-08-14 06:49:18 +00:00
|
|
|
|
|
|
|
import openfl.filters.BitmapFilterQuality;
|
|
|
|
import flixel.text.FlxText;
|
|
|
|
import flixel.group.FlxSpriteGroup;
|
2023-11-07 09:04:22 +00:00
|
|
|
import funkin.graphics.shaders.GaussianBlurShader;
|
2024-05-30 03:34:00 +00:00
|
|
|
import funkin.graphics.shaders.LeftMaskShader;
|
|
|
|
import flixel.math.FlxRect;
|
|
|
|
import flixel.tweens.FlxEase;
|
|
|
|
import flixel.util.FlxTimer;
|
|
|
|
import flixel.tweens.FlxTween;
|
|
|
|
import openfl.display.BlendMode;
|
2024-08-29 23:58:19 +00:00
|
|
|
import flixel.util.FlxColor;
|
2023-08-14 06:49:18 +00:00
|
|
|
|
|
|
|
class CapsuleText extends FlxSpriteGroup
|
|
|
|
{
|
|
|
|
public var blurredText:FlxText;
|
|
|
|
|
|
|
|
var whiteText:FlxText;
|
|
|
|
|
|
|
|
public var text(default, set):String;
|
|
|
|
|
2024-05-30 03:34:00 +00:00
|
|
|
var maskShaderSongName:LeftMaskShader = new LeftMaskShader();
|
|
|
|
|
|
|
|
public var clipWidth(default, set):Int = 255;
|
|
|
|
|
|
|
|
public var tooLong:Bool = false;
|
|
|
|
|
2024-08-29 23:58:19 +00:00
|
|
|
var glowColor:FlxColor = 0xFF00ccff;
|
|
|
|
|
2024-05-30 03:34:00 +00:00
|
|
|
// 255, 27 normal
|
|
|
|
// 220, 27 favourited
|
|
|
|
|
2023-08-14 06:49:18 +00:00
|
|
|
public function new(x:Float, y:Float, songTitle:String, size:Float)
|
|
|
|
{
|
|
|
|
super(x, y);
|
|
|
|
|
|
|
|
blurredText = initText(songTitle, size);
|
|
|
|
blurredText.shader = new GaussianBlurShader(1);
|
|
|
|
whiteText = initText(songTitle, size);
|
|
|
|
// whiteText.shader = new GaussianBlurShader(0.3);
|
|
|
|
text = songTitle;
|
|
|
|
|
2024-08-29 23:58:19 +00:00
|
|
|
blurredText.color = glowColor;
|
2023-08-14 06:49:18 +00:00
|
|
|
whiteText.color = 0xFFFFFFFF;
|
|
|
|
add(blurredText);
|
|
|
|
add(whiteText);
|
|
|
|
}
|
|
|
|
|
|
|
|
function initText(songTitle, size:Float):FlxText
|
|
|
|
{
|
|
|
|
var text:FlxText = new FlxText(0, 0, 0, songTitle, Std.int(size));
|
|
|
|
text.font = "5by7";
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2024-08-29 23:58:19 +00:00
|
|
|
public function applyStyle(styleData:FreeplayStyle):Void
|
|
|
|
{
|
|
|
|
glowColor = styleData.getCapsuleSelCol();
|
|
|
|
blurredText.color = glowColor;
|
|
|
|
whiteText.textField.filters = [
|
|
|
|
new openfl.filters.GlowFilter(glowColor, 1, 5, 5, 210, BitmapFilterQuality.MEDIUM),
|
|
|
|
// new openfl.filters.BlurFilter(5, 5, BitmapFilterQuality.LOW)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2024-05-30 03:34:00 +00:00
|
|
|
// ???? none
|
|
|
|
// 255, 27 normal
|
|
|
|
// 220, 27 favourited
|
|
|
|
|
|
|
|
function set_clipWidth(value:Int):Int
|
|
|
|
{
|
|
|
|
resetText();
|
2024-06-04 20:47:58 +00:00
|
|
|
checkClipWidth(value);
|
|
|
|
return clipWidth = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the text if it's too long, and clips if it is
|
|
|
|
* @param wid
|
|
|
|
*/
|
|
|
|
function checkClipWidth(?wid:Int):Void
|
|
|
|
{
|
|
|
|
if (wid == null) wid = clipWidth;
|
|
|
|
|
|
|
|
if (whiteText.width > wid)
|
2024-05-30 03:34:00 +00:00
|
|
|
{
|
|
|
|
tooLong = true;
|
|
|
|
|
2024-06-04 20:47:58 +00:00
|
|
|
blurredText.clipRect = new FlxRect(0, 0, wid, blurredText.height);
|
|
|
|
whiteText.clipRect = new FlxRect(0, 0, wid, whiteText.height);
|
2024-05-30 03:34:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tooLong = false;
|
|
|
|
|
|
|
|
blurredText.clipRect = null;
|
|
|
|
whiteText.clipRect = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-14 06:49:18 +00:00
|
|
|
function set_text(value:String):String
|
|
|
|
{
|
2023-11-29 01:52:45 +00:00
|
|
|
if (value == null) return value;
|
|
|
|
if (blurredText == null || whiteText == null)
|
|
|
|
{
|
|
|
|
trace('WARN: Capsule not initialized properly');
|
|
|
|
return text = value;
|
|
|
|
}
|
|
|
|
|
2023-08-14 06:49:18 +00:00
|
|
|
blurredText.text = value;
|
|
|
|
whiteText.text = value;
|
2024-06-04 20:47:58 +00:00
|
|
|
checkClipWidth();
|
2023-08-14 06:49:18 +00:00
|
|
|
whiteText.textField.filters = [
|
2024-08-29 23:58:19 +00:00
|
|
|
new openfl.filters.GlowFilter(glowColor, 1, 5, 5, 210, BitmapFilterQuality.MEDIUM),
|
2023-08-14 06:49:18 +00:00
|
|
|
// new openfl.filters.BlurFilter(5, 5, BitmapFilterQuality.LOW)
|
|
|
|
];
|
2024-05-30 03:34:00 +00:00
|
|
|
|
2023-11-29 01:52:45 +00:00
|
|
|
return text = value;
|
2023-08-14 06:49:18 +00:00
|
|
|
}
|
2024-05-30 03:34:00 +00:00
|
|
|
|
|
|
|
var moveTimer:FlxTimer = new FlxTimer();
|
|
|
|
var moveTween:FlxTween;
|
|
|
|
|
|
|
|
public function initMove():Void
|
|
|
|
{
|
|
|
|
moveTimer.start(0.6, (timer) -> {
|
|
|
|
moveTextRight();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function moveTextRight():Void
|
|
|
|
{
|
|
|
|
var distToMove:Float = whiteText.width - clipWidth;
|
|
|
|
moveTween = FlxTween.tween(whiteText.offset, {x: distToMove}, 2,
|
|
|
|
{
|
|
|
|
onUpdate: function(_) {
|
|
|
|
whiteText.clipRect = new FlxRect(whiteText.offset.x, 0, clipWidth, whiteText.height);
|
|
|
|
blurredText.offset = whiteText.offset;
|
|
|
|
blurredText.clipRect = new FlxRect(whiteText.offset.x, 0, clipWidth, blurredText.height);
|
|
|
|
},
|
|
|
|
onComplete: function(_) {
|
|
|
|
moveTimer.start(0.3, (timer) -> {
|
|
|
|
moveTextLeft();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
ease: FlxEase.sineInOut
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function moveTextLeft():Void
|
|
|
|
{
|
|
|
|
moveTween = FlxTween.tween(whiteText.offset, {x: 0}, 2,
|
|
|
|
{
|
|
|
|
onUpdate: function(_) {
|
|
|
|
whiteText.clipRect = new FlxRect(whiteText.offset.x, 0, clipWidth, whiteText.height);
|
|
|
|
blurredText.offset = whiteText.offset;
|
|
|
|
blurredText.clipRect = new FlxRect(whiteText.offset.x, 0, clipWidth, blurredText.height);
|
|
|
|
},
|
|
|
|
onComplete: function(_) {
|
|
|
|
moveTimer.start(0.3, (timer) -> {
|
|
|
|
moveTextRight();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
ease: FlxEase.sineInOut
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function resetText():Void
|
|
|
|
{
|
|
|
|
if (moveTween != null) moveTween.cancel();
|
|
|
|
if (moveTimer != null) moveTimer.cancel();
|
|
|
|
whiteText.offset.x = 0;
|
|
|
|
whiteText.clipRect = new FlxRect(whiteText.offset.x, 0, clipWidth, whiteText.height);
|
|
|
|
blurredText.clipRect = new FlxRect(whiteText.offset.x, 0, clipWidth, whiteText.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
var flickerState:Bool = false;
|
|
|
|
var flickerTimer:FlxTimer;
|
|
|
|
|
|
|
|
public function flickerText():Void
|
|
|
|
{
|
|
|
|
resetText();
|
|
|
|
flickerTimer = new FlxTimer().start(1 / 24, flickerProgress, 19);
|
|
|
|
}
|
|
|
|
|
|
|
|
function flickerProgress(timer:FlxTimer):Void
|
|
|
|
{
|
|
|
|
if (flickerState == true)
|
|
|
|
{
|
|
|
|
whiteText.blend = BlendMode.ADD;
|
|
|
|
blurredText.blend = BlendMode.ADD;
|
|
|
|
blurredText.color = 0xFFFFFFFF;
|
|
|
|
whiteText.color = 0xFFFFFFFF;
|
|
|
|
whiteText.textField.filters = [
|
|
|
|
new openfl.filters.GlowFilter(0xFFFFFF, 1, 5, 5, 210, BitmapFilterQuality.MEDIUM),
|
|
|
|
// new openfl.filters.BlurFilter(5, 5, BitmapFilterQuality.LOW)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-08-29 23:58:19 +00:00
|
|
|
blurredText.color = glowColor;
|
2024-05-30 03:34:00 +00:00
|
|
|
whiteText.color = 0xFFDDDDDD;
|
|
|
|
whiteText.textField.filters = [
|
|
|
|
new openfl.filters.GlowFilter(0xDDDDDD, 1, 5, 5, 210, BitmapFilterQuality.MEDIUM),
|
|
|
|
// new openfl.filters.BlurFilter(5, 5, BitmapFilterQuality.LOW)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
flickerState = !flickerState;
|
|
|
|
}
|
|
|
|
|
|
|
|
override function update(elapsed:Float):Void
|
|
|
|
{
|
|
|
|
super.update(elapsed);
|
|
|
|
}
|
2023-08-14 06:49:18 +00:00
|
|
|
}
|