-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
688 lines (569 loc) · 24.1 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
"""
Copyright (C) 2015 Yannik Marchand
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY Yannik Marchand ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL Yannik Marchand BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation
are those of the authors and should not be interpreted as representing
official policies, either expressed or implied, of Yannik Marchand.
"""
from OpenGL.GL import *
from OpenGL.GLU import *
from PyQt4 import QtGui, QtCore
from PyQt4.QtOpenGL import *
import os, sys
import byml, fmdl, sarc, yaz0
import datetime
now = datetime.datetime.now
color = 1
class CheckBox(QtGui.QCheckBox):
def __init__(self,node):
QtGui.QCheckBox.__init__(self)
self.stateChanged.connect(self.changed)
self.node = node
def changed(self,state):
self.node.changeValue(state==QtCore.Qt.Checked)
class LineEdit(QtGui.QLineEdit):
def __init__(self,value,callback):
QtGui.QLineEdit.__init__(self,str(value))
self.callback = callback
self.textChanged[str].connect(self.changed)
def changed(self,text):
if text:
self.callback(self)
def FloatEdit(v,cb):
edit = LineEdit(v,cb)
edit.setValidator(QtGui.QDoubleValidator())
return edit
def IntEdit(v,cb):
edit = LineEdit(v,cb)
edit.setValidator(QtGui.QIntValidator())
return edit
# renames the settings names, not ported to mk8 yet
def SettingName(oldName):
if oldName == 'Multi2P':
return '2-Player Related'
if oldName == 'Multi4P':
return '4-Player Related'
if oldName == 'WiFi':
return 'WiFi Related'
if oldName == 'WiFi2P':
return '2-Player WiFi Related'
if oldName == 'ObjId':
return 'Object ID'
if oldName == 'UnitIdNum':
return 'Unit Number'
if oldName == 'TopView':
return 'Camera Related??'
return oldName
class SettingsWidget(QtGui.QWidget):
def __init__(self,parent):
QtGui.QWidget.__init__(self,parent)
layout = QtGui.QVBoxLayout(self)
scroll = QtGui.QScrollArea()
scroll.setWidgetResizable(True)
layout.addWidget(scroll)
scrollContents = QtGui.QWidget()
self.layout = QtGui.QVBoxLayout(scrollContents)
self.layout.setAlignment(QtCore.Qt.AlignTop)
scroll.setWidget(scrollContents)
def reset(self):
for i in reversed(range(self.layout.count())):
self.layout.itemAt(i).widget().setParent(None)
def showSettings(self,obj):
# this was slapped together, is getting ObjID from objflow.byaml and displaying that as the config_lbl
modelNameMapping = {}
with open(window.gamePath+'/data/objflow.byaml', 'rb') as f:
b = byml.BYML(f.read(), True)
for thing in b.rootNode.subNodes():
resName = thing.subNodes()['ResName'].subNodes()[0].val
id = thing['ObjId']
modelNameMapping[id] = resName
self.current = obj
self.config_lbl = QtGui.QLabel(obj.fileName) # int to a string
self.config_lbl.setStyleSheet('font-size: 16px')
self.layout.addWidget(self.config_lbl)
self.config_lbl = QtGui.QLabel(str(obj.data['ObjId'])) # int to a string
self.config_lbl.setStyleSheet('font-size: 16px')
self.layout.addWidget(self.config_lbl)
lbl = QtGui.QLabel('Translate:')
lbl.setStyleSheet('font-size: 14px')
self.layout.addWidget(lbl)
self.transx = FloatEdit(obj.posx,self.changed)
self.transy = FloatEdit(obj.posy,self.changed)
self.transz = FloatEdit(obj.posz,self.changed)
self.layout.addWidget(self.transx)
self.layout.addWidget(self.transy)
self.layout.addWidget(self.transz)
lbl = QtGui.QLabel('Rotate:')
lbl.setStyleSheet('font-size: 14px')
self.layout.addWidget(lbl)
self.rotx = FloatEdit(obj.rotx,self.changed)
self.roty = FloatEdit(obj.roty,self.changed)
self.rotz = FloatEdit(obj.rotz,self.changed)
self.layout.addWidget(self.rotx)
self.layout.addWidget(self.roty)
self.layout.addWidget(self.rotz)
lbl = QtGui.QLabel('Scale:')
lbl.setStyleSheet('font-size: 14px')
self.layout.addWidget(lbl)
self.sclx = FloatEdit(obj.sclx,self.changed)
self.scly = FloatEdit(obj.scly,self.changed)
self.sclz = FloatEdit(obj.sclz,self.changed)
self.layout.addWidget(self.sclx)
self.layout.addWidget(self.scly)
self.layout.addWidget(self.sclz)
for key in obj.data.dict:
vnode = obj.data.getSubNode(key)
if not key in ['Scale','Translate','Rotate']:
lbl = QtGui.QLabel(SettingName(key)+':')
if isinstance(vnode,byml.FloatNode):
box = FloatEdit(obj.data[key],self.changed2)
box.node = vnode
elif isinstance(vnode,byml.IntegerNode):
box = IntEdit(obj.data[key],self.changed2)
box.node = vnode
elif isinstance(vnode,byml.BooleanNode):
box = CheckBox(vnode)
if obj.data[key]:
box.toggle()
elif isinstance(vnode,byml.StringNode):
box = LineEdit(str(obj.data[key]),self.changed2)
box.node = vnode
box.setEnabled(False)
else:
box = QtGui.QLineEdit(str(obj.data[key]))
box.setEnabled(False)
self.layout.addWidget(lbl)
self.layout.addWidget(box)
elif key == 'ObjId':
lbl = QtGui.QLabel(key+':')
#box = LineEdit(str(obj.data['UnitConfigName']),self.configNameChanged)
#box.node = vnode
box = QtGui.QLineEdit(str(obj.data[key]))
box.setEnabled(False)
self.layout.addWidget(lbl)
self.layout.addWidget(box)
elif key == 'UnitIdNum':
lbl = QtGui.QLabel(key+':')
if isinstance(vnode,byml.StringNode):
box = LineEdit(str(obj.data['UnitIdNum']),self.modelNameChanged)
box.node = vnode
else:
box = QtGui.QLineEdit(str(obj.data['UnitIdNum']))
box.setEnabled(False)
self.layout.addWidget(lbl)
self.layout.addWidget(box)
def changed(self,box):
if self.transx.text() and self.transy.text() and self.transz.text() and self.rotx.text() and self.roty.text() and self.rotz.text() and self.sclx.text() and self.scly.text() and self.sclz.text():
self.current.posx = float(self.transx.text())
self.current.posy = float(self.transy.text())
self.current.posz = float(self.transz.text())
self.current.rotx = float(self.rotx.text())
self.current.roty = float(self.roty.text())
self.current.rotz = float(self.rotz.text())
self.current.sclx = float(self.sclx.text())
self.current.scly = float(self.scly.text())
self.current.sclz = float(self.sclz.text())
self.current.saveValues()
window.glWidget.updateGL()
def changed2(self,box):
if box.text():
box.node.changeValue(box.text())
#def configNameChanged(self,box):
# if box.text():
# box.node.changeValue(box.text())
# self.config_lbl.setText(box.text())
# self.current.updateModel()
def modelNameChanged(self,box):
if box.text():
box.node.changeValue(box.text())
self.current.updateModel()
class LevelObject:
def __init__(self,obj,dlist,modelName):
global color
self.data = obj
self.color = (color/100/10.0,((color/10)%10)/10.0,(color%10)/10.0)
color+=1
self.list = dlist
self.fileName = modelName
trans = obj['Translate']
self.posx = trans['X']/100
self.posy = trans['Y']/100
self.posz = trans['Z']/100
rot = obj['Rotate']
self.rotx = rot['X']
self.roty = rot['Y']
self.rotz = rot['Z']
scale = obj['Scale']
self.sclx = scale['X']
self.scly = scale['Y']
self.sclz = scale['Z']
def saveValues(self):
obj = self.data
trans = obj['Translate']
if self.posx != trans['X']/100: trans.getSubNode('X').changeValue(self.posx*100)
if self.posy != trans['Y']/100: trans.getSubNode('Y').changeValue(self.posy*100)
if self.posz != trans['Z']/100: trans.getSubNode('Z').changeValue(self.posz*100)
rot = obj['Rotate']
if self.rotx != rot['X']: rot.getSubNode('X').changeValue(self.rotx)
if self.roty != rot['Y']: rot.getSubNode('Y').changeValue(self.roty)
if self.rotz != rot['Z']: rot.getSubNode('Z').changeValue(self.rotz)
scale = obj['Scale']
if self.sclx != scale['X']: scale.getSubNode('X').changeValue(self.sclx)
if self.scly != scale['Y']: scale.getSubNode('Y').changeValue(self.scly)
if self.sclz != scale['Z']: scale.getSubNode('Z').changeValue(self.sclz)
def draw(self,pick):
if pick:
glColor3f(*self.color)
glPushMatrix()
glTranslatef(self.posx,self.posy,self.posz)
glRotatef(self.rotx,1.0,0.0,0.0)
glRotatef(self.roty,0.0,1.0,0.0)
glRotatef(self.rotz,0.0,0.0,1.0)
#glScalef(self.sclx,self.scly,self.sclz)
glCallList(self.list)
glPopMatrix()
# this won't even work right now
def updateModel(self):
model = self.data['UnitIdNum']
if not self.data['UnitIdNum']:
model = self.data['ObjId']
if not model in window.glWidget.cache:
window.glWidget.cache[model] = window.glWidget.loadModel(model)
#window.glWidget.cache[model] = window.glWidget.loadcourseModel(model)
self.list = window.glWidget.cache[model]
window.glWidget.updateGL()
class LevelWidget(QGLWidget):
objects = []
cache = {}
rotx = roty = rotz = 0
posx = posy = 0
posz = -300
picked = None
def __init__(self,parent):
QGLWidget.__init__(self,parent)
def reset(self):
self.objects = []
self.rotx = self.roty = self.rotz = 0
self.posx = self.posy = 0
self.posz = -300
def pickObjects(self,x,y):
self.paintGL(1)
array = (GLuint * 1)(0)
pixel = glReadPixels(x,self.height()-y,1,1,GL_RGB,GL_UNSIGNED_BYTE,array)
r,g,b = [round(((array[0]>>(i*8))&0xFF)/255.0,1) for i in range(3)]
self.picked = None
window.settings.reset()
for obj in self.objects:
if obj.color == (r,g,b):
self.picked = obj
break
if self.picked:
window.settings.showSettings(self.picked)
self.updateGL()
def paintGL(self,pick=0):
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glTranslatef(self.posx,self.posy,self.posz)
glRotatef(self.rotx,1.0,0.0,0.0)
glRotatef(self.roty,0.0,1.0,0.0)
glRotatef(self.rotz,0.0,0.0,1.0)
for obj in self.objects:
if obj == self.picked:
glColor3f(1.0,0.0,0.0)
else:
glColor3f(1.0,1.0,1.0)
obj.draw(pick)
def resizeGL(self,w,h):
if h == 0:
h = 1
glViewport(0,0,w,h)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45.0,float(w)/float(h),0.1,750.0)
glMatrixMode(GL_MODELVIEW)
def initializeGL(self):
glClearColor(0.3,0.3,1.0,0.0)
glDepthFunc(GL_LEQUAL)
glEnable(GL_DEPTH_TEST)
self.generateCubeList()
def addObject(self,obj,modelName):
if not modelName in self.cache:
self.cache[modelName] = self.loadModel(modelName)
#self.cache[modelName] = self.loadcourseModel(modelName)
lobj = LevelObject(obj,self.cache[modelName],modelName)
self.objects.append(lobj)
# trying to duplicate the function
# models are loaded through the model name from /mapobj/objectname/objectname.bfres
def loadModel(self,name):
if not os.path.isfile(window.gamePath+'/mapobj/{0}/{0}.bfres'.format(name)):
return self.cubeList
with open(window.gamePath+'/mapobj/{0}/{0}.bfres'.format(name),'rb') as f:
data = f.read()
#with open(window.gamePath+'/race_common/{0}/{0}.bfres'.format(name),'rb') as f:
# data2 = f.read()
model = fmdl.parse(data)
#model2 = fmdl.parse(data2)
return self.generateList(model)
#return self.generateList(model2)
#return self.cubeList
#def loadcourseModel(self,name):
# #this sucks and should be removed
# with open(window.gamePath+'/course/G64_RainbowRoad/course_model.szs','rb') as f:
# data = f.read()
# bfres = yaz0.decompress(data)
# model = fmdl.parse(bfres)
# return self.generateList(model)
#return self.cubeList
def generateList(self,model):
displayList = glGenLists(1)
glNewList(displayList,GL_COMPILE)
for polygon in model.shapes:
rotation = polygon.rotation
triangles = polygon.indices
vertices = polygon.vertices
glPushMatrix()
glRotatef(rotation[0],1.0,0.0,0.0)
glRotatef(rotation[1],0.0,1.0,0.0)
glRotatef(rotation[2],0.0,0.0,1.0)
glBegin(GL_TRIANGLES)
for vertex in triangles:
glVertex3f(*[vertices[vertex][i]/100 for i in range(3)])
glEnd()
glPushAttrib(GL_CURRENT_BIT)
glColor3f(0.0,0.0,0.0)
for triangle in [triangles[i*3:i*3+3] for i in range(len(triangles)/3)]:
glBegin(GL_LINES)
for vertex in triangle:
glVertex3f(*[vertices[vertex][i]/100 for i in range(3)])
glEnd()
glPopAttrib()
glPopMatrix()
glEndList()
return displayList
def generateCubeList(self):
displayList = glGenLists(1)
glNewList(displayList,GL_COMPILE)
glBegin(GL_QUADS)
self.drawCube()
glEnd()
glBegin(GL_LINES)
glColor3f(0.0,0.0,0.0)
self.drawCube()
glEnd()
glEndList()
self.cubeList = displayList
def drawCube(self):
glVertex3f( 0.2, 0.2,-0.2)
glVertex3f(-0.2, 0.2,-0.2)
glVertex3f(-0.2, 0.2, 0.2)
glVertex3f( 0.2, 0.2, 0.2)
glVertex3f( 0.2,-0.2, 0.2)
glVertex3f(-0.2,-0.2, 0.2)
glVertex3f(-0.2,-0.2,-0.2)
glVertex3f( 0.2,-0.2,-0.2)
glVertex3f( 0.2, 0.2, 0.2)
glVertex3f(-0.2, 0.2, 0.2)
glVertex3f(-0.2,-0.2, 0.2)
glVertex3f( 0.2,-0.2, 0.2)
glVertex3f( 0.2,-0.2,-0.2)
glVertex3f(-0.2,-0.2,-0.2)
glVertex3f(-0.2, 0.2,-0.2)
glVertex3f( 0.2, 0.2,-0.2)
glVertex3f(-0.2, 0.2, 0.2)
glVertex3f(-0.2, 0.2,-0.2)
glVertex3f(-0.2,-0.2,-0.2)
glVertex3f(-0.2,-0.2, 0.2)
glVertex3f( 0.2, 0.2,-0.2)
glVertex3f( 0.2, 0.2, 0.2)
glVertex3f( 0.2,-0.2, 0.2)
glVertex3f( 0.2,-0.2,-0.2)
mousex = mousey = 0
def mousePressEvent(self,event):
if event.button() == 1:
self.pickObjects(event.x(),event.y())
self.mousex = event.x()
self.mousey = event.y()
def mouseMoveEvent(self,event):
deltax = (event.x()-self.mousex)/2
deltay = (event.y()-self.mousey)/2
buttons = event.buttons()
if buttons & QtCore.Qt.LeftButton:
self.posx += deltax
self.posy -= deltay
if buttons & QtCore.Qt.RightButton:
self.roty += deltax
self.rotx += deltay
self.mousex = event.x()
self.mousey = event.y()
self.updateGL()
class MainWindow(QtGui.QMainWindow):
keyPresses = {0x1000020: 0}
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setWindowTitle("MK8-Editor")
self.setGeometry(100,100,1080,720)
self.setupMenu()
self.qsettings = QtCore.QSettings("MrRean / RoadrunnerWMC","MK8 YAML Editor")
self.restoreGeometry(self.qsettings.value("geometry").toByteArray())
self.restoreState(self.qsettings.value("windowState").toByteArray())
self.gamePath = self.qsettings.value('gamePath').toPyObject()
if not self.isValidGameFolder(self.gamePath):
self.changeGamePath(True)
self.settings = SettingsWidget(self)
self.setupGLScene()
self.resizeWidgets()
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.updateCamera)
self.timer.start(30)
self.show()
def closeEvent(self, event):
self.qsettings.setValue("geometry", self.saveGeometry())
self.qsettings.setValue("windowState", self.saveState())
def setupMenu(self):
self.openAction = QtGui.QAction("Open",self)
self.openAction.setShortcut("Ctrl+O")
self.openAction.triggered.connect(self.showLevelDialog)
self.saveAction = QtGui.QAction("Save",self)
self.saveAction.setShortcut("Ctrl+S")
self.saveAction.triggered.connect(self.saveLevel)
self.saveAction.setEnabled(False)
pathAction = QtGui.QAction("Change Game Path",self)
pathAction.setShortcut("Ctrl+G")
pathAction.triggered.connect(self.changeGamePath)
self.menubar = self.menuBar()
fileMenu = self.menubar.addMenu("File")
fileMenu.addAction(self.openAction)
fileMenu.addAction(self.saveAction)
settingsMenu = self.menubar.addMenu("Settings")
settingsMenu.addAction(pathAction)
def changeGamePath(self,disable=False):
path = self.askGamePath()
if path:
self.qsettings.setValue('gamePath',path)
else:
if disable:
self.openAction.setEnabled(False)
QtGui.QMessageBox.warning(self,"Incomplete Folder","The folder you chose doesn't seem to contain the required files.")
def askGamePath(self):
QtGui.QMessageBox.information(self,'Game Path',"You're now going to be asked to pick a folder. This folder must include \course, \mapobj\ and \data.")
folder = QtGui.QFileDialog.getExistingDirectory(self,"Choose Game Path")
if not self.isValidGameFolder(folder):
return None
return folder
def isValidGameFolder(self,folder):
if not folder: return 0
if not os.path.exists(folder+'\course'): return 0
if not os.path.exists(folder+'\mapobj'): return 0
if not os.path.exists(folder+'\data'): return 0
return 1
def loadStageList(self):
# just return worldList as nothing, we don't even use it but the funtion needs to be there because another function needs an argument
#with open(self.gamePath+'\data\objflow.byaml', 'rb') as f:
# self.worldList = byml.BYML(f.read(), True)
self.worldList = None
# edit this to open different types of stages
def showLevelDialog(self):
byamlPath = QtGui.QFileDialog.getOpenFileName(self, 'Open Level','course_muunt.byaml','Level Archive (*.byaml)');
print "path is: "+byamlPath
with open(byamlPath, 'rb') as f:
self.levelData = byml.BYML(f.read(), True)
self.loadLevel(self.levelData.rootNode.subNodes())
def loadLevel(self,levelData):
global modelNameMapping
modelNameMapping = {}
with open(window.gamePath+'/data/objflow.byaml', 'rb') as f: # load objflow to get the model names, and load them
b = byml.BYML(f.read(), True)
for thing in b.rootNode.subNodes():
resName = thing.subNodes()['ResName'].subNodes()[0].val
id = thing['ObjId']
modelNameMapping[id] = resName
stime = now()
self.glWidget.reset()
self.settings.reset()
amount = len(levelData['Obj'])
progress = QtGui.QProgressDialog(self)
progress.setCancelButton(None)
progress.setMinimumDuration(0)
progress.setRange(0,amount)
progress.setWindowModality(QtCore.Qt.WindowModal)
progress.setWindowTitle('Loading...')
i = 1
for obj in levelData['Obj'].subNodes():
progress.setLabelText('Loading object '+str(i)+'/'+str(amount))
print "loading object "+str(obj)
progress.setValue(i)
self.loadObject(obj)
self.glWidget.updateGL()
i+=1
self.saveAction.setEnabled(True)
print now()-stime
print str(amount)+' Objects loaded'
def loadObject(self,obj):
modelName = obj['ObjId']
modelName = modelNameMapping[int(modelName)]
self.glWidget.addObject(obj,modelName)
def saveLevel(self):
fn = QtGui.QFileDialog.getSaveFileName(self,'Save Level','course_muunt.byaml','Level Archive (*.byaml)')
with open(fn,'wb') as f:
self.levelData.saveChanges()
f.write(self.levelData.data)
print('Track '+str(fn)+' saved.')
def setupGLScene(self):
self.glWidget = LevelWidget(self)
self.glWidget.show()
def resizeWidgets(self):
self.glWidget.setGeometry(220,21,self.width(),self.height()-21)
self.settings.setGeometry(0,21,220,self.height()-21)
def resizeEvent(self,event):
self.resizeWidgets()
def updateCamera(self):
spd = self.keyPresses[0x1000020]*2+1
updateScene = False
for key in self.keyPresses:
if self.keyPresses[key]:
if key == ord('I'): self.glWidget.rotx+=spd
elif key == ord('K'): self.glWidget.rotx-=spd
elif key == ord('O'): self.glWidget.roty+=spd
elif key == ord('L'): self.glWidget.roty-=spd
elif key == ord('P'): self.glWidget.rotz+=spd
elif key == ord(';'): self.glWidget.rotz-=spd
elif key == ord('A'): self.glWidget.posx-=spd
elif key == ord('D'): self.glWidget.posx+=spd
elif key == ord('S'): self.glWidget.posy-=spd
elif key == ord('W'): self.glWidget.posy+=spd
elif key == ord('Q'): self.glWidget.posz-=spd
elif key == ord('E'): self.glWidget.posz+=spd
updateScene = True
if updateScene:
self.glWidget.updateGL()
def keyReleaseEvent(self,event):
self.keyPresses[event.key()] = 0
def keyPressEvent(self,event):
self.keyPresses[event.key()] = 1
def wheelEvent(self,event):
self.glWidget.posz += event.delta()/15
self.glWidget.updateGL()
def main():
global window
app = QtGui.QApplication(sys.argv)
window = MainWindow()
sys.exit(app.exec_())
if __name__ == '__main__':
main()