Fix next/previous section button weirdness

This commit is contained in:
Electroblob77
2021-06-19 16:19:22 +01:00
parent 95d9168b6b
commit 8fd1de84e4
@@ -496,24 +496,30 @@ public class GuiWizardHandbook extends GuiScreen {
Section currentSection = null; Section currentSection = null;
if(currentPage < singleToDoublePage(pageCount)){
// Find current section
for(Section section : sections.values()){ for(Section section : sections.values()){
// We always want this button to do something, and taking the right-hand page means it always does // Take the right-hand page if going to the next section, and the left-hand page otherwise
if(section.containsPage(doubleToSinglePage(currentPage, true))){ if(section.containsPage(doubleToSinglePage(currentPage, button == nextSection))){
currentSection = section; currentSection = section;
break; break;
} }
} }
}
if(currentSection != null){
List<Section> visibleSections = new ArrayList<>(sectionList); List<Section> visibleSections = new ArrayList<>(sectionList);
visibleSections.removeIf(s -> !s.isUnlocked()); visibleSections.removeIf(s -> !s.isUnlocked());
int index = visibleSections.indexOf(currentSection); int index = currentSection == null ? visibleSections.size() : visibleSections.indexOf(currentSection);
if(button == nextSection && index + 1 < visibleSections.size()){ if(button == nextSection){
if(index + 1 < visibleSections.size()){
currentPage = singleToDoublePage(visibleSections.get(index + 1).startPage); currentPage = singleToDoublePage(visibleSections.get(index + 1).startPage);
}else if(index > 0){ }else{
currentPage = singleToDoublePage(pageCount);
}
}else{
if(index > 0){
currentPage = singleToDoublePage(visibleSections.get(index - 1).startPage); currentPage = singleToDoublePage(visibleSections.get(index - 1).startPage);
} }
} }