Refonte pour utiliser le systeme de GUI #112
1 changed files with 8 additions and 29 deletions
|
@ -7,6 +7,7 @@ function BoxedList:new(name, x, y, w, slotNumber, isBoxed, smallborder)
|
|||
BoxedList.super.new(self, name, "small", x, y, w, slotNumber, 0)
|
||||
self.paddingLeft = 12
|
||||
self.paddingRight = 4
|
||||
self.canvas.padding = 24
|
||||
|
||||
self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png")
|
||||
self.cursorTransition = 0
|
||||
|
@ -27,35 +28,9 @@ end
|
|||
|
||||
function BoxedList:update(dt)
|
||||
BoxedList.super.update(self, dt)
|
||||
self:updateCursorPosition(dt)
|
||||
end
|
||||
|
||||
function BoxedList:updateCursorPosition(dt)
|
||||
local relativecursor = self.widget.selected - self.view.firstSlot
|
||||
|
||||
local transition = self.cursorTransition - relativecursor
|
||||
if math.abs(transition) < 0.1 then
|
||||
self.cursorTransition = relativecursor
|
||||
else
|
||||
local speed = dt * 45
|
||||
local movement = ((relativecursor) - (self.cursorTransition))
|
||||
self.cursorTransition = (self.cursorTransition) + movement * speed
|
||||
end
|
||||
end
|
||||
|
||||
function BoxedList:drawCursor()
|
||||
local x, y = self:getCursorPosition()
|
||||
love.graphics.draw(self.cursorTexture, x, y)
|
||||
end
|
||||
|
||||
function BoxedList:getCursorPosition()
|
||||
local addition = self.lineHeight
|
||||
local x = self.x + 6
|
||||
local y = self.y + ((self.cursorTransition) * addition) + 1
|
||||
return x, y
|
||||
end
|
||||
|
||||
function BoxedList:draw()
|
||||
function BoxedList:drawTexture()
|
||||
if (self.isBoxed) then
|
||||
local dy = 8
|
||||
if (self.smallborder) then
|
||||
|
@ -63,9 +38,13 @@ function BoxedList:draw()
|
|||
end
|
||||
local w, h = self.box:getDimensions()
|
||||
local diff = (w-self.w)/2
|
||||
love.graphics.draw(self.box, self.x - self.ox - diff, self.y - self.oy - dy)
|
||||
love.graphics.draw(self.box, self.canvas.padding - diff, self.canvas.padding - dy)
|
||||
end
|
||||
BoxedList.super.draw(self)
|
||||
BoxedList.super.drawTexture(self)
|
||||
end
|
||||
|
||||
function BoxedList:drawGraphicalCursor(x, y, w, h)
|
||||
love.graphics.draw(self.cursorTexture, x, y + 1)
|
||||
end
|
||||
|
||||
return BoxedList
|
||||
|
|
Loading…
Reference in a new issue