145 lines
3.5 KiB
Lua
145 lines
3.5 KiB
Lua
|
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
|
||
|
|
||
|
function widgets.ActionWidget:new(character, menu_name, action)
|
||
|
self.actionType = action or ""
|
||
|
widgets.ActionWidget.super.new(self, character, menu_name, action, "")
|
||
|
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
|
||
|
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)
|
||
|
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
|
||
|
|
||
|
widgets.SkillWidget.super.new(self, character, menu_name, self.skillname, "-" .. 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)
|
||
|
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()
|
||
|
self.character:doNothing()
|
||
|
self.assets.sfx["mError"]:play()
|
||
|
end
|
||
|
|
||
|
|
||
|
return widgets
|