Skip to content

Commit

Permalink
music dialog hellyeah
Browse files Browse the repository at this point in the history
  • Loading branch information
KoloInDaCrib committed Dec 9, 2024
1 parent 060bdb3 commit ec5439e
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 13 deletions.
2 changes: 1 addition & 1 deletion assets
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package funkin.ui.debug.char.components.dialogs.results;
import haxe.ui.containers.VBox;
import haxe.ui.containers.HBox;
import haxe.ui.components.Button;
import haxe.ui.events.UIEvent;
import funkin.data.freeplay.player.PlayerData;
import funkin.data.freeplay.player.PlayerRegistry;
import funkin.play.scoring.Scoring.ScoringRank;
Expand Down Expand Up @@ -187,6 +188,8 @@ private class AddRankAnimationDataBox extends HBox
});
}

newBox.pauseEvent(UIEvent.CHANGE, true);

newBox.onOffsetsChange = function() {
var obj = page.currentAnims[newBox.ID];
if (obj?.sprite == null) return;
Expand Down Expand Up @@ -260,6 +263,8 @@ private class AddRankAnimationDataBox extends HBox
copyData(data, newBox.animData);
}

newBox.resumeEvent(UIEvent.CHANGE, true, true);

return newBox;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package funkin.ui.debug.char.components.dialogs.results;

import funkin.data.freeplay.player.PlayerRegistry;
import funkin.play.scoring.Scoring.ScoringRank;
import funkin.ui.debug.char.pages.CharCreatorResultsPage;
import funkin.util.FileUtil;
import haxe.ui.events.UIEvent;
import haxe.io.Path;

@:build(haxe.ui.macros.ComponentMacros.build("assets/exclude/data/ui/char-creator/dialogs/results/results-music-dialog.xml"))
@:access(funkin.ui.debug.char.pages.CharCreatorResultsPage)
class ResultsMusicDialog extends DefaultPageDialog
{
public var musicStuff:Map<ScoringRank, {intro:WizardFile, song:WizardFile}> = [];

override public function new(daPage:CharCreatorResultsPage)
{
super(daPage);

var charId = daPage.data.importedPlayerData ?? "";
var currentChar = PlayerRegistry.instance.fetchEntry(charId);
for (rank in CharCreatorResultsPage.ALL_RANKS)
{
var musKey = currentChar?.getResultsMusicPath(rank) ?? 'resultsNORMAL';

var introPath = Paths.music('$musKey/$musKey-intro');
var intro:WizardFile =
{
name: '$musKey-intro',
bytes: Assets.exists(introPath) ? Assets.getBytes(introPath) : null
};
var song:WizardFile = {name: '$musKey', bytes: Assets.getBytes(Paths.music('$musKey/$musKey'))};

musicStuff.set(rank, {intro: intro, song: song});
}

rankMusicDrop.selectedIndex = 0;
rankMusicDrop.onChange = function(_) {
var daRank = daPage.getRankFromString(rankMusicDrop.safeSelectedItem.text);

rankMusicFrame.pauseEvent(UIEvent.CHANGE, true);

rankMusicIntroField.text = musicStuff[daRank].intro?.name ?? "";
rankMusicSongField.text = musicStuff[daRank].song.name;

rankMusicFrame.resumeEvent(UIEvent.CHANGE, true, true);
}

rankMusicIntroField.onChange = rankMusicSongField.onChange = function(_) {
daPage.setStatusOfEverything(false);

var daRank = daPage.getRankFromString(rankMusicDrop.safeSelectedItem.text);
daPage.rankMusicMap[daRank].destroy();

// bytes check!
var introBytes:haxe.io.Bytes = null;
var songBytes:haxe.io.Bytes = null;

if (Path.isAbsolute(rankMusicIntroField.text) != Path.isAbsolute(rankMusicSongField.text)
&& (rankMusicIntroField.text.length > 0 && rankMusicSongField.text.length > 0))
{
CharCreatorUtil.error("Rank Music", "Paths of the Rank Music but be of the same Type.");
return;
}

if (Path.isAbsolute(rankMusicIntroField.text) || Path.isAbsolute(rankMusicSongField.text))
{
if ((rankMusicIntroField.text.length > 0 && Path.extension(rankMusicIntroField.text) != Constants.EXT_SOUND)
|| (rankMusicSongField.text.length > 0 && Path.extension(rankMusicSongField.text) != Constants.EXT_SOUND))
{
CharCreatorUtil.error("Rank Music", "Rank Music should have an extension of " + Constants.EXT_SOUND + ".");
return;
}

var introFile:WizardFile = {name: rankMusicIntroField.text, bytes: FileUtil.readBytesFromPath(rankMusicIntroField.text)}
var musicFile:WizardFile = {name: rankMusicSongField.text, bytes: FileUtil.readBytesFromPath(rankMusicSongField.text)}

introBytes = introFile.bytes;
songBytes = musicFile.bytes;

musicStuff.set(daRank, {intro: introFile, song: musicFile});
}
else
{
if (rankMusicIntroField.text.length > 0 && rankMusicIntroField.text != rankMusicSongField.text + "-intro")
{
CharCreatorUtil.error("Rank Music", "Rank Intro Music Path should be " + rankMusicSongField.text + "-intro, or none if it doesn't exist.");
return;
}

var musKey = rankMusicSongField.text;
var fullIntroPath = Paths.music('$musKey/$musKey-intro');
var fullPath = Paths.music('$musKey/$musKey');

var introFile:WizardFile = {name: rankMusicIntroField.text, bytes: Assets.exists(fullIntroPath) ? Assets.getBytes(fullIntroPath) : null}
var musicFile:WizardFile = {name: rankMusicSongField.text, bytes: Assets.exists(fullPath) ? Assets.getBytes(fullPath) : null}

introBytes = introFile.bytes;
songBytes = musicFile.bytes;

musicStuff.set(daRank, {intro: introFile, song: musicFile});
}

daPage.rankMusicMap[daRank].reloadSoundsFromBytes(songBytes, introBytes);
}

rankMusicIntroLoad.onClick = function(_) {
FileUtil.browseForBinaryFile("Load Sound File", [FileUtil.FILE_EXTENSION_INFO_SND], function(_) {
if (_?.fullPath == null) return;
rankMusicIntroField.text = _.fullPath;
});
}

rankMusicSongLoad.onClick = function(_) {
FileUtil.browseForBinaryFile("Load Sound File", [FileUtil.FILE_EXTENSION_INFO_SND], function(_) {
if (_?.fullPath == null) return;
rankMusicSongField.text = _.fullPath;
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ class PlayableCharacterSettingsDialog extends DefaultPageDialog
ownedCharBox = new AddOwnedCharBox(daPage);
ownedCharsView.addComponent(ownedCharBox);
ownedCharBox.addPlayerDropdowns();

var playuh = PlayerRegistry.instance.fetchEntry(daPage.data.importedPlayerData ?? "");
if (playuh != null)
{
playerDataName.text = playuh.getName();
playerDataShowUnowned.selected = playuh.shouldShowUnownedChars();
playerDataUnlocked.selected = playuh.isUnlocked();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import haxe.io.Path;
import funkin.data.character.CharacterRegistry;
import funkin.ui.debug.char.components.dialogs.freeplay.FreeplayDJSettingsDialog;
import funkin.ui.debug.char.components.dialogs.results.ResultsAnimDialog;
import funkin.ui.debug.char.components.dialogs.results.ResultsMusicDialog;
import funkin.ui.debug.char.pages.CharCreatorGameplayPage;
import funkin.ui.debug.char.pages.CharCreatorSelectPage;
import funkin.ui.debug.char.pages.CharCreatorFreeplayPage;
Expand Down Expand Up @@ -129,11 +130,14 @@ class CharCreatorImportExportHandler
}
}

var charSelectDialog:funkin.ui.debug.char.components.dialogs.select.PlayableCharacterSettingsDialog = cast selectPage.dialogMap[SettingsDialog];

var playerData:PlayerData = new PlayerData();
playerData.name = "Unknown";
playerData.name = charSelectDialog.playerDataName.text;
playerData.ownedChars = selectPage.ownedCharacters;
playerData.showUnownedChars = false;
playerData.showUnownedChars = charSelectDialog.playerDataShowUnowned.selected;
playerData.freeplayStyle = freeplayPage.useStyle ?? charID;
playerData.unlocked = charSelectDialog.playerDataUnlocked.selected;

playerData.charSelect = new PlayerCharSelectData(selectPage.position,
{
Expand Down Expand Up @@ -191,7 +195,7 @@ class CharCreatorImportExportHandler

playerData.results =
{
music: null,
music: {},
perfectGold: resultPageDialog.rankAnimationDataMap[PERFECT_GOLD],
perfect: resultPageDialog.rankAnimationDataMap[PERFECT],
excellent: resultPageDialog.rankAnimationDataMap[EXCELLENT],
Expand All @@ -200,7 +204,27 @@ class CharCreatorImportExportHandler
loss: resultPageDialog.rankAnimationDataMap[SHIT],
};

playerData.unlocked = true;
var musDialog:ResultsMusicDialog = cast resultPage.dialogMap[Music];
for (rank => data in musDialog.musicStuff)
{
if (!Path.isAbsolute(data.song.name))
{
Reflect.setField(playerData.results.music, Std.string(rank).toUpperCase(), data.song.name.length > 0 ? data.song.name : "resultsNORMAL");
}
else
{
var rankStr = Std.string(rank).toUpperCase();

if (data.intro.bytes != null)
zipEntries.push(FileUtil.makeZIPEntryFromBytes('music/results$rankStr-$charID/results$rankStr-$charID-intro.${Constants.EXT_SOUND}',
data.intro.bytes));

if (data.song.bytes != null)
zipEntries.push(FileUtil.makeZIPEntryFromBytes('music/results$rankStr-$charID/results$rankStr-$charID.${Constants.EXT_SOUND}', data.song.bytes));

Reflect.setField(playerData.results.music, rankStr, rankStr + "-" + charID);
}
}

zipEntries.push(FileUtil.makeZIPEntry('data/players/${charID}.json', playerData.serialize()));
if (selectPage.nametagFile != null) zipEntries.push(FileUtil.makeZIPEntryFromBytes('images/charSelect${charID}Nametag.png', selectPage.nametagFile.bytes));
Expand Down
56 changes: 48 additions & 8 deletions source/funkin/ui/debug/char/pages/CharCreatorResultsPage.hx
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,14 @@ class CharCreatorResultsPage extends CharCreatorDefaultPage

dialogMap = new Map<ResultsDialogType, DefaultPageDialog>();
dialogMap.set(RankAnims, new ResultsAnimDialog(this));
dialogMap.set(Music, new ResultsMusicDialog(this));

if (data.importedPlayerData != null)
{
var player = PlayerRegistry.instance.fetchEntry(data.importedPlayerData);
var player = PlayerRegistry.instance.fetchEntry(data.importedPlayerData ?? "");

for (rank in ALL_RANKS)
rankMusicMap.set(rank, new ResultsMusic(player, rank));
for (rank in ALL_RANKS)
rankMusicMap.set(rank, new ResultsMusic(player, rank));

generateSpritesByData(player.getResultsAnimationDatas(PERFECT_GOLD));
}
if (player != null) generateSpritesByData(player.getResultsAnimationDatas(PERFECT_GOLD));

generateUI();
initFunkinUI();
Expand All @@ -86,6 +84,13 @@ class CharCreatorResultsPage extends CharCreatorDefaultPage
dialogMap[RankAnims].hidden = !animDialog.selected;
}
menu.addComponent(animDialog);

var musicDialog = new MenuCheckBox();
musicDialog.text = "Rank Music";
musicDialog.onClick = function(_) {
dialogMap[Music].hidden = !musicDialog.selected;
}
menu.addComponent(musicDialog);
}

override public function fillUpBottomBar(left:Box, middle:Box, right:Box):Void
Expand Down Expand Up @@ -508,6 +513,24 @@ class CharCreatorResultsPage extends CharCreatorDefaultPage
}
}

public function getRankFromString(str:String)
{
return switch (str.toLowerCase())
{
case "perfect":
PERFECT;
case "excellent":
EXCELLENT;
case "great":
GREAT;
case "good":
GOOD;
case "shit":
SHIT;
default: PERFECT_GOLD;
}
}

var difficulty:FlxSprite;
var songName:FlxBitmapText;
var clearPercentCounter:ClearPercentCounter;
Expand Down Expand Up @@ -633,7 +656,7 @@ private class ResultsMusic
var path = player?.getResultsMusicPath(rank) ?? "";

var musicPath = Paths.music('$path/$path');
music = FunkinSound.load(musicPath, 1.0);
music = FunkinSound.load(musicPath, 1.0, true);

var introMusicPath = Paths.music('$path/$path-intro');
if (openfl.utils.Assets.exists(introMusicPath))
Expand All @@ -644,6 +667,15 @@ private class ResultsMusic
}
}

public function reloadSoundsFromBytes(?musicBytes:haxe.io.Bytes, ?introBytes:haxe.io.Bytes)
{
music = funkin.util.assets.SoundUtil.buildSoundFromBytes(musicBytes);
introMusic = funkin.util.assets.SoundUtil.buildSoundFromBytes(introBytes);

if (introMusic != null) introMusic.onComplete = function() music?.play();
if (music != null) music.looped = true;
}

public function play():Void
{
if (introMusic != null) introMusic?.play();
Expand All @@ -668,6 +700,13 @@ private class ResultsMusic
introMusic?.resume();
music?.resume();
}

public function destroy():Void
{
stop();
introMusic?.destroy();
music?.destroy();
}
}

typedef CharCreatorResultAnim =
Expand All @@ -679,4 +718,5 @@ typedef CharCreatorResultAnim =
enum ResultsDialogType
{
RankAnims;
Music;
}
6 changes: 6 additions & 0 deletions source/funkin/util/FileUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class FileUtil
label: 'PNG Image',
};

public static final FILE_EXTENSION_INFO_SND:FileDialogExtensionInfo =
{
extension: Constants.EXT_SOUND,
label: 'Sound File',
};

public static final FILE_EXTENSION_INFO_FNFS:FileDialogExtensionInfo =
{
extension: 'fnfs',
Expand Down

0 comments on commit ec5439e

Please sign in to comment.