1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-15 11:22:55 +00:00

custom popups and countdowns yay!!!

This commit is contained in:
anysad 2024-07-13 22:45:58 +03:00
parent 9b483de1da
commit 2993e17278
4 changed files with 124 additions and 96 deletions

2
assets

@ -1 +1 @@
Subproject commit 2e1594ee4c04c7148628bae471bdd061c9deb6b7
Subproject commit 514a987ee57827b097ed035a1c2fdd1377a53b17

View file

@ -10,6 +10,7 @@ import funkin.modding.events.ScriptEvent;
import funkin.modding.events.ScriptEvent.CountdownScriptEvent;
import flixel.util.FlxTimer;
import funkin.audio.FunkinSound;
import openfl.utils.Assets;
class Countdown
{
@ -18,6 +19,22 @@ class Countdown
*/
public static var countdownStep(default, null):CountdownStep = BEFORE;
/**
* Which alternate countdown sound effect to use.
* You can set this via script.
* For example, in Week 6 it is `-pixel`.
*/
public static var soundSuffix:String = '';
/**
* Which alternate graphic on countdown to use.
* You can set this via script.
* For example, in Week 6 it is `-pixel`.
*/
public static var graphicSuffix:String = '';
/**
* The currently running countdown. This will be null if there is no countdown running.
*/
@ -29,7 +46,7 @@ class Countdown
* This will automatically stop and restart the countdown if it is already running.
* @returns `false` if the countdown was cancelled by a script.
*/
public static function performCountdown(isPixelStyle:Bool):Bool
public static function performCountdown():Bool
{
countdownStep = BEFORE;
var cancelled:Bool = propagateCountdownEvent(countdownStep);
@ -64,10 +81,10 @@ class Countdown
// PlayState.instance.dispatchEvent(new SongTimeScriptEvent(SONG_BEAT_HIT, 0, 0));
// Countdown graphic.
showCountdownGraphic(countdownStep, isPixelStyle);
showCountdownGraphic(countdownStep, graphicSuffix.toLowerCase().contains('pixel'));
// Countdown sound.
playCountdownSound(countdownStep, isPixelStyle);
playCountdownSound(countdownStep);
// Event handling bullshit.
var cancelled:Bool = propagateCountdownEvent(countdownStep);
@ -176,52 +193,30 @@ class Countdown
}
/**
* Retrieves the graphic to use for this step of the countdown.
* TODO: Make this less dumb. Unhardcode it? Use modules? Use notestyles?
*
* This is public so modules can do lol funny shit.
* Reset the countdown configuration to the default.
*/
public static function showCountdownGraphic(index:CountdownStep, isPixelStyle:Bool):Void
public static function reset()
{
soundSuffix = '';
graphicSuffix = '';
}
/**
* Retrieves the graphic to use for this step of the countdown.
*/
public static function showCountdownGraphic(index:CountdownStep, isGraphicPixel:Bool):Void
{
var spritePath:String = null;
if (isPixelStyle)
{
switch (index)
{
case TWO:
spritePath = 'weeb/pixelUI/ready-pixel';
case ONE:
spritePath = 'weeb/pixelUI/set-pixel';
case GO:
spritePath = 'weeb/pixelUI/date-pixel';
default:
// null
}
}
else
{
switch (index)
{
case TWO:
spritePath = 'ready';
case ONE:
spritePath = 'set';
case GO:
spritePath = 'go';
default:
// null
}
}
spritePath = resolveGraphicPath(graphicSuffix, index);
if (spritePath == null) return;
var countdownSprite:FunkinSprite = FunkinSprite.create(spritePath);
countdownSprite.scrollFactor.set(0, 0);
if (isPixelStyle) countdownSprite.setGraphicSize(Std.int(countdownSprite.width * Constants.PIXEL_ART_SCALE));
if (isGraphicPixel) countdownSprite.setGraphicSize(Std.int(countdownSprite.width * Constants.PIXEL_ART_SCALE));
countdownSprite.antialiasing = !isPixelStyle;
countdownSprite.antialiasing = !isGraphicPixel;
countdownSprite.updateHitbox();
countdownSprite.screenCenter();
@ -238,52 +233,55 @@ class Countdown
PlayState.instance.add(countdownSprite);
}
static function resolveGraphicPath(suffix:String, index:CountdownStep):Null<String>
{
var basePath:String = 'ui/countdown/';
var indexString:String = null;
switch (index)
{
case TWO:
indexString = 'ready';
case ONE:
indexString = 'set';
case GO:
indexString = 'go';
default:
// null
}
basePath += indexString;
var spritePath:String = basePath + suffix;
while (!Assets.exists(Paths.image(spritePath)) && suffix.length > 0)
{
suffix = suffix.split('-').slice(0, -1).join('-');
spritePath = basePath + suffix;
}
if (!Assets.exists(Paths.image(spritePath))) return null;
trace('Resolved sprite path: ' + Paths.image(spritePath));
return spritePath;
}
/**
* Retrieves the sound file to use for this step of the countdown.
* TODO: Make this less dumb. Unhardcode it? Use modules? Use notestyles?
*
* This is public so modules can do lol funny shit.
*/
public static function playCountdownSound(index:CountdownStep, isPixelStyle:Bool):Void
public static function playCountdownSound(index:CountdownStep):Void
{
var soundPath:String = null;
FunkinSound.playOnce(resolveSoundPath(soundSuffix, index), Constants.COUNTDOWN_VOLUME);
}
if (isPixelStyle)
static function resolveSoundPath(suffix:String, step:CountdownStep):Null<String>
{
var basePath:String = 'gameplay/countdown/intro';
if (step != CountdownStep.BEFORE || step != CountdownStep.AFTER) basePath += step;
var soundPath:String = Paths.sound(basePath + suffix);
while (!Assets.exists(soundPath) && suffix.length > 0)
{
switch (index)
{
case THREE:
soundPath = 'intro3-pixel';
case TWO:
soundPath = 'intro2-pixel';
case ONE:
soundPath = 'intro1-pixel';
case GO:
soundPath = 'introGo-pixel';
default:
// null
}
suffix = suffix.split('-').slice(0, -1).join('-');
soundPath = Paths.sound(basePath + suffix);
}
else
{
switch (index)
{
case THREE:
soundPath = 'intro3';
case TWO:
soundPath = 'intro2';
case ONE:
soundPath = 'intro1';
case GO:
soundPath = 'introGo';
default:
// null
}
}
if (soundPath == null) return;
FunkinSound.playOnce(Paths.sound(soundPath), Constants.COUNTDOWN_VOLUME);
if (!Assets.exists(soundPath)) return null;
trace('Resolved sound path: ' + soundPath);
return soundPath;
}
public static function decrement(step:CountdownStep):CountdownStep

View file

@ -899,7 +899,7 @@ class PlayState extends MusicBeatSubState
health = Constants.HEALTH_STARTING;
songScore = 0;
Highscore.tallies.combo = 0;
Countdown.performCountdown(currentStageId.startsWith('school'));
Countdown.performCountdown();
needsReset = false;
}
@ -1920,7 +1920,7 @@ class PlayState extends MusicBeatSubState
public function startCountdown():Void
{
// If Countdown.performCountdown returns false, then the countdown was canceled by a script.
var result:Bool = Countdown.performCountdown(currentStageId.startsWith('school'));
var result:Bool = Countdown.performCountdown();
if (!result) return;
isInCutscene = false;
@ -3061,6 +3061,8 @@ class PlayState extends MusicBeatSubState
GameOverSubState.reset();
PauseSubState.reset();
Countdown.reset();
PopUpStuff.reset();
// Clear the static reference to this state.
instance = null;

View file

@ -7,25 +7,52 @@ import flixel.util.FlxDirection;
import funkin.graphics.FunkinSprite;
import funkin.play.PlayState;
import funkin.util.TimerUtil;
import openfl.utils.Assets;
class PopUpStuff extends FlxTypedGroup<FlxSprite>
{
public var offsets:Array<Int> = [0, 0];
/**
* Which alternate graphic on popup to use.
* You can set this via script.
* For example, in Week 6 it is `-pixel`.
*/
public static var graphicSuffix:String = '';
override public function new()
{
super();
}
static function resolveGraphicPath(suffix:String, index:String):Null<String>
{
var folder:String;
if (suffix != '')
folder = suffix.substring(0, suffix.indexOf("-")) + suffix.substring(suffix.indexOf("-") + 1);
else
folder = 'normal';
var basePath:String = 'gameplay/popup/$folder/$index';
var spritePath:String = basePath + suffix;
trace(spritePath);
while (!Assets.exists(Paths.image(spritePath)) && suffix.length > 0)
{
suffix = suffix.split('-').slice(0, -1).join('-');
spritePath = basePath + suffix;
}
if (!Assets.exists(Paths.image(spritePath))) return null;
return spritePath;
}
public function displayRating(daRating:String)
{
var perfStart:Float = TimerUtil.start();
if (daRating == null) daRating = "good";
var ratingPath:String = daRating;
var ratingPath:String = resolveGraphicPath(graphicSuffix, daRating);
if (PlayState.instance.currentStageId.startsWith('school')) ratingPath = "weeb/pixelUI/" + ratingPath + "-pixel";
//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);
@ -40,7 +67,7 @@ class PopUpStuff extends FlxTypedGroup<FlxSprite>
add(rating);
if (PlayState.instance.currentStageId.startsWith('school'))
if (graphicSuffix.toLowerCase().contains('pixel'))
{
rating.setGraphicSize(Std.int(rating.width * Constants.PIXEL_ART_SCALE * 0.7));
rating.antialiasing = false;
@ -73,15 +100,8 @@ class PopUpStuff extends FlxTypedGroup<FlxSprite>
if (combo == null) combo = 0;
var pixelShitPart1:String = "";
var pixelShitPart2:String = '';
if (PlayState.instance.currentStageId.startsWith('school'))
{
pixelShitPart1 = 'weeb/pixelUI/';
pixelShitPart2 = '-pixel';
}
var comboSpr:FunkinSprite = FunkinSprite.create(pixelShitPart1 + 'combo' + pixelShitPart2);
var comboPath:String = resolveGraphicPath(graphicSuffix, Std.string(combo));
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;
@ -92,7 +112,7 @@ class PopUpStuff extends FlxTypedGroup<FlxSprite>
// add(comboSpr);
if (PlayState.instance.currentStageId.startsWith('school'))
if (graphicSuffix.toLowerCase().contains('pixel'))
{
comboSpr.setGraphicSize(Std.int(comboSpr.width * Constants.PIXEL_ART_SCALE * 0.7));
comboSpr.antialiasing = false;
@ -129,9 +149,9 @@ class PopUpStuff extends FlxTypedGroup<FlxSprite>
var daLoop:Int = 1;
for (i in seperatedScore)
{
var numScore:FunkinSprite = FunkinSprite.create(0, comboSpr.y, pixelShitPart1 + 'num' + Std.int(i) + pixelShitPart2);
var numScore:FunkinSprite = FunkinSprite.create(0, comboSpr.y, resolveGraphicPath(graphicSuffix, 'num' + Std.int(i)));
if (PlayState.instance.currentStageId.startsWith('school'))
if (graphicSuffix.toLowerCase().contains('pixel'))
{
numScore.setGraphicSize(Std.int(numScore.width * Constants.PIXEL_ART_SCALE * 0.7));
numScore.antialiasing = false;
@ -166,4 +186,12 @@ class PopUpStuff extends FlxTypedGroup<FlxSprite>
return combo;
}
/**
* Reset the popup configuration to the default.
*/
public static function reset()
{
graphicSuffix = '';
}
}