2020-08-19 20:44:08 +02:00
|
|
|
local ParentMenu = require "game.modules.menus.parents.menu"
|
2021-05-05 08:30:32 +02:00
|
|
|
local Widget = require "birb.modules.menusystem.widgets"
|
2020-08-19 20:44:08 +02:00
|
|
|
|
|
|
|
local list = {}
|
|
|
|
list.ListMenu = ParentMenu:extend()
|
|
|
|
list.CenteredWidget = Widget.Text:extend()
|
|
|
|
list.DualTextWidget = list.CenteredWidget:extend()
|
|
|
|
list.SubMenuWidget = list.DualTextWidget:extend()
|
|
|
|
|
2020-08-28 00:26:12 +02:00
|
|
|
local MENU_ITEM_HEIGHT = 16
|
2020-08-19 20:44:08 +02:00
|
|
|
|
2020-08-22 10:55:02 +02:00
|
|
|
local gui = require "game.modules.gui"
|
|
|
|
|
2020-08-19 20:44:08 +02:00
|
|
|
-- ListMenu
|
2021-04-23 09:22:58 +02:00
|
|
|
function list.ListMenu:new(scene, name, x, y, w, itemNumber, isBoxed, smallborder)
|
2020-08-19 20:44:08 +02:00
|
|
|
self.scene = scene
|
|
|
|
self.name = name
|
|
|
|
local h = itemNumber * MENU_ITEM_HEIGHT
|
|
|
|
list.ListMenu.super.new(self, scene, name, x, y, w, h, itemNumber)
|
|
|
|
self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png")
|
|
|
|
self.cursorTransition = 0
|
|
|
|
self.submenus = {}
|
|
|
|
self.itemNumber = itemNumber
|
2021-04-23 09:22:58 +02:00
|
|
|
self.smallborder = (smallborder == true)
|
2020-08-19 20:44:08 +02:00
|
|
|
|
|
|
|
self.isBoxed = isBoxed
|
|
|
|
if (self.isBoxed) then
|
2021-04-23 09:22:58 +02:00
|
|
|
local border = h+16
|
|
|
|
if (self.smallborder) then
|
|
|
|
border = h+8
|
|
|
|
end
|
|
|
|
self.box = gui.newTextBox("assets/gui/dialogbox.png", w, border)
|
2020-08-19 20:44:08 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function list.ListMenu:addSubMenu(name, nicerName)
|
|
|
|
local submenu = self:clone(name)
|
|
|
|
self:addSubMenuWidget(name, nicerName)
|
|
|
|
table.insert(self.submenus, name)
|
|
|
|
end
|
|
|
|
|
|
|
|
function list.ListMenu:addSubMenuWidget(newmenu, name)
|
|
|
|
list.SubMenuWidget(self.scene, self.name, newmenu, name)
|
|
|
|
end
|
|
|
|
|
2020-08-20 15:33:28 +02:00
|
|
|
function list.ListMenu:finalize(parent)
|
|
|
|
if (parent ~= "" and parent ~= nil) then
|
|
|
|
self:addSubMenuWidget(parent, "Back")
|
2020-08-19 20:44:08 +02:00
|
|
|
self:setCancelWidget()
|
|
|
|
end
|
|
|
|
|
|
|
|
for i,name in ipairs(self.submenus) do
|
|
|
|
if (self.menusystem.menus[name] ~= nil) then
|
2020-08-20 15:33:28 +02:00
|
|
|
self.menusystem.menus[name]:finalize(self.name)
|
2020-08-19 20:44:08 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function list.ListMenu:clone(name)
|
2020-08-19 23:25:36 +02:00
|
|
|
return list.ListMenu(self.scene, name, self.x, self.y, self.w, self.itemNumber, self.isBoxed)
|
2020-08-19 20:44:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function list.ListMenu:update(dt)
|
|
|
|
list.ListMenu.super.update(self, dt)
|
|
|
|
self:updateCursorPosition(dt)
|
|
|
|
end
|
|
|
|
|
|
|
|
function list.ListMenu: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 list.ListMenu:drawCursor()
|
|
|
|
local x, y = self:getCursorPosition()
|
|
|
|
love.graphics.draw(self.cursorTexture, x, y)
|
|
|
|
end
|
|
|
|
|
|
|
|
function list.ListMenu:getCursorPosition()
|
|
|
|
local addition = MENU_ITEM_HEIGHT
|
2020-08-20 15:33:28 +02:00
|
|
|
local x = self.x + 6
|
2020-10-04 09:34:37 +02:00
|
|
|
local y = self.y + ((self.cursorTransition) * addition) + 1
|
2020-08-19 20:44:08 +02:00
|
|
|
return x, y
|
|
|
|
end
|
|
|
|
|
|
|
|
function list.ListMenu:draw()
|
|
|
|
if (self.isBoxed) then
|
2021-04-23 09:22:58 +02:00
|
|
|
local dy = 8
|
|
|
|
if (self.smallborder) then
|
|
|
|
dy = 4
|
|
|
|
end
|
|
|
|
love.graphics.draw(self.box, self.x, self.y - dy)
|
2020-08-19 20:44:08 +02:00
|
|
|
end
|
|
|
|
self:updateView()
|
|
|
|
local widgety = self.y
|
|
|
|
local widgetx = self.x
|
|
|
|
for i,v in ipairs(self.widget.list) do
|
|
|
|
if (i >= self.view.firstSlot) and (i < self.view.firstSlot + self.view.slotNumber) then
|
|
|
|
v:draw(widgetx, widgety, self.w, self.widget.h)
|
|
|
|
if self.widget.selected == i and self:haveFocus() == true then
|
|
|
|
v:drawSelected(widgetx, widgety, self.w, self.widget.h)
|
|
|
|
else
|
|
|
|
v:draw(widgetx, widgety, self.w, self.widget.h)
|
|
|
|
end
|
|
|
|
widgetx, widgety = self:getNextPosition(widgetx, widgety, self.widget.h)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function list.ListMenu:getNextPosition(x, y, h)
|
|
|
|
return x, y+h
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Widgets
|
|
|
|
-- Tout les widgets pour la liste de base
|
|
|
|
|
|
|
|
-- Widget centré
|
|
|
|
function list.CenteredWidget:new(scene, menu_name, label)
|
|
|
|
local font = scene.assets.fonts["small"]
|
|
|
|
font:setFilter("shadow")
|
|
|
|
self.scene = scene
|
|
|
|
local widgetMenu = scene.menusystem.menus[menu_name]
|
|
|
|
list.CenteredWidget.super.new(self, widgetMenu, font, label)
|
|
|
|
end
|
|
|
|
|
|
|
|
function list.CenteredWidget:drawCanvas()
|
2020-10-04 09:34:37 +02:00
|
|
|
local h = math.floor(self.height / 2) - (self.font:getHeight() / 2) - 2
|
2021-03-13 17:26:36 +01:00
|
|
|
self.font:setColor(self.color[1], self.color[2], self.color[3], 1)
|
2020-08-19 20:44:08 +02:00
|
|
|
self.font:draw(self.label, self.width / 2, h, -1, "center")
|
2021-03-13 17:26:36 +01:00
|
|
|
self.font:setColor(1, 1, 1, 1)
|
|
|
|
utils.graphics.resetColor()
|
2020-08-19 20:44:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Widget avec deux bouts de textes
|
|
|
|
function list.DualTextWidget:new(scene, menu_name, label, label2)
|
|
|
|
self.label2 = label2
|
|
|
|
list.DualTextWidget.super.new(self, scene, menu_name, label)
|
|
|
|
end
|
|
|
|
|
|
|
|
function list.DualTextWidget:drawCanvas()
|
|
|
|
local h = math.floor(self.height / 2) - (self.font:getHeight() / 2)
|
2021-03-13 17:26:36 +01:00
|
|
|
self.font:setColor(self.color[1], self.color[2], self.color[3], 1)
|
2020-08-20 15:33:28 +02:00
|
|
|
self.font:draw(self.label, 16, h, -1, "left")
|
|
|
|
self.font:draw(self.label2, self.width - 8, h, -1, "right")
|
2021-03-13 17:26:36 +01:00
|
|
|
self.font:setColor(1, 1, 1, 1)
|
|
|
|
utils.graphics.resetColor()
|
2020-08-19 20:44:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Widget de sous-menu
|
|
|
|
function list.SubMenuWidget:new(scene, menu_name, newmenu, label)
|
|
|
|
local label2 = ""
|
|
|
|
if (label ~= "Back") then
|
|
|
|
label2 = ">"
|
|
|
|
end
|
|
|
|
list.SubMenuWidget.super.new(self, scene, menu_name, label, label2)
|
|
|
|
self.newmenu = newmenu
|
|
|
|
end
|
|
|
|
|
|
|
|
function list.SubMenuWidget:action()
|
2021-04-11 10:32:49 +02:00
|
|
|
self.scene.assets:playSFX("mBeep")
|
2020-08-19 20:44:08 +02:00
|
|
|
self.scene.menusystem:switchMenu(self.newmenu)
|
|
|
|
self.scene.menusystem.menus[self.newmenu]:activationAction()
|
|
|
|
end
|
|
|
|
|
|
|
|
return list
|