character list search
This commit is contained in:
parent
33ad3c205c
commit
ce91cf1867
157
charselect.py
157
charselect.py
@ -15,27 +15,29 @@ class CharIcon(QtGui.QLabel):
|
||||
super(CharIcon, self).__init__(parent)
|
||||
self.parent = parent
|
||||
self.ind = ind
|
||||
self.charid = 0
|
||||
|
||||
def setCharIndex(self, charid):
|
||||
self.charid = charid
|
||||
|
||||
def mousePressEvent(self, event):
|
||||
self.parent.onCharClicked(self.ind)
|
||||
self.parent.onCharClicked(self.charid)
|
||||
|
||||
class charselect(QtGui.QWidget):
|
||||
setBtnImage = QtCore.pyqtSignal(str, int)
|
||||
setBtnImage = QtCore.pyqtSignal(str, int, int)
|
||||
def __init__(self, parent):
|
||||
super(charselect, self).__init__(parent)
|
||||
self.parent = parent
|
||||
self.populated = False
|
||||
self.page = 0
|
||||
self.image = QtGui.QLabel(self)
|
||||
self.image.setPixmap(QtGui.QPixmap(AO2XPpath+"themes/default/charselect_background.png"))
|
||||
self.image.show()
|
||||
|
||||
self.charDropdown = QtGui.QComboBox(self)
|
||||
self.charDropdown.setEditable(True)
|
||||
self.charDropdown.move(255, 7)
|
||||
self.charDropdown.resize(200, self.charDropdown.sizeHint().height())
|
||||
self.charDropdown.currentIndexChanged.connect(self.onDropdownSelect)
|
||||
self.charDropdown.setToolTip("Select a character from the list")
|
||||
self.charsearch = QtGui.QLineEdit(self)
|
||||
self.charsearch.move(255, 7)
|
||||
self.charsearch.resize(200, self.charsearch.sizeHint().height())
|
||||
self.charsearch.textChanged.connect(self.onSearch)
|
||||
self.charsearch.setPlaceholderText('Search...')
|
||||
|
||||
self.quittolobby = QtGui.QPushButton(self)
|
||||
self.quittolobby.setText("Disconnect")
|
||||
@ -52,6 +54,14 @@ class charselect(QtGui.QWidget):
|
||||
self.buttons = []
|
||||
self.chartaken = []
|
||||
|
||||
self.prevpage = PixmapButton(self, QtGui.QPixmap(AO2XPpath+"themes/default/arrow_left.png"))
|
||||
self.nextpage = PixmapButton(self, QtGui.QPixmap(AO2XPpath+"themes/default/arrow_right.png"))
|
||||
|
||||
self.setButtons()
|
||||
|
||||
self.setBtnImage.connect(self.setButtonImage)
|
||||
|
||||
def setButtons(self):
|
||||
#directly stolen from ao2 source code and default theme because i was stuck (i'm so sorry)
|
||||
btn_width, btn_height = 60, 60
|
||||
x_spacing, y_spacing = 7, 7
|
||||
@ -61,12 +71,12 @@ class charselect(QtGui.QWidget):
|
||||
columns = (width - btn_width) / (x_spacing + btn_width) +1
|
||||
rows = (height - btn_height) / (y_spacing + btn_height) +1
|
||||
self.max_chars_on_page = columns * rows
|
||||
|
||||
for i in range(self.max_chars_on_page):
|
||||
self.buttons.append(CharIcon(self, i))
|
||||
self.chartaken.append(QtGui.QLabel(self))
|
||||
self.chartaken[i].setPixmap(QtGui.QPixmap(AO2XPpath+"themes/default/char_taken.png"))
|
||||
self.chartaken[i].hide()
|
||||
|
||||
x_pos = (btn_width + x_spacing) * x_mod_count
|
||||
y_pos = (btn_height + y_spacing) * y_mod_count
|
||||
self.buttons[i].setGeometry(left+x_pos, top+y_pos, btn_width, btn_height)
|
||||
@ -77,59 +87,24 @@ class charselect(QtGui.QWidget):
|
||||
if x_mod_count == columns:
|
||||
y_mod_count += 1
|
||||
x_mod_count = 0
|
||||
|
||||
self.prevpage = PixmapButton(self, QtGui.QPixmap(AO2XPpath+"themes/default/arrow_left.png"))
|
||||
|
||||
self.prevpage.move(left - self.prevpage.pixmap.size().width(), top + height)
|
||||
self.prevpage.clicked.connect(self.prevPageButton)
|
||||
self.prevpage.show()
|
||||
self.nextpage = PixmapButton(self, QtGui.QPixmap(AO2XPpath+"themes/default/arrow_right.png"))
|
||||
self.nextpage.move(left + width, top + height)
|
||||
self.nextpage.clicked.connect(self.nextPageButton)
|
||||
self.nextpage.show()
|
||||
|
||||
self.setBtnImage.connect(self.setButtonImage)
|
||||
|
||||
def quitToLobby(self):
|
||||
self.parent.gamewindow.returnToMenu()
|
||||
|
||||
def setPic(self, pixmap, ind):
|
||||
self.buttons[ind].setPixmap(QtGui.QPixmap(pixmap))
|
||||
|
||||
def populateCharacterDropdown(self):
|
||||
self.charDropdown.clear()
|
||||
self.charDropdown.addItem("")
|
||||
#model = self.charDropdown.model()
|
||||
self.populated = True
|
||||
|
||||
# Disable characters not in filesystem
|
||||
#for i, char in enumerate(self.charlist):
|
||||
for char in self.charlist:
|
||||
self.charDropdown.addItem(char[0])
|
||||
# if not char[3]:
|
||||
# model.item(i + 1).setEnabled(False)
|
||||
|
||||
def setCharList(self, charlist):
|
||||
self.charlist = charlist
|
||||
self.showCharPage()
|
||||
if not self.populated:
|
||||
self.populateCharacterDropdown()
|
||||
|
||||
def nextPageButton(self):
|
||||
self.page += 1
|
||||
self.showCharPage()
|
||||
|
||||
def prevPageButton(self):
|
||||
self.page -= 1
|
||||
self.showCharPage()
|
||||
|
||||
def showCharSelect(self, can_cancel = True):
|
||||
self.show()
|
||||
self.cancelbtn.setEnabled(can_cancel)
|
||||
|
||||
def showCharPage(self):
|
||||
for ind in range(self.page * self.max_chars_on_page, self.max_chars_on_page * (self.page+1)):
|
||||
def showCharPage(self, charlist=None):
|
||||
if not charlist:
|
||||
filtered = False
|
||||
charlist = self.charlist
|
||||
else:
|
||||
filtered = True
|
||||
|
||||
for ind in range(self.page * self.max_chars_on_page, self.max_chars_on_page * (self.page + 1)):
|
||||
i = ind - (self.page * self.max_chars_on_page)
|
||||
if ind >= len(self.charlist):
|
||||
if ind >= len(charlist):
|
||||
self.chartaken[i].hide()
|
||||
self.buttons[i].hide()
|
||||
self.nextpage.hide()
|
||||
@ -142,37 +117,70 @@ class charselect(QtGui.QWidget):
|
||||
else:
|
||||
self.prevpage.hide()
|
||||
|
||||
char = self.charlist[ind][0].lower()
|
||||
if exists(AOpath+"characters/"+ char +"/char_icon.png"): # AO2
|
||||
self.setBtnImage.emit(AOpath+"characters/"+ char +"/char_icon.png", i)
|
||||
elif exists(AOpath+"misc/demothings/"+ char +"_char_icon.png"): # AO 1.7.5/1.8
|
||||
self.setBtnImage.emit(AOpath+"misc/demothings/"+ char +"_char_icon.png", i)
|
||||
else:
|
||||
self.setBtnImage.emit("placeholder.png", i)
|
||||
char = charlist[ind][0].lower()
|
||||
charid = charlist[ind][2] if filtered else ind
|
||||
|
||||
if self.charlist[ind][1] == 0: # free slot
|
||||
if exists(AOpath+"characters/"+ char +"/char_icon.png"): # AO2
|
||||
self.setBtnImage.emit(AOpath+"characters/"+ char +"/char_icon.png", i, charid)
|
||||
elif exists(AOpath+"misc/demothings/"+ char +"_char_icon.png"): # AO 1.7.5/1.8
|
||||
self.setBtnImage.emit(AOpath+"misc/demothings/"+ char +"_char_icon.png", i, charid)
|
||||
else:
|
||||
self.setBtnImage.emit("placeholder.png", i, charid)
|
||||
|
||||
if charlist[ind][1] == 0: # free slot
|
||||
self.chartaken[i].hide()
|
||||
else:
|
||||
self.chartaken[i].setAttribute(QtCore.Qt.WA_TransparentForMouseEvents)
|
||||
self.chartaken[i].show()
|
||||
|
||||
self.buttons[i].show()
|
||||
self.buttons[i].setToolTip(self.charlist[ind][0])
|
||||
self.buttons[i].setToolTip(charlist[ind][0])
|
||||
|
||||
def showCharPageFiltered(self, name):
|
||||
charlist = []
|
||||
for i, char in enumerate(self.charlist):
|
||||
if name.lower() in char[0].lower():
|
||||
charlist.append([char[0], char[1], i])
|
||||
self.showCharPage(charlist)
|
||||
|
||||
def setButtonImage(self, filename, ind):
|
||||
self.buttons[ind].setPixmap(QtGui.QPixmap(filename))
|
||||
def quitToLobby(self):
|
||||
self.parent.gamewindow.returnToMenu()
|
||||
|
||||
def setCharList(self, charlist):
|
||||
self.charlist = charlist
|
||||
self.showCharPage()
|
||||
|
||||
def onCharClicked(self, ind):
|
||||
char = self.charlist[ind + self.page * self.max_chars_on_page]
|
||||
def nextPageButton(self):
|
||||
self.page += 1
|
||||
self.showCharPage()
|
||||
|
||||
def prevPageButton(self):
|
||||
self.page -= 1
|
||||
self.showCharPage()
|
||||
|
||||
def showCharSelect(self, can_cancel = True):
|
||||
self.show()
|
||||
self.cancelbtn.setEnabled(can_cancel)
|
||||
self.charsearch.setText("") # Automatically calls showCharPage
|
||||
|
||||
def setButtonImage(self, filename, i, charid):
|
||||
self.buttons[i].setPixmap(QtGui.QPixmap(filename))
|
||||
self.buttons[i].setCharIndex(charid)
|
||||
|
||||
def onCharClicked(self, charid):
|
||||
char = self.charlist[charid]
|
||||
if self.parent.charname.lower() == char[0].lower():
|
||||
self.onCancel()
|
||||
return
|
||||
self.selectChar(ind+(self.page*self.max_chars_on_page))
|
||||
self.selectChar(charid)
|
||||
|
||||
def onDropdownSelect(self, index):
|
||||
if index < 1 or self.charDropdown.count() <= 1:
|
||||
return
|
||||
self.selectChar(index - 1)
|
||||
def onSearch(self):
|
||||
self.page = 0
|
||||
text = self.charsearch.text()
|
||||
if text:
|
||||
self.showCharPageFiltered(unicode(text))
|
||||
else:
|
||||
self.showCharPage()
|
||||
|
||||
def selectChar(self, charIndex):
|
||||
self.parent.tcp.send("CC#0#"+str(charIndex)+"#ur mom gay#%")
|
||||
@ -181,9 +189,6 @@ class charselect(QtGui.QWidget):
|
||||
self.hide()
|
||||
self.parent.gamewindow.setFixedSize(self.parent.width, self.parent.height)
|
||||
self.parent.gamewindow.center()
|
||||
|
||||
def onDisconnect(self):
|
||||
self.populated = False
|
||||
|
||||
def show(self):
|
||||
super(charselect, self).show()
|
||||
|
@ -2107,7 +2107,6 @@ class gui(QtGui.QWidget):
|
||||
self.ooclogin.setText("Lo&gin")
|
||||
self.login = False
|
||||
self.privateinv = False
|
||||
self.charselect.onDisconnect()
|
||||
self.tcp.close()
|
||||
self.stopMusic()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user