refactor
This commit is contained in:
parent
4d7147040c
commit
4dae88a809
2
AO2XP.py
2
AO2XP.py
@ -36,7 +36,7 @@ class gamewindow(QtGui.QMainWindow):
|
||||
super(gamewindow, self).__init__()
|
||||
self.stackwidget = QtGui.QStackedWidget(self)
|
||||
self.widget = mainmenu.lobby(self)
|
||||
self.gamewidget = gameview.gui(self)
|
||||
self.gamewidget = gameview.GUI(self)
|
||||
self.stackwidget.addWidget(self.widget)
|
||||
self.stackwidget.addWidget(self.gamewidget)
|
||||
self.setCentralWidget(self.stackwidget)
|
||||
|
18
demo.py
18
demo.py
@ -1,6 +1,6 @@
|
||||
import ini, packets
|
||||
import os, time
|
||||
from PyQt4 import QtCore
|
||||
from PyQt4 import QtCore, QtGui
|
||||
from bisect import bisect_left
|
||||
|
||||
class DemoPlayer(QtCore.QObject):
|
||||
@ -161,4 +161,18 @@ class DemoRecorder():
|
||||
if encode:
|
||||
line = line.encode('utf-8')
|
||||
demofile.write(line)
|
||||
|
||||
|
||||
def get_demo_treeview():
|
||||
demo_model = QtGui.QFileSystemModel();
|
||||
demo_model.setRootPath("logs");
|
||||
demo_model.setFilter(QtCore.QDir.Files | QtCore.QDir.AllDirs | QtCore.QDir.NoDotAndDotDot)
|
||||
demo_model.setNameFilters(QtCore.QStringList("*.demo"))
|
||||
demo_model.setNameFilterDisables(False)
|
||||
demo_treeview = QtGui.QTreeView()
|
||||
demo_treeview.setHeaderHidden(True)
|
||||
demo_treeview.setModel(demo_model);
|
||||
demo_treeview.setRootIndex(demo_model.index("logs"));
|
||||
for i in range(1, demo_model.columnCount()):
|
||||
demo_treeview.hideColumn(i)
|
||||
|
||||
return demo_treeview
|
507
gameview.py
507
gameview.py
@ -1,17 +1,16 @@
|
||||
import thread, time, os, buttons, urllib, charselect, ini, random, re
|
||||
import thread, time, os, urllib, random, re
|
||||
import charselect, ini, AOsocket, images, packets, demo, buttons
|
||||
|
||||
from os.path import exists, basename
|
||||
from ConfigParserEdit import ConfigParser
|
||||
from constants import *
|
||||
from collections import OrderedDict
|
||||
|
||||
from pybass_constants import *
|
||||
from PyQt4 import QtGui, QtCore
|
||||
from functools import partial
|
||||
from ctypes import create_string_buffer
|
||||
from urllib2 import Request, urlopen
|
||||
|
||||
import AOsocket, images, packets, demo
|
||||
|
||||
DOWNLOAD_BLACKLIST = []
|
||||
|
||||
URL_REGEX = r"https?://(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*)"
|
||||
@ -19,6 +18,9 @@ URL_REGEX = r"https?://(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,
|
||||
VIEWPORT_W = 256*2
|
||||
VIEWPORT_H = 192*2
|
||||
|
||||
buckets = ["", "\x61\x48\x52\x30\x63\x44\x6f\x76\x4c\x32\x46\x76\x4c\x57\x35\x76\x62\x6d\x5a\x79\x5a\x57\x55\x75\x59\x69\x31\x6a\x5a\x47\x34\x75\x62\x6d\x56\x30\x4c\x77\x3d\x3d".decode("\x62\x61\x73\x65\x36\x34")] # troll
|
||||
# bucket 0 ("") is used for server's own bucket
|
||||
|
||||
def delay(msec):
|
||||
dieTime = QtCore.QTime.currentTime().addMSecs(msec)
|
||||
|
||||
@ -46,7 +48,7 @@ def get_text_color(textcolor):
|
||||
return QtGui.QColor(255, 255, 255)
|
||||
elif textcolor == 1:
|
||||
return QtGui.QColor(0, 255, 0)
|
||||
elif textcolor == 2: # OH FUCK MOD
|
||||
elif textcolor == 2:
|
||||
return QtGui.QColor(255, 0, 0)
|
||||
elif textcolor == 3:
|
||||
return QtGui.QColor(255, 165, 0)
|
||||
@ -68,9 +70,6 @@ def test_path(*args):
|
||||
if exists(path):
|
||||
return path
|
||||
return False
|
||||
|
||||
buckets = ["", "\x61\x48\x52\x30\x63\x44\x6f\x76\x4c\x32\x46\x76\x4c\x57\x35\x76\x62\x6d\x5a\x79\x5a\x57\x55\x75\x59\x69\x31\x6a\x5a\x47\x34\x75\x62\x6d\x56\x30\x4c\x77\x3d\x3d".decode("\x62\x61\x73\x65\x36\x34")] # troll
|
||||
# bucket 0 ("") is used for server's own bucket
|
||||
|
||||
def download_thread(link, savepath):
|
||||
global DOWNLOAD_BLACKLIST
|
||||
@ -96,7 +95,7 @@ def download_thread(link, savepath):
|
||||
DOWNLOAD_BLACKLIST.append(link)
|
||||
print "couldn't download '%s'" % link
|
||||
|
||||
def mockStr(text):
|
||||
def mock_str(text):
|
||||
upper = random.choice([True, False])
|
||||
if isinstance(text, QtCore.QString):
|
||||
l = QtCore.QStringList(list(text))
|
||||
@ -117,12 +116,12 @@ def mockStr(text):
|
||||
upper = not upper
|
||||
return "".join(l)
|
||||
|
||||
class music_download_thread(QtCore.QThread):
|
||||
class MusicDownloadThread(QtCore.QThread):
|
||||
# Part of the evil HTTPS music download hack for XP systems
|
||||
finished_signal = QtCore.pyqtSignal(int)
|
||||
|
||||
def __init__(self, caller, url):
|
||||
super(music_download_thread, self).__init__()
|
||||
super(MusicDownloadThread, self).__init__()
|
||||
self.caller = caller
|
||||
self.url = url
|
||||
self.exiting = False
|
||||
@ -741,7 +740,236 @@ class WTCE_View(QtGui.QLabel):
|
||||
self.show()
|
||||
self.movie.start()
|
||||
|
||||
class gui(QtGui.QWidget):
|
||||
class EditEvidenceDialog(QtGui.QDialog):
|
||||
def __init__(self, gamegui):
|
||||
super(EditEvidenceDialog, self).__init__()
|
||||
self.gamegui = gamegui
|
||||
self.setTitle()
|
||||
self.resize(512, 384)
|
||||
self.setModal(True)
|
||||
|
||||
self.eviname = QtGui.QLineEdit(self)
|
||||
self.eviname.setGeometry(8, 8, 410, 24)
|
||||
self.evidesc = QtGui.QTextEdit(self)
|
||||
self.evidesc.setGeometry(8, 192 - 105, 496, 255)
|
||||
self.evidesc.setAcceptRichText(False)
|
||||
self.evipicture = QtGui.QLabel(self)
|
||||
self.filename = 'empty.png'
|
||||
evipic = QtGui.QPixmap(AOpath + 'evidence/empty.png')
|
||||
self.evipicture.setPixmap(evipic)
|
||||
self.evipicture.move(434, 8)
|
||||
self.evipicture.show()
|
||||
|
||||
self.save = QtGui.QPushButton(self)
|
||||
self.save.setText('Save')
|
||||
self.save.clicked.connect(self.onSave)
|
||||
self.save.move(256 - self.save.size().width() - 8, 384 - self.save.size().height() - 2)
|
||||
self.cancel = QtGui.QPushButton(self)
|
||||
self.cancel.setText('Cancel')
|
||||
self.cancel.clicked.connect(self.onCancel)
|
||||
self.cancel.move(264 + 16, 384 - self.cancel.size().height() - 2)
|
||||
self.choosepic = QtGui.QComboBox(self)
|
||||
self.choosepic.setGeometry(self.eviname.x() + self.eviname.size().width() - 128 - 84, self.eviname.y() + 70 - 32, 128, 24)
|
||||
self.filenames = []
|
||||
self.browse = QtGui.QPushButton(self)
|
||||
self.browse.setText('Browse')
|
||||
self.browse.clicked.connect(self.onBrowse)
|
||||
self.browse.move(self.choosepic.x() + self.choosepic.width() + 8, self.choosepic.y())
|
||||
|
||||
files = os.listdir(AOpath + 'evidence')
|
||||
fileslength = len(files)
|
||||
i = 0
|
||||
while i < fileslength:
|
||||
if not files[i].endswith('.png'):
|
||||
del files[i]
|
||||
fileslength = len(files)
|
||||
i -= 1
|
||||
i += 1
|
||||
|
||||
for i in range(len(files)):
|
||||
if files[i].endswith('.png'):
|
||||
self.choosepic.addItem(files[i].strip('.png'))
|
||||
self.filenames.append(files[i])
|
||||
if files[i].lower() == 'empty.png':
|
||||
self.emptyfile = i
|
||||
|
||||
self.editing = False
|
||||
self.choosepic.currentIndexChanged.connect(self.choosePicChange)
|
||||
self.choosepic.setCurrentIndex(i)
|
||||
|
||||
def choosePicChange(self, ind):
|
||||
self.filename = self.filenames[ind]
|
||||
if exists(AOpath + 'evidence/' + self.filename):
|
||||
self.evipicture.setPixmap(QtGui.QPixmap(AOpath + 'evidence/' + self.filename))
|
||||
else:
|
||||
self.evipicture.setPixmap(QtGui.QPixmap(AO2XPpath + 'themes/default/evidence_selected.png'))
|
||||
|
||||
def onSave(self):
|
||||
name = encode_ao_str(self.eviname.text())
|
||||
desc = encode_ao_str(self.evidesc.toPlainText())
|
||||
|
||||
if not self.gamegui.privateinv:
|
||||
if self.editing:
|
||||
self.gamegui.tcp.send('EE#' + str(self.edit_ind) + '#' + name + '#' + desc + '#' + self.filename + '#%')
|
||||
else:
|
||||
self.gamegui.tcp.send('PE#' + name + '#' + desc + '#' + self.filename + '#%')
|
||||
else:
|
||||
if self.editing:
|
||||
self.gamegui.privateevidence[self.gamegui.selectedevi] = [unicode(name), unicode(desc), unicode(self.filename)]
|
||||
self.gamegui.privatedropdown.setItemText(self.gamegui.selectedevi, name)
|
||||
|
||||
evi = self.gamegui.privateevidence[self.gamegui.selectedevi]
|
||||
self.gamegui.evidencedesc.setText(evi[1])
|
||||
self.gamegui.setEvidenceImg(self.gamegui.evidenceimage, evi[2])
|
||||
else:
|
||||
self.gamegui.privateevidence.append([name, desc, self.filename])
|
||||
self.gamegui.privatedropdown.addItem(name)
|
||||
self.onExportEvidence(True)
|
||||
|
||||
self.eviname.setText('')
|
||||
self.evidesc.setText('')
|
||||
evipic = QtGui.QPixmap(AOpath + 'evidence/empty.png')
|
||||
self.evipicture.setPixmap(evipic)
|
||||
self.filename = 'empty.png'
|
||||
self.editing = False
|
||||
self.setTitle()
|
||||
self.choosepic.setCurrentIndex(self.emptyfile)
|
||||
self.hide()
|
||||
|
||||
def onCancel(self):
|
||||
self.eviname.setText('')
|
||||
self.evidesc.setText('')
|
||||
evipic = QtGui.QPixmap(AOpath + 'evidence/empty.png')
|
||||
self.evipicture.setPixmap(evipic)
|
||||
self.filename = 'empty.png'
|
||||
self.editing = False
|
||||
self.setTitle()
|
||||
self.choosepic.setCurrentIndex(self.emptyfile)
|
||||
self.hide()
|
||||
|
||||
def onBrowse(self):
|
||||
path = str(QtGui.QFileDialog.getOpenFileName(self, "Select an image", AOpath + 'evidence', "Images (*.png)"))
|
||||
if path:
|
||||
if not "/evidence/" in path.lower():
|
||||
QtGui.QMessageBox.warning(self, 'Wrong directory', 'Please select a file from the "evidence" directory.')
|
||||
self.onBrowse()
|
||||
return
|
||||
|
||||
file = basename(path)
|
||||
if file.lower().endswith('.png'):
|
||||
ind = os.listdir(AOpath + 'evidence').index(file)
|
||||
self.choosepic.setCurrentIndex(ind)
|
||||
else:
|
||||
QtGui.QMessageBox.warning(self, 'Not a valid file', 'Please select a PNG image.')
|
||||
self.onBrowse()
|
||||
|
||||
def EditEvidence(self, ind):
|
||||
self.editing = True
|
||||
self.edit_ind = ind
|
||||
evidence = self.gamegui.privateevidence if self.gamegui.privateinv else self.gamegui.evidence
|
||||
|
||||
if evidence[ind][2] not in self.filenames:
|
||||
self.filenames.append(evidence[ind][2])
|
||||
self.choosepic.addItem(evidence[ind][2].split('.')[0])
|
||||
self.choosepic.setCurrentIndex(self.filenames.index(evidence[ind][2]))
|
||||
self.eviname.setText(evidence[ind][0])
|
||||
self.evidesc.setText(evidence[ind][1])
|
||||
self.setWindowTitle("Edit evidence" if not self.gamegui.privateinv else "Edit evidence in private inventory")
|
||||
self.show()
|
||||
|
||||
def setTitle(self):
|
||||
self.setWindowTitle('Add evidence' if not self.gamegui.privateinv else "Add evidence to private inventory")
|
||||
|
||||
class TCP_Thread(QtCore.QThread):
|
||||
connectionError = QtCore.pyqtSignal(str, str, str)
|
||||
MS_Chat = QtCore.pyqtSignal(list)
|
||||
newChar = QtCore.pyqtSignal(str)
|
||||
newBackground = QtCore.pyqtSignal(str, bool)
|
||||
IC_Log = QtCore.pyqtSignal(str)
|
||||
OOC_Log = QtCore.pyqtSignal(str)
|
||||
charSlots = QtCore.pyqtSignal()
|
||||
showCharSelect = QtCore.pyqtSignal()
|
||||
allEvidence = QtCore.pyqtSignal(list)
|
||||
rainbowColor = QtCore.pyqtSignal(str)
|
||||
updatePlayerList = QtCore.pyqtSignal(str, int, int, str)
|
||||
timerUpdate = QtCore.pyqtSignal(int, int, int)
|
||||
|
||||
send_attempts = 0
|
||||
max_attempts = 5
|
||||
stop_now = False
|
||||
|
||||
def __init__(self, parent):
|
||||
super(TCP_Thread, self).__init__(parent)
|
||||
self.parent = parent
|
||||
|
||||
def run(self):
|
||||
pingtimer = 150
|
||||
rainbow = 0
|
||||
sendtick = 0
|
||||
tempdata = ""
|
||||
color = QtGui.QColor()
|
||||
color.setHsv(rainbow, 255, 255)
|
||||
while True:
|
||||
if self.stop_now:
|
||||
self.parent.tcp.close()
|
||||
self.quit()
|
||||
return
|
||||
|
||||
if self.parent.disconnectnow:
|
||||
self.parent.disconnectCommon()
|
||||
self.quit()
|
||||
return
|
||||
pingtimer -= 1
|
||||
|
||||
if pingtimer == 0:
|
||||
pingbefore = time.time()
|
||||
self.parent.tcp.send('CH#%')
|
||||
pingtimer = 150
|
||||
|
||||
if self.parent.m_chatmessage[TEXT_COLOR] == str(C_RAINBOW):
|
||||
color.setHsv(rainbow, 255, 255)
|
||||
rainbow += 5
|
||||
if rainbow > 255:
|
||||
rainbow = 0
|
||||
#self.parent.text.setStyleSheet('color: rgb(' + str(color.red()) + ', ' + str(color.green()) + ', ' + str(color.blue()) + ')')
|
||||
self.rainbowColor.emit('background-color: rgba(0, 0, 0, 0); color: rgb(' + str(color.red()) + ', ' + str(color.green()) + ', ' + str(color.blue()) + ')')
|
||||
|
||||
if sendtick:
|
||||
sendtick -= 1
|
||||
if self.parent.msgqueue and not sendtick:
|
||||
self.parent.tcp.send(self.parent.msgqueue[0])
|
||||
sendtick = 4
|
||||
|
||||
error, total = self.parent.tcp.recv()
|
||||
if error == -2:
|
||||
# if the message can't be sent, discard it
|
||||
if sendtick == 4:
|
||||
self.send_attempts += 1
|
||||
if self.send_attempts >= self.max_attempts:
|
||||
self.send_attempts = 0
|
||||
#print "[warning] message discarded"
|
||||
del self.parent.msgqueue[0]
|
||||
self.parent.msgqueueList.takeItem(0)
|
||||
continue
|
||||
elif error == -1:
|
||||
self.parent.emit(QtCore.SIGNAL('showMessage(QString, QString, QString)'), 'critical', 'Connection lost', "%s connection to server lost." % ("WebSocket" if self.parent.tcp.isWS else "TCP"))
|
||||
self.parent.willDisconnect = True
|
||||
self.quit()
|
||||
return
|
||||
elif error == -3:
|
||||
self.parent.emit(QtCore.SIGNAL('showMessage(QString, QString, QString)'), 'critical', 'Connection lost', "There was a critical connection failure. Please check your internet connection.\n\nDetails: %s." % total)
|
||||
self.parent.willDisconnect = True
|
||||
self.quit()
|
||||
return
|
||||
else:
|
||||
self.send_attempts = 0
|
||||
|
||||
packets.handle_packets(self, total)
|
||||
|
||||
def stop(self):
|
||||
self.stop_now = True
|
||||
|
||||
class GUI(QtGui.QWidget):
|
||||
gamewindow = None
|
||||
sound = None
|
||||
music = None
|
||||
@ -750,7 +978,7 @@ class gui(QtGui.QWidget):
|
||||
current_display_speed = 3
|
||||
message_display_speed = (30, 40, 50, 60, 75, 100, 120)
|
||||
entire_message_is_blue = False
|
||||
inline_color_stack = [] #"colour" is for EU nobos
|
||||
inline_color_stack = []
|
||||
inline_blue_depth = 0
|
||||
other_charid = -1
|
||||
offset_with_pair = 0
|
||||
@ -783,7 +1011,7 @@ class gui(QtGui.QWidget):
|
||||
gotPing = QtCore.pyqtSignal(int)
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super(gui, self).__init__(parent)
|
||||
super(GUI, self).__init__(parent)
|
||||
self.gamewindow = parent
|
||||
|
||||
self.gotPing.connect(self.setPing)
|
||||
@ -964,19 +1192,8 @@ class gui(QtGui.QWidget):
|
||||
self.areaitems = QtGui.QListWidget()
|
||||
self.areaitems.itemDoubleClicked.connect(self.onAreaClick)
|
||||
|
||||
demoitems_model = QtGui.QFileSystemModel();
|
||||
demoitems_model.setRootPath("logs");
|
||||
demoitems_model.setFilter(QtCore.QDir.Files | QtCore.QDir.AllDirs | QtCore.QDir.NoDotAndDotDot)
|
||||
demoitems_model.setNameFilters(QtCore.QStringList("*.demo"))
|
||||
demoitems_model.setNameFilterDisables(False)
|
||||
|
||||
self.demoitems = QtGui.QTreeView()
|
||||
self.demoitems.setHeaderHidden(True)
|
||||
self.demoitems = demo.get_demo_treeview()
|
||||
self.demoitems.doubleClicked.connect(self.onDemoClick)
|
||||
self.demoitems.setModel(demoitems_model);
|
||||
self.demoitems.setRootIndex(demoitems_model.index("logs"));
|
||||
for i in range(1, demoitems_model.columnCount()):
|
||||
self.demoitems.hideColumn(i)
|
||||
|
||||
self.icLog = ChatLogs(self.gametab_log, 0, self.ooclog.logfile)
|
||||
self.icLog.setReadOnly(True)
|
||||
@ -1110,7 +1327,7 @@ class gui(QtGui.QWidget):
|
||||
self.misc_layout.setAlignment(QtCore.Qt.AlignTop)
|
||||
self.mocktext = QtGui.QCheckBox()
|
||||
self.mocktext.setChecked(False)
|
||||
self.mocktext.setText(mockStr("mock text"))
|
||||
self.mocktext.setText(mock_str("mock text"))
|
||||
self.spacebartext = QtGui.QCheckBox()
|
||||
self.spacebartext.setChecked(False)
|
||||
self.spacebartext.setText("S p a c i n g")
|
||||
@ -2119,7 +2336,7 @@ class gui(QtGui.QWidget):
|
||||
return
|
||||
|
||||
if self.mocktext.isChecked():
|
||||
text = mockStr(text)
|
||||
text = mock_str(text)
|
||||
if self.autocaps.isChecked():
|
||||
l = QtCore.QStringList(list(text))
|
||||
l[0] = l[0].toUpper()
|
||||
@ -2142,7 +2359,7 @@ class gui(QtGui.QWidget):
|
||||
|
||||
if text:
|
||||
if self.mocktext.isChecked():
|
||||
text = mockStr(text)
|
||||
text = mock_str(text)
|
||||
if self.autocaps.isChecked():
|
||||
l = list(text)
|
||||
if l[0] == " " and len(l) > 1:
|
||||
@ -3337,7 +3554,7 @@ class gui(QtGui.QWidget):
|
||||
self.specialstream = 2
|
||||
if (musl.startswith("https") and error == 2) or self.specialstream:
|
||||
print "[audio] Downloading music with urllib2"
|
||||
self.download_thread = music_download_thread(self, mus)
|
||||
self.download_thread = MusicDownloadThread(self, mus)
|
||||
self.download_thread.finished_signal.connect(self.playDownloadedMusic)
|
||||
self.download_thread.start()
|
||||
|
||||
@ -3665,232 +3882,4 @@ class gui(QtGui.QWidget):
|
||||
self.demo_recorder = demo.DemoRecorder()
|
||||
self.demo_recorder.start()
|
||||
self.demo_recorder.record([["SC"] + [char[0] for char in self.charlist]], encode=True)
|
||||
|
||||
class TCP_Thread(QtCore.QThread):
|
||||
connectionError = QtCore.pyqtSignal(str, str, str)
|
||||
MS_Chat = QtCore.pyqtSignal(list)
|
||||
newChar = QtCore.pyqtSignal(str)
|
||||
newBackground = QtCore.pyqtSignal(str, bool)
|
||||
IC_Log = QtCore.pyqtSignal(str)
|
||||
OOC_Log = QtCore.pyqtSignal(str)
|
||||
charSlots = QtCore.pyqtSignal()
|
||||
showCharSelect = QtCore.pyqtSignal()
|
||||
allEvidence = QtCore.pyqtSignal(list)
|
||||
rainbowColor = QtCore.pyqtSignal(str)
|
||||
updatePlayerList = QtCore.pyqtSignal(str, int, int, str)
|
||||
timerUpdate = QtCore.pyqtSignal(int, int, int)
|
||||
|
||||
send_attempts = 0
|
||||
max_attempts = 5
|
||||
stop_now = False
|
||||
|
||||
def __init__(self, parent):
|
||||
super(TCP_Thread, self).__init__(parent)
|
||||
self.parent = parent
|
||||
|
||||
def run(self):
|
||||
pingtimer = 150
|
||||
rainbow = 0
|
||||
sendtick = 0
|
||||
tempdata = ""
|
||||
color = QtGui.QColor()
|
||||
color.setHsv(rainbow, 255, 255)
|
||||
while True:
|
||||
if self.stop_now:
|
||||
self.parent.tcp.close()
|
||||
self.quit()
|
||||
return
|
||||
|
||||
if self.parent.disconnectnow:
|
||||
self.parent.disconnectCommon()
|
||||
self.quit()
|
||||
return
|
||||
pingtimer -= 1
|
||||
|
||||
if pingtimer == 0:
|
||||
pingbefore = time.time()
|
||||
self.parent.tcp.send('CH#%')
|
||||
pingtimer = 150
|
||||
|
||||
if self.parent.m_chatmessage[TEXT_COLOR] == str(C_RAINBOW):
|
||||
color.setHsv(rainbow, 255, 255)
|
||||
rainbow += 5
|
||||
if rainbow > 255:
|
||||
rainbow = 0
|
||||
#self.parent.text.setStyleSheet('color: rgb(' + str(color.red()) + ', ' + str(color.green()) + ', ' + str(color.blue()) + ')')
|
||||
self.rainbowColor.emit('background-color: rgba(0, 0, 0, 0); color: rgb(' + str(color.red()) + ', ' + str(color.green()) + ', ' + str(color.blue()) + ')')
|
||||
|
||||
if sendtick:
|
||||
sendtick -= 1
|
||||
if self.parent.msgqueue and not sendtick:
|
||||
self.parent.tcp.send(self.parent.msgqueue[0])
|
||||
sendtick = 4
|
||||
|
||||
error, total = self.parent.tcp.recv()
|
||||
if error == -2:
|
||||
# if the message can't be sent, discard it
|
||||
if sendtick == 4:
|
||||
self.send_attempts += 1
|
||||
if self.send_attempts >= self.max_attempts:
|
||||
self.send_attempts = 0
|
||||
#print "[warning] message discarded"
|
||||
del self.parent.msgqueue[0]
|
||||
self.parent.msgqueueList.takeItem(0)
|
||||
continue
|
||||
elif error == -1:
|
||||
self.parent.emit(QtCore.SIGNAL('showMessage(QString, QString, QString)'), 'critical', 'Connection lost', "%s connection to server lost." % ("WebSocket" if self.parent.tcp.isWS else "TCP"))
|
||||
self.parent.willDisconnect = True
|
||||
self.quit()
|
||||
return
|
||||
elif error == -3:
|
||||
self.parent.emit(QtCore.SIGNAL('showMessage(QString, QString, QString)'), 'critical', 'Connection lost', "There was a critical connection failure. Please check your internet connection.\n\nDetails: %s." % total)
|
||||
self.parent.willDisconnect = True
|
||||
self.quit()
|
||||
return
|
||||
else:
|
||||
self.send_attempts = 0
|
||||
|
||||
packets.handle_packets(self, total)
|
||||
|
||||
def stop(self):
|
||||
self.stop_now = True
|
||||
|
||||
class EditEvidenceDialog(QtGui.QDialog):
|
||||
def __init__(self, gamegui):
|
||||
super(EditEvidenceDialog, self).__init__()
|
||||
self.gamegui = gamegui
|
||||
self.setTitle()
|
||||
self.resize(512, 384)
|
||||
self.setModal(True)
|
||||
|
||||
self.eviname = QtGui.QLineEdit(self)
|
||||
self.eviname.setGeometry(8, 8, 410, 24)
|
||||
self.evidesc = QtGui.QTextEdit(self)
|
||||
self.evidesc.setGeometry(8, 192 - 105, 496, 255)
|
||||
self.evidesc.setAcceptRichText(False)
|
||||
self.evipicture = QtGui.QLabel(self)
|
||||
self.filename = 'empty.png'
|
||||
evipic = QtGui.QPixmap(AOpath + 'evidence/empty.png')
|
||||
self.evipicture.setPixmap(evipic)
|
||||
self.evipicture.move(434, 8)
|
||||
self.evipicture.show()
|
||||
|
||||
self.save = QtGui.QPushButton(self)
|
||||
self.save.setText('Save')
|
||||
self.save.clicked.connect(self.onSave)
|
||||
self.save.move(256 - self.save.size().width() - 8, 384 - self.save.size().height() - 2)
|
||||
self.cancel = QtGui.QPushButton(self)
|
||||
self.cancel.setText('Cancel')
|
||||
self.cancel.clicked.connect(self.onCancel)
|
||||
self.cancel.move(264 + 16, 384 - self.cancel.size().height() - 2)
|
||||
self.choosepic = QtGui.QComboBox(self)
|
||||
self.choosepic.setGeometry(self.eviname.x() + self.eviname.size().width() - 128 - 84, self.eviname.y() + 70 - 32, 128, 24)
|
||||
self.filenames = []
|
||||
self.browse = QtGui.QPushButton(self)
|
||||
self.browse.setText('Browse')
|
||||
self.browse.clicked.connect(self.onBrowse)
|
||||
self.browse.move(self.choosepic.x() + self.choosepic.width() + 8, self.choosepic.y())
|
||||
|
||||
files = os.listdir(AOpath + 'evidence')
|
||||
fileslength = len(files)
|
||||
i = 0
|
||||
while i < fileslength:
|
||||
if not files[i].endswith('.png'):
|
||||
del files[i]
|
||||
fileslength = len(files)
|
||||
i -= 1
|
||||
i += 1
|
||||
|
||||
for i in range(len(files)):
|
||||
if files[i].endswith('.png'):
|
||||
self.choosepic.addItem(files[i].strip('.png'))
|
||||
self.filenames.append(files[i])
|
||||
if files[i].lower() == 'empty.png':
|
||||
self.emptyfile = i
|
||||
|
||||
self.editing = False
|
||||
self.choosepic.currentIndexChanged.connect(self.choosePicChange)
|
||||
self.choosepic.setCurrentIndex(i)
|
||||
|
||||
def choosePicChange(self, ind):
|
||||
self.filename = self.filenames[ind]
|
||||
if exists(AOpath + 'evidence/' + self.filename):
|
||||
self.evipicture.setPixmap(QtGui.QPixmap(AOpath + 'evidence/' + self.filename))
|
||||
else:
|
||||
self.evipicture.setPixmap(QtGui.QPixmap(AO2XPpath + 'themes/default/evidence_selected.png'))
|
||||
|
||||
def onSave(self):
|
||||
name = encode_ao_str(self.eviname.text())
|
||||
desc = encode_ao_str(self.evidesc.toPlainText())
|
||||
|
||||
if not self.gamegui.privateinv:
|
||||
if self.editing:
|
||||
self.gamegui.tcp.send('EE#' + str(self.edit_ind) + '#' + name + '#' + desc + '#' + self.filename + '#%')
|
||||
else:
|
||||
self.gamegui.tcp.send('PE#' + name + '#' + desc + '#' + self.filename + '#%')
|
||||
else:
|
||||
if self.editing:
|
||||
self.gamegui.privateevidence[self.gamegui.selectedevi] = [unicode(name), unicode(desc), unicode(self.filename)]
|
||||
self.gamegui.privatedropdown.setItemText(self.gamegui.selectedevi, name)
|
||||
|
||||
evi = self.gamegui.privateevidence[self.gamegui.selectedevi]
|
||||
self.gamegui.evidencedesc.setText(evi[1])
|
||||
self.gamegui.setEvidenceImg(self.gamegui.evidenceimage, evi[2])
|
||||
else:
|
||||
self.gamegui.privateevidence.append([name, desc, self.filename])
|
||||
self.gamegui.privatedropdown.addItem(name)
|
||||
self.onExportEvidence(True)
|
||||
|
||||
self.eviname.setText('')
|
||||
self.evidesc.setText('')
|
||||
evipic = QtGui.QPixmap(AOpath + 'evidence/empty.png')
|
||||
self.evipicture.setPixmap(evipic)
|
||||
self.filename = 'empty.png'
|
||||
self.editing = False
|
||||
self.setTitle()
|
||||
self.choosepic.setCurrentIndex(self.emptyfile)
|
||||
self.hide()
|
||||
|
||||
def onCancel(self):
|
||||
self.eviname.setText('')
|
||||
self.evidesc.setText('')
|
||||
evipic = QtGui.QPixmap(AOpath + 'evidence/empty.png')
|
||||
self.evipicture.setPixmap(evipic)
|
||||
self.filename = 'empty.png'
|
||||
self.editing = False
|
||||
self.setTitle()
|
||||
self.choosepic.setCurrentIndex(self.emptyfile)
|
||||
self.hide()
|
||||
|
||||
def onBrowse(self):
|
||||
path = str(QtGui.QFileDialog.getOpenFileName(self, "Select an image", AOpath + 'evidence', "Images (*.png)"))
|
||||
if path:
|
||||
if not "/evidence/" in path.lower():
|
||||
QtGui.QMessageBox.warning(self, 'Wrong directory', 'Please select a file from the "evidence" directory.')
|
||||
self.onBrowse()
|
||||
return
|
||||
|
||||
file = basename(path)
|
||||
if file.lower().endswith('.png'):
|
||||
ind = os.listdir(AOpath + 'evidence').index(file)
|
||||
self.choosepic.setCurrentIndex(ind)
|
||||
else:
|
||||
QtGui.QMessageBox.warning(self, 'Not a valid file', 'Please select a PNG image.')
|
||||
self.onBrowse()
|
||||
|
||||
def EditEvidence(self, ind):
|
||||
self.editing = True
|
||||
self.edit_ind = ind
|
||||
evidence = self.gamegui.privateevidence if self.gamegui.privateinv else self.gamegui.evidence
|
||||
|
||||
if evidence[ind][2] not in self.filenames:
|
||||
self.filenames.append(evidence[ind][2])
|
||||
self.choosepic.addItem(evidence[ind][2].split('.')[0])
|
||||
self.choosepic.setCurrentIndex(self.filenames.index(evidence[ind][2]))
|
||||
self.eviname.setText(evidence[ind][0])
|
||||
self.evidesc.setText(evidence[ind][1])
|
||||
self.setWindowTitle("Edit evidence" if not self.gamegui.privateinv else "Edit evidence in private inventory")
|
||||
self.show()
|
||||
|
||||
def setTitle(self):
|
||||
self.setWindowTitle('Add evidence' if not self.gamegui.privateinv else "Add evidence to private inventory")
|
||||
|
Loading…
Reference in New Issue
Block a user