mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-06 15:47:39 +03:00
Update XtcReaderChapterSelectionActivity.cpp
This commit is contained in:
parent
b19e0b3c80
commit
93be1e072b
@ -84,32 +84,31 @@ void XtcReaderChapterSelectionActivity::loop() {
|
|||||||
const int pageItems = getPageItems();
|
const int pageItems = getPageItems();
|
||||||
|
|
||||||
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
|
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<int>(chapters.size())) {
|
if (!chapters.empty() && selectorIndex >= 0 && selectorIndex < static_cast<int>(chapters.size())) {
|
||||||
onSelectPage(chapters[selectorIndex].startPage);
|
onSelectPage(chapters[selectorIndex].startPage);
|
||||||
}
|
}
|
||||||
} else if (mappedInput.wasReleased(MappedInputManager::Button::Back)) {
|
} else if (mappedInput.wasReleased(MappedInputManager::Button::Back)) {
|
||||||
onGoBack();
|
onGoBack();
|
||||||
} else if (prevReleased) {
|
} else if (prevReleased) {
|
||||||
const int total = static_cast<int>(xtc->getChapters().size());
|
bool isUpKey = mappedInput.wasReleased(MappedInputManager::Button::Up);
|
||||||
if (total == 0) {
|
if (skipPage || isUpKey) {
|
||||||
return;
|
page -= 1;
|
||||||
}
|
if(page < 1) page = 1;
|
||||||
if (skipPage) {
|
selectorIndex = (page-1)*pageItems;
|
||||||
selectorIndex = ((selectorIndex / pageItems - 1) * pageItems + total) % total;
|
|
||||||
} else {
|
} else {
|
||||||
selectorIndex = (selectorIndex + total - 1) % total;
|
selectorIndex--;
|
||||||
|
if(selectorIndex < 0) selectorIndex = 0;
|
||||||
}
|
}
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
} else if (nextReleased) {
|
} else if (nextReleased) {
|
||||||
const int total = static_cast<int>(xtc->getChapters().size());
|
bool isDownKey = mappedInput.wasReleased(MappedInputManager::Button::Down);
|
||||||
if (total == 0) {
|
if (skipPage || isDownKey) {
|
||||||
return;
|
page += 1;
|
||||||
}
|
selectorIndex = (page-1)*pageItems;
|
||||||
if (skipPage) {
|
|
||||||
selectorIndex = ((selectorIndex / pageItems + 1) * pageItems) % total;
|
|
||||||
} else {
|
} else {
|
||||||
selectorIndex = (selectorIndex + 1) % total;
|
selectorIndex++;
|
||||||
}
|
}
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
}
|
}
|
||||||
@ -143,14 +142,21 @@ void XtcReaderChapterSelectionActivity::renderScreen() {
|
|||||||
|
|
||||||
const auto pageStartIndex = selectorIndex / pageItems * pageItems;
|
const auto pageStartIndex = selectorIndex / pageItems * pageItems;
|
||||||
renderer.fillRect(0, 60 + (selectorIndex % pageItems) * 30 - 2, pageWidth - 1, 30);
|
renderer.fillRect(0, 60 + (selectorIndex % pageItems) * 30 - 2, pageWidth - 1, 30);
|
||||||
for (int i = pageStartIndex; i < static_cast<int>(chapters.size()) && i < pageStartIndex + pageItems; i++) {
|
for (int i = pagebegin; i <= pagebegin + pageItems - 1; i++) {
|
||||||
const auto& chapter = chapters[i];
|
int localIdx = i - pagebegin;
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto labels = mappedInput.mapLabels("« Back", "Select", "Up", "Down");
|
uint32_t currOffset = this->xtc->getChapterstartpage(i);
|
||||||
renderer.drawButtonHints(UI_10_FONT_ID, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
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;
|
||||||
|
|
||||||
|
Serial.printf("选中的选项是:%d\n",selectorIndex);
|
||||||
|
renderer.drawText(UI_10_FONT_ID, 20, drawY, title, i!= selectorIndex);
|
||||||
|
}
|
||||||
|
|
||||||
renderer.displayBuffer();
|
renderer.displayBuffer();
|
||||||
}
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user