2020-08-20 15:33:28 +02:00
|
|
|
local fancy = require "game.modules.menus.fancy"
|
|
|
|
|
|
|
|
local widgets = {}
|
|
|
|
|
|
|
|
widgets.BattleWidget = fancy.BaseWidget:extend()
|
|
|
|
widgets.ActionWidget = widgets.BattleWidget:extend()
|
|
|
|
widgets.SubMenuWidget = widgets.BattleWidget:extend()
|
|
|
|
widgets.BackMenuWidget = widgets.BattleWidget:extend()
|
|
|
|
widgets.SkillWidget = widgets.BattleWidget:extend()
|
|
|
|
widgets.ItemWidget = widgets.BattleWidget:extend()
|
|
|
|
|
|
|
|
-- WIDGETS
|
|
|
|
-- All widgets used by the Characters menus
|
|
|
|
|
|
|
|
-- Basic Battle Widget
|
|
|
|
-- The base used by all battle widgets
|
|
|
|
|
|
|
|
function widgets.BattleWidget:new(character, menu_name, label1, label2)
|
|
|
|
local label1 = label1 or ""
|
|
|
|
local label2 = label2 or ""
|
|
|
|
|
|
|
|
self.character = character
|
|
|
|
local scene = self.character.turnSystem.scene
|
|
|
|
|
|
|
|
widgets.BattleWidget.super.new(self, scene, menu_name, label1, label2)
|
|
|
|
self.assets = self.scene.assets
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Internal functions
|
|
|
|
|
|
|
|
function widgets.BattleWidget:selectAction()
|
|
|
|
-- Rien de base, à voir ensuite comment je gère
|
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.BattleWidget:action()
|
|
|
|
self.scene:flushKeys()
|
|
|
|
self.scene.menusystem:deactivate()
|
|
|
|
|
|
|
|
self:sendCharacterData()
|
|
|
|
end
|
|
|
|
|
|
|
|
-- External functions
|
|
|
|
|
|
|
|
function widgets.BattleWidget:sendCharacterData()
|
|
|
|
self.character:doNothing()
|
|
|
|
end
|
|
|
|
|
|
|
|
-- ActionWidget
|
|
|
|
-- The basic action widget
|
|
|
|
|
2020-08-23 08:53:44 +02:00
|
|
|
function widgets.ActionWidget:new(character, menu_name, action, label)
|
2020-08-20 15:33:28 +02:00
|
|
|
self.actionType = action or ""
|
2020-08-23 08:53:44 +02:00
|
|
|
local label = label or self.actionType
|
|
|
|
widgets.ActionWidget.super.new(self, character, menu_name, label, "")
|
2020-08-20 15:33:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.ActionWidget:sendCharacterData()
|
|
|
|
self.character:doBasicAction(self.actionType)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- SubMenuWidget
|
|
|
|
-- A simple widget to change menu
|
|
|
|
|
|
|
|
function widgets.SubMenuWidget:new(character, menu_name, label, newmenu)
|
|
|
|
local label2 = ""
|
|
|
|
self.sfx = "mBack"
|
|
|
|
if label ~= "back" then
|
|
|
|
label2 = ">"
|
|
|
|
self.sfx = "mBeep"
|
|
|
|
end
|
2020-09-13 16:59:24 +02:00
|
|
|
widgets.SubMenuWidget.super.new(self, character, menu_name, label, label2)
|
2020-08-20 15:33:28 +02:00
|
|
|
self.newmenu = newmenu or "BaseMenu"
|
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.SubMenuWidget:action()
|
|
|
|
self.assets.sfx[self.sfx]:play()
|
|
|
|
self.scene.menusystem:switchMenu(self.newmenu)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- BackMenuWidget
|
|
|
|
-- Quit the menu
|
|
|
|
|
|
|
|
function widgets.BackMenuWidget:new(character, menu_name)
|
2020-09-13 16:59:24 +02:00
|
|
|
widgets.BackMenuWidget.super.new(self, character, menu_name, "back", "")
|
2020-08-20 15:33:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.BackMenuWidget:sendCharacterData()
|
|
|
|
self.assets.sfx["mBack"]:play()
|
|
|
|
self.character:receiveBackSignal()
|
|
|
|
end
|
|
|
|
|
|
|
|
-- SkillWidget
|
|
|
|
-- A widget to handle skills
|
|
|
|
|
|
|
|
function widgets.SkillWidget:new(character, menu_name, skill)
|
|
|
|
self.skillname = skill
|
|
|
|
local label2 = "00"
|
|
|
|
|
2021-05-16 08:48:05 +02:00
|
|
|
self.skilldata = core.datas:get("skills", skill)
|
2020-08-20 15:33:28 +02:00
|
|
|
|
|
|
|
if self.skilldata ~= nil then
|
|
|
|
label2 = self.skilldata.cost or 0
|
|
|
|
if label2 < 10 then
|
|
|
|
label2 = "0" .. label2
|
|
|
|
end
|
|
|
|
end
|
2021-03-13 17:28:25 +01:00
|
|
|
local color = {1, 1, 1}
|
|
|
|
if (self.skilldata.cost > character.abstract.pp) then
|
|
|
|
color = {1, 0.3, 0.3}
|
|
|
|
end
|
2021-08-15 15:30:20 +02:00
|
|
|
local fullName = self:getFullName(character)
|
2020-08-20 15:33:28 +02:00
|
|
|
|
2021-08-15 15:30:20 +02:00
|
|
|
widgets.SkillWidget.super.new(self, character, menu_name, fullName, "-" .. label2, "skills")
|
2021-03-13 17:28:25 +01:00
|
|
|
self.color = color
|
2020-08-20 15:33:28 +02:00
|
|
|
end
|
|
|
|
|
2021-08-15 15:30:20 +02:00
|
|
|
function widgets.SkillWidget:getFullName(character)
|
|
|
|
if (self.skilldata.altName == nil) then
|
|
|
|
return self.skilldata.fullname
|
|
|
|
end
|
|
|
|
if (self.skilldata.altName[character.abstract.simplename] ~= nil) then
|
|
|
|
return self.skilldata.altName[character.abstract.simplename]
|
|
|
|
else
|
|
|
|
return self.skilldata.fullname
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-20 15:33:28 +02:00
|
|
|
function widgets.SkillWidget:sendCharacterData()
|
|
|
|
|
2021-03-12 20:03:00 +01:00
|
|
|
if (self.skilldata ~= nil and self.skilldata.cost <= self.character.abstract.pp) then
|
2020-08-20 15:33:28 +02:00
|
|
|
self.assets.sfx["mSelect"]:play()
|
|
|
|
self.character:useSkill(self.skillname)
|
|
|
|
else
|
|
|
|
core.debug:warning("cbs/menu", "skill " .. self.skillname .. " doesn't exist")
|
|
|
|
self.character:doNothing()
|
|
|
|
self.assets.sfx["mError"]:play()
|
2021-03-13 17:28:25 +01:00
|
|
|
self.scene.turns.hud:showMessage("You haven't enough PP!")
|
2020-08-20 15:33:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
-- ItemWidget
|
|
|
|
-- A widget to handle items
|
|
|
|
|
|
|
|
function widgets.ItemWidget:new(character, menu_name, item)
|
2020-08-22 23:10:22 +02:00
|
|
|
self.category = menu_name
|
2020-08-20 15:33:28 +02:00
|
|
|
self.itemname = item
|
|
|
|
local label2 = "00"
|
|
|
|
|
|
|
|
self.number = game.loot:getItemNumber(menu_name, item)
|
2021-05-15 21:43:15 +02:00
|
|
|
self.itemdata = core.datas:get("items", item)
|
2020-08-20 15:33:28 +02:00
|
|
|
|
|
|
|
label2 = self.number
|
|
|
|
|
|
|
|
widgets.ItemWidget.super.new(self, character, menu_name, self.itemdata.fullname, "x" .. label2, "skills")
|
|
|
|
end
|
|
|
|
|
|
|
|
function widgets.ItemWidget:sendCharacterData()
|
2020-08-22 23:10:22 +02:00
|
|
|
self.character:useItem(self.category, self.itemname)
|
|
|
|
self.assets.sfx["mBeep"]:play()
|
2020-08-20 15:33:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
return widgets
|