-
Notifications
You must be signed in to change notification settings - Fork 15
/
messageBoxState.lua
48 lines (38 loc) · 1.41 KB
/
messageBoxState.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
local State = require("state")
local Menu = require("menu")
local MessageBoxState = {}
MessageBoxState.__index = MessageBoxState
setmetatable(MessageBoxState, State)
function MessageBoxState.create(parent, message)
local self = setmetatable(State.create(), MessageBoxState)
self.inputs = parent.inputs
self.cursors = parent.cursors
self.message = message
local font = ResMgr.getFont("menu")
self.limit = 500
self.width, self.lines = font:getWrap(message, self.limit)
self.height = table.getn(self.lines) * font:getHeight()+48
self.x = (WIDTH-self.width)/2
self.y = (HEIGHT-self.height)/2
self.menu = self:addComponent(Menu.create((WIDTH-180)/2, self.y+self.height-32, 180, 32, 24, self))
self.menu:addButton("OKAY", "okay")
return self
end
function MessageBoxState:draw()
love.graphics.setFont(ResMgr.getFont("menu"))
love.graphics.setColor(23, 23, 23, 255)
love.graphics.rectangle("fill", self.x-25, self.y-25, self.width+50, self.height+50)
love.graphics.setColor(241, 148, 0, 255)
love.graphics.rectangle("line", self.x-24.5, self.y-24.5, self.width+50, self.height+50)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.printf(self.message, self.x, self.y, self.width, "center")
end
function MessageBoxState:buttonPressed(id, source)
if id == "okay" then
playSound("click")
love.timer.sleep(0.15)
popState()
end
end
function MessageBoxState:isTransparent() return true end
return MessageBoxState