diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
commit | 6352e8e3196f78388b6c771073f9e03eaa612673 (patch) | |
tree | e23772f79a7fbc41bc9108951e9e136857484bf4 /source/frontend/StarSongbookInterface.cpp | |
parent | 6741a057e5639280d85d0f88ba26f000baa58f61 (diff) |
everything everywhere
all at once
Diffstat (limited to 'source/frontend/StarSongbookInterface.cpp')
-rw-r--r-- | source/frontend/StarSongbookInterface.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/source/frontend/StarSongbookInterface.cpp b/source/frontend/StarSongbookInterface.cpp new file mode 100644 index 0000000..4848f4e --- /dev/null +++ b/source/frontend/StarSongbookInterface.cpp @@ -0,0 +1,61 @@ +#include "StarSongbookInterface.hpp" +#include "StarGuiReader.hpp" +#include "StarRoot.hpp" +#include "StarListWidget.hpp" +#include "StarLabelWidget.hpp" +#include "StarTextBoxWidget.hpp" +#include "StarPlayer.hpp" +#include "StarAssets.hpp" + +namespace Star { + +SongbookInterface::SongbookInterface(PlayerPtr player) { + m_player = move(player); + + auto assets = Root::singleton().assets(); + + GuiReader reader; + + reader.registerCallback("close", [=](Widget*) { dismiss(); }); + reader.registerCallback("btnPlay", + [=](Widget*) { + if (play()) + dismiss(); + }); + reader.registerCallback("group", [=](Widget*) {}); + + reader.construct(assets->json("/interface/windowconfig/songbook.config:paneLayout"), this); + + auto songList = fetchChild<ListWidget>("songs.list"); + + StringList files = assets->scan(".abc"); + sort(files, [](String const& a, String const& b) -> bool { return b.compare(a, String::CaseInsensitive) > 0; }); + for (auto s : files) { + auto song = s.substr(7, s.length() - (7 + 4)); + auto widget = songList->addItem(); + widget->setData(s); + auto songName = widget->fetchChild<LabelWidget>("songName"); + songName->setText(song); + + widget->show(); + } +} + +bool SongbookInterface::play() { + auto songList = fetchChild<ListWidget>("songs.list"); + auto songWidget = songList->selectedWidget(); + if (!songWidget) + return false; + auto songName = songWidget->data().toString(); + auto group = fetchChild<TextBoxWidget>("group")->getText(); + + JsonObject song; + song["resource"] = songName; + auto buffer = Root::singleton().assets()->bytes(songName); + song["abc"] = String(buffer->ptr(), buffer->size()); + + m_player->songbook()->play(song, group); + return true; +} + +} |