Skip to content

Commit cd6727b

Browse files
committed
Initial commit
0 parents  commit cd6727b

11 files changed

Lines changed: 323 additions & 0 deletions

File tree

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
server/
3+
4+
make/
5+
6+
build/
7+
8+
dist/
9+
10+
cefpython/
11+
12+
__pycache__/

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
minecraft_launcher

compile.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import subprocess, platform, os
2+
3+
lambda: os.system('cls' if os.name=='nt' else 'clear')
4+
5+
try:
6+
fh = open('build/launcher.exe', 'r')
7+
print("File launcher.exe exists. Overwrite? (y/N)")
8+
inp=input(": ")
9+
while inp.lower() != "y" or inp.lower() != "n":
10+
lambda: os.system('cls' if os.name=='nt' else 'clear')
11+
print("File launcher.exe exists. Overwrite? (y/N)")
12+
inp=input(": ")
13+
14+
except FileNotFoundError:
15+
pass
16+
17+
print("Building for "+platform.system())
18+
p=subprocess.Popen('pyinstaller -y -F -w -i "favicon.ico" --add-data "dirt.png";"." --add-data "favicon.png";"." --add-data "logo.png";"." "launcher.py"', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
19+
for line in p.stdout.readlines():
20+
print(line)
21+
retval = p.wait()

config.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import appdirs, os, sys
2+
MC_DIR=appdirs.user_data_dir(".minecraft", "", roaming=True)
3+
TEST_URL="http://google.cn/generate_204"
4+
NAME="Minecraft Launcher"
5+
VER="v0.1 Alpha"
6+
PLAYERNAME="TEST"
7+
BOTTOM_BACKGROUND="dirt.png"
8+
LOGO="logo.png"
9+
ICON="favicon.png"
10+
UPDATE_URL="https://github.com/calmilamsy/b1.7.3_minecraft_launcher/raw/master/version.json" # github link to the version.json file.
11+
12+
##version.json:
13+
## Should have this format:
14+
## {
15+
## "version": "1.0",
16+
## "method": "mediafire", OR "github"
17+
## "link": "b1yv2baktdkqhry (the stuff after /file/ but before /modpack.zip in the url)" OR "https://github.com/user/project/raw/master/modpack.zip (supports any url that gives the modpack file directly as response.)"
18+
## }

dirt.png

1.16 KB
Loading

favicon.ico

33.6 KB
Binary file not shown.

favicon.png

1.34 KB
Loading

launcher.py

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
import os,urllib.request,sys,threading,config,json,requests,subprocess,time,math
2+
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel, QLineEdit, QMessageBox, QDialog
3+
from PyQt5.QtGui import QIcon, QPixmap, QImageReader, QPainter
4+
from PyQt5.QtCore import pyqtSlot, Qt, pyqtSignal, QUrl
5+
from PyQt5.QtWebEngineWidgets import *
6+
7+
update=True
8+
prc=""
9+
running=False
10+
threadingEvent=threading.Event()
11+
12+
def resource_path(relative_path):
13+
try:
14+
base_path = sys._MEIPASS
15+
except Exception:
16+
base_path = os.path.abspath(".")
17+
18+
return os.path.join(base_path, relative_path)
19+
20+
21+
config.ICON=resource_path(config.ICON)
22+
config.LOGO=resource_path(config.LOGO)
23+
config.BOTTOM_BACKGROUND=resource_path(config.BOTTOM_BACKGROUND)
24+
25+
class mainWindow(QWidget):
26+
guiElements=[]
27+
dirt=[]
28+
guiMove=[]
29+
def __init__(self):
30+
super().__init__()
31+
screen_resolution = app.desktop().screenGeometry()
32+
self.title = config.NAME+" "+config.VER
33+
self.setWindowIcon(QIcon(config.ICON))
34+
self.left = screen_resolution.width()/2-(854/2)
35+
self.top = screen_resolution.height()/2-(480/2)
36+
self.dirtImage= QPixmap(config.BOTTOM_BACKGROUND)
37+
self.logoImage= QPixmap(config.LOGO)
38+
self.initUI()
39+
40+
def initUI(self):
41+
self.setWindowTitle(self.title)
42+
self.setGeometry(self.left, self.top, 854, 480)
43+
##self.setFixedSize(self.size())
44+
self.colorBackground()
45+
self.createButtons()
46+
self.createLogin()
47+
self.createLogo()
48+
self.createTheInternet()
49+
self.show()
50+
self.checkAlive(threadingEvent)
51+
r = requests.get(config.TEST_URL)
52+
if r.status_code!=204:
53+
self.error("Unable to connect to the internet. Updates are disabled.")
54+
update=False
55+
56+
if os.path.exists(config.MC_DIR)==False:
57+
self.error("Missing Minecraft directory. Is minecraft installed?")
58+
59+
@pyqtSlot()
60+
def resizeEvent(self, event):
61+
for index in range(len(self.guiElements)):
62+
self.guiElements[index].move(self.size().width()+self.guiMove[index][0], self.size().height()+self.guiMove[index][1])
63+
self.createImages()
64+
for index in range(len(self.guiElements)):
65+
self.guiElements[index].raise_()
66+
self.logo.move(32, self.size().height()-(49+32))
67+
self.theInternet.resize(self.size().width(), self.size().height()-100)
68+
69+
70+
@pyqtSlot()
71+
def login(self):
72+
self.launch()
73+
self.loginButton.setEnabled(False)
74+
self.loginBox.setEnabled(False)
75+
self.optionButton.setEnabled(False)
76+
##if self.loginBox.contents.isalnum() == False:
77+
78+
@pyqtSlot()
79+
def optionsMenu(self):
80+
self.optionWindow=optionWindow(self).exec_()
81+
82+
def colorBackground(self):
83+
self.setAutoFillBackground(True)
84+
p = self.palette()
85+
p.setColor(self.backgroundRole(), Qt.darkGray)
86+
self.setPalette(p)
87+
88+
def createButtons(self):
89+
self.loginButton = QPushButton("Login", self)
90+
self.guiMove.append([-(11+70), -(35+22)])
91+
self.loginButton.resize(70,22)
92+
self.loginButton.clicked.connect(self.login)
93+
self.guiElements.append(self.loginButton)
94+
95+
self.optionButton = QPushButton("Options", self)
96+
self.guiMove.append([-(11+70), -(35+22+4+21)])
97+
self.optionButton.resize(70,22)
98+
self.optionButton.clicked.connect(self.optionsMenu)
99+
self.guiElements.append(self.optionButton)
100+
101+
def createLogin(self):
102+
self.loginBox=QLineEdit(self)
103+
self.guiMove.append([-255, -(35+22+4+22)])
104+
self.loginBox.resize(166, 22)
105+
self.guiElements.append(self.loginBox)
106+
107+
self.passBox=QLineEdit(self)
108+
self.guiMove.append([-255, -(35+22)])
109+
self.passBox.resize(166, 22)
110+
self.guiElements.append(self.passBox)
111+
self.passBox.setText("Coming soon!")
112+
self.passBox.setEnabled(False)
113+
114+
def createLogo(self):
115+
self.logo=QLabel(self)
116+
self.logo.resize(256, 49)
117+
self.logo.setPixmap(self.logoImage.scaled(self.logo.size(), Qt.KeepAspectRatio))
118+
119+
def createTheInternet(self):
120+
self.theInternet = QWebEngineView(self)
121+
self.theInternet.load(QUrl("https://mcupdate.tumblr.com"))
122+
self.theInternet.show()
123+
124+
def createImages(self):
125+
for index in range(len(self.dirt)):
126+
for indexy in range(len(self.dirt[index])):
127+
self.dirt[index][indexy].deleteLater()
128+
129+
self.dirt=[]
130+
131+
for index in range(math.ceil(self.size().width()/64)):
132+
self.dirt.append([])
133+
self.dirt[index].append(QLabel(self))
134+
self.dirt[index].append(QLabel(self))
135+
136+
for index in range(math.ceil(self.size().width()/64)):
137+
for indexy in range(len(self.dirt[0])):
138+
self.dirt[index][indexy].show()
139+
self.dirt[index][indexy].resize(64,64)
140+
self.dirt[index][indexy].setPixmap(self.dirtImage)
141+
self.dirt[index][indexy].move(64*index, self.size().height()-100+(indexy*64))
142+
143+
self.logo.raise_()
144+
145+
146+
#Game ---------------------------------------------------------------------------------------
147+
148+
def checkAlive(self, threadingEvent):
149+
global prc
150+
try:
151+
poll = prc.poll()
152+
if poll == None:
153+
running=True
154+
else: raise(AttributeError)
155+
except AttributeError as exc:
156+
try:
157+
self.loginButton.setEnabled(True)
158+
self.loginBox.setEnabled(True)
159+
self.optionButton.setEnabled(True)
160+
except: pass
161+
running=False
162+
if not threadingEvent.is_set():
163+
threading.Timer(1, self.checkAlive, [threadingEvent]).start()
164+
165+
def launch(self):
166+
global prc
167+
try: prc.kill()
168+
except: pass
169+
try:
170+
if self.loginBox.text() == "":
171+
raise(TypeError)
172+
elif self.loginBox.text().isalnum() == False:
173+
raise(TypeError)
174+
prc=subprocess.Popen('java -Xms{} -Xmx{} -cp "{}\\bin\\minecraft.jar;{}\\bin\\jinput.jar;{}\\bin\\lwjgl.jar;{}\\bin\\lwjgl_util.jar" -Djava.library.path="{}\\bin\\natives" net.minecraft.client.Minecraft {}'.format("256m","256m",config.MC_DIR,config.MC_DIR,config.MC_DIR,config.MC_DIR,config.MC_DIR,self.loginBox.text()))
175+
except TypeError as exc:
176+
self.error("Minecraft is unable to start. Make sure you have java and minecraft installed and an alphanumeric username set.")
177+
178+
def error(self, err):
179+
QMessageBox.warning(self, "Warning", err, QMessageBox.Ok, QMessageBox.Ok)
180+
181+
182+
def forceQuit():
183+
global prc
184+
try:
185+
prc.kill()
186+
prc=""
187+
except Exception as exc: pass
188+
189+
class optionWindow(QDialog):
190+
def __init__(self, parent=None):
191+
super().__init__(parent)
192+
screen_resolution = app.desktop().screenGeometry()
193+
self.title = config.NAME+" "+config.VER+" Options"
194+
self.setWindowIcon(QIcon(config.ICON))
195+
self.left = screen_resolution.width()/2-(480/2)
196+
self.top = screen_resolution.height()/2-(240/2)
197+
self.logoImage= QPixmap(config.LOGO)
198+
self.initUI()
199+
200+
def initUI(self):
201+
self.setWindowTitle(self.title)
202+
self.setGeometry(self.left, self.top, 480, 240)
203+
self.setFixedSize(self.size())
204+
self.createLabels()
205+
self.createSettingInputs()
206+
207+
def createSettingInputs(self):
208+
self.javaArgs=QLineEdit(self)
209+
self.javaArgs.resize(310, 24)
210+
self.javaArgs.move(150, 20)
211+
212+
self.maxRamAllocation=QLineEdit(self)
213+
self.maxRamAllocation.resize(100, 24)
214+
self.maxRamAllocation.move(150+55, 20+4+24)
215+
216+
self.minRamAllocation=QLineEdit(self)
217+
self.minRamAllocation.resize(100, 24)
218+
self.minRamAllocation.move(150+50+60+100, 20+4+24)
219+
220+
def createLabels(self):
221+
self.javaArgsLabel=QLabel(self, text="Java arguments:")
222+
self.javaArgsLabel.resize(100, 20)
223+
self.javaArgsLabel.move(20, 22)
224+
225+
self.ramAllocationLabel=QLabel(self, text="RAM Allocation:")
226+
self.ramAllocationLabel.resize(100, 20)
227+
self.ramAllocationLabel.move(20, 22+6+22)
228+
229+
self.maxRamAllocationLabel=QLabel(self, text="Maximum:")
230+
self.maxRamAllocationLabel.move(20+100+30, 22+6+22)
231+
self.maxRamAllocationLabel.resize(100, 20)
232+
233+
self.minRamAllocationLabel=QLabel(self, text="Minimum:")
234+
self.minRamAllocationLabel.move(20+100+150+40, 22+6+22)
235+
self.minRamAllocationLabel.resize(100, 20)
236+
237+
238+
239+
app = QApplication(sys.argv)
240+
mainWin = mainWindow()
241+
242+
sys.exit(app.exec_())

launcher.spec

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- mode: python -*-
2+
3+
block_cipher = None
4+
5+
6+
a = Analysis(['launcher.py'],
7+
pathex=['C:\\Users\\bumbi\\Desktop\\Launcher'],
8+
binaries=[],
9+
datas=[('dirt.png', '.'), ('favicon.png', '.'), ('logo.png', '.')],
10+
hiddenimports=[],
11+
hookspath=[],
12+
runtime_hooks=[],
13+
excludes=[],
14+
win_no_prefer_redirects=False,
15+
win_private_assemblies=False,
16+
cipher=block_cipher)
17+
pyz = PYZ(a.pure, a.zipped_data,
18+
cipher=block_cipher)
19+
exe = EXE(pyz,
20+
a.scripts,
21+
a.binaries,
22+
a.zipfiles,
23+
a.datas,
24+
name='launcher',
25+
debug=False,
26+
strip=False,
27+
upx=True,
28+
runtime_tmpdir=None,
29+
console=False , icon='favicon.ico')

logo.png

17.5 KB
Loading

0 commit comments

Comments
 (0)