- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.lua
More file actions
Latest commit
63 lines (57 loc) · 1.62 KB
/
Copy pathchat.lua
File metadata and controls
63 lines (57 loc) · 1.62 KB
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
}
functionchat.addMsg(v)
table.insert(chat.log, v)
chat.lastMsgTime=gameTime
end
functionchat.submit()
ifchat.val~='' then
client.sendMessage(chat.val)
chat.lastMsgTime=gameTime
end
chat.val=''
chat.active=false
end
functionchat.textinput(t)
chat.val=chat.val..t
end
functionchat.keypressed(k, scancode, isrepeat)
ifchat.activethen
ifk=='escape' then
chat.val=''
chat.active=false
elseifk=='return' andnotisrepeatthen
chat.submit()
elseifk=='backspace' then
chat.val=chat.val:sub(0, math.max(chat.val:len()-1, 0))
elseifk=='v' and (love.keyboard.isScancodeDown('lctrl') orlove.keyboard.isScancodeDown('rctrl')) then
localpaste=love.system.getClipboardText()
chat.val=chat.val..paste
end
elseifhud.chatPanel.openthen
ifk=='escape' then
hud.chatPanel.open=false
end
end
end
functionchat.draw()
love.graphics.setColor(1, 1, 1)
love.graphics.setFont(fonts.c17)
localstartIdx=math.max(#chat.log-10+1, 1)
localnumMsgs=#chat.log-startIdx+1
localcpy=hud.chatPanel.y
fori=1, numMsgsdo
localv=chat.log[startIdx+ (i-1)]
localy=cpy+118- (numMsgs- (i-1) +1)*10+8
text.printSmall(v, 14, y)
end
localtxt=chat.val
ifchat.activethen
txt=txt.. (time%1<0.5and'' or'|')
end
text.printSmall(txt, 14, cpy+118)
end