sonic-bluestreak/sonic-bluestreak.love/game/modules/gui/boxedmenu.lua

72 lines
2 KiB
Lua
Raw Permalink Normal View History

local ParentMenu = require "birb.modules.gui.textmenu"
local BoxedList = ParentMenu:extend()
local gui = require "game.modules.gui"
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.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png")
self.cursorTransition = 0
self.isBoxed = isBoxed
if (isBoxed) then
local border = self.h + 16
if (smallborder == true) then
border = self.h + 8
end
self.box = gui.newTextBox("assets/gui/dialogbox.png", w + 8, border)
end
end
function BoxedList:finalize()
self:setCancelWidget()
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()
if (self.isBoxed) then
local dy = 8
if (self.smallborder) then
dy = 4
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)
end
BoxedList.super.draw(self)
end
return BoxedList