From 93be1e072b5d471b6461c6e9a0d4b32099107616 Mon Sep 17 00:00:00 2001 From: icannotttt <141535655+icannotttt@users.noreply.github.com> Date: Thu, 29 Jan 2026 19:26:46 +0800 Subject: [PATCH] Update XtcReaderChapterSelectionActivity.cpp --- .../XtcReaderChapterSelectionActivity.cpp | 56 ++++++++++--------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/src/activities/reader/XtcReaderChapterSelectionActivity.cpp b/src/activities/reader/XtcReaderChapterSelectionActivity.cpp index b2cfecaa..07174fc8 100644 --- a/src/activities/reader/XtcReaderChapterSelectionActivity.cpp +++ b/src/activities/reader/XtcReaderChapterSelectionActivity.cpp @@ -84,32 +84,31 @@ void XtcReaderChapterSelectionActivity::loop() { const int pageItems = getPageItems(); if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) { - const auto& chapters = xtc->getChapters(); + pagebegin=(page-1)*pageItems; + const auto& chapters = xtc->getChapters_gd(pagebegin); if (!chapters.empty() && selectorIndex >= 0 && selectorIndex < static_cast(chapters.size())) { onSelectPage(chapters[selectorIndex].startPage); } - } else if (mappedInput.wasReleased(MappedInputManager::Button::Back)) { + } else if (mappedInput.wasReleased(MappedInputManager::Button::Back)) { onGoBack(); } else if (prevReleased) { - const int total = static_cast(xtc->getChapters().size()); - if (total == 0) { - return; - } - if (skipPage) { - selectorIndex = ((selectorIndex / pageItems - 1) * pageItems + total) % total; + bool isUpKey = mappedInput.wasReleased(MappedInputManager::Button::Up); + if (skipPage || isUpKey) { + page -= 1; + if(page < 1) page = 1; + selectorIndex = (page-1)*pageItems; } else { - selectorIndex = (selectorIndex + total - 1) % total; + selectorIndex--; + if(selectorIndex < 0) selectorIndex = 0; } updateRequired = true; } else if (nextReleased) { - const int total = static_cast(xtc->getChapters().size()); - if (total == 0) { - return; - } - if (skipPage) { - selectorIndex = ((selectorIndex / pageItems + 1) * pageItems) % total; + bool isDownKey = mappedInput.wasReleased(MappedInputManager::Button::Down); + if (skipPage || isDownKey) { + page += 1; + selectorIndex = (page-1)*pageItems; } else { - selectorIndex = (selectorIndex + 1) % total; + selectorIndex++; } updateRequired = true; } @@ -143,14 +142,21 @@ void XtcReaderChapterSelectionActivity::renderScreen() { const auto pageStartIndex = selectorIndex / pageItems * pageItems; renderer.fillRect(0, 60 + (selectorIndex % pageItems) * 30 - 2, pageWidth - 1, 30); - for (int i = pageStartIndex; i < static_cast(chapters.size()) && i < pageStartIndex + pageItems; i++) { - const auto& chapter = chapters[i]; - const char* title = chapter.name.empty() ? "Unnamed" : chapter.name.c_str(); - renderer.drawText(UI_10_FONT_ID, 20, 60 + (i % pageItems) * 30, title, i != selectorIndex); - } + for (int i = pagebegin; i <= pagebegin + pageItems - 1; i++) { + int localIdx = i - pagebegin; + + uint32_t currOffset = this->xtc->getChapterstartpage(i); + std::string dirTitle = this->xtc->getChapterTitleByIndex(i); + + Serial.printf("[%lu] [XTC_CHAPTER] 第%d章,名字为:%s,页码为%d\n", millis(), i, dirTitle.c_str(),currOffset); + static char title[64]; + strncpy(title, dirTitle.c_str(), sizeof(title)-1); + title[sizeof(title)-1] = '\0'; + + int drawY = BASE_Y + localIdx * FIX_LINE_HEIGHT; - const auto labels = mappedInput.mapLabels("« Back", "Select", "Up", "Down"); - renderer.drawButtonHints(UI_10_FONT_ID, labels.btn1, labels.btn2, labels.btn3, labels.btn4); + Serial.printf("选中的选项是:%d\n",selectorIndex); + renderer.drawText(UI_10_FONT_ID, 20, drawY, title, i!= selectorIndex); + } - renderer.displayBuffer(); -} + renderer.displayBuffer();