2019-03-31 16:43:04 +02:00
|
|
|
local ListBox = require "core.modules.menusystem.listbox"
|
|
|
|
local Widget = require "core.modules.menusystem.widgets"
|
|
|
|
|
2019-03-31 12:05:17 +02:00
|
|
|
local MenuConstructor = Object:extend()
|
2019-03-31 16:43:04 +02:00
|
|
|
local CharacterMenu = ListBox:extend()
|
|
|
|
local CharMenuWidget = Widget.Text:extend()
|
|
|
|
|
2019-03-10 13:11:26 +01:00
|
|
|
local BaseMenu = {"attack", "techs", "object", "defend", "flee", "back"}
|
|
|
|
|
|
|
|
local MENUPOS_X1, MENUPOS_X2, MENUPOS_Y = 32, 32, 110
|
2019-03-31 16:43:04 +02:00
|
|
|
local MENU_WIDTH, MENU_ITEM_HEIGHT = 112, 17
|
|
|
|
local MENU_ITEM_NUMBER = 6
|
2019-03-10 13:11:26 +01:00
|
|
|
|
2019-03-31 12:05:17 +02:00
|
|
|
function MenuConstructor:new( controller )
|
2019-03-10 13:11:26 +01:00
|
|
|
self.controller = controller
|
|
|
|
self.isActive = false
|
|
|
|
self.techList = {}
|
|
|
|
|
|
|
|
self.menu = {}
|
|
|
|
self.menu[1] = BaseMenu
|
|
|
|
|
|
|
|
self.texture = love.graphics.newImage("assets/gui/attacklist.png")
|
|
|
|
self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png")
|
2019-03-10 13:56:49 +01:00
|
|
|
self.font = love.graphics.newFont("assets/gui/fonts/PixelOperator.ttf", 16)
|
2019-03-31 16:43:04 +02:00
|
|
|
self.controller.assets:addFont("small", "assets/gui/fonts/PixelOperator.ttf", 16)
|
2019-03-10 13:11:26 +01:00
|
|
|
self.cursor = 1
|
|
|
|
self.cursorTransition = 1
|
|
|
|
self.view = 1
|
|
|
|
end
|
|
|
|
|
2019-03-31 16:43:04 +02:00
|
|
|
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)
|
|
|
|
for i,v in ipairs(BaseMenu) do
|
2019-03-31 16:53:21 +02:00
|
|
|
CharMenuWidget(self.controller, "BaseMenu", v, "", character)
|
2019-03-31 16:43:04 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-31 12:05:17 +02:00
|
|
|
function MenuConstructor:set(currentCharacter)
|
2019-03-10 13:11:26 +01:00
|
|
|
self.isActive = true
|
|
|
|
self.cursor = 1
|
|
|
|
self.cursorTransition = 0
|
|
|
|
self.activeMenu = 1
|
|
|
|
|
|
|
|
self.character = currentCharacter
|
|
|
|
|
2019-03-31 16:43:04 +02:00
|
|
|
--self:reconstruct(currentCharacter)
|
|
|
|
|
2019-03-10 13:11:26 +01:00
|
|
|
self.menu[2] = self:getSkillList()
|
|
|
|
self.menu[3] = {"healitems", "rings", "wisps", "other", "back"}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2019-03-31 12:05:17 +02:00
|
|
|
function MenuConstructor:getSkillList()
|
2019-03-10 13:11:26 +01:00
|
|
|
local list = game.characters:getSkillList(self.character.charid)
|
|
|
|
local skillmenu = {}
|
|
|
|
for k,v in pairs(list) do
|
|
|
|
table.insert(skillmenu, k)
|
|
|
|
end
|
|
|
|
|
|
|
|
table.insert(skillmenu, "back")
|
|
|
|
|
|
|
|
return skillmenu
|
|
|
|
end
|
|
|
|
|
2019-03-31 12:05:17 +02:00
|
|
|
function MenuConstructor:unset( )
|
2019-03-10 13:11:26 +01:00
|
|
|
self.isActive = false
|
|
|
|
end
|
|
|
|
|
2019-03-31 12:05:17 +02:00
|
|
|
function MenuConstructor:update(dt)
|
2019-03-10 13:11:26 +01:00
|
|
|
if (self.isActive) then
|
2019-03-23 11:45:20 +01:00
|
|
|
local keys = self.controller.keys
|
2019-03-10 13:11:26 +01:00
|
|
|
|
|
|
|
if self.cursor < self.view then
|
|
|
|
self.view = self.cursor
|
|
|
|
end
|
|
|
|
if self.cursor > self.view + 5 then
|
|
|
|
self.view = self.cursor - 5
|
|
|
|
end
|
|
|
|
|
|
|
|
local relativecursor = self.cursor - self.view
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
if (keys["up"].isPressed) then
|
|
|
|
if (self.cursor == 1) then
|
|
|
|
self.cursor = #self.menu[self.activeMenu]
|
|
|
|
else
|
|
|
|
self.cursor = self.cursor - 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if (keys["down"].isPressed) then
|
|
|
|
if (self.cursor == #self.menu[self.activeMenu]) then
|
|
|
|
self.cursor = 1
|
|
|
|
else
|
|
|
|
self.cursor = self.cursor + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if keys["left"].isPressed then
|
|
|
|
self.character.direction = -1
|
|
|
|
end
|
|
|
|
|
|
|
|
if keys["right"].isPressed then
|
|
|
|
self.character.direction = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if (keys["A"].isPressed) then
|
|
|
|
if self.activeMenu == 1 then
|
|
|
|
if (self.cursor == 2 or self.cursor == 3) then
|
|
|
|
self.activeMenu = self.cursor
|
|
|
|
self.cursor = 1
|
|
|
|
else
|
|
|
|
self:sendSignal(self.activeMenu, self.cursor)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self:sendSignal(self.activeMenu, self.cursor)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if (keys["B"].isPressed) then
|
|
|
|
if self.activeMenu == 1 then
|
|
|
|
self:sendSignal(1, 6)
|
|
|
|
else
|
|
|
|
self.cursor = self.activeMenu
|
|
|
|
self.activeMenu = 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-31 12:05:17 +02:00
|
|
|
function MenuConstructor:sendSignal(menu, id)
|
2019-03-10 13:11:26 +01:00
|
|
|
--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
|
|
|
|
|
2019-03-31 12:05:17 +02:00
|
|
|
function MenuConstructor:draw()
|
2019-03-10 13:11:26 +01:00
|
|
|
if (self.isActive) then
|
|
|
|
local x, y, addition
|
|
|
|
x = 32
|
|
|
|
y = 32
|
|
|
|
addition = 16
|
|
|
|
local currentMenu = self.menu[self.activeMenu]
|
|
|
|
-- MENUPOS_X1, MENUPOS_X2, MENUPOS_Y
|
|
|
|
local MENUPOS_X = MENUPOS_X1
|
|
|
|
local maxView = math.min(#currentMenu, (self.view + 5))
|
|
|
|
|
|
|
|
for i = self.view, maxView do
|
|
|
|
love.graphics.draw(self.texture, MENUPOS_X - 16, MENUPOS_Y + (i-self.view)*addition + 3)
|
|
|
|
love.graphics.setFont(self.font)
|
|
|
|
love.graphics.setColor(0, 0, 0, .8)
|
|
|
|
love.graphics.print(currentMenu[i], MENUPOS_X + 1, MENUPOS_Y + (i-self.view)*addition + 1)
|
|
|
|
if (i == self.cursor) then
|
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
|
|
else
|
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
|
|
end
|
|
|
|
love.graphics.print(currentMenu[i], MENUPOS_X, MENUPOS_Y + (i-self.view)*addition)
|
|
|
|
|
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
love.graphics.draw(self.cursorTexture, MENUPOS_X - 12, MENUPOS_Y + (self.cursorTransition) * addition + 2 )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-31 16:43:04 +02:00
|
|
|
-- 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)
|
2019-03-31 16:51:58 +02:00
|
|
|
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
|
|
|
|
|
2019-03-31 16:43:04 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function CharacterMenu:drawCursor()
|
2019-03-31 16:51:58 +02:00
|
|
|
local addition = 17
|
|
|
|
love.graphics.draw(self.cursorTexture, self.x + 4, self.y + (self.cursorTransition) * addition )
|
2019-03-31 16:43:04 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- WIDGETS
|
|
|
|
-- All widgets used by the Characters menus
|
|
|
|
|
2019-03-31 16:53:21 +02:00
|
|
|
function CharMenuWidget:new(scene, menu_name, label1, label2, character)
|
2019-03-31 16:43:04 +02:00
|
|
|
self.character = character
|
2019-03-31 16:57:57 +02:00
|
|
|
self.menuname = menu_name
|
|
|
|
self.scene = scene
|
2019-03-31 16:43:04 +02:00
|
|
|
local menu = scene.menusystem.menus[menu_name] or error("menu " ..menu_name .. " doesn't exist")
|
2019-03-31 16:53:21 +02:00
|
|
|
local font = scene.assets.fonts["small"]
|
2019-03-31 16:43:04 +02:00
|
|
|
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
|
|
|
|
|
2019-03-31 16:57:57 +02:00
|
|
|
function CharMenuWidget:action()
|
|
|
|
self.character:getSignal(self.menuname, self.label)
|
|
|
|
self.scene.menusystem:reset()
|
|
|
|
end
|
|
|
|
|
2019-03-31 12:05:17 +02:00
|
|
|
return MenuConstructor
|