use setidpopup for page changes

This commit is contained in:
Cvolton 2024-06-04 19:39:36 +02:00
parent bb64bf8bc0
commit 25fe269c68
No known key found for this signature in database
2 changed files with 7 additions and 12 deletions
loader/src/ui/mods

View file

@ -531,15 +531,11 @@ void ModsLayer::keyBackClicked() {
this->onBack(nullptr);
}
void ModsLayer::setTextPopupClosed(SetTextPopup* popup, gd::string value) {
void ModsLayer::setIDPopupClosed(SetIDPopup* popup, int num) {
if (popup->getID() == "go-to-page"_spr) {
if (auto res = numFromString<size_t>(value)) {
size_t num = res.unwrap();
// The page indices are 0-based but people think in 1-based
if (num > 0) num -= 1;
if (m_currentSource) {
m_lists.at(m_currentSource)->gotoPage(num);
}
if (num > 0) num -= 1;
if (m_currentSource) {
m_lists.at(m_currentSource)->gotoPage(num);
}
}
}
@ -581,9 +577,8 @@ void ModsLayer::onBack(CCObject*) {
ModListSource::clearAllCaches();
}
void ModsLayer::onGoToPage(CCObject*) {
auto popup = SetTextPopup::create("", "Page", 5, "Go to Page", "OK", true, 60.f);
auto popup = SetIDPopup::create(m_lists.at(m_currentSource)->getPage() + 1, 1, m_currentSource->getPageCount().value(), "Go to Page", "Go", true, 1, 60.f, false, false);
popup->m_delegate = this;
popup->m_input->m_allowedChars = getCommonFilterAllowedChars(CommonFilter::Uint);
popup->setID("go-to-page"_spr);
popup->show();
}

View file

@ -39,7 +39,7 @@ public:
static ModsStatusNode* create();
};
class ModsLayer : public CCLayer, public SetTextPopupDelegate {
class ModsLayer : public CCLayer, public SetIDPopupDelegate {
protected:
CCNode* m_frame;
std::vector<CCMenuItemSpriteExtra*> m_tabs;
@ -56,7 +56,7 @@ protected:
bool init();
void keyBackClicked() override;
void setTextPopupClosed(SetTextPopup*, gd::string value) override;
void setIDPopupClosed(SetIDPopup*, int value) override;
void onTab(CCObject* sender);
void onBigView(CCObject*);