forked from headshot2017/AIO
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuttons.py
More file actions
148 lines (122 loc) · 4.74 KB
/
buttons.py
File metadata and controls
148 lines (122 loc) · 4.74 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import os
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import ini
class AIOButton(QLabel):
clicked = pyqtSignal()
rightClicked = pyqtSignal()
def __init__(self, parent=None):
QLabel.__init__(self, parent)
def mousePressEvent(self, ev):
if ev.buttons() == Qt.LeftButton:
self.clicked.emit()
elif ev.buttons() == Qt.RightButton:
self.rightClicked.emit()
class AIOIndexButton(QLabel):
clicked = pyqtSignal(int)
rightClicked = pyqtSignal(int)
mouseEnter = pyqtSignal(int)
mouseLeave = pyqtSignal(int)
def __init__(self, parent=None, ind=-1):
super(AIOIndexButton, self).__init__(parent)
self.ind = ind
def __del__(self):
self.deleteLater()
def event(self, event):
if event.type() == QEvent.Enter:
self.mouseEnter.emit(self.ind)
elif event.type() == QEvent.Leave:
self.mouseLeave.emit(self.ind)
super(AIOIndexButton, self).event(event)
return True
def mousePressEvent(self, ev):
if ev.buttons() == Qt.LeftButton:
self.clicked.emit(self.ind)
elif ev.buttons() == Qt.RightButton:
self.rightClicked.emit(self.ind)
class AIOCharButton(AIOIndexButton):
def __init__(self, parent, ao_app, ind):
super(AIOCharButton, self).__init__(parent, ind)
self.ind = ind
self.ao_app = ao_app
self.setPixmap(QPixmap("data/misc/char_icon.png"))
self.resize(64, 64)
self.charpic = QLabel(self)
self.charpic.move(0, -8)
self.show()
self.showChar()
def showChar(self):
prefix = ini.read_ini("data/characters/"+self.ao_app.charlist[self.ind]+"/char.ini", "Options", "imgprefix")+"-"
prefix = "" if prefix == "-" else prefix
scale = True
if os.path.exists("data/characters/"+self.ao_app.charlist[self.ind]+"/char_icon.png"):
pix = QPixmap("data/characters/"+self.ao_app.charlist[self.ind]+"/char_icon.png")
scale = False
elif os.path.exists("data/characters/"+self.ao_app.charlist[self.ind]+"/"+prefix+"spin.gif"):
pix = QPixmap("data/characters/"+self.ao_app.charlist[self.ind]+"/"+prefix+"spin.gif")
else:
pix = QPixmap("data/misc/error.gif")
if scale:
scale = ini.read_ini_float("data/characters/"+self.ao_app.charlist[self.ind]+"/char.ini", "Options", "scale", 1.0)*2
self.charpic.setPixmap(pix.scaled(pix.size().width()*scale, pix.size().height()*scale))
if self.charpic.pixmap().size().width() > self.pixmap().size().width():
self.charpic.move(-(self.charpic.pixmap().size().width()/4) + 8, -8)
elif self.charpic.pixmap().size().width() < self.pixmap().size().width():
self.charpic.move((self.charpic.pixmap().size().width()/4) - 4, -8)
else:
self.charpic.setPixmap(pix)
self.charpic.move(0, 0)
self.charpic.show()
def __del__(self):
self.charpic.deleteLater()
super(AIOCharButton, self).__del__()
class PenaltyBar(QLabel):
minusClicked = pyqtSignal(int)
plusClicked = pyqtSignal(int)
def __init__(self, parent=None, type=0):
super(PenaltyBar, self).__init__(parent)
self.parent = parent
self.penaltybars = []
self.type = type
self.health = 10
def setupUi(self, parent, theme):
self.parent = parent
if self.type == 0: #defense bar.
for i in range(11):
self.penaltybars.append(QPixmap("data/themes/"+theme+"/defensebar"+str(i)+".png"))
self.side = "def"
elif self.type == 1: #prosecution bar
for i in range(11):
self.penaltybars.append(QPixmap("data/themes/"+theme+"/prosecutionbar"+str(i)+".png"))
self.side = "pro"
self.minusbtn = AIOButton(parent.IngameUI)
self.plusbtn = AIOButton(parent.IngameUI)
self.resize(self.penaltybars[0].size())
self.minusbtn.setPixmap(QPixmap("data/themes/"+theme+"/"+self.side+"minus.png"))
self.plusbtn.setPixmap(QPixmap("data/themes/"+theme+"/"+self.side+"plus.png"))
self.minusbtn.clicked.connect(self.minusClick)
self.plusbtn.clicked.connect(self.plusClick)
self.setPixmap(self.penaltybars[10])
self.minusbtn.show()
self.plusbtn.show()
self.show()
self.move(self.x(), self.y())
def move(self, x, y):
self.minusbtn.move(x - (self.minusbtn.pixmap().size().width()/2), y + (self.size().height()/2) - (self.minusbtn.pixmap().size().width()/2))
self.plusbtn.move(x + self.size().width() - (self.plusbtn.pixmap().size().width()/2), y + (self.size().height()/2) - (self.plusbtn.pixmap().size().width()/2))
super(PenaltyBar, self).move(x, y)
def plusClick(self):
self.plusClicked.emit(self.type)
def minusClick(self):
self.minusClicked.emit(self.type)
def setHealth(self, health):
self.setPixmap(self.penaltybars[health])
self.health = health
def hide(self):
self.minusbtn.hide()
self.plusbtn.hide()
super(PenaltyBar, self).hide()
def show(self):
self.minusbtn.show()
self.plusbtn.show()
super(PenaltyBar, self).show()