-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChatCommandButton.py
124 lines (109 loc) · 4.18 KB
/
ChatCommandButton.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
from WindowElements import Widget
from Manialink import *
"""
\file ChatCommandButton.py
\brief Contains the ChatCommandButten-Widget-Class
"""
class ChatCommandButton(Widget):
"""
\brief A button to trigger a chat command
When this button is pressed, its assigned chatcommand will be triggered
"""
def __init__(self, commandLine = None):
"""
\brief Construct the button
"""
super(ChatCommandButton, self).__init__()
self.__commandLine = commandLine #The chat command to execute
self.__style = None #The logo on the button
self.__image = None #The image on the button
self.__text = None #The text of the button
self.__manialink = None #The manialink of the button
self.setSize((6, 10))
def setIcon(self, style):
"""
\brief Set the icon of the button
\param style (style, substyle)
"""
self.__style = style
def setImage(self, image, imageFocus = None):
"""
\brief Set the image of the button
\param image The image url
\param imageFocus The image url on mouseover (defaults to image)
"""
if imageFocus != None:
self.__image = (image, imageFocus)
else:
self.__image = (image, image)
def setManialink(self, ml):
"""
\brief Set the manialink of the button
\param ml The manialink address
"""
self.__manialink = ml
def setText(self, text):
"""
\brief Set the text of the button
\param text The new text
"""
self.__text = text
def getManialink(self):
"""
\brief Get the manialink hierarchie
"""
pos = self.getPos()
frame = Frame()
frame['posn'] = '{:d} {:d} {:d}'.format(*pos)
bgQuad = Quad()
bgQuad['valign'] = 'center'
bgQuad['halign'] = 'center'
bgQuad['style'] = 'Bgs1'
bgQuad['substyle'] = 'BgList'
#bgQuad['posn'] = '{:d} {:d} {:d}'.format(0, 0, 0)
bgQuad['sizen'] = '{:d} {:d}'.format(6, 10)
if self.__manialink != None:
bgQuad['manialink'] = self.__manialink
cbName = self.getWindowManager().getCallbackAddress(
self.getUser(),
self.getName(),
'cb_trigger')
bgQuad.setCallback(cbName, self.__commandLine)
frame.addChild(bgQuad)
logoQuad = Quad()
logoQuad['halign'] = 'center'
logoQuad['valign'] = 'center'
logoQuad['posn'] = '{:d} {:d} {:d}'.format(0, 2, 1)
logoQuad['sizen'] = '{:d} {:d}'.format(6, 6)
if self.__style != None:
logoQuad['style'] = self.__style[0]
logoQuad['substyle'] = self.__style[1]
if self.__image != None:
logoQuad['image'] = self.__image[0]
logoQuad['imagefocus'] = self.__image[1]
if self.__manialink != None:
logoQuad['manialink'] = self.__manialink
logoQuad.setCallback(cbName, self.__commandLine)
frame.addChild(logoQuad)
if self.__text != None:
textLabel = Label()
textLabel['text'] = self.__text
textLabel['halign'] = 'center'
textLabel['valign'] = 'bottom'
textLabel['posn'] = '{:d} {:d} {:d}'.format(0, -4, 1)
textLabel['sizen'] = '{:d} {:d}'.format(5, 2)
frame.addChild(textLabel)
return frame
def cb_trigger(self, entries, login, commandLine):
"""
\brief The button was triggered, call the chat command
\param entries Should be empty
\param login The login of the calling player
\param commandLine The chat command to execute
"""
if commandLine != None:
self.getWindowManager().callMethod(('TmChat', 'PlayerChat'),
0,
login,
commandLine,
True)