Ratings event addition to the engine (#1015)

* Update PlayState.hx

Implemented RatingsShowEvent

* Add files via upload

* Update pixel.hx

Update because of ratings commits

* Update PlayState.hx

put the flxpoints after they're used, forgot to use event.tweenDuration in displayRatingNumbers

* Update PlayState.hx

oops

* Update PlayState.hx

I'm so not careful

* Update PlayState.hx

Commited NoteHitEvent checks for all display rating functions

* Update PlayState.hx

oops 2

* Update NoteHitEvent.hx

made the rating vars null class

* Update PlayState.hx

juust in case

* Update PlayState.hx

oops 3

* Update RatingsShowEvent.hx

Implemented a rating var which allows you to change the rating sprite.

* Update PlayState.hx

Implemented a rating var (In RatingsShowEvent) which allows you to change the rating sprite.

* Update PlayState.hx

now it should support displayRating/Combo being set from note hit event

* Update PlayState.hx

fixed a possibility where if the display bool was set to false or the event was cancelled, then it would still display the sprite as a haxeflixel logo
This commit is contained in:
pharaotisReal
2026-06-28 09:31:59 +07:00
committed by GitHub
parent cb4ecc521f
commit a485080c27
4 changed files with 206 additions and 66 deletions
+1 -1
View File
@@ -75,7 +75,7 @@ function onCountdown(event) {
};
}
function onPlayerHit(event:NoteHitEvent) {
function onRatingsShown(event:RatingsShowEvent) {
if (!enablePixelUI) return;
event.ratingPrefix = "stages/school/ui/";
event.ratingScale = daPixelZoom * 0.7;
@@ -0,0 +1,91 @@
package funkin.backend.scripting.events.gameplay;
import flixel.math.FlxPoint;
final class RatingsShowEvent extends CancellableEvent
{
/**
* Rating sprite (may be null)
*/
public var ratingSprite:Null<FlxSprite>;
/**
* Number sprite (may be null)
*/
public var numberSprite:Null<FlxSprite>;
/**
* Combo sprite (may be null)
*/
public var comboSprite:Null<FlxSprite>;
/**
* Scale of combo numbers. (may be null)
*/
public var numScale:Null<Float> = 0.5;
/**
* Whenever antialiasing should be enabled on combo numbers. (may be null)
*/
public var numAntialiasing:Null<Bool> = true;
/**
* Scale of the rating sprites. (may be null)
*/
public var ratingScale:Null<Float> = 0.7;
/**
* Whenever antialiasing should be enabled on ratings. (may be null)
*/
public var ratingAntialiasing:Null<Bool> = true;
/**
* Prefix of the rating sprite path. Defaults to "game/score/"
*/
public var ratingPrefix:String;
/**
* Suffix of the rating sprite path.
*/
public var ratingSuffix:String;
/**
* The sprite's acceleration.
*/
public var acceleration:Float;
/**
* A FlxPoint which x or y properties preposition the sprites current velocity.
*/
public var velocity:FlxPoint;
/**
* The duration of the sprite's alpha tween.
*/
public var tweenDuration:Float;
/**
* The start delay of the sprite's alpha tween.
*/
public var startDelay:Float;
/**
* Whenever the Rating sprites should be shown or not.
*/
public var displayRating:Bool;
/**
* Whenever the Rating sprites should be shown or not.
*/
public var displayNumbers:Bool;
/**
* Whenever the Combo sprite should be shown or not (like old Week 7 patches).
*/
public var displayCombo:Bool;
/**
* Whether the sprite should be tweened or not.
*/
public var tween:Bool;
/**
* The amount of spacing for the combo numbers. (may be null)
*/
public var numSpacing:Null<Float>;
/**
* The position of the sprite.
*/
public var position:FlxPoint;
/**
* Whether to reset the sprite or not.
*/
public var resetSprite:Bool;
/**
* The rating name of the rating sprite. (may be null)
*/
public var rating:Null<String>;
}
@@ -34,11 +34,11 @@ final class NoteHitEvent extends CancellableEvent {
/**
* Whenever the Rating sprites should be shown or not.
*/
public var displayRating:Bool;
public var displayRating:Null<Bool>;
/**
* Whenever the Combo sprite should be shown or not (like old Week 7 patches).
*/
public var displayCombo:Bool;
public var displayCombo:Null<Bool>;
/**
* Note that has been pressed
*/
@@ -66,11 +66,11 @@ final class NoteHitEvent extends CancellableEvent {
/**
* Prefix of the rating sprite path. Defaults to "game/score/"
*/
public var ratingPrefix:String;
public var ratingPrefix:Null<String>;
/**
* Suffix of the rating sprite path.
*/
public var ratingSuffix:String;
public var ratingSuffix:Null<String>;
/**
* Direction of the press (0 = Left, 1 = Down, 2 = Up, 3 = Right)
*/
@@ -98,19 +98,19 @@ final class NoteHitEvent extends CancellableEvent {
/**
* Scale of combo numbers.
*/
public var numScale:Float = 0.5;
public var numScale:Null<Float>;
/**
* Whenever antialiasing should be enabled on combo number.
*/
public var numAntialiasing:Bool = true;
public var numAntialiasing:Null<Bool>;
/**
* Scale of ratings.
*/
public var ratingScale:Float = 0.7;
public var ratingScale:Null<Float>;
/**
* Whenever antialiasing should be enabled on ratings.
*/
public var ratingAntialiasing:Bool = true;
public var ratingAntialiasing:Null<Bool>;
/**
* Whenever the animation should be forced to play (if it's null it will be forced based on the sprite's data xml, if it has one).
*/
+106 -57
View File
@@ -1966,9 +1966,9 @@ class PlayState extends MusicBeatState
var event:NoteHitEvent;
if (strumLine != null && !strumLine.cpu)
event = EventManager.get(NoteHitEvent).recycle(rating.breaksCombo, !note.isSustainNote, !note.isSustainNote, null, defaultDisplayRating, defaultDisplayCombo, note, strumLine.characters, true, note.noteType, note.animSuffix.getDefault(note.strumID < strumLine.members.length ? strumLine.members[note.strumID].animSuffix : strumLine.animSuffix), "game/score/", "", note.strumID, rating.score, note.isSustainNote ? null : rating.accuracy, rating.health, rating.name, Options.splashesEnabled && !note.isSustainNote && rating.splash, 0.5, true, 0.7, true, true, iconP1);
event = EventManager.get(NoteHitEvent).recycle(rating.breaksCombo, !note.isSustainNote, !note.isSustainNote, null, null, null, note, strumLine.characters, true, note.noteType, note.animSuffix.getDefault(note.strumID < strumLine.members.length ? strumLine.members[note.strumID].animSuffix : strumLine.animSuffix), null, null, note.strumID, rating.score, note.isSustainNote ? null : rating.accuracy, rating.health, rating.name, Options.splashesEnabled && !note.isSustainNote && rating.splash, null, null, null, null, null, iconP1);
else
event = EventManager.get(NoteHitEvent).recycle(rating.breaksCombo, false, false, null, defaultDisplayRating, defaultDisplayCombo, note, strumLine.characters, false, note.noteType, note.animSuffix.getDefault(note.strumID < strumLine.members.length ? strumLine.members[note.strumID].animSuffix : strumLine.animSuffix), "game/score/", "", note.strumID, 0, null, 0, rating.name, false, 0.5, true, 0.7, true, true, iconP2);
event = EventManager.get(NoteHitEvent).recycle(rating.breaksCombo, false, false, null, null, null, note, strumLine.characters, false, note.noteType, note.animSuffix.getDefault(note.strumID < strumLine.members.length ? strumLine.members[note.strumID].animSuffix : strumLine.animSuffix), null, null, note.strumID, 0, null, 0, rating.name, false, null, null, null, null, true, iconP2);
event.deleteNote = !note.isSustainNote; // work around, to allow sustain notes to be deleted
event = scripts.event(strumLine != null && !strumLine.cpu ? "onPlayerHit" : "onDadHit", event);
strumLine.onHit.dispatch(event);
@@ -1993,8 +1993,8 @@ class PlayState extends MusicBeatState
if (event.showRating || (event.showRating == null && event.player))
{
displayCombo(event);
if (event.displayRating)
displayRating(event.rating, event);
displayRatingNumbers(event);
displayRating(event.rating, event);
ratingNum += 1;
}
if (event.player) hits[rating.name] += 1;
@@ -2031,81 +2031,130 @@ class PlayState extends MusicBeatState
gameAndCharsEvent("onPostNoteHit", event);
}
public function displayRating(myRating:String, ?evt:NoteHitEvent = null):Void {
var hasEvent = evt != null;
var pre:String = hasEvent ? evt.ratingPrefix : "";
var suf:String = hasEvent ? evt.ratingSuffix : "";
public function displayRating(myRating:String, ?evt:NoteHitEvent):Void
{
var event:RatingsShowEvent = EventManager.get(RatingsShowEvent).recycle(comboGroup.recycleLoop(FlxSprite), null, null, null, null, 0.7, true, "game/score/", "", 550, FlxPoint.get(FlxG.random.int(0, 10), FlxG.random.int(140, 175)), 0.2, (Conductor.crochet * 0.001), true, false, false, true, null, FlxPoint.get(comboGroup.x + -40, comboGroup.y + -60), true, myRating);
gameAndCharsEvent("onRatingsShown", event);
var rating:FlxSprite = comboGroup.recycleLoop(FlxSprite);
CoolUtil.resetSprite(rating, comboGroup.x + -40, comboGroup.y + -60);
rating.loadAnimatedGraphic(Paths.image('${pre}${myRating}${suf}'));
rating.acceleration.y = 550;
rating.velocity.y -= FlxG.random.int(140, 175);
rating.velocity.x -= FlxG.random.int(0, 10);
if (hasEvent) {
rating.scale.set(evt.ratingScale, evt.ratingScale);
rating.antialiasing = evt.ratingAntialiasing;
if (event.cancelled || !event.displayRating) return event.ratingSprite.kill(); // TODO: Find a better way for this?
var hasEvent:Bool = evt != null;
var pre:String = hasEvent && evt.ratingPrefix != null ? evt.ratingPrefix : event.ratingPrefix;
var suf:String = hasEvent && evt.ratingSuffix != null ? evt.ratingSuffix : event.ratingSuffix;
var ratingScale:Float = hasEvent && evt.ratingScale != null ? evt.ratingScale : event.ratingScale;
var rating:FlxSprite = event.ratingSprite.loadAnimatedGraphic(Paths.image('${pre}${event.rating}${suf}'));
if (event.resetSprite) {
CoolUtil.resetSprite(rating, event.position.x, event.position.y);
}
rating.acceleration.y = event.acceleration;
rating.velocity.y -= event.velocity.y;
rating.velocity.x -= event.velocity.x;
rating.scale.set(ratingScale, ratingScale);
rating.antialiasing = hasEvent && evt.ratingAntialiasing != null ? evt.ratingAntialiasing : event.ratingAntialiasing;
rating.updateHitbox();
FlxTween.tween(rating, {alpha: 0}, 0.2, {
startDelay: Conductor.crochet * 0.001,
onComplete: function(tween:FlxTween) {
rating.kill();
}
});
if (event.tween) {
FlxTween.tween(rating, {alpha: 0}, event.tweenDuration, {
startDelay: event.startDelay,
onComplete: function(tween:FlxTween) {
rating.kill();
}
});
}
gameAndCharsEvent("onPostRatingsShown", event);
event.velocity.put();
event.position.put();
}
public function displayCombo(?evt:NoteHitEvent = null):Void {
public function displayCombo(?evt:NoteHitEvent):Void {
if (minDigitDisplay >= 0 && (combo == 0 || combo >= minDigitDisplay)) {
var hasEvent = evt != null;
var pre:String = hasEvent ? evt.ratingPrefix : "";
var suf:String = hasEvent ? evt.ratingSuffix : "";
var event:RatingsShowEvent = EventManager.get(RatingsShowEvent).recycle(null, null, comboGroup.recycleLoop(FlxSprite), null, null, 0.7, true, "game/score/", "", 600, FlxPoint.get(FlxG.random.int(0, 10), 150), 0.2, (Conductor.crochet * 0.001), false, false, evt != null && evt.displayCombo != null ? evt.displayCombo : defaultDisplayCombo, true, null, FlxPoint.get(comboGroup.x, comboGroup.y), true, null);
gameAndCharsEvent("onRatingsShown", event);
if (evt.displayCombo) {
var comboSpr:FlxSprite = comboGroup.recycleLoop(FlxSprite).loadAnimatedGraphic(Paths.image('${pre}combo${suf}'));
CoolUtil.resetSprite(comboSpr, comboGroup.x, comboGroup.y);
comboSpr.acceleration.y = 600;
comboSpr.velocity.y -= 150;
comboSpr.velocity.x += FlxG.random.int(1, 10);
if (event.cancelled || !event.displayCombo) return event.comboSprite.kill(); // TODO: Find a better way for this?
if (hasEvent) {
comboSpr.scale.set(evt.ratingScale, evt.ratingScale);
comboSpr.antialiasing = evt.ratingAntialiasing;
}
comboSpr.updateHitbox();
var hasEvent:Bool = evt != null;
FlxTween.tween(comboSpr, {alpha: 0}, 0.2, {
onComplete: function(tween:FlxTween)
{
var pre:String = hasEvent && evt.ratingPrefix != null ? evt.ratingPrefix : event.ratingPrefix;
var suf:String = hasEvent && evt.ratingSuffix != null ? evt.ratingSuffix : event.ratingSuffix;
var ratingScale:Float = hasEvent && evt.ratingScale != null ? evt.ratingScale : event.ratingScale;
var comboSpr:FlxSprite = event.comboSprite.loadAnimatedGraphic(Paths.image('${pre}combo${suf}'));
if (event.resetSprite) {
CoolUtil.resetSprite(comboSpr, event.position.x, event.position.y);
}
comboSpr.acceleration.y = event.acceleration;
comboSpr.velocity.y -= event.velocity.y;
comboSpr.velocity.x += event.velocity.x;
comboSpr.scale.set(ratingScale, ratingScale);
comboSpr.antialiasing = hasEvent && evt.ratingAntialiasing != null ? evt.ratingAntialiasing : event.ratingAntialiasing;
comboSpr.updateHitbox();
if (event.tween) {
FlxTween.tween(comboSpr, {alpha: 0}, event.tweenDuration, {
onComplete: function(tween:FlxTween) {
comboSpr.kill();
},
startDelay: Conductor.crochet * 0.001
startDelay: event.startDelay
});
}
gameAndCharsEvent("onPostRatingsShown", event);
event.velocity.put();
event.position.put();
}
}
public function displayRatingNumbers(?evt:NoteHitEvent):Void {
if (minDigitDisplay >= 0 && (combo == 0 || combo >= minDigitDisplay)) {
var separatedScore:String = Std.string(combo).addZeros(3);
for (i in 0...separatedScore.length)
{
var numScore:FlxSprite = comboGroup.recycleLoop(FlxSprite).loadAnimatedGraphic(Paths.image('${pre}num${separatedScore.charAt(i)}${suf}'));
CoolUtil.resetSprite(numScore, comboGroup.x + (43 * i) - 90, comboGroup.y + 80);
if (hasEvent) {
numScore.antialiasing = evt.numAntialiasing;
numScore.scale.set(evt.numScale, evt.numScale);
var event:RatingsShowEvent = EventManager.get(RatingsShowEvent).recycle(null, comboGroup.recycleLoop(FlxSprite), null, 0.5, true, null, null, "game/score/", "", FlxG.random.int(200, 300), FlxPoint.get(FlxG.random.float(-5, 5), FlxG.random.int(140, 160)), 0.2, (Conductor.crochet * 0.002), false, true, false, true, 43, FlxPoint.get(), true, null);
gameAndCharsEvent("onRatingsShown", event);
if (event.cancelled || !event.displayNumbers) { // TODO: Find a better way for this?
event.numberSprite.kill();
continue;
}
var hasEvent:Bool = evt != null;
var pre:String = hasEvent && evt.ratingPrefix != null ? evt.ratingPrefix : event.ratingPrefix;
var suf:String = hasEvent && evt.ratingSuffix != null ? evt.ratingSuffix : event.ratingSuffix;
var numScale:Float = hasEvent && evt.numScale != null ? evt.numScale : event.numScale;
var numScore:FlxSprite = event.numberSprite.loadAnimatedGraphic(Paths.image('${pre}num${separatedScore.charAt(i)}${suf}'));
event.position.set(comboGroup.x + (event.numSpacing * i) - 90, comboGroup.y + 80); // TODO: Maybe find a better way to do this?
if (event.resetSprite) {
CoolUtil.resetSprite(numScore, event.position.x, event.position.y);
}
numScore.antialiasing = hasEvent && evt.numAntialiasing != null ? evt.numAntialiasing : event.numAntialiasing;
numScore.scale.set(numScale, numScale);
numScore.updateHitbox();
numScore.acceleration.y = FlxG.random.int(200, 300);
numScore.velocity.y -= FlxG.random.int(140, 160);
numScore.velocity.x = FlxG.random.float(-5, 5);
numScore.acceleration.y = event.acceleration;
numScore.velocity.y -= event.velocity.y;
numScore.velocity.x = event.velocity.x;
FlxTween.tween(numScore, {alpha: 0}, 0.2, {
onComplete: function(tween:FlxTween)
{
numScore.kill();
},
startDelay: Conductor.crochet * 0.002
});
if (event.tween) {
FlxTween.tween(numScore, {alpha: 0}, event.tweenDuration, {
onComplete: function(tween:FlxTween) {
numScore.kill();
},
startDelay: event.startDelay
});
}
gameAndCharsEvent("onPostRatingsShown", event);
event.velocity.put();
event.position.put();
}
}
}