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

147 lines
3.7 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"
self.skilldata = game.skills:getSkillData(skill)
if self.skilldata ~= nil then
label2 = self.skilldata.cost or 0
if label2 < 10 then
label2 = "0" .. label2
end
end
2020-08-23 08:53:44 +02:00
widgets.SkillWidget.super.new(self, character, menu_name, self.skilldata.fullname, "-" .. label2, "skills")
end
function widgets.SkillWidget:sendCharacterData()
if self.skilldata ~= nil 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()
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 = game.loot:getItemData(menu_name, 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