core/menusystem: port everything to new widget var names

This commit is contained in:
Kazhnuz 2019-02-10 14:28:08 +01:00
parent 9d413db186
commit 05c8691c56
4 changed files with 94 additions and 94 deletions

View file

@ -17,7 +17,7 @@ function FlowBox:new(x,y,w,h,slots_hor,slots_vert)
end
function FlowBox:update(dt)
local col, line = self:getCoord(self.selected)
local col, line = self:getCoord(self.widget.selected)
local begincol, beginline = self:getCoord(self.begin)
if line < beginline then
@ -44,8 +44,8 @@ function FlowBox:getCoord(id_selected)
end
function FlowBox:moveCursor(new_col, new_line)
local col, line = self:getCoord(self.selected)
local lastcol, lastline = self:getCoord(#self.listWidget)
local col, line = self:getCoord(self.widget.selected)
local lastcol, lastline = self:getCoord(#self.widget.list)
if new_line < 0 then
@ -78,11 +78,11 @@ function FlowBox:moveCursor(new_col, new_line)
end
end
self.selected = (new_line * self.slots_hor) + new_col + 1
self.widget.selected = (new_line * self.slots_hor) + new_col + 1
end
function FlowBox:keyreleased(key, code)
local col, line = self:getCoord(self.selected)
local col, line = self:getCoord(self.widget.selected)
if key == 'left' then
self:moveCursor(col - 1, line)
end
@ -100,55 +100,55 @@ function FlowBox:keyreleased(key, code)
end
if key == "A" then
self.listWidget[self.selected]:action()
self.widget.list[self.widget.selected]:action()
end
end
function FlowBox:mousemoved(x, y)
local col, line = self:getCoord(self.selected)
local col, line = self:getCoord(self.widget.selected)
local begincol, beginline = self:getCoord(self.begin)
local newcol, newline
newline = beginline + math.floor(y / self.widgetsH)
newcol = math.floor(x / self.widgetsW)
self.selected = (newline * self.slots_hor) + newcol + 1
self.widget.selected = (newline * self.slots_hor) + newcol + 1
if self.selected < 1 then
self.selected = 1
if self.widget.selected < 1 then
self.widget.selected = 1
end
if self.selected > #self.listWidget then
self.selected = #self.listWidget
if self.widget.selected > #self.widget.list then
self.widget.selected = #self.widget.list
end
end
function FlowBox:mousepressed(x, y, button, isTouch)
local col, line = self:getCoord(self.selected)
local col, line = self:getCoord(self.widget.selected)
local begincol, beginline = self:getCoord(self.begin)
local newline, newcol
newline = beginline + math.floor(y / self.widgetsH)
newcol = math.floor(x / self.widgetsW)
self.selected = (newline * self.slots_hor) + newcol + 1
self.widget.selected = (newline * self.slots_hor) + newcol + 1
if self.selected < 1 then
self.selected = 1
if self.widget.selected < 1 then
self.widget.selected = 1
end
if self.selected > #self.listWidget then
self.selected = #self.listWidget
if self.widget.selected > #self.widget.list then
self.widget.selected = #self.widget.list
end
if #self.listWidget > 0 then
self.listWidget[self.selected]:action()
if #self.widget.list > 0 then
self.widget.list[self.widget.selected]:action()
end
end
function FlowBox:draw()
local widgety = self.y
local widgetx = self.x
for i,v in ipairs(self.listWidget) do
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)
if self.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)
else
v:draw(widgetx, widgety, self.widgetsW, self.widgetsH)

View file

@ -37,14 +37,14 @@ function GridBox:update(dt)
if self.listSlot[slotID].isSlave > 0 then
slotID = self.listSlot[slotID].isSlave
end
self.selected = self.listSlot[slotID].widgetID
self.widget.selected = self.listSlot[slotID].widgetID
self.cursor.x, self.cursor.y = self:getCoord(slotID)
end
function GridBox:regenSlots()
local widgetID = 1
for i,v in ipairs(self.listSlot) do
if v.isSlave == 0 and (widgetID <= #self.listWidget) then
if v.isSlave == 0 and (widgetID <= #self.widget.list) then
self.listSlot[i].widgetID = widgetID
widgetID = widgetID + 1
end
@ -118,8 +118,8 @@ function GridBox:moveCursor(newcol, newline)
previousSlot = self:getSlotbyCoord(col, line)
newSlot = self:getSlotbyCoord(self.cursor.x, self.cursor.y)
if (self.listSlot[newSlot].isSlave > 0) or (self.listSlot[newSlot].widgetID > #self.listWidget) then
if (self.listSlot[newSlot].isSlave == previousSlot) or (self.listSlot[newSlot].widgetID > #self.listWidget) then
if (self.listSlot[newSlot].isSlave > 0) or (self.listSlot[newSlot].widgetID > #self.widget.list) then
if (self.listSlot[newSlot].isSlave == previousSlot) or (self.listSlot[newSlot].widgetID > #self.widget.list) then
self:moveCursor(self.cursor.x + relcol, self.cursor.y + relline)
end
end
@ -127,7 +127,7 @@ function GridBox:moveCursor(newcol, newline)
end
function GridBox:keyreleased(key, code)
slotID = self:getSlot(self.selected)
slotID = self:getSlot(self.widget.selected)
local col, line = self.cursor.x, self.cursor.y
if key == 'left' then
--self:moveCol(-1)
@ -147,13 +147,13 @@ function GridBox:keyreleased(key, code)
self:moveCursor(col, line + 1)
end
if key == "A" and self.selected <= #self.listWidget then
self.listWidget[self.selected]:action()
if key == "A" and self.widget.selected <= #self.widget.list then
self.widget.list[self.widget.selected]:action()
end
end
function GridBox:mousemoved(x, y)
local col, line = self:getCoord(self.selected)
local col, line = self:getCoord(self.widget.selected)
local begincol, beginline = self:getCoord(self.begin)
local newcol, newline
local newselect, slotID
@ -163,17 +163,17 @@ function GridBox:mousemoved(x, y)
self.cursor.x = newcol
self.cursor.y = newline
if self.selected < 1 then
self.selected = 1
if self.widget.selected < 1 then
self.widget.selected = 1
end
if self.selected > #self.listWidget then
self.selected = #self.listWidget
if self.widget.selected > #self.widget.list then
self.widget.selected = #self.widget.list
end
end
function GridBox:mousepressed(x, y, button, isTouch)
local col, line = self:getCoord(self.selected)
local col, line = self:getCoord(self.widget.selected)
local begincol, beginline = self:getCoord(self.begin)
local newcol, newline
local newselect, slotID
@ -188,10 +188,10 @@ function GridBox:mousepressed(x, y, button, isTouch)
slotID = newselect
end
self.selected = self.listSlot[slotID].widgetID
self.widget.selected = self.listSlot[slotID].widgetID
if #self.listWidget > 0 and self.selected > 1 and self.selected <= #self.listWidget then
self.listWidget[self.selected]:action()
if #self.widget.list > 0 and self.widget.selected > 1 and self.widget.selected <= #self.widget.list then
self.widget.list[self.widget.selected]:action()
end
end
@ -201,12 +201,12 @@ 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.listWidget) then
--self.listWidget[v.widgetID]:draw(widgetx, widgety, self.widgetsW * v.sizeW, self.widgetsH * v.sizeH)
if self.selected == v.widgetID and self.focus == true then
self.listWidget[v.widgetID]:drawSelected(widgetx, widgety, self.widgetsW * v.sizeW, self.widgetsH * v.sizeH)
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)
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)
else
self.listWidget[v.widgetID]:draw(widgetx, widgety, self.widgetsW * v.sizeW, self.widgetsH * v.sizeH)
self.widget.list[v.widgetID]:draw(widgetx, widgety, self.widgetsW * v.sizeW, self.widgetsH * v.sizeH)
end
end
if (v.isSlave > 0) and false then

View file

@ -13,11 +13,11 @@ function ListBox:new(x,y,w,h,slots)
end
function ListBox:update(dt)
if self.selected < self.begin then
self.begin = self.selected
if self.widget.selected < self.begin then
self.begin = self.widget.selected
end
if self.selected > self.begin + self.slots - 1 then
self.begin = self.selected - self.slots + 1
if self.widget.selected > self.begin + self.slots - 1 then
self.begin = self.widget.selected - self.slots + 1
end
if self.begin < 1 then
@ -28,48 +28,48 @@ end
function ListBox:keyreleased(key, code)
if key == 'up' then
self:moveCursor(self.selected - 1)
self:moveCursor(self.widget.selected - 1)
end
if key == 'down' then
self:moveCursor(self.selected + 1)
self:moveCursor(self.widget.selected + 1)
end
if key == "A" then
self.listWidget[self.selected]:action()
self.widget.list[self.widget.selected]:action()
end
end
function ListBox:mousemoved(x, y)
self.selected = self.begin + math.floor(y / self.widgetsH)
if self.selected < 1 then
self.selected = 1
self.widget.selected = self.begin + math.floor(y / self.widgetsH)
if self.widget.selected < 1 then
self.widget.selected = 1
end
if self.selected > #self.listWidget then
self.selected = #self.listWidget
if self.widget.selected > #self.widget.list then
self.widget.selected = #self.widget.list
end
end
function ListBox:mousepressed(x, y, button, isTouch)
self.selected = self.begin + math.floor(y / self.widgetsH)
if self.selected < 1 then
self.selected = 1
self.widget.selected = self.begin + math.floor(y / self.widgetsH)
if self.widget.selected < 1 then
self.widget.selected = 1
end
if self.selected > #self.listWidget then
self.selected = #self.listWidget
if self.widget.selected > #self.widget.list then
self.widget.selected = #self.widget.list
end
if #self.listWidget > 0 then
self.listWidget[self.selected]:action()
if #self.widget.list > 0 then
self.widget.list[self.widget.selected]:action()
end
end
function ListBox:draw()
local widgety = self.y
for i,v in ipairs(self.listWidget) do
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)
if self.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)
else
v:draw(self.x, widgety, self.w, self.widgetsH)

View file

@ -43,12 +43,12 @@ end
function TextMenu:update(dt)
self:getBoundingBox()
if self.selected ~= 0 then
if self.selected < self.begin then
self.begin = self.selected
if self.widget.selected ~= 0 then
if self.widget.selected < self.begin then
self.begin = self.widget.selected
end
if self.selected > self.begin + self.slots - 1 then
self.begin = self.selected - self.slots + 1
if self.widget.selected > self.begin + self.slots - 1 then
self.begin = self.widget.selected - self.slots + 1
end
end
@ -60,7 +60,7 @@ end
function TextMenu:setWidthAuto()
local width = self.w
for i,v in ipairs(self.listWidget) do
for i,v in ipairs(self.widget.list) do
local stringWidth = self.font:getWidth(v.beginlabel .. v.label .. v.endlabel)
width = math.max(stringWidth, width)
end
@ -82,16 +82,16 @@ end
function TextMenu:keyreleased(key, code)
if key == 'up' then
self:moveCursor(self.selected - 1)
self:moveCursor(self.widget.selected - 1)
end
if key == 'down' then
self:moveCursor(self.selected + 1)
self:moveCursor(self.widget.selected + 1)
end
if key == "A" then
if (self.selected > 0) and (self.selected <= #self.listWidget) then
self.listWidget[self.selected]:action()
if (self.widget.selected > 0) and (self.widget.selected <= #self.widget.list) then
self.widget.list[self.widget.selected]:action()
end
end
@ -102,33 +102,33 @@ function TextMenu:keyreleased(key, code)
end
function TextMenu:mousemoved(x, y)
local selectedPrevous = self.selected
self.selected = self.begin + math.floor(y / self.widgetsH)
if self.selected < 1 then
self.selected = 1
local selectedPrevous = self.widget.selected
self.widget.selected = self.begin + math.floor(y / self.widgetsH)
if self.widget.selected < 1 then
self.widget.selected = 1
end
if self.selected > #self.listWidget then
self.selected = #self.listWidget
if self.widget.selected > #self.widget.list then
self.widget.selected = #self.widget.list
end
if self.selected ~= selectedPrevious then
if self.widget.selected ~= selectedPrevious then
self.canvas.needRedraw = true
end
end
function TextMenu:mousepressed(x, y, button, isTouch)
self.selected = self.begin + math.floor(y / self.widgetsH)
if self.selected < 1 then
self.selected = 1
self.widget.selected = self.begin + math.floor(y / self.widgetsH)
if self.widget.selected < 1 then
self.widget.selected = 1
end
if self.selected > #self.listWidget then
self.selected = #self.listWidget
if self.widget.selected > #self.widget.list then
self.widget.selected = #self.widget.list
end
if #self.listWidget > 0 then
self.listWidget[self.selected]:action()
if #self.widget.list > 0 then
self.widget.list[self.widget.selected]:action()
end
if self.selected ~= selectedPrevious then
if self.widget.selected ~= selectedPrevious then
self.canvas.needRedraw = true
end
end
@ -146,7 +146,7 @@ function TextMenu:drawCanvas()
local x = 0
self.font:set()
for i, v in ipairs(self.listWidget) do
for i, v in ipairs(self.widget.list) do
if (i >= self.begin) and (i < self.begin + self.slots) then
self:drawWidget(i, widgety)
@ -159,14 +159,14 @@ function TextMenu:drawCanvas()
end
function TextMenu:drawWidget(widgetID, y)
local widget = self.listWidget[widgetID]
local widget = self.widget.list[widgetID]
print(widget)
if widget.canvas.needRedraw == true then
self:drawWidgetCanvas(widget)
widget.canvas.needRedraw = false
end
if self.selected == widgetID and self.focus == true then
if self.widget.selected == widgetID and self.focus == true then
love.graphics.setColor(1, 1, 0, 1)
else
love.graphics.setColor(1, 1, 1, 1)
@ -194,7 +194,7 @@ end
function Menu:moveView(begin, absolute)
--local absolute = absolute or true
self.selected = 0
self.widget.selected = 0
if (absolute) then
self.begin = begin
@ -215,7 +215,7 @@ function Menu:isViewAtBeggining()
end
function Menu:isViewAtEnd()
return ((self.begin + self.slots) > (#self.listWidget))
return ((self.begin + self.slots) > (#self.widget.list))
end
return TextMenu