-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat.lua
63 lines (57 loc) · 1.62 KB
/
chat.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
chat = {
log = {},
active = false,
val = '',
lastMsgTime = -1
}
function chat.addMsg(v)
table.insert(chat.log, v)
chat.lastMsgTime = gameTime
end
function chat.submit()
if chat.val ~= '' then
client.sendMessage(chat.val)
chat.lastMsgTime = gameTime
end
chat.val = ''
chat.active = false
end
function chat.textinput(t)
chat.val = chat.val .. t
end
function chat.keypressed(k, scancode, isrepeat)
if chat.active then
if k == 'escape' then
chat.val = ''
chat.active = false
elseif k == 'return' and not isrepeat then
chat.submit()
elseif k == 'backspace' then
chat.val = chat.val:sub(0, math.max(chat.val:len()-1, 0))
elseif k == 'v' and (love.keyboard.isScancodeDown('lctrl') or love.keyboard.isScancodeDown('rctrl')) then
local paste = love.system.getClipboardText()
chat.val = chat.val .. paste
end
elseif hud.chatPanel.open then
if k == 'escape' then
hud.chatPanel.open = false
end
end
end
function chat.draw()
love.graphics.setColor(1, 1, 1)
love.graphics.setFont(fonts.c17)
local startIdx = math.max(#chat.log - 10 + 1, 1)
local numMsgs = #chat.log - startIdx + 1
local cpy = hud.chatPanel.y
for i=1, numMsgs do
local v = chat.log[startIdx + (i-1)]
local y = cpy + 118 - (numMsgs - (i-1) + 1)*10 + 8
text.printSmall(v, 14, y)
end
local txt = chat.val
if chat.active then
txt = txt .. (time % 1 < 0.5 and '' or '|')
end
text.printSmall(txt, 14, cpy + 118)
end