diff options
author | Vladimir Krasheninnikov <boba09@list.ru> | 2025-02-08 20:40:33 +0100 |
---|---|---|
committer | Vladimir Krasheninnikov <boba09@list.ru> | 2025-02-08 20:40:33 +0100 |
commit | 0d860dc2e3832d5cb460e4d474b7e08c090a791a (patch) | |
tree | 1923174c217f39ad11451dc8f18961e4785dd068 /source/frontend | |
parent | 4244b60fd27122368d6a685199ddf325dfdd1c2e (diff) |
Search character by name
Diffstat (limited to 'source/frontend')
-rw-r--r-- | source/frontend/StarCharSelection.cpp | 27 | ||||
-rw-r--r-- | source/frontend/StarCharSelection.hpp | 2 |
2 files changed, 22 insertions, 7 deletions
diff --git a/source/frontend/StarCharSelection.cpp b/source/frontend/StarCharSelection.cpp index 4c56d59..2bf4f93 100644 --- a/source/frontend/StarCharSelection.cpp +++ b/source/frontend/StarCharSelection.cpp @@ -2,6 +2,7 @@ #include "StarGuiReader.hpp" #include "StarRoot.hpp" #include "StarLargeCharPlateWidget.hpp" +#include "StarTextBoxWidget.hpp" #include "StarAssets.hpp" #include "StarRandom.hpp" #include "StarInputEvent.hpp" @@ -14,6 +15,8 @@ CharSelectionPane::CharSelectionPane(PlayerStoragePtr playerStorage, DeleteCharacterCallback deleteCallback) : m_playerStorage(playerStorage), m_downScroll(0), + m_filteredList({}), + m_search(""), m_createCallback(createCallback), m_selectCallback(selectCallback), m_deleteCallback(deleteCallback) { @@ -28,6 +31,11 @@ CharSelectionPane::CharSelectionPane(PlayerStoragePtr playerStorage, guiReader.registerCallback("charSelector3", [=](Widget*) { selectCharacter(2); }); guiReader.registerCallback("charSelector4", [=](Widget*) { selectCharacter(3); }); guiReader.registerCallback("createCharButton", [=](Widget*) { m_createCallback(); }); + guiReader.registerCallback("searchCharacter", [=](Widget* obj) { + m_downScroll = 0; + m_search = convert<TextBoxWidget>(obj)->getText().trim().toLower(); + updateCharacterPlates(); + }); guiReader.construct(root.assets()->json("/interface/windowconfig/charselection.config"), this); } @@ -55,13 +63,14 @@ void CharSelectionPane::show() { } void CharSelectionPane::shiftCharacters(int shift) { - m_downScroll = std::max<int>(std::min<int>(m_downScroll + shift, m_playerStorage->playerCount() - 3), 0); + m_downScroll = std::max<int>(std::min<int>(m_downScroll + shift, m_filteredList.size() - 3), 0); updateCharacterPlates(); } void CharSelectionPane::selectCharacter(unsigned buttonIndex) { - if (auto playerUuid = m_playerStorage->playerUuidAt(m_downScroll + buttonIndex)) { - auto player = m_playerStorage->loadPlayer(*playerUuid); + if (m_downScroll + buttonIndex < m_filteredList.size()) { + auto playerUuid = m_filteredList.get(m_downScroll + buttonIndex); + auto player = m_playerStorage->loadPlayer(playerUuid); if (player->isPermaDead() && !player->isAdmin()) { auto sound = Random::randValueFrom( Root::singleton().assets()->json("/interface.config:buttonClickFailSound").toArray(), "") @@ -75,13 +84,17 @@ void CharSelectionPane::selectCharacter(unsigned buttonIndex) { } void CharSelectionPane::updateCharacterPlates() { + auto updatePlayerLine = [this](String name, unsigned scrollPosition) { + m_filteredList = m_playerStorage->playerUuidListByName(m_search); auto charSelector = fetchChild<LargeCharPlateWidget>(name); - if (auto playerUuid = m_playerStorage->playerUuidAt(scrollPosition)) { - if (auto player = m_playerStorage->loadPlayer(*playerUuid)) { + + if (m_filteredList.size() > 0 && scrollPosition < m_filteredList.size()) { + auto playerUuid = m_filteredList.get(scrollPosition); + if (auto player = m_playerStorage->loadPlayer(playerUuid)) { player->humanoid()->setFacingDirection(Direction::Right); charSelector->setPlayer(player); - charSelector->enableDelete([this, playerUuid](Widget*) { m_deleteCallback(*playerUuid); }); + charSelector->enableDelete([this, playerUuid](Widget*) { m_deleteCallback(playerUuid); }); return; } } @@ -99,7 +112,7 @@ void CharSelectionPane::updateCharacterPlates() { else fetchChild("playerUpButton")->hide(); - if (m_downScroll < m_playerStorage->playerCount() - 3) + if (m_downScroll < m_filteredList.size() - 3) fetchChild("playerDownButton")->show(); else fetchChild("playerDownButton")->hide(); diff --git a/source/frontend/StarCharSelection.hpp b/source/frontend/StarCharSelection.hpp index 64e1343..b4837ca 100644 --- a/source/frontend/StarCharSelection.hpp +++ b/source/frontend/StarCharSelection.hpp @@ -26,6 +26,8 @@ private: PlayerStoragePtr m_playerStorage; unsigned m_downScroll; + String m_search; + List<Uuid> m_filteredList; CreateCharCallback m_createCallback; SelectCharacterCallback m_selectCallback; |