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()
|
2019-03-31 17:08:02 +02:00
|
|
|
|
2019-03-31 16:43:04 +02:00
|
|
|
local CharMenuWidget = Widget.Text:extend()
|
2019-03-31 17:08:02 +02:00
|
|
|
local SubMenuWidget = CharMenuWidget:extend()
|
2019-03-31 17:35:55 +02:00
|
|
|
local BackMenuWidget = CharMenuWidget:extend()
|
2019-08-14 17:07:42 +02:00
|
|
|
local SkillWidget = Widget.Text:extend()
|
2019-03-31 16:43:04 +02:00
|
|
|
|
2019-03-10 13:11:26 +01:00
|
|
|
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
|
|
|
|
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)
|
2019-03-31 17:12:48 +02:00
|
|
|
self:buildSkillMenu(character)
|
2019-03-31 17:21:27 +02:00
|
|
|
self:buildObjectMenu(character)
|
2019-03-31 16:43:04 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function MenuConstructor:buildBaseMenu(character)
|
|
|
|
CharacterMenu(self.controller, "BaseMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
2019-08-14 17:07:42 +02:00
|
|
|
CharMenuWidget(self.controller, "BaseMenu", "attack", "", character)
|
|
|
|
SubMenuWidget(self.controller, "BaseMenu", "skills", "SkillMenu", character)
|
|
|
|
SubMenuWidget(self.controller, "BaseMenu", "objects", "ObjectMenu", character)
|
|
|
|
CharMenuWidget(self.controller, "BaseMenu", "defend", "", character)
|
|
|
|
CharMenuWidget(self.controller, "BaseMenu", "flee", "", character)
|
|
|
|
BackMenuWidget(self.controller, "BaseMenu", "back", character)
|
2019-03-31 17:07:45 +02:00
|
|
|
|
|
|
|
self.controller.menusystem.menus["BaseMenu"]:setCancelWidget()
|
2019-03-31 16:43:04 +02:00
|
|
|
end
|
|
|
|
|
2019-03-31 12:05:17 +02:00
|
|
|
function MenuConstructor:set(currentCharacter)
|
2019-03-31 17:02:02 +02:00
|
|
|
self:reconstruct(currentCharacter)
|
2019-03-10 13:11:26 +01:00
|
|
|
end
|
|
|
|
|
2019-03-31 17:12:48 +02:00
|
|
|
function MenuConstructor:buildSkillMenu(character)
|
2019-03-31 17:07:45 +02:00
|
|
|
CharacterMenu(self.controller, "SkillMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
2019-03-31 17:12:48 +02:00
|
|
|
local list = game.characters:getSkillList(character.charid)
|
2019-08-17 00:55:29 +02:00
|
|
|
for k, skill in pairs(list) do
|
|
|
|
SkillWidget(self.controller, "SkillMenu", skill.name, "", character)
|
2019-03-10 13:11:26 +01:00
|
|
|
end
|
2019-08-14 17:07:42 +02:00
|
|
|
SubMenuWidget(self.controller, "SkillMenu", "back", "BaseMenu", character)
|
2019-03-10 13:11:26 +01:00
|
|
|
|
2019-03-31 17:07:45 +02:00
|
|
|
self.controller.menusystem.menus["SkillMenu"]:setCancelWidget()
|
2019-03-10 13:11:26 +01:00
|
|
|
end
|
|
|
|
|
2019-03-31 17:21:27 +02:00
|
|
|
function MenuConstructor:buildObjectMenu(character)
|
|
|
|
CharacterMenu(self.controller, "ObjectMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
|
|
|
|
|
|
|
CharacterMenu(self.controller, "MedMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
|
|
|
CharacterMenu(self.controller, "RingMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
|
|
|
CharacterMenu(self.controller, "WispMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
|
|
|
CharacterMenu(self.controller, "OtherMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
|
|
|
|
|
|
|
|
2019-08-14 17:07:42 +02:00
|
|
|
SubMenuWidget(self.controller, "ObjectMenu", "heal", "MedMenu", character)
|
|
|
|
SubMenuWidget(self.controller, "ObjectMenu", "rings", "RingMenu", character)
|
|
|
|
SubMenuWidget(self.controller, "ObjectMenu", "wisps", "WispMenu", character)
|
|
|
|
SubMenuWidget(self.controller, "ObjectMenu", "other", "OtherMenu", character)
|
2019-03-31 17:21:27 +02:00
|
|
|
|
2019-08-14 17:07:42 +02:00
|
|
|
SubMenuWidget(self.controller, "ObjectMenu", "back", "BaseMenu", character)
|
|
|
|
SubMenuWidget(self.controller, "MedMenu", "back", "ObjectMenu", character)
|
|
|
|
SubMenuWidget(self.controller, "RingMenu", "back", "ObjectMenu", character)
|
|
|
|
SubMenuWidget(self.controller, "WispMenu", "back", "ObjectMenu", character)
|
|
|
|
SubMenuWidget(self.controller, "OtherMenu", "back", "ObjectMenu", character)
|
2019-03-31 17:21:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
self.controller.menusystem.menus["ObjectMenu"]:setCancelWidget()
|
|
|
|
|
|
|
|
self.controller.menusystem.menus["MedMenu"]:setCancelWidget()
|
|
|
|
self.controller.menusystem.menus["RingMenu"]:setCancelWidget()
|
|
|
|
self.controller.menusystem.menus["WispMenu"]:setCancelWidget()
|
|
|
|
self.controller.menusystem.menus["OtherMenu"]:setCancelWidget()
|
|
|
|
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 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-08-14 17:07:42 +02:00
|
|
|
self.actionType = label1
|
|
|
|
|
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-08-14 17:07:42 +02:00
|
|
|
CharMenuWidget.super.new(self, menu, font, core.lang:translate("battle", label1))
|
2019-03-31 16:43:04 +02:00
|
|
|
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()
|
2019-08-14 17:32:33 +02:00
|
|
|
self.character:receiveSignal(self.actionType)
|
2019-08-14 16:26:23 +02:00
|
|
|
self.scene:flushKeys()
|
2019-03-31 16:57:57 +02:00
|
|
|
self.scene.menusystem:reset()
|
|
|
|
end
|
|
|
|
|
2019-03-31 17:07:45 +02:00
|
|
|
-- 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()
|
2019-03-31 17:15:27 +02:00
|
|
|
self.scene.menusystem:switchMenu(self.newmenu)
|
2019-03-31 17:07:45 +02:00
|
|
|
end
|
|
|
|
|
2019-03-31 17:35:55 +02:00
|
|
|
-- Back Widget
|
|
|
|
|
|
|
|
function BackMenuWidget:new(scene, menu_name, label, character)
|
2019-08-14 17:07:42 +02:00
|
|
|
BackMenuWidget.super.new(self, scene, menu_name, "back", "", character)
|
2019-03-31 17:35:55 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function BackMenuWidget:action()
|
2019-08-14 17:32:33 +02:00
|
|
|
self.character:receiveBackSignal()
|
2019-04-01 08:20:29 +02:00
|
|
|
self.scene:flushKeys()
|
2019-03-31 17:35:55 +02:00
|
|
|
self.scene.menusystem:reset()
|
|
|
|
end
|
|
|
|
|
2019-08-14 17:07:42 +02:00
|
|
|
-- Skill Widget
|
|
|
|
|
|
|
|
function SkillWidget:new(scene, menu_name, label1, label2, character)
|
|
|
|
self.character = character
|
|
|
|
self.menuname = menu_name
|
|
|
|
self.scene = scene
|
|
|
|
self.actionType = label1
|
|
|
|
|
|
|
|
local menu = scene.menusystem.menus[menu_name] or error("menu " ..menu_name .. " doesn't exist")
|
|
|
|
local font = scene.assets.fonts["small"]
|
2019-08-22 22:04:14 +02:00
|
|
|
|
|
|
|
self.skilldata = game.skills:getSkillData(self.actionType)
|
|
|
|
|
2019-08-14 17:07:42 +02:00
|
|
|
CharMenuWidget.super.new(self, menu, font, core.lang:translate("skills", label1))
|
2019-08-22 22:04:14 +02:00
|
|
|
|
|
|
|
if self.skilldata ~= nil then
|
|
|
|
self.label2 = self.skilldata.cost or 0
|
|
|
|
if self.label2 < 10 then
|
|
|
|
self.label2 = "0" .. self.label2
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self.label2 = "n"
|
|
|
|
end
|
2019-08-14 17:07:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function SkillWidget: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 SkillWidget:action()
|
2019-08-22 22:04:14 +02:00
|
|
|
if self.skilldata ~= nil then
|
|
|
|
self.character:receiveSignal("skill", self.actionType)
|
|
|
|
else
|
|
|
|
core.debug:warning("cbs/menu", "skill " .. self.actionType .. " doesn't exist")
|
|
|
|
self.character:receiveSignal("none")
|
|
|
|
end
|
2019-08-14 17:07:42 +02:00
|
|
|
self.scene:flushKeys()
|
|
|
|
self.scene.menusystem:reset()
|
|
|
|
end
|
2019-03-31 17:35:55 +02:00
|
|
|
|
2019-03-31 12:05:17 +02:00
|
|
|
return MenuConstructor
|