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

75 lines
2.1 KiB
Lua
Raw 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:draw(self.label, 16, h, -1, "left")
self.font:draw(self.label2, self.width -8, h, -1, "right")
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.menusystem:switchMenu(self.newmenu)
self.scene.menusystem.menus[self.newmenu]:activationAction()
end
return fancy