sonic-radiance/sonic-radiance.love/scenes/battlesystem/gui/menus/widgets.lua

165 lines
4.3 KiB
Lua
Raw Normal View History

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)
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, "")
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)
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", "")
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)
if self.skilldata ~= nil then
label2 = self.skilldata.cost or 0
if label2 < 10 then
label2 = "0" .. label2
end
end
local color = {1, 1, 1}
if (self.skilldata.cost > character.abstract.pp) then
color = {1, 0.3, 0.3}
end
local fullName = self:getFullName(character)
widgets.SkillWidget.super.new(self, character, menu_name, fullName, "-" .. label2, "skills")
self.color = color
end
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
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
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()
self.scene.turns.hud:showMessage("You haven't enough PP!")
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
self.itemname = item
local label2 = "00"
self.number = game.loot:getItemNumber(menu_name, item)
self.itemdata = core.datas:get("items", item)
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()
end
return widgets