From 4f157f307aa07d47c2b59da801aa713e1120941c Mon Sep 17 00:00:00 2001 From: Cadin Batrack Date: Sat, 30 Sep 2023 10:56:45 -0700 Subject: [PATCH 1/2] resolve chapter menu index bug --- Panels.lua | 3 +++ modules/Menus.lua | 24 +++++++++++++----------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Panels.lua b/Panels.lua index 48458a9..025d52f 100644 --- a/Panels.lua +++ b/Panels.lua @@ -1,3 +1,6 @@ +-- Panels version 1.5.1 +-- https://cadin.github.io/panels/ + import "CoreLibs/object" import "CoreLibs/graphics" import "CoreLibs/sprites" diff --git a/modules/Menus.lua b/modules/Menus.lua index f3aaf7a..a5917d2 100644 --- a/modules/Menus.lua +++ b/modules/Menus.lua @@ -279,7 +279,9 @@ end local function isLastUnlockedSequence(index) for i = index + 1, #Panels.unlockedSequences, 1 do - if Panels.unlockedSequences[i] == true then + if i > #sections then return true end + local sectionIndex = sections[i].index + if Panels.unlockedSequences[sectionIndex] == true then return false end end @@ -288,7 +290,8 @@ end local function isFirstUnlockedSequence(index) for i = index - 1, 1, -1 do - if Panels.unlockedSequences[i] == true then + local sectionIndex = sections[i].index + if Panels.unlockedSequences[sectionIndex] == true then return false end end @@ -297,7 +300,8 @@ end local function getNextUnlockedSequence(index) for i = index + 1, #Panels.unlockedSequences, 1 do - if Panels.unlockedSequences[i] == true then + local sectionIndex = sections[i].index + if Panels.unlockedSequences[sectionIndex] == true then return i end end @@ -306,7 +310,8 @@ end local function getPreviousUnlockedSequence(index) for i = index - 1, 1, -1 do - if Panels.unlockedSequences[i] == true then + local sectionIndex = sections[i].index + if Panels.unlockedSequences[sectionIndex] == true then return i end end @@ -341,9 +346,8 @@ local function createChapterMenu(data) local selectedRow = chapterList:getSelectedRow() local item = sections[selectedRow] if not isLastUnlockedSequence(item.index) then - local next = getNextUnlockedSequence(item.index) - local row = getRowForSequenceIndex(next) - chapterList:setSelectedRow(row) + local next = getNextUnlockedSequence(selectedRow) + chapterList:setSelectedRow(next) if Panels.Settings.playMenuSounds then selectionSound:play() end @@ -361,9 +365,8 @@ local function createChapterMenu(data) local item = sections[selectedRow] if not isFirstUnlockedSequence(item.index) then - local prev = getPreviousUnlockedSequence(item.index) - local row = getRowForSequenceIndex(prev) - chapterList:setSelectedRow(row) + local prev = getPreviousUnlockedSequence(selectedRow) + chapterList:setSelectedRow(prev) if Panels.Settings.playMenuSounds then selectionRevSound:play() end @@ -399,7 +402,6 @@ function chapterList:drawCell(section, row, column, selected, x, y, width, heigh if selected then gfx.setColor(gfx.kColorBlack) gfx.fillRoundRect(x, y + chapterOffset, width, height, 4) - -- gfx.drawRoundRect(x + 1, y, width - 2, height, 4) gfx.setImageDrawMode(gfx.kDrawModeFillWhite) chapterOffset = 0 else From 68ca0b1bfd38a79a4e1e521c7b80716c3bfcc585 Mon Sep 17 00:00:00 2001 From: Cadin Batrack Date: Sat, 30 Sep 2023 11:06:35 -0700 Subject: [PATCH 2/2] fix indexing in input handlers too --- modules/Menus.lua | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/modules/Menus.lua b/modules/Menus.lua index a5917d2..d8f46dd 100644 --- a/modules/Menus.lua +++ b/modules/Menus.lua @@ -344,8 +344,7 @@ local function createChapterMenu(data) downButtonUp = function() chapterOffset = 4 local selectedRow = chapterList:getSelectedRow() - local item = sections[selectedRow] - if not isLastUnlockedSequence(item.index) then + if not isLastUnlockedSequence(selectedRow) then local next = getNextUnlockedSequence(selectedRow) chapterList:setSelectedRow(next) if Panels.Settings.playMenuSounds then @@ -360,11 +359,8 @@ local function createChapterMenu(data) upButtonUp = function() chapterOffset = -4 - local selectedRow = chapterList:getSelectedRow() - local item = sections[selectedRow] - - if not isFirstUnlockedSequence(item.index) then + if not isFirstUnlockedSequence(selectedRow) then local prev = getPreviousUnlockedSequence(selectedRow) chapterList:setSelectedRow(prev) if Panels.Settings.playMenuSounds then