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() { public static function playShell() {
AudioManager.manager.stopByName("music"); AudioManager.manager.stopByName("music");
var sndres = ResourceLoader.getAudio("data/sound/pianoforte.ogg"); var sndres = ResourceLoader.getAudio("data/sound/music/Pianoforte.ogg");
if (sndres == null) if (sndres == null)
return; return;
sndres.acquire(); sndres.acquire();

View file

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

View file

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

View file

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