sonic-radiance/sonic-radiance.love/game/events/event/dialogbox.lua

68 lines
2 KiB
Lua
Raw Normal View History

local StepParent = require "game.events.event.parent"
local DialogBox = StepParent:extend()
2021-05-05 08:30:32 +02:00
local Talkies = require('birb.libs.talkies')
function DialogBox:new(controller, args)
DialogBox.super.new(self, controller, args)
Talkies.font = love.graphics.newFont("assets/gui/fonts/PixelOperator.ttf", 16)
2021-03-22 20:02:54 +01:00
Talkies.talkSound = love.audio.newSource("assets/sfx/talk.wav", "static")
Talkies.optionOnSelectSound = love.audio.newSource("assets/sfx/menus/select.wav", "static")
Talkies.optionSwitchSound = love.audio.newSource("assets/sfx/menus/beep.wav", "static")
end
function DialogBox:start()
2021-03-22 14:57:21 +01:00
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)
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
2021-03-22 20:02:54 +01:00
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;