feat: initial gui version of radiance's menus
This commit is contained in:
parent
759daf5ec0
commit
83a89dc69b
2 changed files with 103 additions and 0 deletions
71
sonic-radiance.love/game/modules/gui/boxedmenu.lua
Normal file
71
sonic-radiance.love/game/modules/gui/boxedmenu.lua
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
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
|
32
sonic-radiance.love/game/modules/gui/fancymenu.lua
Normal file
32
sonic-radiance.love/game/modules/gui/fancymenu.lua
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
local ParentMenu = require "birb.modules.gui.textmenu"
|
||||||
|
local FancyMenu = ParentMenu:extend()
|
||||||
|
|
||||||
|
local gui = require "game.modules.gui"
|
||||||
|
|
||||||
|
function FancyMenu:new(name, x, y, w, itemNumber, haveBiseau)
|
||||||
|
FancyMenu.super.new(self, name, "small", x, y, w, itemNumber)
|
||||||
|
self.biseau = utils.math.either(haveBiseau, 8, 0)
|
||||||
|
self.itemNumber = itemNumber
|
||||||
|
self.box = gui.newChoiceBack(self.w + 24)
|
||||||
|
self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png")
|
||||||
|
end
|
||||||
|
|
||||||
|
function FancyMenu:getDimensions()
|
||||||
|
local w, h = FancyMenu.super.getDimensions(self)
|
||||||
|
return w + (self.biseau*self.itemNumber), h
|
||||||
|
end
|
||||||
|
|
||||||
|
function FancyMenu:getListPart(i)
|
||||||
|
local x, y, w, h = FancyMenu.super.getListPart(self, i)
|
||||||
|
return x + (self.biseau*i), y, w, h
|
||||||
|
end
|
||||||
|
|
||||||
|
function FancyMenu:drawWidgetBackground(x, y, w, h)
|
||||||
|
love.graphics.draw(self.box, x - 8, y + 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
function FancyMenu:drawGraphicalCursor(x, y, w, h)
|
||||||
|
love.graphics.draw(self.cursorTexture, x - 3, y + 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
return FancyMenu
|
Loading…
Reference in a new issue