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-08-31 14:09:48 +02:00
|
|
|
local BattleWidget = Widget.Text:extend()
|
|
|
|
local ActionWidget = BattleWidget:extend()
|
|
|
|
local SubMenuWidget = BattleWidget:extend()
|
|
|
|
local BackMenuWidget = BattleWidget:extend()
|
|
|
|
local SkillWidget = BattleWidget:extend()
|
2019-03-31 16:43:04 +02:00
|
|
|
|
2020-07-19 21:41:14 +02:00
|
|
|
local AttackWidget = ActionWidget:extend()
|
|
|
|
|
2019-03-10 13:11:26 +01:00
|
|
|
local MENUPOS_X1, MENUPOS_X2, MENUPOS_Y = 32, 32, 110
|
2019-08-31 15:04:44 +02:00
|
|
|
local MENU_WIDTH, MENU_ITEM_HEIGHT = 148, 17
|
2019-03-31 16:43:04 +02:00
|
|
|
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 )
|
2020-07-19 18:09:53 +02:00
|
|
|
self.scene = controller
|
2019-03-10 13:11:26 +01:00
|
|
|
end
|
|
|
|
|
2019-03-31 16:43:04 +02:00
|
|
|
function MenuConstructor:reconstruct(character)
|
2020-07-19 18:09:53 +02:00
|
|
|
core.debug:print("cbs/menu", "Reconstructing the menu")
|
|
|
|
self.scene.menusystem:reset()
|
2019-03-31 16:43:04 +02:00
|
|
|
self:build(character)
|
|
|
|
|
2020-07-19 18:09:53 +02:00
|
|
|
self.scene.menusystem:switchMenu("BaseMenu")
|
2019-03-31 16:43:04 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function MenuConstructor:build(character)
|
2020-07-19 18:09:53 +02:00
|
|
|
core.debug:print("cbs/menu", "Building the menu")
|
2019-03-31 16:43:04 +02:00
|
|
|
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-08-31 15:44:34 +02:00
|
|
|
|
2020-07-19 18:09:53 +02:00
|
|
|
self.scene.menusystem:setSoundFromSceneAssets("mBeep")
|
2020-07-19 21:41:14 +02:00
|
|
|
self.scene.menusystem:activate()
|
2019-03-31 16:43:04 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function MenuConstructor:buildBaseMenu(character)
|
2020-07-19 18:09:53 +02:00
|
|
|
CharacterMenu(self.scene, "BaseMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
2020-07-19 21:41:14 +02:00
|
|
|
AttackWidget(character, "BaseMenu")
|
2019-08-31 14:09:48 +02:00
|
|
|
SubMenuWidget(character, "BaseMenu", "skills", "SkillMenu")
|
|
|
|
SubMenuWidget(character, "BaseMenu", "objects", "ObjectMenu")
|
|
|
|
ActionWidget(character, "BaseMenu", "defend")
|
|
|
|
ActionWidget(character, "BaseMenu", "flee")
|
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)
|
2020-07-19 18:09:53 +02:00
|
|
|
CharacterMenu(self.scene, "SkillMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
|
|
|
local list = character.abstract.skills
|
2019-08-17 00:55:29 +02:00
|
|
|
for k, skill in pairs(list) do
|
2019-08-31 14:09:48 +02:00
|
|
|
SkillWidget(character, "SkillMenu", skill.name, "")
|
2019-03-10 13:11:26 +01:00
|
|
|
end
|
2019-08-31 14:09:48 +02:00
|
|
|
SubMenuWidget(character, "SkillMenu", "back", "BaseMenu")
|
2019-03-10 13:11:26 +01:00
|
|
|
|
2020-07-19 18:09:53 +02:00
|
|
|
self.scene.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)
|
2020-07-19 18:09:53 +02:00
|
|
|
CharacterMenu(self.scene, "ObjectMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
2019-03-31 17:21:27 +02:00
|
|
|
|
2020-07-19 18:09:53 +02:00
|
|
|
CharacterMenu(self.scene, "MedMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
|
|
|
CharacterMenu(self.scene, "RingMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
|
|
|
CharacterMenu(self.scene, "WispMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
|
|
|
CharacterMenu(self.scene, "OtherMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
2019-03-31 17:21:27 +02:00
|
|
|
|
|
|
|
|
2019-08-31 14:09:48 +02:00
|
|
|
SubMenuWidget(character, "ObjectMenu", "heal", "MedMenu")
|
|
|
|
SubMenuWidget(character, "ObjectMenu", "rings", "RingMenu")
|
|
|
|
SubMenuWidget(character, "ObjectMenu", "wisps", "WispMenu")
|
|
|
|
SubMenuWidget(character, "ObjectMenu", "other", "OtherMenu")
|
2019-03-31 17:21:27 +02:00
|
|
|
|
2019-08-31 14:09:48 +02:00
|
|
|
SubMenuWidget(character, "ObjectMenu", "back", "BaseMenu")
|
|
|
|
SubMenuWidget(character, "MedMenu", "back", "ObjectMenu")
|
|
|
|
SubMenuWidget(character, "RingMenu", "back", "ObjectMenu")
|
|
|
|
SubMenuWidget(character, "WispMenu", "back", "ObjectMenu")
|
|
|
|
SubMenuWidget(character, "OtherMenu", "back", "ObjectMenu")
|
2019-03-31 17:21:27 +02:00
|
|
|
|
|
|
|
|
2020-07-19 18:09:53 +02:00
|
|
|
self.scene.menusystem.menus["ObjectMenu"]:setCancelWidget()
|
2019-03-31 17:21:27 +02:00
|
|
|
|
2020-07-19 18:09:53 +02:00
|
|
|
self.scene.menusystem.menus["MedMenu"]:setCancelWidget()
|
|
|
|
self.scene.menusystem.menus["RingMenu"]:setCancelWidget()
|
|
|
|
self.scene.menusystem.menus["WispMenu"]:setCancelWidget()
|
|
|
|
self.scene.menusystem.menus["OtherMenu"]:setCancelWidget()
|
2019-03-31 17:21:27 +02:00
|
|
|
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")
|
2020-07-19 21:41:14 +02:00
|
|
|
self.cursorTransition = 0
|
2019-03-31 16:51:58 +02:00
|
|
|
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-08-31 14:09:48 +02:00
|
|
|
-- Basic Battle Widget
|
|
|
|
-- The base used by all battle widgets
|
2019-08-14 17:07:42 +02:00
|
|
|
|
2019-08-31 14:09:48 +02:00
|
|
|
function BattleWidget:new(character, menu_name, label1, label2, translationdata)
|
|
|
|
local menu = self:getControllers(character, menu_name)
|
|
|
|
|
|
|
|
local translationdata = translationdata or "battle"
|
|
|
|
local label1 = label1 or ""
|
|
|
|
local label2 = label2 or ""
|
|
|
|
label1 = core.lang:translate(translationdata, label1)
|
|
|
|
|
|
|
|
local font = self.assets.fonts["small"]
|
|
|
|
|
|
|
|
BattleWidget.super.new(self, menu, font, label1)
|
|
|
|
|
|
|
|
self.label2 = label2
|
2019-08-22 22:40:31 +02:00
|
|
|
end
|
|
|
|
|
2019-08-31 14:09:48 +02:00
|
|
|
function BattleWidget:getControllers(character, menu_name)
|
|
|
|
self.character = character or core.debug:error("cbs/widget", "character must not be nil")
|
|
|
|
|
2020-07-19 18:09:53 +02:00
|
|
|
self.scene = self.character.turnSystem.scene
|
2019-08-31 14:09:48 +02:00
|
|
|
self.assets = self.character.assets
|
|
|
|
self.menusystem = self.scene.menusystem
|
|
|
|
|
|
|
|
self.menuname = menu_name
|
|
|
|
|
|
|
|
local menu = self.menusystem.menus[menu_name] or error("menu " ..menu_name .. " doesn't exist")
|
|
|
|
|
|
|
|
return menu
|
2019-08-22 22:40:31 +02:00
|
|
|
end
|
|
|
|
|
2019-08-31 14:09:48 +02:00
|
|
|
-- Internal functions
|
|
|
|
|
|
|
|
function BattleWidget:update(dt)
|
|
|
|
BattleWidget.super.update(self, dt)
|
|
|
|
end
|
|
|
|
|
|
|
|
function BattleWidget:selectAction()
|
2020-07-19 18:09:53 +02:00
|
|
|
-- Rien de base, à voir ensuite comment je gère
|
2019-03-31 16:43:04 +02:00
|
|
|
end
|
|
|
|
|
2019-08-31 14:09:48 +02:00
|
|
|
function BattleWidget:drawCanvas()
|
2019-03-31 16:43:04 +02:00
|
|
|
local h
|
2019-08-31 15:04:44 +02:00
|
|
|
local asset = love.graphics.newImage("assets/gui/attacklist.png")
|
|
|
|
local sw, sh = asset:getDimensions()
|
|
|
|
local startAsset = love.graphics.newQuad(0, 0, 16, sh, sw, sh)
|
|
|
|
local midAsset = love.graphics.newQuad(16, 0, 1, sh, sw, sh)
|
|
|
|
local endAsset = love.graphics.newQuad(sw-16, 0, 16, sh, sw, sh)
|
|
|
|
|
|
|
|
love.graphics.draw(asset, startAsset, 0, (self.height - 13) / 2)
|
|
|
|
love.graphics.draw(asset, endAsset, self.width-16, (self.height - 13) / 2)
|
|
|
|
|
|
|
|
local iterations = self.width-32
|
|
|
|
|
|
|
|
for i=0,iterations do
|
|
|
|
love.graphics.draw(asset, midAsset, 16+i, (self.height - 13) / 2)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-03-31 16:43:04 +02:00
|
|
|
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-08-31 14:09:48 +02:00
|
|
|
function BattleWidget:action()
|
2019-08-14 16:26:23 +02:00
|
|
|
self.scene:flushKeys()
|
2020-07-19 21:41:14 +02:00
|
|
|
self.scene.menusystem:deactivate()
|
|
|
|
|
|
|
|
self:sendCharacterData()
|
2019-03-31 16:57:57 +02:00
|
|
|
end
|
|
|
|
|
2019-08-31 14:09:48 +02:00
|
|
|
-- External functions
|
|
|
|
|
|
|
|
function BattleWidget:sendCharacterData()
|
2020-07-19 18:09:53 +02:00
|
|
|
self.character:doNothing()
|
2019-08-31 14:09:48 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- ActionWidget
|
|
|
|
-- The basic action widget
|
|
|
|
|
|
|
|
function ActionWidget:new(character, menu_name, action)
|
|
|
|
self.actionType = action or ""
|
|
|
|
ActionWidget.super.new(self, character, menu_name, action, "")
|
|
|
|
end
|
|
|
|
|
|
|
|
function ActionWidget:sendCharacterData()
|
2020-07-19 18:09:53 +02:00
|
|
|
self.character:doNothing()
|
2019-08-31 14:09:48 +02:00
|
|
|
end
|
|
|
|
|
2020-07-19 21:41:14 +02:00
|
|
|
-- AttackWidget
|
|
|
|
-- The basic action widget
|
|
|
|
|
|
|
|
function AttackWidget:new(character, menu_name)
|
|
|
|
self.actionType = "attack"
|
|
|
|
ActionWidget.super.new(self, character, menu_name, "attack", "")
|
|
|
|
end
|
|
|
|
|
|
|
|
function AttackWidget:sendCharacterData()
|
|
|
|
self.character:attack()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-08-31 14:09:48 +02:00
|
|
|
-- SubMenuWidget
|
|
|
|
-- A simple widget to change menu
|
|
|
|
|
|
|
|
function SubMenuWidget:new(character, menu_name, label, newmenu)
|
2019-08-31 15:04:44 +02:00
|
|
|
local label2 = ""
|
2019-08-31 15:44:34 +02:00
|
|
|
self.sfx = "mBack"
|
2019-08-31 15:04:44 +02:00
|
|
|
if label ~= "back" then
|
|
|
|
label2 = ">"
|
2019-08-31 15:44:34 +02:00
|
|
|
self.sfx = "mBeep"
|
2019-08-31 15:04:44 +02:00
|
|
|
end
|
|
|
|
SubMenuWidget.super.new(self, character, menu_name, label, label2)
|
2019-03-31 17:07:45 +02:00
|
|
|
self.newmenu = newmenu or "BaseMenu"
|
|
|
|
end
|
|
|
|
|
|
|
|
function SubMenuWidget:action()
|
2019-08-31 15:44:34 +02:00
|
|
|
self.assets.sfx[self.sfx]:play()
|
2019-03-31 17:15:27 +02:00
|
|
|
self.scene.menusystem:switchMenu(self.newmenu)
|
2019-03-31 17:07:45 +02:00
|
|
|
end
|
|
|
|
|
2019-08-31 14:09:48 +02:00
|
|
|
-- BackMenuWidget
|
|
|
|
-- Quit the menu
|
2019-03-31 17:35:55 +02:00
|
|
|
|
2019-08-31 14:09:48 +02:00
|
|
|
function BackMenuWidget:new(character, menu_name)
|
|
|
|
BackMenuWidget.super.new(self, character, menu_name, "back", "")
|
2019-03-31 17:35:55 +02:00
|
|
|
end
|
|
|
|
|
2019-08-31 14:09:48 +02:00
|
|
|
function BackMenuWidget:sendCharacterData()
|
2019-08-31 15:44:34 +02:00
|
|
|
self.assets.sfx["mBack"]:play()
|
2019-08-14 17:32:33 +02:00
|
|
|
self.character:receiveBackSignal()
|
2019-03-31 17:35:55 +02:00
|
|
|
end
|
|
|
|
|
2019-08-31 14:09:48 +02:00
|
|
|
-- SkillWidget
|
|
|
|
-- A widget to handle skills
|
2019-08-14 17:07:42 +02:00
|
|
|
|
2019-08-31 14:09:48 +02:00
|
|
|
function SkillWidget:new(character, menu_name, skill)
|
|
|
|
self.skillname = skill
|
|
|
|
local label2 = "00"
|
2019-08-22 22:04:14 +02:00
|
|
|
|
2019-08-31 14:09:48 +02:00
|
|
|
self.skilldata = game.skills:getSkillData(skill)
|
2019-08-22 22:04:14 +02:00
|
|
|
|
|
|
|
if self.skilldata ~= nil then
|
2019-08-31 14:09:48 +02:00
|
|
|
label2 = self.skilldata.cost or 0
|
|
|
|
if label2 < 10 then
|
|
|
|
label2 = "0" .. label2
|
2019-08-22 22:04:14 +02:00
|
|
|
end
|
|
|
|
end
|
2019-08-31 14:09:48 +02:00
|
|
|
|
|
|
|
SkillWidget.super.new(self, character, menu_name, self.skillname, "-" .. label2, "skills")
|
2019-08-14 17:07:42 +02:00
|
|
|
end
|
|
|
|
|
2019-08-31 14:09:48 +02:00
|
|
|
function SkillWidget:sendCharacterData()
|
2019-08-25 10:38:06 +02:00
|
|
|
|
2019-08-22 22:04:14 +02:00
|
|
|
if self.skilldata ~= nil then
|
2020-07-19 18:09:53 +02:00
|
|
|
self.assets.sfx["mSelect"]:play()
|
|
|
|
self.character:doNothing()
|
|
|
|
--self.character:useSkill(self.skillname, self.character.x, self.character.y)
|
2019-08-22 22:04:14 +02:00
|
|
|
else
|
2019-08-31 14:09:48 +02:00
|
|
|
core.debug:warning("cbs/menu", "skill " .. self.skillname .. " doesn't exist")
|
2020-07-19 18:09:53 +02:00
|
|
|
self.character:doNothing()
|
2019-08-31 15:44:34 +02:00
|
|
|
self.assets.sfx["mError"]:play()
|
2019-08-22 22:04:14 +02:00
|
|
|
end
|
2019-08-31 14:09:48 +02:00
|
|
|
|
2019-08-14 17:07:42 +02:00
|
|
|
end
|
2019-03-31 17:35:55 +02:00
|
|
|
|
2019-03-31 12:05:17 +02:00
|
|
|
return MenuConstructor
|