From 997a66e90153169b532f72835820b00ae13139fd Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 12 Feb 2019 18:58:26 +0100 Subject: [PATCH] core/menusystem: don't draw cursor and allow selection when it overflow --- .../core/modules/menusystem/flowbox.lua | 16 ++++++++++------ .../core/modules/menusystem/listbox.lua | 12 ++++++++---- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/sonic-boost.love/core/modules/menusystem/flowbox.lua b/sonic-boost.love/core/modules/menusystem/flowbox.lua index f1d2f23..2da91c8 100644 --- a/sonic-boost.love/core/modules/menusystem/flowbox.lua +++ b/sonic-boost.love/core/modules/menusystem/flowbox.lua @@ -107,7 +107,9 @@ function FlowBox:keyreleased(key, code) end if key == "A" then - self.widget.list[self.widget.selected]:action() + if (self.widget.selected >= 1 and self.widget.selected <= #self.widget.list) then + self.widget.list[self.widget.selected]:action() + end end end @@ -164,11 +166,13 @@ function FlowBox:draw() end function FlowBox:drawCursor() - local w, h = self:getWidgetSize() - local col, line = self:getCoord(self.widget.selected) - local x = (col) * h - local y = (line) * h - menuutils.drawCursor(self.x + x, self.y + y, w, h) + if (self.widget.selected >= 1 and self.widget.selected <= #self.widget.list) then + local w, h = self:getWidgetSize() + local col, line = self:getCoord(self.widget.selected) + local x = (col) * h + local y = (line) * h + menuutils.drawCursor(self.x + x, self.y + y, w, h) + end end return FlowBox diff --git a/sonic-boost.love/core/modules/menusystem/listbox.lua b/sonic-boost.love/core/modules/menusystem/listbox.lua index e2643d9..04f43ed 100644 --- a/sonic-boost.love/core/modules/menusystem/listbox.lua +++ b/sonic-boost.love/core/modules/menusystem/listbox.lua @@ -42,7 +42,9 @@ function ListBox:keyreleased(key, code) end if key == "A" then - self.widget.list[self.widget.selected]:action() + if (self.widget.selected >= 1 and self.widget.selected <= #self.widget.list) then + self.widget.list[self.widget.selected]:action() + end end end @@ -85,9 +87,11 @@ function ListBox:draw() end function ListBox:drawCursor() - local w, h = self:getWidgetSize() - local y = (self.widget.selected - 1) * h - menuutils.drawCursor(self.x,self.y + y, w, h) + if (self.widget.selected >= 1 and self.widget.selected <= #self.widget.list) then + local w, h = self:getWidgetSize() + local y = (self.widget.selected - 1) * h + menuutils.drawCursor(self.x,self.y + y, w, h) + end end return ListBox