import subprocess, sys, thread, time, os, platform, __builtin__ from os.path import exists, abspath try: import Cocoa # mac except: pass from PyQt4 import QtGui, QtCore import audio as AUDIO import ini from constants import * import gameview, mainmenu, options, demo __builtin__.audio = AUDIO del AUDIO osname = platform.system() if exists("certifi/cacert.pem"): os.environ['REQUESTS_CA_BUNDLE'] = "certifi/cacert.pem" if osname == "Linux": QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_X11InitThreads) # Linux fix app = QtGui.QApplication(sys.argv) path = sys.argv[0] demofile = None # Experimental. No setting for this yet. tabsEnabled = False tabAmount = 2 if len(sys.argv) > 1: demofile = sys.argv[-1] if not exists(demofile): QtGui.QMessageBox.critical(None, "Unable to load demo", "The demo file '%s' doesn't exist." % (demofile)) os._exit(-2) if osname == "Darwin": path = Cocoa.NSBundle.mainBundle() os.chdir(path.resourcePath()) missing = audio.checkAvailable() if missing: QtGui.QMessageBox.critical(None, "Unable to launch game", "Couldn't find the file %s on the client folder.\nAO2XP needs this file in order to play sounds and music.\nThe file is included in the client's zip file, make sure it's in the same folder as the AO2XP exe.\n\nAdditional info:\n%s\n%s" % (missing, sys.argv, os.getcwd())) os._exit(-2) class MainWindow(QtGui.QMainWindow): def __init__(self): super(MainWindow, self).__init__() self.widgetStackList = None self.gameWidgetList = None self.menuWidgetList = None self.gameWidget = None self.mainMenuWidget = None self.gameWidget = None self.currentTab = 0 if tabsEnabled: self.gameTabs = QtGui.QTabWidget(self) self.gameTabs.currentChanged.connect(self.currentTabChanged) self.widgetStackList = [] self.gameWidgetList = [] self.menuWidgetList = [] for i in range(tabAmount): print "[debug] Added instance", i self.widgetStackList.append(QtGui.QStackedWidget(self)) self.gameWidgetList.append(gameview.GUI(self)) self.menuWidgetList.append(mainmenu.Lobby(self, demofile)) for i, stack in enumerate(self.widgetStackList): self.gameTabs.addTab(stack, "Game %s" % (i + 1)) stack.addWidget(self.menuWidgetList[i]) stack.addWidget(self.gameWidgetList[i]) self.gameWidgetList[i].setObjectName("AO2XPGameWidget") stack.setCurrentWidget(self.mainMenuWidget) self.widgetStack = self.widgetStackList[self.currentTab] self.mainMenuWidget = self.menuWidgetList[self.currentTab] self.gameWidget = self.gameWidgetList[self.currentTab] self.setCentralWidget(self.gameTabs) self.setFixedSize(self.mainMenuWidget.lobbyimg.size().width(), self.mainMenuWidget.lobbyimg.size().height(), True) else: self.mainMenuWidget = mainmenu.Lobby(self, demofile) self.gameWidget = gameview.GUI(self) self.gameWidget.setObjectName("AO2XPGameWidget") self.widgetStack = QtGui.QStackedWidget(self) self.widgetStack.addWidget(self.mainMenuWidget) self.widgetStack.addWidget(self.gameWidget) self.widgetStack.setCurrentWidget(self.mainMenuWidget) self.setCentralWidget(self.widgetStack) self.setFixedSize(self.mainMenuWidget.lobbyimg.size().width(), self.mainMenuWidget.lobbyimg.size().height(), True) self.center() self.setWindowTitle("AO2XP") self.setWindowIcon(QtGui.QIcon("AO2XP.ico")) self.setWindowFlags(QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowMinimizeButtonHint | QtCore.Qt.WindowCloseButtonHint) self.settingsWidget = options.Settings(self) self.demoPickerWidget = demo.DemoPicker(self) if demofile: self.gameWidget.startDemo(demofile) self.widgetStack.setCurrentWidget(self.gameWidget) def center(self): frameGm = self.frameGeometry() centerPoint = QtGui.QDesktopWidget().availableGeometry().center() frameGm.moveCenter(centerPoint) self.move(frameGm.topLeft()) def showGame(self, gameData): self.gameWidget.disconnectNow = False self.gameWidget.startGame(*gameData) self.widgetStack.setCurrentWidget(self.gameWidget) def returnToMenu(self): self.gameWidget.disconnectNow = True self.setFixedSize(self.mainMenuWidget.lobbyimg.size().width(), self.mainMenuWidget.lobbyimg.size().height()) self.mainMenuWidget.onClickedCancelconnect() self.widgetStack.setCurrentWidget(self.mainMenuWidget) self.setWindowTitle("AO2XP") self.center() def showSettings(self): self.settingsWidget.showSettings() def showDemoPicker(self): self.demoPickerWidget.show() def showAboutBox(self): box = QtGui.QMessageBox() box.setText("AO2XP %s\nRunning on %s %s %s (Python %s)\n\n2019-%s headshot / cidoku" % (GAME_VERSION, platform.system(), platform.release(), platform.machine(), platform.python_version(), YEAR)) box.setWindowTitle("About AO2XP") box.setStandardButtons(QtGui.QMessageBox.Close) box.setWindowIcon(QtGui.QIcon("AO2XP.ico")) box.setIconPixmap(QtGui.QPixmap(AO2XPpath + "icons/about.png")) box.button(QtGui.QMessageBox.Close).setText('Take that!') box.exec_() def currentTabChanged(self): self.currentTab = self.gameTabs.currentIndex() self.widgetStack = self.widgetStackList[self.currentTab] self.mainMenuWidget = self.menuWidgetList[self.currentTab] self.gameWidget = self.gameWidgetList[self.currentTab] def setFixedSize(self, w, h, initial = False): if tabsEnabled: if initial: super(MainWindow, self).setFixedSize(w + 4, h + self.gameTabs.tabBar().height()) return tabH = self.gameTabs.tabBar().height() oldW = self.width() - 4 oldH = self.height() - tabH super(MainWindow, self).setFixedSize(max(w, oldW) + 4, max(h, oldH) + tabH) else: super(MainWindow, self).setFixedSize(w, h) def aboutToQuit(self): if tabsEnabled: for widget in self.gameWidgetList: widget.exitCommon() else: self.gameWidget.exitCommon() # Vanilla downloader forceDownloader = len(sys.argv) > 1 and sys.argv[1] == "download" if forceDownloader or (not exists(BASE_PATH + "background") and not exists(BASE_PATH + "characters") and not exists(BASE_PATH + "sounds") and not exists(BASE_PATH + "evidence")): jm = QtGui.QMessageBox.information(None, "Warning", "You seem to be missing the included Attorney Online content.\nWould you like to download them automatically?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) if jm == QtGui.QMessageBox.Yes: import basedownloader code = basedownloader.downloadVanilla() if code != 0: os._exit(code) else: os._exit(-3) # AO2XP update checker # Automatic updates are opt-in! canUpdate = ini.read_ini_bool("AO2XP.ini", "General", "install updates", False) forceUpdate = "forceupdate" in sys.argv[1:] if canUpdate or forceUpdate: import updater code = updater.checkForUpdates(forceUpdate) if code == 0: subprocess.Popen(["./AO2XPupdat"]) os._exit(0) # This hides stupid useless QT warnings def handler(msg_type, msg_string): pass QtCore.qInstallMsgHandler(handler) audio.init() game = MainWindow() game.show() app.aboutToQuit.connect(game.aboutToQuit) returnc = app.exec_() audio.free() sys.exit(returnc)