From 81ab5b638b5da3aba2625e3ed814493c4278854b Mon Sep 17 00:00:00 2001 From: JamesTheMaker Date: Fri, 8 Mar 2024 11:39:39 -0500 Subject: [PATCH] Added searchbar to songbook --- .../windowconfig/songbook.config.patch | 23 +++++++++ source/frontend/StarSongbookInterface.cpp | 49 +++++++++++++++---- source/frontend/StarSongbookInterface.hpp | 4 ++ 3 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 assets/opensb/interface/windowconfig/songbook.config.patch diff --git a/assets/opensb/interface/windowconfig/songbook.config.patch b/assets/opensb/interface/windowconfig/songbook.config.patch new file mode 100644 index 0000000..36991a5 --- /dev/null +++ b/assets/opensb/interface/windowconfig/songbook.config.patch @@ -0,0 +1,23 @@ +{ + "paneLayout" : { + "group" : { + "position" : [8, 71] + }, + "search" : { + "type" : "textbox", + "position" : [86, 71], + "hint" : "Search", + "maxWidth" : 50 + }, + + "lblBandInput" : { + "position" : [3, 68] + }, + "lblSearchInput" : { + "type" : "image", + "file" : "/interface/songbook/band.png", + "position" : [81, 68], + "zlevel" : -3 + } + } +} \ No newline at end of file diff --git a/source/frontend/StarSongbookInterface.cpp b/source/frontend/StarSongbookInterface.cpp index 8ccb437..cc6a17d 100644 --- a/source/frontend/StarSongbookInterface.cpp +++ b/source/frontend/StarSongbookInterface.cpp @@ -23,21 +23,52 @@ SongbookInterface::SongbookInterface(PlayerPtr player) { dismiss(); }); reader.registerCallback("group", [=](Widget*) {}); + reader.registerCallback("search", [=](Widget*) {}); reader.construct(assets->json("/interface/windowconfig/songbook.config:paneLayout"), this); auto songList = fetchChild("songs.list"); + auto search = fetchChild("search")->getText(); - 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) { + if (m_searchValue != search) + m_searchValue = search; + + m_files = assets->scan(".abc"); + sort(m_files, [](String const& a, String const& b) -> bool { return b.compare(a, String::CaseInsensitive) > 0; }); + for (auto s : m_files) { auto song = s.substr(7, s.length() - (7 + 4)); - auto widget = songList->addItem(); - widget->setData(s); - auto songName = widget->fetchChild("songName"); - songName->setText(song); + if (song.contains(m_searchValue, String::CaseInsensitive)) { + auto widget = songList->addItem(); + widget->setData(s); + auto songName = widget->fetchChild("songName"); + songName->setText(song); - widget->show(); + widget->show(); + } + } +} + +void SongbookInterface::update(float dt) { + Pane::update(dt); + + auto search = fetchChild("search")->getText(); + if (m_searchValue != search) { + m_searchValue = search; + + auto songList = fetchChild("songs.list"); + songList->clear(); + + for (auto s : m_files) { + auto song = s.substr(7, s.length() - (7 + 4)); + if (song.contains(m_searchValue, String::CaseInsensitive)) { + auto widget = songList->addItem(); + widget->setData(s); + auto songName = widget->fetchChild("songName"); + songName->setText(song); + + widget->show(); + } + } } } @@ -58,4 +89,4 @@ bool SongbookInterface::play() { return true; } -} +} \ No newline at end of file diff --git a/source/frontend/StarSongbookInterface.hpp b/source/frontend/StarSongbookInterface.hpp index 47622a4..f8a6cb2 100644 --- a/source/frontend/StarSongbookInterface.hpp +++ b/source/frontend/StarSongbookInterface.hpp @@ -13,8 +13,12 @@ class SongbookInterface : public Pane { public: SongbookInterface(PlayerPtr player); + void update(float dt) override; + private: PlayerPtr m_player; + StringList m_files; + String m_searchValue; bool play(); };