From bf77a0674166f47604481cc55dcd19e8ee8c0d31 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 10 Feb 2019 14:34:04 +0100 Subject: [PATCH] core/menusystem: new size variable for widget handling --- .../core/modules/menusystem/flowbox.lua | 26 +++++++-------- .../core/modules/menusystem/grid.lua | 32 +++++++++---------- .../core/modules/menusystem/listbox.lua | 17 +++++----- .../core/modules/menusystem/parent.lua | 6 ++++ .../core/modules/menusystem/textmenu.lua | 12 +++---- 5 files changed, 50 insertions(+), 43 deletions(-) diff --git a/sonic-boost.love/core/modules/menusystem/flowbox.lua b/sonic-boost.love/core/modules/menusystem/flowbox.lua index a2a88e5..df176bb 100644 --- a/sonic-boost.love/core/modules/menusystem/flowbox.lua +++ b/sonic-boost.love/core/modules/menusystem/flowbox.lua @@ -9,10 +9,10 @@ function FlowBox:new(x,y,w,h,slots_hor,slots_vert) self.slots_hor = slots_hor self.slots_vert = slots_vert self.begin = 1 - self.widgetsH = math.floor( self.h / slots_vert ) - self.widgetsW = math.floor( self.w / slots_hor ) - self.h = slots_vert * self.widgetsH -- On fait en sorte que la hauteur - self.w = slots_hor * self.widgetsW -- et la largeur + self.widget.h = math.floor( self.h / slots_vert ) + self.widget.w = math.floor( self.w / slots_hor ) + self.h = slots_vert * self.widget.h -- On fait en sorte que la hauteur + self.w = slots_hor * self.widget.w -- et la largeur -- soit un multiple du nombre de slot et de leur dimensions end @@ -109,8 +109,8 @@ function FlowBox:mousemoved(x, y) local begincol, beginline = self:getCoord(self.begin) local newcol, newline - newline = beginline + math.floor(y / self.widgetsH) - newcol = math.floor(x / self.widgetsW) + newline = beginline + math.floor(y / self.widget.h) + newcol = math.floor(x / self.widget.w) self.widget.selected = (newline * self.slots_hor) + newcol + 1 if self.widget.selected < 1 then @@ -126,8 +126,8 @@ function FlowBox:mousepressed(x, y, button, isTouch) local begincol, beginline = self:getCoord(self.begin) local newline, newcol - newline = beginline + math.floor(y / self.widgetsH) - newcol = math.floor(x / self.widgetsW) + newline = beginline + math.floor(y / self.widget.h) + newcol = math.floor(x / self.widget.w) self.widget.selected = (newline * self.slots_hor) + newcol + 1 if self.widget.selected < 1 then @@ -147,16 +147,16 @@ function FlowBox:draw() local widgetx = self.x for i,v in ipairs(self.widget.list) do if (i >= self.begin) and (i < self.begin + self.slots) then - v:draw(widgetx, widgety, self.widgetsW, self.widgetsH) + v:draw(widgetx, widgety, self.widget.w, self.widget.h) if self.widget.selected == i and self.focus == true then - v:drawSelected(widgetx, widgety, self.widgetsW, self.widgetsH) + v:drawSelected(widgetx, widgety, self.widget.w, self.widget.h) else - v:draw(widgetx, widgety, self.widgetsW, self.widgetsH) + v:draw(widgetx, widgety, self.widget.w, self.widget.h) end - widgetx = widgetx + self.widgetsW + widgetx = widgetx + self.widget.w if widgetx == (self.x + self.w) then widgetx = self.x - widgety = widgety + self.widgetsH + widgety = widgety + self.widget.h end end end diff --git a/sonic-boost.love/core/modules/menusystem/grid.lua b/sonic-boost.love/core/modules/menusystem/grid.lua index 05fb4f8..e9cf653 100644 --- a/sonic-boost.love/core/modules/menusystem/grid.lua +++ b/sonic-boost.love/core/modules/menusystem/grid.lua @@ -10,10 +10,10 @@ function GridBox:new(x,y,w,h,slots_hor,slots_vert) self.slots_hor = slots_hor self.slots_vert = slots_vert self.begin = 1 - self.widgetsH = math.floor( self.h / slots_vert ) - self.widgetsW = math.floor( self.w / slots_hor ) - self.h = slots_vert * self.widgetsH -- On fait en sorte que la hauteur - self.w = slots_hor * self.widgetsW -- et la largeur + self.widget.h = math.floor( self.h / slots_vert ) + self.widget.w = math.floor( self.w / slots_hor ) + self.h = slots_vert * self.widget.h -- On fait en sorte que la hauteur + self.w = slots_hor * self.widget.w -- et la largeur -- soit un multiple du nombre de slot et de leur dimensions self.cursor = {} self.cursor.x = 0 @@ -158,8 +158,8 @@ function GridBox:mousemoved(x, y) local newcol, newline local newselect, slotID - newline = beginline + math.floor(y / self.widgetsH) - newcol = math.floor(x / self.widgetsW) + newline = beginline + math.floor(y / self.widget.h) + newcol = math.floor(x / self.widget.w) self.cursor.x = newcol self.cursor.y = newline @@ -178,8 +178,8 @@ function GridBox:mousepressed(x, y, button, isTouch) local newcol, newline local newselect, slotID - newline = beginline + math.floor(y / self.widgetsH) - newcol = math.floor(x / self.widgetsW) + newline = beginline + math.floor(y / self.widget.h) + newcol = math.floor(x / self.widget.w) newselect = (newline * self.slots_hor) + newcol + 1 if self.listSlot[newselect].isSlave > 0 then @@ -202,30 +202,30 @@ function GridBox:draw() self:regenSlots() -- On reget les slots au cas où :p for i,v in ipairs(self.listSlot) do if (v.isSlave == 0) and (v.widgetID <= #self.widget.list) then - --self.widget.list[v.widgetID]:draw(widgetx, widgety, self.widgetsW * v.sizeW, self.widgetsH * v.sizeH) + --self.widget.list[v.widgetID]:draw(widgetx, widgety, self.widget.w * v.sizeW, self.widget.h * v.sizeH) if self.widget.selected == v.widgetID and self.focus == true then - self.widget.list[v.widgetID]:drawSelected(widgetx, widgety, self.widgetsW * v.sizeW, self.widgetsH * v.sizeH) + self.widget.list[v.widgetID]:drawSelected(widgetx, widgety, self.widget.w * v.sizeW, self.widget.h * v.sizeH) else - self.widget.list[v.widgetID]:draw(widgetx, widgety, self.widgetsW * v.sizeW, self.widgetsH * v.sizeH) + self.widget.list[v.widgetID]:draw(widgetx, widgety, self.widget.w * v.sizeW, self.widget.h * v.sizeH) end end if (v.isSlave > 0) and false then love.graphics.setColor(255,255,255,128) - love.graphics.rectangle("fill", widgetx, widgety, self.widgetsW, self.widgetsH) + love.graphics.rectangle("fill", widgetx, widgety, self.widget.w, self.widget.h) end local col, line = self:getCoord(i) if (col == self.cursor.x) and (line == self.cursor.y) and false then love.graphics.setColor(255,255,0,128) - love.graphics.rectangle("fill", widgetx, widgety, self.widgetsW, self.widgetsH) + love.graphics.rectangle("fill", widgetx, widgety, self.widget.w, self.widget.h) end --love.graphics.setColor(0,0,0,10) - --love.graphics.rectangle("line", widgetx, widgety, self.widgetsW, self.widgetsH) - widgetx = widgetx + self.widgetsW + --love.graphics.rectangle("line", widgetx, widgety, self.widget.w, self.widget.h) + widgetx = widgetx + self.widget.w if widgetx == (self.x + self.w) then widgetx = self.x - widgety = widgety + self.widgetsH + widgety = widgety + self.widget.h end end end diff --git a/sonic-boost.love/core/modules/menusystem/listbox.lua b/sonic-boost.love/core/modules/menusystem/listbox.lua index c9b023e..ae593db 100644 --- a/sonic-boost.love/core/modules/menusystem/listbox.lua +++ b/sonic-boost.love/core/modules/menusystem/listbox.lua @@ -7,8 +7,9 @@ function ListBox:new(x,y,w,h,slots) ListBox.super.new(self, x, y, w, h) self.slots = slots self.begin = 1 - self.widgetsH = math.floor( self.h / slots ) - self.h = slots * self.widgetsH -- On fait en sorte que la hauteur + self.widget.w = self.w + self.widget.h = math.floor( self.h / slots ) + self.h = slots * self.widget.h -- On fait en sorte que la hauteur -- soit un multiple du nombre de slot et de leur hauteur end @@ -42,7 +43,7 @@ function ListBox:keyreleased(key, code) end function ListBox:mousemoved(x, y) - self.widget.selected = self.begin + math.floor(y / self.widgetsH) + self.widget.selected = self.begin + math.floor(y / self.widget.h) if self.widget.selected < 1 then self.widget.selected = 1 end @@ -52,7 +53,7 @@ function ListBox:mousemoved(x, y) end function ListBox:mousepressed(x, y, button, isTouch) - self.widget.selected = self.begin + math.floor(y / self.widgetsH) + self.widget.selected = self.begin + math.floor(y / self.widget.h) if self.widget.selected < 1 then self.widget.selected = 1 end @@ -68,13 +69,13 @@ function ListBox:draw() local widgety = self.y for i,v in ipairs(self.widget.list) do if (i >= self.begin) and (i < self.begin + self.slots) then - v:draw(self.x, widgety, self.w, self.widgetsH) + v:draw(self.x, widgety, self.w, self.widget.h) if self.widget.selected == i and self.focus == true then - v:drawSelected(self.x, widgety, self.w, self.widgetsH) + v:drawSelected(self.x, widgety, self.w, self.widget.h) else - v:draw(self.x, widgety, self.w, self.widgetsH) + v:draw(self.x, widgety, self.w, self.widget.h) end - widgety = widgety + self.widgetsH + widgety = widgety + self.widget.h end end end diff --git a/sonic-boost.love/core/modules/menusystem/parent.lua b/sonic-boost.love/core/modules/menusystem/parent.lua index c4834da..8cf64f5 100644 --- a/sonic-boost.love/core/modules/menusystem/parent.lua +++ b/sonic-boost.love/core/modules/menusystem/parent.lua @@ -11,6 +11,8 @@ function Menu:new(x,y,w,h) self.widget.selected = 0 self.widget.selectedPrevious = 0 self.widget.cancel = 0 + self.widget.h = 0 + self.widget.w = 0 self.isdestroyed = false self.focus = false @@ -28,6 +30,10 @@ function Menu:setCancelWidget(id) self.widget.cancel = #self.widget.list end +function Menu:getWidgetSize(id) + return self.widget.h, self.widget.w +end + function Menu:cancelAction() if (self.widget.cancel ~= 0) then self.widget.list[self.widget.cancel]:action() diff --git a/sonic-boost.love/core/modules/menusystem/textmenu.lua b/sonic-boost.love/core/modules/menusystem/textmenu.lua index ac2ce9a..39f2d20 100644 --- a/sonic-boost.love/core/modules/menusystem/textmenu.lua +++ b/sonic-boost.love/core/modules/menusystem/textmenu.lua @@ -18,8 +18,8 @@ end function TextMenu:getBoundingBox() self:setWidthAuto() - self.widgetsH = self.font:getHeight() - self.h = self.widgetsH * self.slots + self.widget.h = self.font:getHeight() + self.h = self.widget.h * self.slots if self.align == "right" then self.x = self.ox - self.w @@ -103,7 +103,7 @@ end function TextMenu:mousemoved(x, y) local selectedPrevous = self.widget.selected - self.widget.selected = self.begin + math.floor(y / self.widgetsH) + self.widget.selected = self.begin + math.floor(y / self.widget.h) if self.widget.selected < 1 then self.widget.selected = 1 end @@ -117,7 +117,7 @@ function TextMenu:mousemoved(x, y) end function TextMenu:mousepressed(x, y, button, isTouch) - self.widget.selected = self.begin + math.floor(y / self.widgetsH) + self.widget.selected = self.begin + math.floor(y / self.widget.h) if self.widget.selected < 1 then self.widget.selected = 1 end @@ -150,7 +150,7 @@ function TextMenu:drawCanvas() if (i >= self.begin) and (i < self.begin + self.slots) then self:drawWidget(i, widgety) - widgety = widgety + self.widgetsH + widgety = widgety + self.widget.h end end utils.draw.resetColor() @@ -176,7 +176,7 @@ function TextMenu:drawWidget(widgetID, y) end function TextMenu:drawWidgetCanvas(widget) - widget.canvas.texture = love.graphics.newCanvas(self.w, self.widgetsH) + widget.canvas.texture = love.graphics.newCanvas(self.w, self.widget.h) love.graphics.setCanvas( widget.canvas.texture )