working jukebox

This commit is contained in:
RandomityGuy 2022-11-25 22:25:13 +05:30
parent a22565855c
commit f3cc59066a
40 changed files with 45 additions and 19 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
data/sound/music/Grudge.ogg Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
data/sound/music/Shell.ogg Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -58,7 +58,7 @@ class AudioManager {
public static function playShell() {
AudioManager.manager.stopByName("music");
var sndres = ResourceLoader.getAudio("data/sound/pianoforte.ogg");
var sndres = ResourceLoader.getAudio("data/sound/music/Pianoforte.ogg");
if (sndres == null)
return;
sndres.acquire();

View file

@ -228,7 +228,7 @@ class MarbleWorld extends Scheduler {
}
public function loadMusic(onFinish:Void->Void) {
var musicFileName = 'sound/' + this.mission.missionInfo.music;
var musicFileName = 'sound/music/' + this.mission.missionInfo.music;
ResourceLoader.load(musicFileName).entry.load(onFinish);
}
@ -238,7 +238,7 @@ class MarbleWorld extends Scheduler {
this._ready = true;
this.playGui.init(this.scene2d);
var musicFileName = 'data/sound/' + this.mission.missionInfo.music;
var musicFileName = 'data/sound/music/' + this.mission.missionInfo.music;
AudioManager.playMusic(ResourceLoader.getResource(musicFileName, ResourceLoader.getAudio, this.soundResources), this.mission.missionInfo.music);
MarbleGame.canvas.clearContent();
this.endPad.generateCollider();

View file

@ -88,6 +88,7 @@ class GuiTextListCtrl extends GuiControl {
public override function render(scene2d:Scene) {
var renderRect = this.getRenderRectangle();
var htr = this.getHitTestRect();
if (scene2d.contains(g))
scene2d.removeChild(g);
@ -97,8 +98,6 @@ class GuiTextListCtrl extends GuiControl {
if (scrollable) {
this.flow = new Flow();
var htr = this.getHitTestRect();
this.flow.maxWidth = cast htr.extent.x;
this.flow.maxHeight = cast htr.extent.y;
this.flow.multiline = true;
@ -134,7 +133,7 @@ class GuiTextListCtrl extends GuiControl {
}
}
redrawSelectionRect(renderRect);
redrawSelectionRect(htr);
super.render(scene2d);
}

View file

@ -32,12 +32,10 @@ class JukeboxDlg extends GuiImage {
var markerFelt24 = markerFelt32b.toSdfFont(cast 18 * Settings.uiScale, MultiChannel);
var markerFelt18 = markerFelt32b.toSdfFont(cast 14 * Settings.uiScale, MultiChannel);
var songList = [
"Astrolabe", "Beach Party", "Challenge", "Classic Vibe", "Comforting Mystery", "Endurance", "Flanked", "Groove Police", "Grudge", "MBP Old Shell",
"Metropolis", "Pianoforte", "Quiet Lab", "Rising Temper", "Seaside Revisited", "Shell", "The Race", "Tim Trance", "Xmas Trance"
];
var songFiles = ResourceLoader.fileSystem.dir("data/sound/music");
var songList = songFiles.map(x -> StringTools.replace(x.name, ".ogg", ""));
var playing:Bool = AudioManager.currentMusicPaused;
var playing:Bool = !AudioManager.currentMusicPaused;
var selectedIdx:Int = 0;
var currentPlayingSong = StringTools.replace(AudioManager.currentMusicName, ".ogg", "");
@ -71,13 +69,27 @@ class JukeboxDlg extends GuiImage {
songCtrl.textYOffset = -6;
songCtrl.selectedColor = 0;
songCtrl._prevSelected = selectedIdx;
songCtrl.onSelectedFunc = (idx) -> {
selectedIdx = idx;
songTitle.text.text = '<p align="center">Title: ${songList[idx]}</p>';
};
scroll.addChild(songCtrl);
scroll.setScrollMax(songCtrl.calculateFullHeight());
function setCurrentSong(idx:Int) {
selectedIdx = idx;
songCtrl._prevSelected = idx;
songTitle.text.text = '<p align="center">Title: ${songList[idx]}</p>';
songCtrl.redrawSelectionRect(songCtrl.getHitTestRect());
if (playing) {
songFiles[idx].load(() -> {
var audiores = ResourceLoader.getAudio(songFiles[idx].path).resource;
AudioManager.playMusic(audiores, songList[idx]);
});
}
}
songCtrl.onSelectedFunc = (idx) -> {
setCurrentSong(idx);
};
var stopBtn = new GuiButton(loadButtonImages("data/ui/jukebox/stop"));
stopBtn.position = new Vector(219, 306);
stopBtn.extent = new Vector(96, 45);
@ -93,6 +105,7 @@ class JukeboxDlg extends GuiImage {
playBtn.render(MarbleGame.canvas.scene2d);
playing = false;
songStatus.text.text = '<p align="center">${playing ? "Playing" : "Stopped"}</p>';
AudioManager.pauseMusic(true);
};
playBtn.pressedAction = (e) -> {
@ -101,14 +114,25 @@ class JukeboxDlg extends GuiImage {
stopBtn.render(MarbleGame.canvas.scene2d);
playing = true;
songStatus.text.text = '<p align="center">${playing ? "Playing" : "Stopped"}</p>';
if (AudioManager.currentMusicName != songList[selectedIdx]) {
songFiles[selectedIdx].load(() -> {
var audiores = ResourceLoader.getAudio(songFiles[selectedIdx].path).resource;
AudioManager.playMusic(audiores, songList[selectedIdx]);
});
} else {
AudioManager.pauseMusic(false);
}
};
var prevBtn = new GuiButton(loadButtonImages("data/ui/play/prev"));
prevBtn.position = new Vector(145, 307);
prevBtn.extent = new Vector(72, 43);
prevBtn.pressedAction = (e) -> {
if (selectedIdx > 1)
songCtrl.onSelectedFunc(selectedIdx - 1);
if (selectedIdx >= 1) {
setCurrentSong(selectedIdx - 1);
} else {
setCurrentSong(songList.length - 1);
}
}
this.addChild(prevBtn);
@ -116,8 +140,11 @@ class JukeboxDlg extends GuiImage {
nextBtn.position = new Vector(317, 307);
nextBtn.extent = new Vector(72, 43);
nextBtn.pressedAction = (e) -> {
if (selectedIdx < songList.length)
songCtrl.onSelectedFunc(selectedIdx + 1);
if (selectedIdx < songList.length - 1) {
setCurrentSong(selectedIdx + 1);
} else {
setCurrentSong(0);
}
}
this.addChild(nextBtn);