core/menusystem: new size variable for widget handling

This commit is contained in:
Kazhnuz 2019-02-10 14:34:04 +01:00
parent 05c8691c56
commit bf77a06741
5 changed files with 50 additions and 43 deletions

View file

@ -9,10 +9,10 @@ function FlowBox:new(x,y,w,h,slots_hor,slots_vert)
self.slots_hor = slots_hor self.slots_hor = slots_hor
self.slots_vert = slots_vert self.slots_vert = slots_vert
self.begin = 1 self.begin = 1
self.widgetsH = math.floor( self.h / slots_vert ) self.widget.h = math.floor( self.h / slots_vert )
self.widgetsW = math.floor( self.w / slots_hor ) self.widget.w = math.floor( self.w / slots_hor )
self.h = slots_vert * self.widgetsH -- On fait en sorte que la hauteur self.h = slots_vert * self.widget.h -- On fait en sorte que la hauteur
self.w = slots_hor * self.widgetsW -- et la largeur self.w = slots_hor * self.widget.w -- et la largeur
-- soit un multiple du nombre de slot et de leur dimensions -- soit un multiple du nombre de slot et de leur dimensions
end end
@ -109,8 +109,8 @@ function FlowBox:mousemoved(x, y)
local begincol, beginline = self:getCoord(self.begin) local begincol, beginline = self:getCoord(self.begin)
local newcol, newline local newcol, newline
newline = beginline + math.floor(y / self.widgetsH) newline = beginline + math.floor(y / self.widget.h)
newcol = math.floor(x / self.widgetsW) newcol = math.floor(x / self.widget.w)
self.widget.selected = (newline * self.slots_hor) + newcol + 1 self.widget.selected = (newline * self.slots_hor) + newcol + 1
if self.widget.selected < 1 then 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 begincol, beginline = self:getCoord(self.begin)
local newline, newcol local newline, newcol
newline = beginline + math.floor(y / self.widgetsH) newline = beginline + math.floor(y / self.widget.h)
newcol = math.floor(x / self.widgetsW) newcol = math.floor(x / self.widget.w)
self.widget.selected = (newline * self.slots_hor) + newcol + 1 self.widget.selected = (newline * self.slots_hor) + newcol + 1
if self.widget.selected < 1 then if self.widget.selected < 1 then
@ -147,16 +147,16 @@ function FlowBox:draw()
local widgetx = self.x local widgetx = self.x
for i,v in ipairs(self.widget.list) do for i,v in ipairs(self.widget.list) do
if (i >= self.begin) and (i < self.begin + self.slots) then 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 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 else
v:draw(widgetx, widgety, self.widgetsW, self.widgetsH) v:draw(widgetx, widgety, self.widget.w, self.widget.h)
end end
widgetx = widgetx + self.widgetsW widgetx = widgetx + self.widget.w
if widgetx == (self.x + self.w) then if widgetx == (self.x + self.w) then
widgetx = self.x widgetx = self.x
widgety = widgety + self.widgetsH widgety = widgety + self.widget.h
end end
end end
end end

View file

@ -10,10 +10,10 @@ function GridBox:new(x,y,w,h,slots_hor,slots_vert)
self.slots_hor = slots_hor self.slots_hor = slots_hor
self.slots_vert = slots_vert self.slots_vert = slots_vert
self.begin = 1 self.begin = 1
self.widgetsH = math.floor( self.h / slots_vert ) self.widget.h = math.floor( self.h / slots_vert )
self.widgetsW = math.floor( self.w / slots_hor ) self.widget.w = math.floor( self.w / slots_hor )
self.h = slots_vert * self.widgetsH -- On fait en sorte que la hauteur self.h = slots_vert * self.widget.h -- On fait en sorte que la hauteur
self.w = slots_hor * self.widgetsW -- et la largeur self.w = slots_hor * self.widget.w -- et la largeur
-- soit un multiple du nombre de slot et de leur dimensions -- soit un multiple du nombre de slot et de leur dimensions
self.cursor = {} self.cursor = {}
self.cursor.x = 0 self.cursor.x = 0
@ -158,8 +158,8 @@ function GridBox:mousemoved(x, y)
local newcol, newline local newcol, newline
local newselect, slotID local newselect, slotID
newline = beginline + math.floor(y / self.widgetsH) newline = beginline + math.floor(y / self.widget.h)
newcol = math.floor(x / self.widgetsW) newcol = math.floor(x / self.widget.w)
self.cursor.x = newcol self.cursor.x = newcol
self.cursor.y = newline self.cursor.y = newline
@ -178,8 +178,8 @@ function GridBox:mousepressed(x, y, button, isTouch)
local newcol, newline local newcol, newline
local newselect, slotID local newselect, slotID
newline = beginline + math.floor(y / self.widgetsH) newline = beginline + math.floor(y / self.widget.h)
newcol = math.floor(x / self.widgetsW) newcol = math.floor(x / self.widget.w)
newselect = (newline * self.slots_hor) + newcol + 1 newselect = (newline * self.slots_hor) + newcol + 1
if self.listSlot[newselect].isSlave > 0 then if self.listSlot[newselect].isSlave > 0 then
@ -202,30 +202,30 @@ function GridBox:draw()
self:regenSlots() -- On reget les slots au cas où :p self:regenSlots() -- On reget les slots au cas où :p
for i,v in ipairs(self.listSlot) do for i,v in ipairs(self.listSlot) do
if (v.isSlave == 0) and (v.widgetID <= #self.widget.list) then 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 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 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
end end
if (v.isSlave > 0) and false then if (v.isSlave > 0) and false then
love.graphics.setColor(255,255,255,128) 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 end
local col, line = self:getCoord(i) local col, line = self:getCoord(i)
if (col == self.cursor.x) and (line == self.cursor.y) and false then if (col == self.cursor.x) and (line == self.cursor.y) and false then
love.graphics.setColor(255,255,0,128) 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 end
--love.graphics.setColor(0,0,0,10) --love.graphics.setColor(0,0,0,10)
--love.graphics.rectangle("line", widgetx, widgety, self.widgetsW, self.widgetsH) --love.graphics.rectangle("line", widgetx, widgety, self.widget.w, self.widget.h)
widgetx = widgetx + self.widgetsW widgetx = widgetx + self.widget.w
if widgetx == (self.x + self.w) then if widgetx == (self.x + self.w) then
widgetx = self.x widgetx = self.x
widgety = widgety + self.widgetsH widgety = widgety + self.widget.h
end end
end end
end end

View file

@ -7,8 +7,9 @@ function ListBox:new(x,y,w,h,slots)
ListBox.super.new(self, x, y, w, h) ListBox.super.new(self, x, y, w, h)
self.slots = slots self.slots = slots
self.begin = 1 self.begin = 1
self.widgetsH = math.floor( self.h / slots ) self.widget.w = self.w
self.h = slots * self.widgetsH -- On fait en sorte que la hauteur 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 -- soit un multiple du nombre de slot et de leur hauteur
end end
@ -42,7 +43,7 @@ function ListBox:keyreleased(key, code)
end end
function ListBox:mousemoved(x, y) 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 if self.widget.selected < 1 then
self.widget.selected = 1 self.widget.selected = 1
end end
@ -52,7 +53,7 @@ function ListBox:mousemoved(x, y)
end end
function ListBox:mousepressed(x, y, button, isTouch) 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 if self.widget.selected < 1 then
self.widget.selected = 1 self.widget.selected = 1
end end
@ -68,13 +69,13 @@ function ListBox:draw()
local widgety = self.y local widgety = self.y
for i,v in ipairs(self.widget.list) do for i,v in ipairs(self.widget.list) do
if (i >= self.begin) and (i < self.begin + self.slots) then 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 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 else
v:draw(self.x, widgety, self.w, self.widgetsH) v:draw(self.x, widgety, self.w, self.widget.h)
end end
widgety = widgety + self.widgetsH widgety = widgety + self.widget.h
end end
end end
end end

View file

@ -11,6 +11,8 @@ function Menu:new(x,y,w,h)
self.widget.selected = 0 self.widget.selected = 0
self.widget.selectedPrevious = 0 self.widget.selectedPrevious = 0
self.widget.cancel = 0 self.widget.cancel = 0
self.widget.h = 0
self.widget.w = 0
self.isdestroyed = false self.isdestroyed = false
self.focus = false self.focus = false
@ -28,6 +30,10 @@ function Menu:setCancelWidget(id)
self.widget.cancel = #self.widget.list self.widget.cancel = #self.widget.list
end end
function Menu:getWidgetSize(id)
return self.widget.h, self.widget.w
end
function Menu:cancelAction() function Menu:cancelAction()
if (self.widget.cancel ~= 0) then if (self.widget.cancel ~= 0) then
self.widget.list[self.widget.cancel]:action() self.widget.list[self.widget.cancel]:action()

View file

@ -18,8 +18,8 @@ end
function TextMenu:getBoundingBox() function TextMenu:getBoundingBox()
self:setWidthAuto() self:setWidthAuto()
self.widgetsH = self.font:getHeight() self.widget.h = self.font:getHeight()
self.h = self.widgetsH * self.slots self.h = self.widget.h * self.slots
if self.align == "right" then if self.align == "right" then
self.x = self.ox - self.w self.x = self.ox - self.w
@ -103,7 +103,7 @@ end
function TextMenu:mousemoved(x, y) function TextMenu:mousemoved(x, y)
local selectedPrevous = self.widget.selected 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 if self.widget.selected < 1 then
self.widget.selected = 1 self.widget.selected = 1
end end
@ -117,7 +117,7 @@ function TextMenu:mousemoved(x, y)
end end
function TextMenu:mousepressed(x, y, button, isTouch) 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 if self.widget.selected < 1 then
self.widget.selected = 1 self.widget.selected = 1
end end
@ -150,7 +150,7 @@ function TextMenu:drawCanvas()
if (i >= self.begin) and (i < self.begin + self.slots) then if (i >= self.begin) and (i < self.begin + self.slots) then
self:drawWidget(i, widgety) self:drawWidget(i, widgety)
widgety = widgety + self.widgetsH widgety = widgety + self.widget.h
end end
end end
utils.draw.resetColor() utils.draw.resetColor()
@ -176,7 +176,7 @@ function TextMenu:drawWidget(widgetID, y)
end end
function TextMenu:drawWidgetCanvas(widget) 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 ) love.graphics.setCanvas( widget.canvas.texture )