sonic-bluestreak/sonic-bluestreak.love/game/modules/menus/fancy.lua

79 lines
2.3 KiB
Lua
Raw Permalink Normal View History

local List = require "game.modules.menus.list"
local fancy = {}
fancy.FancyMenu = List.ListMenu:extend()
fancy.BaseWidget = List.CenteredWidget:extend()
fancy.SubMenuWidget = fancy.BaseWidget:extend()
local MENU_ITEM_HEIGHT = 16
local gui = require "game.modules.gui"
function fancy.FancyMenu:new(scene, name, x, y, w, itemNumber, haveBiseau)
fancy.FancyMenu.super.new(self, scene, name, x, y, w, itemNumber, false)
self.haveBiseau = haveBiseau
end
function fancy.FancyMenu:getCursorPosition()
if (self.haveBiseau) then
local addition = MENU_ITEM_HEIGHT
local x = self.x + 4 + ((self.cursorTransition) * addition)/2
local y = self.y + ((self.cursorTransition) * addition)
return x, y
else
return fancy.FancyMenu.super.getCursorPosition(self)
end
end
function fancy.FancyMenu:getNextPosition(x, y, h)
if (self.haveBiseau) then
return (x + (h/2)), y+h
else
return fancy.FancyMenu.super.getNextPosition(self, x, y, h)
end
end
function fancy.FancyMenu:clone(name)
return fancy.FancyMenu(self.scene, name, self.x, self.y, self.w, self.itemNumber, self.haveBiseau)
end
function fancy.FancyMenu:addSubMenuWidget(newmenu, name)
fancy.SubMenuWidget(self.scene, self.name, newmenu, name)
end
-- FancyWidgets
-- Add Fancy Widgets
function fancy.BaseWidget:new(scene, menu_name, label, label2)
self.label2 = label2
fancy.BaseWidget.super.new(self, scene, menu_name, label)
self.box = gui.newChoiceBack(self.menu.w + 24)
end
function fancy.BaseWidget:drawCanvas()
love.graphics.draw(self.box, 0, 0)
local h = math.floor(self.height / 2) - (self.font:getHeight() / 2) - 2
self.font:setColor(self.color[1], self.color[2], self.color[3], 1)
self.font:draw(self.label, 16, h, -1, "left")
self.font:draw(self.label2, self.width -8, h, -1, "right")
self.font:setColor(1, 1, 1, 1)
utils.graphics.resetColor()
end
-- Widget de sous-menu
function fancy.SubMenuWidget:new(scene, menu_name, newmenu, label)
local label2 = ""
if (label ~= "Back") then
label2 = ">"
end
fancy.SubMenuWidget.super.new(self, scene, menu_name, label, label2)
self.newmenu = newmenu
end
function fancy.SubMenuWidget:action()
self.scene.assets:playSFX("mBeep")
self.scene.menusystem:switchMenu(self.newmenu)
self.scene.menusystem.menus[self.newmenu]:activationAction()
end
return fancy