2021-06-21 22:57:55 -04:00
import subprocess , sys , thread , time , os , platform , __builtin__
2021-06-16 17:02:07 -04:00
from os . path import exists , abspath
2021-06-25 09:59:05 -04:00
try :
import Cocoa # mac
except : pass
2021-02-17 06:46:27 -05:00
2020-08-06 22:04:06 -04:00
from PyQt4 import QtGui , QtCore
2019-04-03 10:57:23 -04:00
2021-06-20 01:29:40 -04:00
import audio as AUDIO
2021-06-21 22:57:55 -04:00
import ini
2025-02-20 16:54:54 -05:00
from constants import *
2021-06-21 22:57:55 -04:00
2021-06-20 01:29:40 -04:00
__builtin__ . audio = AUDIO
del AUDIO
2021-01-06 20:25:55 -05:00
osname = platform . system ( )
2021-02-17 06:46:27 -05:00
2021-06-22 11:56:40 -04:00
if osname == " Linux " : QtCore . QCoreApplication . setAttribute ( QtCore . Qt . AA_X11InitThreads ) # Linux fix
app = QtGui . QApplication ( sys . argv )
2021-02-17 06:46:27 -05:00
path = sys . argv [ 0 ]
2021-06-25 09:59:05 -04:00
if osname == " Darwin " :
path = Cocoa . NSBundle . mainBundle ( )
os . chdir ( path . resourcePath ( ) )
2021-01-06 20:25:55 -05:00
2020-08-01 22:15:07 -04:00
debugmode = len ( sys . argv ) > 1 and sys . argv [ 1 ] == " debug "
if not debugmode :
2021-06-20 01:29:40 -04:00
fakebass = len ( sys . argv ) > 1 and sys . argv [ 1 ] == " ignorebass "
missing = audio . checkAvailable ( )
if missing or fakebass :
QtGui . QMessageBox . critical ( None , " Unable to launch game " , " Couldn ' t find the file %s on the client folder. \n AO2XP needs this file in order to play sounds and music. \n The file is included in the client ' s zip file, make sure it ' s in the same folder as the AO2XP exe. \n \n Additional info: \n %s \n %s " % ( missing , sys . argv , os . getcwd ( ) ) )
2020-08-08 18:58:58 -04:00
os . _exit ( - 2 )
2019-04-03 10:57:23 -04:00
class gamewindow ( QtGui . QMainWindow ) :
2025-02-20 13:38:30 -05:00
def __init__ ( self ) :
super ( gamewindow , self ) . __init__ ( )
self . stackwidget = QtGui . QStackedWidget ( self )
self . widget = mainmenu . lobby ( self )
self . gamewidget = gameview . gui ( self )
self . stackwidget . addWidget ( self . widget )
self . stackwidget . addWidget ( self . gamewidget )
self . setCentralWidget ( self . stackwidget )
self . stackwidget . setCurrentWidget ( self . widget )
self . setFixedSize ( self . widget . lobbyimg . size ( ) . width ( ) , self . widget . lobbyimg . size ( ) . height ( ) )
self . center ( )
self . setWindowTitle ( " AO2XP " )
self . setWindowIcon ( QtGui . QIcon ( " AO2XP.ico " ) )
2025-02-20 16:54:54 -05:00
self . setWindowFlags ( QtCore . Qt . WindowSystemMenuHint | QtCore . Qt . WindowTitleHint | QtCore . Qt . WindowMinimizeButtonHint | QtCore . Qt . WindowCloseButtonHint )
2025-02-20 13:38:30 -05:00
2025-02-20 16:54:54 -05:00
self . settingsgui = options . Settings ( self )
self . aboutgui = self . aboutBox ( )
2025-02-20 13:38:30 -05:00
def center ( self ) :
frameGm = self . frameGeometry ( )
centerPoint = QtGui . QDesktopWidget ( ) . availableGeometry ( ) . center ( )
frameGm . moveCenter ( centerPoint )
self . move ( frameGm . topLeft ( ) )
def showGame ( self , tcp , playerlist , charlist , musiclist , background , evidence , areas , features = [ ] , oocjoin = [ ] , hplist = [ ] , webAO_bucket = " " ) :
self . gamewidget . disconnectnow = False
self . gamewidget . startGame ( tcp , playerlist , charlist , musiclist , background , evidence , areas , features , oocjoin , hplist , webAO_bucket )
self . stackwidget . setCurrentWidget ( self . gamewidget )
def returnToMenu ( self ) :
self . gamewidget . disconnectnow = True
self . setFixedSize ( self . widget . lobbyimg . size ( ) . width ( ) , self . widget . lobbyimg . size ( ) . height ( ) )
self . widget . onClicked_cancelconnect ( )
self . stackwidget . setCurrentWidget ( self . widget )
self . setWindowTitle ( " AO2XP " )
2025-02-20 17:35:54 -05:00
self . center ( )
2025-02-20 13:38:30 -05:00
def showSettings ( self ) :
self . settingsgui . showSettings ( )
2025-02-20 16:54:54 -05:00
def aboutBox ( self ) :
box = QtGui . QMessageBox ( )
box . setText ( " AO2XP %s \n Running on %s %s %s (Python %s ) \n \n 2019-2025 headshot / cidoku " % ( GAME_VERSION , platform . system ( ) , platform . release ( ) , platform . machine ( ) , platform . python_version ( ) ) )
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! ' )
return box
2019-04-03 10:57:23 -04:00
if not debugmode :
2021-06-21 22:57:55 -04:00
# Vanilla downloader
2020-08-06 22:04:06 -04:00
force_downloader = len ( sys . argv ) > 1 and sys . argv [ 1 ] == " download "
if force_downloader or ( not exists ( " base/background " ) and not exists ( " base/characters " ) and not exists ( " base/sounds " ) and not exists ( " base/evidence " ) ) :
jm = QtGui . QMessageBox . information ( None , " Warning " , " You seem to be missing the included Attorney Online content. \n Would you like to download them automatically? " , QtGui . QMessageBox . Yes | QtGui . QMessageBox . No )
if jm == QtGui . QMessageBox . Yes :
import basedownloader
code = basedownloader . downloadVanilla ( )
2020-08-08 18:58:58 -04:00
if code != 0 : os . _exit ( code )
2020-08-06 22:04:06 -04:00
else :
2020-08-08 18:58:58 -04:00
os . _exit ( - 3 )
2020-08-06 22:04:06 -04:00
2021-06-21 22:57:55 -04:00
# AO2XP update checker
2025-02-19 15:10:41 -05:00
can_update = ini . read_ini_bool ( " AO2XP.ini " , " General " , " install updates " , False ) # Automatic updates are opt-in!
2021-06-21 22:57:55 -04:00
force_update = " forceupdate " in sys . argv [ 1 : ]
if can_update or force_update :
import updater
code = updater . checkForUpdates ( force_update )
if code == 0 :
subprocess . Popen ( [ " ./AO2XPupdat " ] )
os . _exit ( 0 )
2021-06-25 09:59:05 -04:00
elif osname == " Darwin " : # bundle
os . chdir ( path . resourcePath ( ) ) # return to Resources folder
2021-06-21 22:57:55 -04:00
import gameview , mainmenu , options
2019-04-03 10:57:23 -04:00
2025-02-17 14:45:06 -05:00
# This hides stupid useless QT warnings
def handler ( msg_type , msg_string ) :
pass
QtCore . qInstallMsgHandler ( handler )
2021-06-20 01:29:40 -04:00
audio . init ( )
2025-02-20 16:54:54 -05:00
game = gamewindow ( )
game . show ( )
2021-06-20 01:29:40 -04:00
returnc = app . exec_ ( )
audio . free ( )
sys . exit ( returnc )