sonic-radiance/sonic-radiance.love/game/events/event/dialogbox.lua
2021-03-22 14:57:21 +01:00

65 lines
1.8 KiB
Lua

local StepParent = require "game.events.event.parent"
local DialogBox = StepParent:extend()
local Talkies = require('core.libs.talkies')
function DialogBox:new(controller, args)
DialogBox.super.new(self, controller, args)
Talkies.font = love.graphics.newFont("assets/gui/fonts/PixelOperator.ttf", 16)
end
function DialogBox:start()
local args = self:addOptions()
if (args == nil) then
Talkies.say(self.arguments.title, self.arguments.message)
else
Talkies.say(self.arguments.title, self.arguments.message, args)
end
end
function DialogBox:addOptions()
local args = {}
args.options = {}
local haveAddedSomething = false
if (self.arguments.option1 ~= nil) then
table.insert(args.options, {self.arguments.option1, function() self:setOption(1) end})
haveAddedSomething = true
end
if (self.arguments.option2 ~= nil) then
table.insert(args.options, {self.arguments.option2, function() self:setOption(2) end})
haveAddedSomething = true
end
if (self.arguments.option3 ~= nil) then
table.insert(args.options, {self.arguments.option3, function() self:setOption(3) end})
haveAddedSomething = true
end
if (haveAddedSomething) then
return args
end
end
function DialogBox:setOption(num)
print("option " .. num .. " chosen")
self.events:addFlag(self.arguments.flag, num)
self:finish()
end
function DialogBox:update(dt)
Talkies.update(dt)
if (not Talkies.isOpen()) then
self:finish()
end
local keys = self.events.scene.sources[1].keys
if (keys["up"].isPressed) then Talkies.prevOption()
elseif (keys["down"].isPressed) then Talkies.nextOption()
elseif (keys["A"].isPressed) then Talkies.onAction()
end
end
function DialogBox:draw()
Talkies.draw()
end
return DialogBox;