2022-03-14 13:11:34 +00:00
#!/usr/bin/python3
2022-03-02 01:39:02 +00:00
"""
Copyright ( C ) 2022 Alexey Pavlov
2022-03-03 02:13:28 +00:00
Copyright ( C ) 2022 Red - Exe - Engineer
2022-03-02 01:39:02 +00:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License along
with this program ; if not , write to the Free Software Foundation , Inc . ,
51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA .
"""
import sys
2022-03-03 02:13:28 +00:00
import os
2022-03-04 01:09:31 +00:00
import random
from datetime import date
import json
2022-03-12 01:01:30 +00:00
import pathlib
2022-03-02 01:39:02 +00:00
2022-03-14 13:11:34 +00:00
absolute_path = pathlib . Path ( __file__ ) . parent . absolute ( )
if str ( absolute_path ) . startswith ( " /usr/bin " ) :
absolute_path = " /usr/lib/planet-launcher/ "
sys . path . append ( absolute_path )
if os . path . exists ( " /usr/lib/planet-launcher/ " ) :
sys . path . append ( " /usr/lib/planet-launcher/ " )
import launcher
from splashes import SPLASHES
2022-03-12 01:14:27 +00:00
2022-03-02 01:39:02 +00:00
from PyQt5 . QtCore import *
from PyQt5 . QtWidgets import *
from PyQt5 . QtGui import *
2022-03-12 01:01:30 +00:00
from PyQt5 . QtWebKit import *
from PyQt5 . QtWebKitWidgets import *
2022-03-02 01:39:02 +00:00
2022-03-12 01:01:30 +00:00
import qdarktheme
2022-03-14 01:07:20 +00:00
import pypresence
2022-03-10 00:31:14 +00:00
2022-03-12 01:10:07 +00:00
dark_stylesheet = qdarktheme . load_stylesheet ( )
2022-03-10 00:31:14 +00:00
2022-03-04 01:09:31 +00:00
USER = os . getenv ( " USER " )
2022-03-03 02:13:28 +00:00
if not os . path . exists ( f " /home/ { USER } /.planet-launcher/mods " ) :
os . makedirs ( f " /home/ { USER } /.planet-launcher/mods " )
2022-03-12 01:14:27 +00:00
# if os.path.exists(f"/home/{USER}/.gmcpil.json"):
2022-03-10 01:17:29 +00:00
# with open(f"/home/{USER}/.gmcpil.json") as f:
# DEFAULT_FEATURES = json.loads(f.read())["features"]
2022-03-12 01:14:27 +00:00
# else:
# TODO: Add a tab with a button to import features from gMCPIL
2022-03-04 01:09:31 +00:00
2022-03-13 01:16:02 +00:00
class ConfigPluto ( QDialog ) :
def __init__ ( self ) :
super ( ) . __init__ ( )
self . setWindowFlag ( Qt . FramelessWindowHint )
layout = QVBoxLayout ( )
titlelayout = QGridLayout ( )
2022-03-14 13:11:34 +00:00
logopixmap = QPixmap ( f " { absolute_path } /assets/logo512.png " ) . scaled ( 100 , 100 , Qt . KeepAspectRatio )
2022-03-13 01:16:02 +00:00
namelabel = QLabel ( " Pluto Wizard " )
logolabel = QLabel ( )
logolabel . setPixmap ( logopixmap )
logolabel . setAlignment ( Qt . AlignRight )
font = namelabel . font ( )
font . setPointSize ( 30 )
namelabel . setFont ( font )
namelabel . setAlignment ( Qt . AlignLeft )
titlelayout . addWidget ( logolabel , 0 , 0 )
titlelayout . addWidget ( namelabel , 0 , 1 )
titlewidget = QWidget ( )
titlewidget . setLayout ( titlelayout )
2022-03-13 20:46:07 +00:00
info_label = QLabel ( " Please select the executable you downloaded. \n If you installed a DEB, please select the \" Link \" option " )
2022-03-13 01:16:02 +00:00
self . executable_btn = QPushButton ( " Select executable " )
self . executable_btn . clicked . connect ( self . get_appimage )
2022-03-13 20:46:07 +00:00
self . premade_btn = QPushButton ( " Link /usr/bin/minecraft-pi-reborn-client " )
self . premade_btn . clicked . connect ( self . link_appimage )
2022-03-13 01:16:02 +00:00
layout . addWidget ( titlewidget )
layout . addWidget ( info_label )
layout . addWidget ( self . executable_btn )
2022-03-13 20:46:07 +00:00
layout . addWidget ( self . premade_btn )
2022-03-13 01:16:02 +00:00
self . setLayout ( layout )
def mousePressEvent ( self , event ) :
if event . button ( ) == Qt . LeftButton :
self . moveFlag = True
self . movePosition = event . globalPos ( ) - self . pos ( )
self . setCursor ( QCursor ( Qt . OpenHandCursor ) )
event . accept ( )
def mouseMoveEvent ( self , event ) :
if Qt . LeftButton and self . moveFlag :
self . move ( event . globalPos ( ) - self . movePosition )
event . accept ( )
def mouseReleaseEvent ( self , event ) :
self . moveFlag = False
self . setCursor ( Qt . ArrowCursor )
def get_appimage ( self ) :
self . hide ( )
self . filename = QFileDialog . getOpenFileName ( self , ' Select executable ' , ' / ' , " Executable files (*.AppImage *.bin *.sh *) " )
2022-03-13 20:46:07 +00:00
def link_appimage ( self ) :
self . hide ( )
os . symlink ( " /usr/bin/minecraft-pi-reborn-client " , f " /home/ { USER } /.planet-launcher/minecraft.AppImage " )
self . filename = list ( )
self . filename . append ( False )
2022-03-02 01:39:02 +00:00
2022-03-10 00:31:14 +00:00
2022-03-13 01:16:02 +00:00
class Planet ( QMainWindow ) :
2022-03-05 00:43:14 +00:00
launchfeatures = dict ( )
env = os . environ . copy ( )
2022-03-10 00:31:14 +00:00
2022-03-02 01:39:02 +00:00
def __init__ ( self ) :
super ( ) . __init__ ( )
2022-03-12 23:18:20 +00:00
2022-03-14 01:07:20 +00:00
RPC = pypresence . Presence ( 787496148763541505 )
try :
RPC = pypresence . Presence ( 787496148763541505 )
RPC . connect ( )
RPC . update ( state = " Launched with Planet Launcher " , details = " Minecraft Pi Edition: Reborn " , large_image = " logo " , small_image = random . choice ( [ " heart " , " portal " , " multiplayer " , " pi " ] ) )
except :
print ( " Unable to initalize Discord RPC. Skipping. " )
2022-03-12 23:18:20 +00:00
if not os . path . exists ( f " /home/ { USER } /.planet-launcher/config.json " ) :
self . conf = {
" username " : " StevePi " ,
2022-03-13 02:02:43 +00:00
" options " : launcher . get_features_dict ( f " /home/ { USER } /.planet-launcher/minecraft.AppImage " ) ,
2022-03-12 23:18:20 +00:00
" hidelauncher " : True ,
2022-03-13 01:16:02 +00:00
" profile " : " Modded MCPE " ,
" render_distance " : " Short " ,
" theme " : " QDarkTheme Light " ,
2022-03-14 01:07:20 +00:00
" discord_rpc " : True ,
2022-03-12 23:18:20 +00:00
}
with open ( f " /home/ { USER } /.planet-launcher/config.json " , " w " ) as file :
file . write ( json . dumps ( self . conf ) )
else :
with open ( f " /home/ { USER } /.planet-launcher/config.json " ) as file :
self . conf = json . loads ( file . read ( ) )
2022-03-02 01:39:02 +00:00
self . setWindowTitle ( " Planet " )
2022-03-14 13:11:34 +00:00
self . setWindowIcon ( QIcon ( f " { absolute_path } /assets/logo512.png " ) )
2022-03-02 01:39:02 +00:00
tabs = QTabWidget ( )
tabs . setTabPosition ( QTabWidget . West )
tabs . setMovable ( True )
2022-03-10 00:31:14 +00:00
play_tab = tabs . addTab ( self . play_tab ( ) , " Play " )
2022-03-14 13:11:34 +00:00
tabs . setTabIcon ( play_tab , QIcon ( f " { absolute_path } /assets/logo512.png " ) )
2022-03-10 00:31:14 +00:00
features_tab = tabs . addTab ( self . features_tab ( ) , " Features " )
2022-03-14 13:11:34 +00:00
tabs . setTabIcon ( features_tab , QIcon ( f " { absolute_path } /assets/heart512.png " ) )
2022-03-14 00:36:24 +00:00
servers_tab = tabs . addTab ( self . servers_tab ( ) , " Servers " )
2022-03-14 13:11:34 +00:00
tabs . setTabIcon ( servers_tab , QIcon ( f " { absolute_path } /assets/multiplayer512.png " ) )
2022-03-14 01:07:20 +00:00
#mods_tab = tabs.addTab(self.custom_mods_tab(), "Mods")
2022-03-14 13:11:34 +00:00
#tabs.setTabIcon(mods_tab, QIcon(f"{absolute_path}/assets/portal512.png"))
2022-03-12 01:01:30 +00:00
changelog_tab = tabs . addTab ( self . changelog_tab ( ) , " Changelog " )
2022-03-14 13:11:34 +00:00
tabs . setTabIcon ( changelog_tab , QIcon ( f " { absolute_path } /assets/pi512.png " ) )
2022-03-02 01:39:02 +00:00
self . setCentralWidget ( tabs )
2022-03-04 01:09:31 +00:00
2022-03-14 01:15:06 +00:00
self . setGeometry ( 600 , 900 , 200 , 200 )
2022-03-12 23:18:20 +00:00
self . usernameedit . setText ( self . conf [ " username " ] )
2022-03-13 01:16:02 +00:00
self . profilebox . setCurrentText ( self . conf [ " profile " ] )
self . distancebox . setCurrentText ( self . conf [ " render_distance " ] )
for feature in self . features :
if self . conf [ " options " ] [ feature ] :
self . features [ feature ] . setCheckState ( Qt . Checked )
else :
self . features [ feature ] . setCheckState ( Qt . Unchecked )
self . showlauncher . setChecked ( self . conf [ " hidelauncher " ] )
2022-03-10 00:31:14 +00:00
self . set_features ( )
2022-03-02 01:39:02 +00:00
def play_tab ( self ) - > QWidget :
layout = QGridLayout ( )
2022-03-12 01:14:27 +00:00
2022-03-10 00:31:14 +00:00
titlelayout = QGridLayout ( )
2022-03-12 01:14:27 +00:00
2022-03-14 13:11:34 +00:00
logopixmap = QPixmap ( f " { absolute_path } /assets/logo512.png " ) . scaled ( 100 , 100 , Qt . KeepAspectRatio )
2022-03-12 01:14:27 +00:00
2022-03-10 00:31:14 +00:00
logolabel = QLabel ( )
logolabel . setPixmap ( logopixmap )
logolabel . setAlignment ( Qt . AlignRight )
namelabel = QLabel ( )
2022-03-12 01:14:27 +00:00
if date . today ( ) . month == 4 and date . today ( ) . day == 1 :
2022-03-04 01:09:31 +00:00
namelabel . setText ( " Banana Launcher " )
else :
2022-03-12 01:14:27 +00:00
if random . randint ( 1 , 100 ) == 1 :
2022-03-04 01:09:31 +00:00
namelabel . setText ( " Pluto Launcher " )
else :
2022-03-12 01:14:27 +00:00
namelabel . setText ( " Planet Launcher " )
2022-03-10 00:31:14 +00:00
2022-03-02 01:39:02 +00:00
font = namelabel . font ( )
font . setPointSize ( 30 )
namelabel . setFont ( font )
2022-03-10 00:31:14 +00:00
namelabel . setAlignment ( Qt . AlignLeft )
2022-03-12 01:14:27 +00:00
splashlabel = QLabel ( f ' <font color= " gold " > { random . choice ( SPLASHES ) } </font> ' )
2022-03-04 01:09:31 +00:00
splashlabel . adjustSize ( )
splashlabel . setAlignment ( Qt . AlignHCenter )
2022-03-02 01:39:02 +00:00
usernamelabel = QLabel ( " Username " )
2022-03-04 01:09:31 +00:00
self . usernameedit = QLineEdit ( )
self . usernameedit . setPlaceholderText ( " StevePi " )
2022-03-02 01:39:02 +00:00
distancelabel = QLabel ( " Render Distance " )
2022-03-04 01:09:31 +00:00
self . distancebox = QComboBox ( )
self . distancebox . addItems ( [ " Far " , " Normal " , " Short " , " Tiny " ] )
self . distancebox . setCurrentText ( " Short " )
2022-03-02 01:39:02 +00:00
profilelabel = QLabel ( " Profile " )
self . profilebox = QComboBox ( )
self . profilebox . addItems (
[ " Vanilla MCPi " , " Modded MCPi " , " Modded MCPE " , " Optimized MCPE " , " Custom " ]
)
self . profilebox . setCurrentText ( " Modded MCPE " )
2022-03-04 01:09:31 +00:00
2022-03-02 01:39:02 +00:00
self . showlauncher = QRadioButton ( " Hide Launcher " )
2022-03-04 01:09:31 +00:00
self . playbutton = QPushButton ( " Play " )
2022-03-10 00:31:14 +00:00
2022-03-05 00:43:14 +00:00
self . playbutton . setCheckable ( True )
self . playbutton . clicked . connect ( self . launch )
2022-03-02 01:39:02 +00:00
2022-03-10 00:31:14 +00:00
titlelayout . addWidget ( logolabel , 0 , 0 )
titlelayout . addWidget ( namelabel , 0 , 1 )
2022-03-12 01:14:27 +00:00
2022-03-10 00:31:14 +00:00
titlewidget = QWidget ( )
titlewidget . setLayout ( titlelayout )
2022-03-12 01:14:27 +00:00
layout . addWidget ( titlewidget , 0 , 0 , 2 , 5 )
layout . addWidget ( splashlabel , 2 , 0 , 1 , 6 )
2022-03-02 01:39:02 +00:00
2022-03-04 01:09:31 +00:00
layout . addWidget ( usernamelabel , 3 , 0 )
layout . addWidget ( self . usernameedit , 3 , 4 , 1 , 2 )
2022-03-02 01:39:02 +00:00
2022-03-04 01:09:31 +00:00
layout . addWidget ( distancelabel , 4 , 0 )
layout . addWidget ( self . distancebox , 4 , 4 , 1 , 2 )
2022-03-02 01:39:02 +00:00
2022-03-04 01:09:31 +00:00
layout . addWidget ( profilelabel , 5 , 0 )
layout . addWidget ( self . profilebox , 5 , 4 , 1 , 2 )
layout . addWidget ( self . showlauncher , 6 , 4 , 1 , 2 )
2022-03-02 01:39:02 +00:00
2022-03-04 01:09:31 +00:00
layout . addWidget ( self . playbutton , 8 , 5 )
2022-03-02 01:39:02 +00:00
widget = QWidget ( )
widget . setLayout ( layout )
return widget
2022-03-04 01:09:31 +00:00
2022-03-03 00:55:02 +00:00
def features_tab ( self ) - > QWidget :
2022-03-04 01:09:31 +00:00
2022-03-03 00:55:02 +00:00
layout = QVBoxLayout ( )
2022-03-10 00:31:14 +00:00
2022-03-04 01:09:31 +00:00
self . features = dict ( )
2022-03-13 23:44:27 +00:00
default_features = launcher . get_features_dict ( f " /home/ { USER } /.planet-launcher/minecraft.AppImage " )
2022-03-04 01:09:31 +00:00
2022-03-13 23:44:27 +00:00
for feature in default_features :
2022-03-03 00:55:02 +00:00
checkbox = QCheckBox ( feature )
2022-03-13 23:44:27 +00:00
if default_features [ feature ] :
2022-03-03 00:55:02 +00:00
checkbox . setCheckState ( Qt . Checked )
else :
checkbox . setCheckState ( Qt . Unchecked )
2022-03-10 00:31:14 +00:00
2022-03-05 00:43:14 +00:00
checkbox . clicked . connect ( self . set_features )
2022-03-10 00:31:14 +00:00
2022-03-04 01:09:31 +00:00
self . features [ feature ] = checkbox
2022-03-03 00:55:02 +00:00
layout . addWidget ( checkbox )
2022-03-04 01:09:31 +00:00
2022-03-03 00:55:02 +00:00
fakewidget = QWidget ( )
fakewidget . setLayout ( layout )
2022-03-04 01:09:31 +00:00
2022-03-03 00:55:02 +00:00
scroll = QScrollArea ( )
2022-03-04 01:09:31 +00:00
2022-03-03 00:55:02 +00:00
scroll . setVerticalScrollBarPolicy ( Qt . ScrollBarAlwaysOn )
scroll . setHorizontalScrollBarPolicy ( Qt . ScrollBarAlwaysOff )
scroll . setWidgetResizable ( True )
scroll . setWidget ( fakewidget )
2022-03-04 01:09:31 +00:00
2022-03-03 00:55:02 +00:00
fakelayout = QGridLayout ( )
2022-03-04 01:09:31 +00:00
fakelayout . addWidget ( scroll , 0 , 0 )
2022-03-03 00:55:02 +00:00
2022-03-03 02:13:28 +00:00
widget = QWidget ( )
widget . setLayout ( fakelayout )
return widget
2022-03-14 00:36:24 +00:00
def servers_tab ( self ) - > QWidget :
widget = QWidget ( )
layout = QGridLayout ( )
self . serversedit = QTextEdit ( )
self . serversedit . textChanged . connect ( self . save_servers )
with open ( f " /home/ { USER } /.minecraft-pi/servers.txt " ) as servers :
self . serversedit . setPlainText ( servers . read ( ) )
infolabel = QLabel ( " Servers are stored in the format of <font color= \" gold \" >IP: </font><font color= \" blue \" >Port</font> " )
layout . addWidget ( self . serversedit , 0 , 0 )
layout . addWidget ( infolabel , 6 , 0 )
widget . setLayout ( layout )
return widget
2022-03-04 01:09:31 +00:00
2022-03-03 02:13:28 +00:00
def custom_mods_tab ( self ) - > QWidget :
layout = QVBoxLayout ( )
2022-03-04 01:09:31 +00:00
2022-03-03 02:13:28 +00:00
for mod in os . listdir ( f " /home/ { USER } /.planet-launcher/mods/ " ) :
checkbox = QCheckBox ( mod )
checkbox . setCheckState ( Qt . Unchecked )
2022-03-04 01:09:31 +00:00
2022-03-03 02:13:28 +00:00
layout . addWidget ( checkbox )
2022-03-04 01:09:31 +00:00
2022-03-03 02:13:28 +00:00
fakewidget = QWidget ( )
fakewidget . setLayout ( layout )
2022-03-04 01:09:31 +00:00
2022-03-03 02:13:28 +00:00
scroll = QScrollArea ( )
2022-03-04 01:09:31 +00:00
2022-03-03 02:13:28 +00:00
scroll . setVerticalScrollBarPolicy ( Qt . ScrollBarAlwaysOn )
scroll . setHorizontalScrollBarPolicy ( Qt . ScrollBarAlwaysOff )
scroll . setWidgetResizable ( True )
scroll . setWidget ( fakewidget )
2022-03-04 01:09:31 +00:00
2022-03-03 02:13:28 +00:00
fakelayout = QGridLayout ( )
2022-03-04 01:09:31 +00:00
fakelayout . addWidget ( scroll , 0 , 0 )
2022-03-03 02:13:28 +00:00
2022-03-03 00:55:02 +00:00
widget = QWidget ( )
widget . setLayout ( fakelayout )
return widget
2022-03-12 01:14:27 +00:00
2022-03-12 01:01:30 +00:00
def changelog_tab ( self ) :
web = QWebView ( )
2022-03-12 01:14:27 +00:00
web . load (
QUrl ( ) . fromLocalFile (
2022-03-14 13:11:34 +00:00
f " { absolute_path } /assets/changelog.html "
2022-03-12 01:14:27 +00:00
)
)
2022-03-13 01:16:02 +00:00
2022-03-12 01:01:30 +00:00
return web
2022-03-10 00:31:14 +00:00
2022-03-05 00:43:14 +00:00
def set_features ( self ) :
for feature in self . features :
if self . features [ feature ] . isChecked ( ) :
self . launchfeatures [ feature ] = True
else :
self . launchfeatures [ feature ] = False
2022-03-13 01:16:02 +00:00
def save_profile ( self ) :
self . conf [ " username " ] = self . usernameedit . text ( )
self . conf [ " options " ] = self . launchfeatures
self . conf [ " render_distance " ] = self . distancebox . currentText ( )
self . conf [ " hidelauncher " ] = self . showlauncher . isChecked ( )
with open ( f " /home/ { USER } /.planet-launcher/config.json " , " w " ) as file :
file . write ( json . dumps ( self . conf ) )
2022-03-14 00:36:24 +00:00
def save_servers ( self ) :
with open ( f " /home/ { USER } /.minecraft-pi/servers.txt " , " w " ) as file :
file . write ( self . serversedit . toPlainText ( ) )
2022-03-10 00:31:14 +00:00
2022-03-05 00:43:14 +00:00
def launch ( self ) :
2022-03-13 01:16:02 +00:00
self . save_profile ( )
2022-03-12 01:14:27 +00:00
self . env = launcher . set_username ( self . env , self . usernameedit . text ( ) )
self . env = launcher . set_options ( self . env , self . launchfeatures )
self . env = launcher . set_render_distance (
self . env , self . distancebox . currentText ( )
)
2022-03-10 00:31:14 +00:00
2022-03-05 00:43:14 +00:00
print ( self . env )
2022-03-12 03:58:33 +00:00
if self . showlauncher . isChecked ( ) == True :
2022-03-12 18:48:28 +00:00
self . hide ( )
2022-03-13 02:02:43 +00:00
launcher . run ( self . env , f " /home/ { USER } /.planet-launcher/minecraft.AppImage " )
2022-03-12 01:30:19 +00:00
self . show ( )
2022-03-02 01:39:02 +00:00
if __name__ == " __main__ " :
2022-03-12 23:18:20 +00:00
2022-03-13 01:16:02 +00:00
apppath = str ( )
2022-03-02 01:39:02 +00:00
app = QApplication ( sys . argv )
2022-03-12 01:01:30 +00:00
app . setPalette ( qdarktheme . load_palette ( " dark " ) )
2022-03-13 01:16:02 +00:00
2022-03-02 01:39:02 +00:00
2022-03-13 01:16:02 +00:00
2022-03-13 02:02:43 +00:00
if not os . path . exists ( f " /home/ { USER } /.planet-launcher/minecraft.AppImage " ) :
2022-03-13 01:16:02 +00:00
pluto = ConfigPluto ( )
pluto . show ( )
pluto . exec ( )
2022-03-13 20:46:07 +00:00
if pluto . filename [ 0 ] == ' ' :
sys . exit ( - 1 )
elif pluto . filename [ 0 ] == False :
print ( " Using /usr/bin as an executable. " )
else :
with open ( pluto . filename [ 0 ] , " rb " ) as appimage :
with open ( f " /home/ { USER } /.planet-launcher/minecraft.AppImage " , " wb " ) as out :
out . write ( appimage . read ( ) )
os . chmod ( f " /home/ { USER } /.planet-launcher/minecraft.AppImage " , 0o777 )
2022-03-13 01:16:02 +00:00
2022-03-02 01:39:02 +00:00
window = Planet ( )
window . show ( )
2022-03-13 01:16:02 +00:00
2022-03-02 01:39:02 +00:00
app . exec ( )