local assertArgs = include "assertArgs" local util = include "util" local ToastManager = lib "class" ("ToastManager") ToastManager:include(mixin "Position") ToastManager:include(mixin "Angle") ToastManager.static.TOAST_DURATION = 3.5 -- seconds ToastManager.static.TOAST_FADE_TIME = 0.2 ToastManager.static.TOAST_DIMENSIONS = { width = 0.2, height = 0.1, depth = 0.02 } function ToastManager:initialize(args) assertArgs(args, "x", "y", "z", "angle", "ax", "ay", "az") self:setPosition(args.x, args.y, args.z) self:setAngle(args.angle, args.ax, args.ay, args.az) self.toasts = {} return self end function ToastManager:addToast(message) self.toasts[#self.toasts + 1] = { message = message, time = ToastManager.static.TOAST_DURATION, lerpedIndex = #self.toasts } end function ToastManager:update(dt) util.foreachirev(self.toasts, function(toast, i) toast.time = toast.time - dt if toast.time <= 0 then table.remove(self.toasts, i) end toast.lerpedIndex = util.lerp(toast.lerpedIndex, i, 5 * dt) end) end function ToastManager:draw() util.foreachi(self.toasts, function(toast, i) local fade = math.min(toast.time, ToastManager.static.TOAST_FADE_TIME) / ToastManager.static.TOAST_FADE_TIME lovr.graphics.setColor(1, 1, 1, fade) local x, y, z = self:getX() + (1 - fade) * 0.2, self:getY() - (toast.lerpedIndex - 1) * 0.12, self:getZ() local angle, ax, ay, az = self:getAngle(), self:getAX(), self:getAY(), self:getAZ() lovr.graphics.box( "line", x, y, z, ToastManager.static.TOAST_DIMENSIONS.width, ToastManager.static.TOAST_DIMENSIONS.height, ToastManager.static.TOAST_DIMENSIONS.depth, angle, ax, ay, az ) lovr.graphics.print( toast.message, x, y, z, 0.02, angle, ax, ay, az ) end) end return ToastManager