start work on jukebox

This commit is contained in:
RandomityGuy 2022-11-25 19:40:02 +05:30
parent af67c9eac0
commit a22565855c
18 changed files with 163 additions and 6 deletions

BIN
data/ui/common/noscroll.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
data/ui/jukebox/close_d.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
data/ui/jukebox/close_h.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
data/ui/jukebox/close_n.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
data/ui/jukebox/play_d.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

BIN
data/ui/jukebox/play_h.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

BIN
data/ui/jukebox/play_n.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

BIN
data/ui/jukebox/stop_d.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
data/ui/jukebox/stop_h.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
data/ui/jukebox/stop_n.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
data/ui/jukebox/window.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View file

@ -16,6 +16,10 @@ class AudioManager {
static var soundGroup:hxd.snd.SoundGroup;
static var musicGroup:hxd.snd.SoundGroup;
static var currentMusic:hxd.snd.Channel;
public static var currentMusicName:String;
public static var currentMusicPaused:Bool = true;
static var currentMusicResource:Resource<Sound>;
public static function init() {
@ -61,16 +65,25 @@ class AudioManager {
if (currentMusicResource != null)
currentMusicResource.release();
currentMusicResource = sndres;
var ch = AudioManager.manager.play(sndres.resource, null, musicGroup);
ch.loop = true;
currentMusic = AudioManager.manager.play(sndres.resource, null, musicGroup);
currentMusic.loop = true;
}
public static function playMusic(music:Sound) {
public static function playMusic(music:Sound, musicName:String) {
AudioManager.manager.stopByName("music");
if (music == null)
return;
var ch = AudioManager.manager.play(music, null, musicGroup);
ch.loop = true;
AudioManager.currentMusicName = musicName;
currentMusic = AudioManager.manager.play(music, null, musicGroup);
currentMusicPaused = false;
currentMusic.loop = true;
}
public static function pauseMusic(paused:Bool) {
if (currentMusic != null) {
currentMusic.pause = paused;
currentMusicPaused = paused;
}
}
public static function stopAllSounds() {

View file

@ -239,7 +239,7 @@ class MarbleWorld extends Scheduler {
this._ready = true;
this.playGui.init(this.scene2d);
var musicFileName = 'data/sound/' + this.mission.missionInfo.music;
AudioManager.playMusic(ResourceLoader.getResource(musicFileName, ResourceLoader.getAudio, this.soundResources));
AudioManager.playMusic(ResourceLoader.getResource(musicFileName, ResourceLoader.getAudio, this.soundResources), this.mission.missionInfo.music);
MarbleGame.canvas.clearContent();
this.endPad.generateCollider();
this.playGui.formatGemCounter(this.gemCount, this.totalGems);

View file

@ -1,5 +1,6 @@
package gui;
import src.MarbleGame;
import hxd.res.BitmapFont;
import h3d.Vector;
import src.ResourceLoader;
@ -61,5 +62,16 @@ class ExitGameDlg extends GuiControl {
dialogImg.addChild(restartButton);
this.addChild(dialogImg);
var jukeboxButton = new GuiButton(loadButtonImages("data/ui/jukebox/jb_pausemenu"));
jukeboxButton.vertSizing = Top;
jukeboxButton.horizSizing = Left;
jukeboxButton.position = new Vector(439, 403);
jukeboxButton.extent = new Vector(187, 65);
jukeboxButton.pressedAction = (e) -> {
MarbleGame.canvas.pushDialog(new JukeboxDlg());
}
this.addChild(jukeboxButton);
}
}

132
src/gui/JukeboxDlg.hx Normal file
View file

@ -0,0 +1,132 @@
package gui;
import h2d.filter.DropShadow;
import hxd.res.BitmapFont;
import h3d.Vector;
import src.ResourceLoader;
import src.MarbleGame;
import src.Settings;
import src.AudioManager;
class JukeboxDlg extends GuiImage {
public function new() {
var img = ResourceLoader.getImage("data/ui/jukebox/window.png");
super(img.resource.toTile());
this.horizSizing = Center;
this.vertSizing = Center;
this.position = new Vector(39, 35);
this.extent = new Vector(541, 409);
function loadButtonImages(path:String) {
var normal = ResourceLoader.getResource('${path}_n.png', ResourceLoader.getImage, this.imageResources).toTile();
var hover = ResourceLoader.getResource('${path}_h.png', ResourceLoader.getImage, this.imageResources).toTile();
var pressed = ResourceLoader.getResource('${path}_d.png', ResourceLoader.getImage, this.imageResources).toTile();
return [normal, hover, pressed];
}
var markerFelt32fontdata = ResourceLoader.getFileEntry("data/font/MarkerFelt.fnt");
var markerFelt32b = new BitmapFont(markerFelt32fontdata.entry);
@:privateAccess markerFelt32b.loader = ResourceLoader.loader;
var markerFelt32 = markerFelt32b.toSdfFont(cast 26 * Settings.uiScale, MultiChannel);
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 playing:Bool = AudioManager.currentMusicPaused;
var selectedIdx:Int = 0;
var currentPlayingSong = StringTools.replace(AudioManager.currentMusicName, ".ogg", "");
selectedIdx = songList.indexOf(currentPlayingSong);
var songTitle = new GuiMLText(markerFelt24, null);
songTitle.position = new Vector(61, 262);
songTitle.extent = new Vector(416, 22);
songTitle.text.filter = new DropShadow(1.414, 0.785, 0x0000007F, 1, 0, 0.4, 1, true);
songTitle.text.textColor = 0xFFFFFF;
songTitle.text.text = '<p align="center">Title: ${songList[selectedIdx]}</p>';
this.addChild(songTitle);
var songStatus = new GuiMLText(markerFelt24, null);
songStatus.position = new Vector(56, 283);
songStatus.extent = new Vector(421, 22);
songStatus.text.filter = new DropShadow(1.414, 0.785, 0x0000007F, 1, 0, 0.4, 1, true);
songStatus.text.textColor = 0xFFFFFF;
songStatus.text.text = '<p align="center">${playing ? "Playing" : "Stopped"}</p>';
this.addChild(songStatus);
var scroll = new GuiScrollCtrl(ResourceLoader.getResource("data/ui/common/philscroll.png", ResourceLoader.getImage, this.imageResources).toTile());
scroll.position = new Vector(51, 39);
scroll.extent = new Vector(439, 216);
this.addChild(scroll);
var songCtrl = new GuiTextListCtrl(markerFelt24, songList);
songCtrl.position = new Vector(0, 0);
songCtrl.extent = new Vector(423, 456);
songCtrl.scrollable = true;
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());
var stopBtn = new GuiButton(loadButtonImages("data/ui/jukebox/stop"));
stopBtn.position = new Vector(219, 306);
stopBtn.extent = new Vector(96, 45);
this.addChild(stopBtn);
var playBtn = new GuiButton(loadButtonImages("data/ui/jukebox/play"));
playBtn.position = new Vector(219, 306);
playBtn.extent = new Vector(96, 45);
stopBtn.pressedAction = (e) -> {
this.removeChild(stopBtn);
this.addChild(playBtn);
playBtn.render(MarbleGame.canvas.scene2d);
playing = false;
songStatus.text.text = '<p align="center">${playing ? "Playing" : "Stopped"}</p>';
};
playBtn.pressedAction = (e) -> {
this.removeChild(playBtn);
this.addChild(stopBtn);
stopBtn.render(MarbleGame.canvas.scene2d);
playing = true;
songStatus.text.text = '<p align="center">${playing ? "Playing" : "Stopped"}</p>';
};
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);
}
this.addChild(prevBtn);
var nextBtn = new GuiButton(loadButtonImages("data/ui/play/next"));
nextBtn.position = new Vector(317, 307);
nextBtn.extent = new Vector(72, 43);
nextBtn.pressedAction = (e) -> {
if (selectedIdx < songList.length)
songCtrl.onSelectedFunc(selectedIdx + 1);
}
this.addChild(nextBtn);
var closeBtn = new GuiButton(loadButtonImages("data/ui/jukebox/close"));
closeBtn.position = new Vector(47, 307);
closeBtn.extent = new Vector(94, 45);
closeBtn.pressedAction = (e) -> {
MarbleGame.canvas.popDialog(this);
}
this.addChild(closeBtn);
}
}