Funkin/source/funkin/play/components/PopUpStuff.hx

222 lines
6.2 KiB
Haxe
Raw Normal View History

package funkin.play.components;
import flixel.FlxSprite;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.tweens.FlxTween;
import flixel.util.FlxDirection;
import funkin.graphics.FunkinSprite;
import funkin.play.PlayState;
2024-03-13 21:47:15 -04:00
import funkin.util.TimerUtil;
2024-06-19 23:47:11 -04:00
import funkin.util.EaseUtil;
2024-07-13 15:45:58 -04:00
import openfl.utils.Assets;
2024-07-16 13:53:12 -04:00
import funkin.data.notestyle.NoteStyleRegistry;
import funkin.play.notes.notestyle.NoteStyle;
2024-06-19 23:47:11 -04:00
class PopUpStuff extends FlxTypedGroup<FunkinSprite>
{
public var offsets:Array<Int> = [0, 0];
2024-07-13 15:45:58 -04:00
/**
* Which alternate graphic on popup to use.
2024-07-16 13:53:12 -04:00
* This is set via the current notestyle.
* For example, in Week 6 it is `pixel`.
2024-07-13 15:45:58 -04:00
*/
2024-07-16 13:53:12 -04:00
static var noteStyle:NoteStyle;
static var isPixel:Bool = false;
2024-07-13 15:45:58 -04:00
override public function new()
{
super();
2024-07-16 13:53:12 -04:00
var fetchedNoteStyle:NoteStyle = NoteStyleRegistry.instance.fetchEntry(PlayState.instance.currentChart.noteStyle);
if (fetchedNoteStyle == null) noteStyle = NoteStyleRegistry.instance.fetchDefault();
else
noteStyle = fetchedNoteStyle;
if (noteStyle._data.assets.note.isPixel) isPixel = true;
}
2024-07-16 13:53:12 -04:00
static function resolveGraphicPath(noteStyle:NoteStyle, index:String):Null<String>
2024-07-13 15:45:58 -04:00
{
2024-07-16 13:53:12 -04:00
var basePath:String = 'ui/popup/';
var spritePath:String = basePath + noteStyle.id + '/$index';
// If nothing is found, revert it to default notestyle skin
if (!Assets.exists(Paths.image(spritePath)))
2024-07-13 15:45:58 -04:00
{
2024-07-16 13:53:12 -04:00
if (!isPixel) spritePath = basePath + Constants.DEFAULT_NOTE_STYLE + '/$index';
else
spritePath = basePath + Constants.DEFAULT_PIXEL_NOTE_STYLE + '/$index';
2024-07-13 15:45:58 -04:00
}
2024-07-16 13:53:12 -04:00
2024-07-13 15:45:58 -04:00
return spritePath;
}
public function displayRating(daRating:String)
{
2024-03-13 21:47:15 -04:00
var perfStart:Float = TimerUtil.start();
if (daRating == null) daRating = "good";
2024-07-16 13:53:12 -04:00
var ratingPath:String = resolveGraphicPath(noteStyle, daRating);
2024-07-13 15:45:58 -04:00
// if (PlayState.instance.currentStageId.startsWith('school')) ratingPath = "weeb/pixelUI/" + ratingPath + "-pixel";
var rating:FunkinSprite = FunkinSprite.create(0, 0, ratingPath);
rating.scrollFactor.set(0.2, 0.2);
rating.zIndex = 1000;
rating.x = (FlxG.width * 0.474) + offsets[0];
// rating.x -= FlxG.camera.scroll.x * 0.2;
rating.y = (FlxG.camera.height * 0.45 - 60) + offsets[1];
rating.acceleration.y = 550;
rating.velocity.y -= FlxG.random.int(140, 175);
rating.velocity.x -= FlxG.random.int(0, 10);
add(rating);
2024-06-19 23:47:11 -04:00
var fadeEase = null;
2024-07-16 13:53:12 -04:00
if (isPixel)
{
2024-04-28 21:21:44 -04:00
rating.setGraphicSize(Std.int(rating.width * Constants.PIXEL_ART_SCALE * 0.7));
rating.antialiasing = false;
2024-06-19 23:47:11 -04:00
rating.pixelPerfectRender = true;
rating.pixelPerfectPosition = true;
fadeEase = EaseUtil.stepped(2);
}
else
{
rating.setGraphicSize(Std.int(rating.width * 0.65));
rating.antialiasing = true;
}
rating.updateHitbox();
rating.x -= rating.width / 2;
rating.y -= rating.height / 2;
FlxTween.tween(rating, {alpha: 0}, 0.2,
{
2023-06-08 16:30:45 -04:00
onComplete: function(tween:FlxTween) {
remove(rating, true);
rating.destroy();
},
2024-06-19 23:47:11 -04:00
startDelay: Conductor.instance.beatLengthMs * 0.001,
ease: fadeEase
});
2024-03-13 21:47:15 -04:00
trace('displayRating took: ${TimerUtil.seconds(perfStart)}');
}
public function displayCombo(?combo:Int = 0):Int
{
2024-03-13 21:47:15 -04:00
var perfStart:Float = TimerUtil.start();
if (combo == null) combo = 0;
2024-07-16 13:53:12 -04:00
var comboPath:String = resolveGraphicPath(noteStyle, 'combo');
2024-07-13 15:45:58 -04:00
var comboSpr:FunkinSprite = FunkinSprite.create(comboPath);
comboSpr.y = (FlxG.camera.height * 0.44) + offsets[1];
comboSpr.x = (FlxG.width * 0.507) + offsets[0];
// comboSpr.x -= FlxG.camera.scroll.x * 0.2;
comboSpr.acceleration.y = 600;
comboSpr.velocity.y -= 150;
comboSpr.velocity.x += FlxG.random.int(1, 10);
// add(comboSpr);
2024-06-19 23:47:11 -04:00
var fadeEase = null;
2024-07-13 15:45:58 -04:00
if (graphicSuffix.toLowerCase().contains('pixel'))
{
2024-06-19 23:47:11 -04:00
comboSpr.setGraphicSize(Std.int(comboSpr.width * Constants.PIXEL_ART_SCALE * 1));
comboSpr.antialiasing = false;
2024-06-19 23:47:11 -04:00
comboSpr.pixelPerfectRender = true;
comboSpr.pixelPerfectPosition = true;
fadeEase = EaseUtil.stepped(2);
}
else
{
comboSpr.setGraphicSize(Std.int(comboSpr.width * 0.7));
comboSpr.antialiasing = true;
}
comboSpr.updateHitbox();
FlxTween.tween(comboSpr, {alpha: 0}, 0.2,
{
2023-06-08 16:30:45 -04:00
onComplete: function(tween:FlxTween) {
remove(comboSpr, true);
comboSpr.destroy();
},
2024-06-19 23:47:11 -04:00
startDelay: Conductor.instance.beatLengthMs * 0.001,
ease: fadeEase
});
var seperatedScore:Array<Int> = [];
var tempCombo:Int = combo;
while (tempCombo != 0)
{
seperatedScore.push(tempCombo % 10);
tempCombo = Std.int(tempCombo / 10);
}
while (seperatedScore.length < 3)
seperatedScore.push(0);
// seperatedScore.reverse();
var daLoop:Int = 1;
for (i in seperatedScore)
{
2024-07-16 13:53:12 -04:00
var numScore:FunkinSprite = FunkinSprite.create(0, comboSpr.y, resolveGraphicPath(noteStyle, 'num' + Std.int(i)));
2024-07-13 15:45:58 -04:00
if (graphicSuffix.toLowerCase().contains('pixel'))
{
2024-06-19 23:47:11 -04:00
numScore.setGraphicSize(Std.int(numScore.width * Constants.PIXEL_ART_SCALE * 1));
numScore.antialiasing = false;
2024-06-19 23:47:11 -04:00
numScore.pixelPerfectRender = true;
numScore.pixelPerfectPosition = true;
}
else
{
numScore.setGraphicSize(Std.int(numScore.width * 0.45));
numScore.antialiasing = true;
}
numScore.updateHitbox();
numScore.x = comboSpr.x - (36 * daLoop) - 65; //- 90;
numScore.acceleration.y = FlxG.random.int(250, 300);
numScore.velocity.y -= FlxG.random.int(130, 150);
numScore.velocity.x = FlxG.random.float(-5, 5);
add(numScore);
FlxTween.tween(numScore, {alpha: 0}, 0.2,
{
2023-06-08 16:30:45 -04:00
onComplete: function(tween:FlxTween) {
remove(numScore, true);
numScore.destroy();
},
2024-06-19 23:47:11 -04:00
startDelay: Conductor.instance.beatLengthMs * 0.002,
ease: fadeEase
});
daLoop++;
}
2024-03-13 21:47:15 -04:00
trace('displayCombo took: ${TimerUtil.seconds(perfStart)}');
return combo;
}
2024-07-13 15:45:58 -04:00
/**
* Reset the popup configuration to the default.
*/
public static function reset()
{
2024-07-16 13:53:12 -04:00
noteStyle = NoteStyleRegistry.instance.fetchDefault();
isPixel = false;
2024-07-13 15:45:58 -04:00
}
}