153 lines
4.6 KiB
Lua
153 lines
4.6 KiB
Lua
local ListBox = require "core.modules.menusystem.listbox"
|
|
local Widget = require "core.modules.menusystem.widgets"
|
|
|
|
local MenuConstructor = Object:extend()
|
|
local CharacterMenu = ListBox:extend()
|
|
|
|
local CharMenuWidget = Widget.Text:extend()
|
|
local SubMenuWidget = CharMenuWidget:extend()
|
|
|
|
local MENUPOS_X1, MENUPOS_X2, MENUPOS_Y = 32, 32, 110
|
|
local MENU_WIDTH, MENU_ITEM_HEIGHT = 112, 17
|
|
local MENU_ITEM_NUMBER = 6
|
|
|
|
function MenuConstructor:new( controller )
|
|
self.controller = controller
|
|
self.controller.assets:addFont("small", "assets/gui/fonts/PixelOperator.ttf", 16)
|
|
end
|
|
|
|
function MenuConstructor:reconstruct(character)
|
|
self.controller.menusystem:reset()
|
|
self:build(character)
|
|
|
|
self.controller.menusystem:switchMenu("BaseMenu")
|
|
end
|
|
|
|
function MenuConstructor:build(character)
|
|
self:buildBaseMenu(character)
|
|
end
|
|
|
|
function MenuConstructor:buildBaseMenu(character)
|
|
CharacterMenu(self.controller, "BaseMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
|
CharMenuWidget(self.controller, "BaseMenu", "Attaquer", "", character)
|
|
CharMenuWidget(self.controller, "BaseMenu", "Techniques", "", character)
|
|
CharMenuWidget(self.controller, "BaseMenu", "Objets", "", character)
|
|
CharMenuWidget(self.controller, "BaseMenu", "Défendre", "", character)
|
|
CharMenuWidget(self.controller, "BaseMenu", "Fuite", "", character)
|
|
CharMenuWidget(self.controller, "BaseMenu", "Retour", "", character)
|
|
|
|
self.controller.menusystem.menus["BaseMenu"]:setCancelWidget()
|
|
end
|
|
|
|
function MenuConstructor:set(currentCharacter)
|
|
self:reconstruct(currentCharacter)
|
|
end
|
|
|
|
function MenuConstructor:buildSkillMenu()
|
|
CharacterMenu(self.controller, "SkillMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
|
local list = game.characters:getSkillList(self.character.charid)
|
|
for k,v in pairs(list) do
|
|
CharMenuWidget(self.controller, "SkillMenu", k, "", character)
|
|
end
|
|
CharMenuWidget(self.controller, "Back", v, "", character)
|
|
|
|
self.controller.menusystem.menus["SkillMenu"]:setCancelWidget()
|
|
end
|
|
|
|
function MenuConstructor:unset( )
|
|
self.isActive = false
|
|
end
|
|
|
|
function MenuConstructor:update(dt)
|
|
if (self.isActive) then
|
|
end
|
|
end
|
|
|
|
function MenuConstructor:sendSignal(menu, id)
|
|
--print(self.menu[menu][id])
|
|
self.isActive = false
|
|
if (menu == 1) then
|
|
self.character:getSignal(BaseMenu[id], 1)
|
|
else
|
|
self.character:getSignal(BaseMenu[menu], id)
|
|
end
|
|
end
|
|
|
|
function MenuConstructor:draw()
|
|
-- remove in order to avoid crash
|
|
end
|
|
|
|
-- CHARACTER_MENU
|
|
-- The actuals menus in the character menu
|
|
|
|
function CharacterMenu:new(scene, name, x, y)
|
|
self.scene = scene
|
|
local w, h = MENU_WIDTH, MENU_ITEM_NUMBER * MENU_ITEM_HEIGHT
|
|
CharacterMenu.super.new(self, scene.menusystem, name, x, y, w, h, MENU_ITEM_NUMBER)
|
|
self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png")
|
|
self.cursorTransition = 1
|
|
end
|
|
|
|
function CharacterMenu:update(dt)
|
|
CharacterMenu.super.update(self, 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
|
|
self.cursorTransition = (self.cursorTransition) + ((relativecursor) - (self.cursorTransition)) * dt*45
|
|
end
|
|
|
|
end
|
|
|
|
function CharacterMenu:drawCursor()
|
|
local addition = 17
|
|
love.graphics.draw(self.cursorTexture, self.x + 4, self.y + (self.cursorTransition) * addition )
|
|
end
|
|
|
|
-- WIDGETS
|
|
-- All widgets used by the Characters menus
|
|
|
|
function CharMenuWidget:new(scene, menu_name, label1, label2, character)
|
|
self.character = character
|
|
self.menuname = menu_name
|
|
self.scene = scene
|
|
local menu = scene.menusystem.menus[menu_name] or error("menu " ..menu_name .. " doesn't exist")
|
|
local font = scene.assets.fonts["small"]
|
|
CharMenuWidget.super.new(self, menu, font, label1)
|
|
self.label2 = label2 or ""
|
|
end
|
|
|
|
function CharMenuWidget:drawCanvas()
|
|
local h
|
|
local asset = love.graphics.newImage("assets/gui/attacklist.png")
|
|
love.graphics.draw(asset, 0, (self.height - 13) / 2)
|
|
h = math.floor(self.height / 2) - (self.font:getHeight() / 2)
|
|
love.graphics.setColor(0, 0, 0, .8)
|
|
self.font:print(self.label, 17, h, "left")
|
|
self.font:print(self.label2, self.width - 8, h, "right")
|
|
utils.graphics.resetColor()
|
|
self.font:print(self.label, 16, h, "left")
|
|
self.font:print(self.label2, self.width - 9, h, "right")
|
|
end
|
|
|
|
function CharMenuWidget:action()
|
|
self.character:getSignal(self.menuname, self.label)
|
|
self.scene.menusystem:reset()
|
|
end
|
|
|
|
-- Submenu Widget
|
|
|
|
function SubMenuWidget:new(scene, menu_name, label, newmenu, character)
|
|
SubMenuWidget.super.new(self, scene, menu_name, label, "", character)
|
|
self.newmenu = newmenu or "BaseMenu"
|
|
end
|
|
|
|
function SubMenuWidget:action()
|
|
self.scene.menusystem:switchMenu(newmenu)
|
|
end
|
|
|
|
return MenuConstructor
|