-
Notifications
You must be signed in to change notification settings - Fork 0
/
nChat.py
133 lines (112 loc) · 4.41 KB
/
nChat.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
###############################################################
# nChat - Simple chat app with multiple lines and a detached
# input box. Background of the chat window and around the
# input become transparent as well as the chat text eventually
#
# I basically just ripped off the way XyChat works because it
# was crashing my game when I used my countdown app lol and I
# also wanted a detached input box and some other things.
###############################################################
import ac
import acsys
import math
import random
appWindow = 0
inputWindow = 0
textInput = 0
messages = []
lines = []
updateTrans = 1001
currentTrans = 0
updateText = 3001
currentText = 0
maxLines = 6
title = None
driver = ac.getDriverName(0).strip()
def acMain(ac_version):
global textInput, appWindow, inputWindow, messages, lines, maxLines
appWindow = ac.newApp('nChat')
inputWindow = ac.newApp('nInput')
ac.setSize(appWindow, 500, 100)
ac.drawBorder(appWindow, 0)
ac.setTitle(appWindow, '')
ac.setIconPosition(appWindow, -9000, 0)
ac.setBackgroundOpacity(appWindow, 0)
ac.setSize(inputWindow, 435, 62)
ac.drawBorder(inputWindow, 0)
ac.setTitle(inputWindow, '')
ac.setIconPosition(inputWindow, -9000, 0)
ac.setBackgroundOpacity(inputWindow, 0)
textInput = ac.addTextInput(inputWindow, 'TEXT_INPUT')
ac.setPosition(textInput, 1, 32)
ac.setSize(textInput, 435, 30)
ac.addOnChatMessageListener(appWindow, onChatMessage)
ac.addOnClickedListener(appWindow, onWindowClick)
ac.addOnValidateListener(textInput, onValidateListener)
ac.addOnClickedListener(inputWindow, onWindowClick)
for i in range(0, maxLines):
lines.append([ac.addLabel(appWindow, ''), ac.addLabel(appWindow, '')])
for x in range(0, 2):
ac.setSize(lines[i][x], 14*60, 14)
ac.setPosition(lines[i][x], 0, i*14+5)
ac.setFontSize(lines[i][x], 14)
# Maybe add back in later
#lines.reverse()
onChatMessage('Loaded...', 'nChat')
return "nChat"
def onChatMessage(message, author) :
global messages, lines, maxLines, currentText
currentText = 1
messages.append([author, message])
if len(messages) > maxLines:
messages = messages[len(messages)-maxLines:]
for i in range(0, maxLines):
if i < len(messages):
msg = messages[len(messages)-1-i]
scale = abs(float(-2))
n_width = 14*len(msg[0])/scale
m_width = 14*len(msg[1])/scale
ac.setText(lines[maxLines-1-i][1], msg[1])
ac.setSize(lines[maxLines-1-i][0], n_width, 14*1.4)
ac.setSize(lines[maxLines-1-i][1], m_width, 14*1.4)
if msg[0].strip().find(driver) > -1:
ac.setFontColor(lines[maxLines-1-i][0], 0, 1, 0, 1)
else:
ac.setFontColor(lines[maxLines-1-i][0], random.random(), random.random(), random.random(), 1)
ac.setFontColor(lines[maxLines-1-i][1], 1, 1, 1, 1)
ac.setVisible(lines[maxLines-1-i][0], 1)
ac.setVisible(lines[maxLines-1-i][1], 1)
ac.setPosition(lines[maxLines-1-i][0], 0, ac.getPosition(lines[maxLines-1-i][0])[1])
ac.setFontAlignment(lines[maxLines-1-i][0], "left")
ac.setPosition(lines[maxLines-1-i][1], n_width+5, ac.getPosition(lines[maxLines-1-i][1])[1])
ac.setFontAlignment(lines[maxLines-1-i][1], "left")
ac.setText(lines[maxLines-1-i][0], msg[0]+":")
def onValidateListener(string):
global textInput
text = ac.getText(textInput)
ac.setText(textInput, '')
ac.setFocus(textInput, 1)
ac.sendChatMessage(text)
def onWindowClick(x, y):
global currentTrans, currentText, lines, maxLines
currentTrans = 1
currentText = 1
for i in range(0, maxLines):
for x in range(0, 2):
ac.setVisible(lines[i][x], 1)
def acUpdate(deltaT):
global appWindow, inputWindow, currentTrans, updateTrans, currentText, updateText, lines, maxLines
if currentTrans != 0:
if currentTrans < updateTrans:
currentTrans += 1
else:
ac.setBackgroundOpacity(appWindow, 0)
ac.setBackgroundOpacity(inputWindow, 0)
currentTrans = 0
if currentText != 0:
if currentText < updateText:
currentText += 1
else:
for i in range(0, maxLines):
for x in range(0, 2):
ac.setVisible(lines[i][x], 0)