-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_old.py
More file actions
1685 lines (1407 loc) · 66.8 KB
/
main_old.py
File metadata and controls
1685 lines (1407 loc) · 66.8 KB
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
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
import sys
sys.path.append("prefabs/")
import os.path
import os
from PySide.QtCore import *
from PySide.QtGui import *
import importlib
import createPrefab
from PIL import Image
from PIL.ImageQt import ImageQt
import generateSkybox
import light_create
import subprocess
import pickle
import pprint
import random
import glob
import webbrowser
import wave
import zipfile
import shutil
class GridBtn(QWidget):
def __init__(self, parent, x, y, btn_id):
super(GridBtn, self).__init__()
self.button = QPushButton("", parent)
self.x = x
self.y = y
self.btn_id = btn_id
#self.button.move(self.x,self.y)
self.button.resize(32,32)
self.button.setFixedSize(32, 32)
self.button.pressed.connect(lambda: self.click_func(parent, x, y,
btn_id))
self.button.setMouseTracking(True)
self.button.installEventFilter(self)
self.button.show()
self.icon = ""
def reset_icon(self):
self.button.setIcon(QIcon(""))
def click_func(self, parent, x, y, btn_id, clicked=True, h_moduleName="None", h_icon="", h_rot=""): #h_moduleName and h_icon and h_rot are used when undoing/redoing
global world_id_num
global id_num
global entity_num
global entity_list
global placeholder_list
global icon
global rotation
global totalblocks
global levels
global rotation, currentfilename
global history
if clicked:
if self.icon:
#print(self.icon.split("_")[-1].replace('.jpg',''))
moduleName = eval(prefab_list[parent.tile_list.currentRow()])
history.append((x,y,moduleName,self.icon,self.icon.split("_")[-1].replace('.jpg',''),level)) #make work even without rotations enabled
else:
history.append((x,y,"","","",level))
else: #0 = right, 1 = down, 2 = left, 3 = right
rot_old = rotation
rotation = 0 if h_rot == "right" else 1 if h_rot == "down" else 2 if h_rot == "left" else 3 if h_rot == "right" else rotation
#print(history)
def clear_btn():
self.button.setIcon(QIcon())
totalblocks[level][btn_id] = ''
entity_list[level][btn_id] = ''
iconlist[level][btn_id] = ''
self.icon = ""
if self.checkForCtrl(clicked):
clear_btn()
else:
if clicked:
moduleName = eval(prefab_list[parent.tile_list.currentRow()])
else:
moduleName = h_moduleName if h_moduleName != "" else clear_btn()
if h_moduleName != "":
print('h_moduleName:',h_moduleName)
try:
try:
try:
try:
create = moduleName.createTile(x, y, id_num, world_id_num, entity_num, placeholder_list, rotation, level)
except Exception as e:
create = moduleName.createTile(x, y, id_num, world_id_num, entity_num, placeholder_list, rotation, level)
except Exception as e:
create = moduleName.createTile(x, y, id_num, world_id_num, level)
except Exception as e:
create = moduleName.createTile(x, y, id_num, world_id_num, entity_num, placeholder_list, level)
except Exception as e:
create = moduleName.createTile(x, y, id_num, world_id_num, rotation, level)
id_num = create[1]
world_id_num = create[2]
try:
entity_num = create[3]
placeholder_list = create[5]
except IndexError:
pass
#if parent.comboBox.currentIndex() != 0:
#create2 = ground_prefab.createTile(x, y, id_num, world_id_num)
#world_id_num +=1
#create = create + create2
#else:
#pass
###
###
if clicked:
#print("not using h_icon")
try:
#print(rotation)
current_prefab_icon_list = open('prefab_template/rot_prefab_list.txt', 'r+')
current_prefab_icon_list = current_prefab_icon_list.readlines()
current_prefab_icon_list = current_prefab_icon_list[parent.tile_list.currentRow()]
if "\n" in current_prefab_icon_list:
current_prefab_icon_list = current_prefab_icon_list[:-1]
current_prefab_icon_list = open('prefab_template/iconlists/'+current_prefab_icon_list, 'r+')
current_prefab_icon_list = current_prefab_icon_list.readlines()
icon = current_prefab_icon_list[rotation]
if "\n" in icon:
icon = icon[:-1]
except Exception as e:
print(str(e))
icon = prefab_icon_list[parent.tile_list.currentRow()]
else:
icon = h_icon
#print("using h_icon")
self.button.setIcon(QIcon(icon))
self.button.setIconSize(QSize(32,32))
iconlist[level][btn_id] = icon
totalblocks[level][btn_id] = create[0]
try:
entity_list[level][btn_id] = create[4]
except Exception as e:
print(str(e))
if "*" not in currentfilename:
#currentfilename = currentfilename+'*'
parent.setWindowTitle("Easy TF2 Mapper* - ["+currentfilename+"]")
self.icon = icon
if not clicked:
rotation = rot_old
print(history)
def checkForCtrl(self, clicked):
if clicked:
modifiers = QApplication.keyboardModifiers()
if modifiers == Qt.ControlModifier:
return True
else:
return False
else:
return False
class MainWindow(QMainWindow):
def __init__(self):
#create the main window
super(MainWindow, self).__init__()
self.setGeometry(100, 25, 875, 750)
self.setWindowTitle("Easy TF2 Mapper")
self.setWindowIcon(QIcon("icons\icon.ico"))
namelist = ['gravelpit','2fort','upward','mvm']
palette = QPalette()
palette.setBrush(QPalette.Background,QBrush(QPixmap("icons/backgrounds/background_"+namelist[random.randint(0,3)]+".jpg")))
self.setPalette(palette)
#create menubar
exitAction = QAction("&Exit", self)
exitAction.setShortcut("Ctrl+Q")
exitAction.setStatusTip("Exit Application")
exitAction.triggered.connect(self.close_application)
openAction = QAction("&Open", self)
openAction.setShortcut("Ctrl+O")
openAction.setStatusTip("Open .vmf file")
openAction.triggered.connect(self.file_open)
saveAction = QAction("&Save", self)
saveAction.setShortcut("Ctrl+S")
saveAction.setStatusTip("Save File as .ezm save, allowing for use by others/you later.")
saveAction.triggered.connect(self.file_save)
saveAsAction = QAction("&Save As", self)
saveAsAction.setShortcut("Ctrl+Shift+S")
saveAsAction.setStatusTip("Save File as .ezm save, allowing for use by others/you later.")
saveAsAction.triggered.connect(lambda: self.file_save(False, True))
helpAction = QAction("&Wiki",self)
helpAction.triggered.connect(lambda: webbrowser.open_new_tab('http://github.com/baldengineers/easytf2_mapper/wiki'))
tutorialAction = QAction("&Reference Guide",self)
tutorialAction.setStatusTip("Quick reference guide on the TF2Mapper website.")
tutorialAction.triggered.connect(lambda: webbrowser.open_new_tab('http://tf2mapper.com/tutorial.html'))
newAction = QAction("&New", self)
newAction.setShortcut("Ctrl+n")
newAction.setStatusTip("Create a New File")
newAction.triggered.connect(lambda: self.grid_change(0,0,0,True,False,True))
hammerAction = QAction("&Open Hammer",self)
hammerAction.setShortcut("Ctrl+H")
hammerAction.setStatusTip("Opens up Hammer.")
hammerAction.triggered.connect(lambda: self.open_hammer(0,"null"))
changeHammer = QAction("&Change Hammer Directory",self)
changeHammer.setShortcut("Ctrl+Shift+H")
changeHammer.setStatusTip("Changes default hammer directory.")
changeHammer.triggered.connect(lambda: self.open_hammer(0,"null",True))
changeLightAction = QAction("&Change Lighting", self)
changeLightAction.setShortcut("Ctrl+J")
changeLightAction.setStatusTip("Change the environment lighting of the map.")
changeLightAction.triggered.connect(self.change_light)
exportAction = QAction("&as .VMF", self)
exportAction.setShortcut("Ctrl+E")
exportAction.setStatusTip("Export as .vmf")
exportAction.triggered.connect(self.file_export)
undoAction = QAction("&Undo", self)
undoAction.setShortcut("Ctrl+Z")
undoAction.setStatusTip("Undo previous action")
undoAction.triggered.connect(lambda: self.undo(True))
redoAction = QAction("&Redo", self)
redoAction.setShortcut("Ctrl+Shift+Z")
redoAction.setStatusTip("Redo previous action")
redoAction.triggered.connect(lambda: self.undo(False))
removeAction = QAction("&Remove Last Prefab(s)",self)
removeAction.setShortcut("Ctrl+R")
removeAction.setStatusTip("Delete a variable amount of prefabs from the end of the list")
removeAction.triggered.connect(self.remove_prefabs)
gridAction = QAction("&Set Grid Size", self)
gridAction.setShortcut("Ctrl+G")
gridAction.setStatusTip("Set Grid Height and Width. RESETS ALL BLOCKS.")
gridAction.triggered.connect(lambda: self.grid_change(0,0,0,True,False,True))
createPrefabAction = QAction("&Create Prefab", self)
createPrefabAction.setShortcut("Ctrl+I")
createPrefabAction.setStatusTip("View the readme for a good idea on formatting Hammer Prefabs.")
createPrefabAction.triggered.connect(self.create_prefab)
consoleAction = QAction("&Open Dev Console", self)
consoleAction.setShortcut("`")
consoleAction.setStatusTip("Run functions/print variables manually")
consoleAction.triggered.connect(self.open_console)
changeSkybox = QAction("&Change Skybox", self)
changeSkybox.setStatusTip("Change the skybox of the map.")
changeSkybox.setShortcut("Ctrl+B")
changeSkybox.triggered.connect(self.change_skybox)
importPrefab = QAction("&Prefab",self)
importPrefab.setStatusTip("Import a prefab in a .zip file. You can find some user-made ones at http://tf2mapper.com")
importPrefab.setShortcut("Ctrl+Shift+I")
importPrefab.triggered.connect(self.import_prefab)
bspExportAction = QAction("&as .BSP",self)
bspExportAction.setStatusTip("Export as .bsp")
bspExportAction.setShortcut("Ctrl+Shift+E")
bspExportAction.triggered.connect(self.file_export_bsp)
self.statusBar()
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu("&File")
optionsMenu = mainMenu.addMenu("&Options")
toolsMenu = mainMenu.addMenu("&Tools")
helpMenu = mainMenu.addMenu("&Help")
fileMenu.addAction(newAction)
fileMenu.addAction(openAction)
fileMenu.addAction(saveAction)
fileMenu.addAction(saveAsAction)
fileMenu.addSeparator()
importMenu = fileMenu.addMenu("&Import")
importMenu.addAction(importPrefab)
exportMenu = fileMenu.addMenu("&Export")
exportMenu.addAction(exportAction)
exportMenu.addAction(bspExportAction)
fileMenu.addSeparator()
fileMenu.addAction(undoAction)
fileMenu.addAction(redoAction)
fileMenu.addSeparator()
fileMenu.addAction(exitAction)
optionsMenu.addAction(gridAction)
optionsMenu.addAction(changeSkybox)
optionsMenu.addAction(changeHammer)
toolsMenu.addAction(createPrefabAction)
toolsMenu.addAction(hammerAction)
toolsMenu.addSeparator()
toolsMenu.addAction(consoleAction)
helpMenu.addAction(tutorialAction)
helpMenu.addAction(helpAction)
self.home()
self.change_skybox()
self.level_select()
def open_hammer(self,loaded,file,reloc = False):
self.open_file()
if "loaded_first_time" not in self.files or reloc:
self.file.close()
self.open_file(True)
hammer_location = QFileDialog.getOpenFileName(self, "Find Hammer Location", "/","Hammer Executable (*.exe *.bat)")
hammer_location = str(hammer_location[0])
self.file.write("loaded_first_time\n")
self.file.write(hammer_location)
self.file.close()
if loaded == 1:
subprocess.Popen(hammer_location +" "+ file)
else:
subprocess.Popen(hammer_location)
else:
try:
if loaded == 1:
subprocess.Popen(self.fileloaded[1] + " "+file)
else:
subprocess.Popen(self.fileloaded[1])
except Exception as e:
print(str(e))
self.pootup = QMessageBox()
self.pootup.setText("ERROR!")
self.pootup.setInformativeText("Hammer executable/batch moved or renamed!")
self.pootup.exec_()
self.file.close()
os.remove("startupcache/startup.su")
self.open_hammer(0,"null")
def open_file(self,reloc = False):
if reloc:
os.remove("startupcache/startup.su")
try:
self.file = open("startupcache/startup.su", "r+")
except:
self.file = open("startupcache/startup.su", "w+")
self.fileloaded = self.file.readlines()
self.files = "".join(self.fileloaded)
def remove_prefabs(self):
import removeText
num = QInputDialog.getText(self,("Remove Prefabs"),("Remove x number of prefabs from the back of the list. REQUIRES RESTART"))
try:
num = int(num[0])
except:
QMessageBox.critical(self, "Error", "Please enter a number.")
self.remove_prefabs()
removeText.reset(num)
def closeEvent(self, event):
#closeEvent runs close_application when the x button is pressed
event.ignore()
self.close_application()
def home(self):
global levels
self.central_widget = QWidget()
self.setCentralWidget(self.central_widget)
self.scrollArea = QScrollArea()
self.scrollArea.setStyleSheet("background-color: rgb(50, 50, 50, 100);")
self.scrollArea.setBackgroundRole(QPalette.Light)
try:
self.scrollArea.setGeometry(QRect(0, 0, self.grid_x*32, self.grid_y*32))
except:
self.scrollArea.setGeometry(QRect(0,0,580,580))
try:
if self.grid_x > 16:
self.scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
if self.grid_y > 16:
self.scrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
except:
pass
actiondict = {}
self.buttonLabel = QLabel("Rotation:",self)
self.listLabel = QLabel("List of prefabs:",self)
self.gridLabel = QLabel("Work Area:",self)
self.divider = QFrame(self)
self.divider.setFrameShape(QFrame.VLine)
self.divider.setLineWidth(10)
self.dividerH = QFrame(self)
self.dividerH.setFrameShape(QFrame.HLine)
self.dividerH.setLineWidth(10)
self.current = QPushButton("",self)
self.current.setIcon(QIcon(''))
self.current.setIconSize(QSize(40,40))
self.current.setFixedSize(QSize(40,40))
self.current.setFlat(True)
self.current.clicked.connect(self.heavy)
self.level = QPushButton(self)
self.level.setText("Level: 1")
self.level.setFixedSize(QSize(150,30))
self.level.clicked.connect(self.level_select)
self.levelup = QToolButton(self)
self.levelup.setIcon(QIcon('icons/up.png'))
self.levelup.setIconSize(QSize(20,20))
self.levelup.clicked.connect(lambda: self.change_level(True, True))
self.levelup.setAutoRaise(True)
self.leveldown = QToolButton(self)
self.leveldown.setIcon(QIcon('icons/down.png'))
self.leveldown.setIconSize(QSize(20,20))
self.leveldown.clicked.connect(lambda: self.change_level(True, False))
self.leveldown.setAutoRaise(True)
self.rotateCW = QToolButton(self)
self.rotateCW.setShortcut(QKeySequence(Qt.Key_Right))
self.rotateCW.setIcon(QIcon('icons/rotate_cw.png'))
self.rotateCW.setIconSize(QSize(40,40))
self.rotateCW.setFixedSize(QSize(40,40))
self.rotateCW.setAutoRaise(True)
self.rotateCCW = QToolButton(self)
self.rotateCCW.setShortcut(QKeySequence(Qt.Key_Left))
self.rotateCCW.setIcon(QIcon('icons/rotate_ccw.png'))
self.rotateCCW.setIconSize(QSize(40,40))
self.rotateCCW.setFixedSize(QSize(40,40))
self.rotateCCW.setAutoRaise(True)
#sets rotation value. 0 = right, 1 = down, 2 = left, 3 = right
self.rotateCW.clicked.connect(self.rotateCW_func)
self.rotateCCW.clicked.connect(self.rotateCCW_func)
self.button_rotate_layout = QHBoxLayout()
self.button_rotate_layout.addWidget(self.buttonLabel)
self.button_rotate_layout.addWidget(self.rotateCCW)
self.button_rotate_layout.addWidget(self.current)
self.button_rotate_layout.addWidget(self.rotateCW)
self.button_rotate_layout.addWidget(self.divider)
self.button_rotate_layout.addWidget(self.level)
self.button_rotate_layout.addWidget(self.levelup)
self.button_rotate_layout.addWidget(self.leveldown)
self.button_rotate_layout.addStretch(1)
self.tile_list = QListWidget()
self.tile_list.setMaximumWidth(200)
self.tile_list.setStyleSheet("QListWidget { background-color: rgb(50, 50, 50, 100); }")
self.up_tool_btn = QToolButton(self)
self.up_tool_btn.setIcon(QIcon('icons/up.png'))
self.up_tool_btn.clicked.connect(self.prefab_list_up)
self.down_tool_btn = QToolButton(self)
self.down_tool_btn.setIcon(QIcon('icons/down.png'))
self.down_tool_btn.clicked.connect(self.prefab_list_down)
self.del_tool_btn = QToolButton(self)
self.del_tool_btn.setIcon(QIcon('icons/delete.png'))
self.del_tool_btn.clicked.connect(lambda: self.prefab_list_del(self.tile_list.currentRow(), self.tile_list.currentItem()))
self.add_tool_btn = QToolButton(self)
self.add_tool_btn.setIcon(QIcon('icons/add.png'))
self.add_tool_btn.clicked.connect(self.create_prefab)
self.tile_toolbar = QToolBar()
self.tile_toolbar.addWidget(self.up_tool_btn)
self.tile_toolbar.addSeparator()
self.tile_toolbar.addWidget(self.down_tool_btn)
self.tile_toolbar.addSeparator()
self.tile_toolbar.addWidget(self.del_tool_btn)
self.tile_toolbar.addSeparator()
self.tile_toolbar.addWidget(self.add_tool_btn)
for index, text in enumerate(prefab_text_list):
item = QListWidgetItem(QIcon(prefab_icon_list[index]), text)
self.tile_list.addItem(item)
self.tile_list.currentItemChanged.connect(self.changeIcon)
#contains label and list vertically
self.tile_list_layout = QVBoxLayout()
self.tile_list_layout.addWidget(self.listLabel)
self.tile_list_layout.addWidget(self.tile_list)
self.tile_list_layout.addWidget(self.tile_toolbar)
self.button_grid_layout = QGridLayout()
self.button_grid_layout.setSpacing(0)
self.grid_widget = QWidget()
self.grid_widget.setLayout(self.button_grid_layout)
self.scrollArea.setWidget(self.grid_widget)
self.scrollArea.setWidgetResizable(True)
#contains label and grid vertically
self.gridLayout = QVBoxLayout()
self.gridLayout.addWidget(self.gridLabel)
self.gridLayout.addWidget(self.scrollArea)
self.button_grid_all = QVBoxLayout()
self.button_grid_all.addLayout(self.button_rotate_layout)
self.button_grid_all.addWidget(self.dividerH)
self.button_grid_all.addLayout(self.gridLayout)
self.column = QHBoxLayout()
self.column.addLayout(self.button_grid_all)
self.column.addLayout(self.tile_list_layout)
self.row = QVBoxLayout(self.central_widget)
self.row.addLayout(self.column)
try:
f = open('startupcache/firsttime.su', 'r+')
lines = f.readlines()
except:
f = open('startupcache/firsttime.su','w+')
lines = f.readlines()
if "startup" not in lines:
'''
self.popup = QMessageBox(self)
self.popup.setGeometry(100,100,500,250)
self.popup.setWindowTitle("First Launch")
self.popup.setInformativeText("You haven't launched this before! Try looking at the <a href=\"https://github.com/baldengineers/easytf2_mapper/wiki/Texture-bug\">wiki</a> for help!")
self.popup.setText("First Launch!")
self.popup.exec_()
#this is obsolete - jony
'''
QMessageBox.information(self, "First Launch", "First Launch!\n\nYou haven't launched this before! Try looking at the <a href=\"https://github.com/baldengineers/easytf2_mapper/wiki/Texture-bug\">wiki</a> for help!")
f.write("startup")
f.close
subprocess.Popen("associconwin.bat")
#WILL ONLY WORK IN REDIST FORM
else:
pass
self.grid_change(0,0,0,True, False, True)
'''
while True:
try:
if self.tile_list.currentItemChanged:
self.changeIcon()
except:
pass
'''
self.show()
def level_select(self):
self.windowl = QDialog(self)
global levels
self.levellist = QListWidget()
self.levellist.setIconSize(QSize(200, 25))
try:
for i in range(levels):
item = QListWidgetItem(QIcon("icons/level.jpg"),"Level "+str(i+1))
self.levellist.addItem(item)
except Exception as e:
print(str(e))
pass
self.levellist.itemClicked.connect(lambda: self.change_level(False, False))
self.layoutl = QHBoxLayout()
self.layoutl.addWidget(self.levellist)
self.windowl.setGeometry(150,150,400,300)
self.windowl.setWindowTitle("Choose a level")
self.windowl.setWindowIcon(QIcon("icons/icon.ico"))
self.windowl.setLayout(self.layoutl)
self.windowl.exec_()
def change_level(self, but = False, up = False):
global level, levels
if not but:
self.file_save(True)
level = int(self.levellist.currentRow()) #+1 X First level should be 0
print(level)
self.file_open(True)
self.windowl.close()
self.level.setText("Level: " + str(level+1))
if up:
self.file_save(True)
if level != levels-1:
level = int(level+1)
else:
pass
print(level)
self.file_open(True)
self.level.setText("Level: " + str(level+1))
elif not up and but:
self.file_save(True)
if level != 0:
level = int(level-1)
else:
pass
print(level)
self.file_open(True)
self.level.setText("Level: " + str(level+1))
#change grid to grid for level
def rotateCW_func(self):
global rotation
if rotation < 3:
rotation = rotation + 1
else:
rotation = 0
self.changeIcon()
def rotateCCW_func(self):
global rotation
if rotation == 0:
rotation = 3
else:
rotation = rotation - 1
self.changeIcon()
def prefab_list_up(self):
currentRow = self.tile_list.currentRow()
if currentRow > 0:
currentItem = self.tile_list.takeItem(currentRow)
self.tile_list.insertItem(currentRow - 1, currentItem)
self.tile_list.setCurrentRow(currentRow - 1)
self.update_list_file(currentRow, currentRow - 1)
self.changeIcon()
def prefab_list_down(self):
currentRow = self.tile_list.currentRow()
if currentRow < self.tile_list.count() - 1:
currentItem = self.tile_list.takeItem(currentRow)
self.tile_list.insertItem(currentRow + 1, currentItem)
self.tile_list.setCurrentRow(currentRow + 1)
self.update_list_file(currentRow, currentRow + 1)
self.changeIcon()
def update_list_file(self, old_index, new_index):
file_list = ["prefab_template/prefab_list.txt", "prefab_template/prefab_icon_list.txt", "prefab_template/prefab_text_list.txt"]
list_list = [prefab_list, prefab_icon_list, prefab_text_list]
for l in list_list:
l.insert(new_index, l.pop(old_index))
with open(file_list[list_list.index(l)], "w") as file:
if list_list.index(l) == 0:
rot_file = open("prefab_template/rot_prefab_list.txt", "w")
for item in l:
file.write(item + "\n")
if list_list.index(l) == 0:
rot_file.write(item + "_icon_list.txt" + "\n")
#stupid icon lists, making me add more lines of code to my already concise function
def prefab_list_del(self, currentprefab, currentText):
self.restartCheck = QCheckBox()
self.restartCheck.setText("Restart after deletion?")
choice = QMessageBox.question(self,"Delete Prefab (DO NOT DELETE STOCK PREFABS)","Are you sure you want to delete \"%s\"?\nThis is mainly for developers." %(prefab_text_list[currentprefab]),
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if choice == QMessageBox.Yes:
text_list = ['prefab_template/prefab_text_list.txt','prefab_template/rot_prefab_list.txt',
'prefab_template/prefab_list.txt', 'prefab_template/prefab_icon_list.txt']
for cur in text_list:
file = open(cur, 'r+')
cur_list = file.readlines()
file.seek(0)
file.truncate()
del cur_list[currentprefab]
cur_str = "".join(cur_list)
file.write(cur_str)
file.close()
restart_btn = QPushButton("Restart")
later_btn = QPushButton("Later")
choice = QMessageBox(self)
choice.setIcon(QMessageBox.Question)
choice.setWindowTitle("Prefab Successfully Deleted")
choice.setText("Program must be restarted for changes to take effect.")
choice.setInformativeText("Restart? You will lose any unsaved progress.")
choice.addButton(restart_btn, QMessageBox.YesRole)
choice.addButton(later_btn, QMessageBox.NoRole)
choice.setDefaultButton(later_btn)
if choice.exec_() == 0:
try:
subprocess.Popen('EasyTF2Mapper.exe')
except:
subprocess.Popen('python main.py')
sys.exit()
else:
pass
else:
del choice
def changeIcon(self):
global rotation
try:
current_prefab_icon_list2 = open('prefab_template/rot_prefab_list.txt', 'r+')
current_prefab_icon_list2 = current_prefab_icon_list2.readlines()
current_prefab_icon_list2 = current_prefab_icon_list2[self.tile_list.currentRow()]
if "\n" in current_prefab_icon_list2:
current_prefab_icon_list2 = current_prefab_icon_list2[:-1]
current_prefab_icon_list2 = open('prefab_template/iconlists/'+current_prefab_icon_list2, 'r+')
current_prefab_icon_list2 = current_prefab_icon_list2.readlines()
icon2 = current_prefab_icon_list2[rotation]
if "\n" in icon2:
icon2 = icon2[:-1]
self.current.setIcon(QIcon(icon2))
self.current.setIconSize(QSize(32,32))
except Exception as e:
print(str(e))
icon = prefab_icon_list[self.tile_list.currentRow()]
self.current.setIcon(QIcon(icon))
self.current.setIconSize(QSize(32,32))
#might consider using the following code in the future
'''
im_rot = Image.open(prefab_icon_list[self.tile_list.currentRow()])
im_rot = im_rot.rotate(360-(rotation*90))
data = im_rot.tobytes('raw')#('raw', 'RGBA')
im_rot_qt = QImage(data, im_rot.size[0], im_rot.size[1], QImage.Format_ARGB32)
im_rot.close()
icon = QPixmap.fromImage(im_rot_qt)
self.current.setIcon(QIcon(icon))
self.current.setIconSize(QSize(32,32))
'''
def file_open(self, tmp = False, first = False):
global grid_list, iconlist, level, totalblocks,entity_list, currentfilename, file_loaded, latest_path
print(latest_path)
if not tmp:
name = QFileDialog.getOpenFileName(self, "Open File", latest_path,"*.ezm")
latest_path,file = str(name[0]),open(name[0], "rb")
level = 0
iconlist=[]
while True:
header = pickle.load(file)
if "levels" in header:
openlines = pickle.load(file)
levelcountload = openlines
elif "grid_size" in header:
openlines = pickle.load(file)
self.grid_change(openlines[0],openlines[1],openlines[2],False, True, True)
elif "totalblocks" in header:
totalblocks=[]
openlines = pickle.load(file)
for item in openlines:
totalblocks.append(item)
elif "entity_list" in header:
entity_list=[]
openlines = pickle.load(file)
for item in openlines:
entity_list.append(item)
elif "icon_list" in header:
global grid_list
iconlist=[]
openlines = pickle.load(file)
for item in openlines:
iconlist.append(item)
for index, icon in enumerate(iconlist[0]):
if "icons" in icon:
grid_list[index].button.setIcon(QIcon(icon))
grid_list[index].button.setIconSize(QSize(32,32))
elif "skybox2_list" in header:
openlines = pickle.load(file)
skybox2_list.setCurrentRow(openlines)
else:
break
for i in range(levelcountload):
file = open("leveltemp/level" + str(i)+".tmp", "wb")
pickle.dump(iconlist[i], file)
file.close()
self.change_skybox()
file.close()
self.setWindowTitle("Easy TF2 Mapper - [" + str(name[0]) + "]")
currentfilename = str(name[0])
file_loaded = True
else:
try:
file = open("leveltemp/level" + str(level)+".tmp", "rb")
iconlist[level] = pickle.load(file)
file.close()
for index, icon in enumerate(iconlist[level]):
grid_list[index].button.setIcon(QIcon(icon))
grid_list[index].button.setIconSize(QSize(32,32))
except Exception as e:
print(str(e))
def file_save(self, tmp = False, saveAs = False):
global grid_x, grid_y, iconlist, levels, level, currentfilename, file_loaded, latest_path
print(latest_path)
gridsize_list = (grid_x,grid_y,levels)
skybox_sav = skybox2_list.currentRow()
if not tmp:
if not file_loaded or saveAs:
name = QFileDialog.getSaveFileName(self, "Save File", latest_path, "*.ezm")[0]
latest_path = name
else:
if "*" in currentfilename:
name = currentfilename[:-1]
else:
name = currentfilename
file = open(name, "wb")
pickle.dump("<levels>",file)
pickle.dump(levels,file)
pickle.dump("<grid_size>", file)
pickle.dump(gridsize_list, file)
pickle.dump("<totalblocks>", file)
pickle.dump(totalblocks, file)
pickle.dump("<entity_list>", file)
pickle.dump(entity_list, file)
pickle.dump("<icon_list>", file)
pickle.dump(iconlist, file)
pickle.dump("<skybox>", file)
pickle.dump(skybox_sav, file)
file.close()
QMessageBox.information(self, "File Saved", "File saved as %s" %(name))
self.setWindowTitle("Easy TF2 Mapper - [" + name + "]")
currentfilename = name
file_loaded = True
else:
try:#writes tmp file to save the icons for each level
file = open("leveltemp/level" + str(level)+".tmp", "wb")
pickle.dump(iconlist[level], file)
file.close()
except Exception as e:
print(str(e))
def file_export(self,bsp=False):
global cur_vmf_location,id_num, grid_y, grid_x, world_id_num, count_btns, currentlight, skybox, skybox2_list, entity_list, skybox_light_list, skybox_angle_list, latest_path
skyboxgeolist = []
skyboxz = QInputDialog.getText(self,("Set Skybox Height"),("Skybox Height(hammer units, %d minimum recommended):" %(levels*512)))
try:
skyboxz = int(skyboxz[0])
except:
QMessageBox.critical(self, "Error", "Please enter a number.")
if bsp == False:
self.file_export()
else:
self.file_export(True)
#generate skybox stuff now
create = generateSkybox.createSkyboxLeft(grid_x,grid_y,skyboxz,id_num,world_id_num)
skyboxgeolist.append(create[0])
id_num = create[1]
world_id_num = create[2]
create = generateSkybox.createSkyboxNorth(grid_x,grid_y,skyboxz,id_num,world_id_num)
skyboxgeolist.append(create[0])
id_num = create[1]
world_id_num = create[2]
create = generateSkybox.createSkyboxRight(grid_x,grid_y,skyboxz,id_num,world_id_num)
skyboxgeolist.append(create[0])
id_num = create[1]
world_id_num = create[2]
create = generateSkybox.createSkyboxTop(grid_x,grid_y,skyboxz,id_num,world_id_num)
skyboxgeolist.append(create[0])
id_num = create[1]
world_id_num = create[2]
create = generateSkybox.createSkyboxSouth(grid_x,grid_y,skyboxz,id_num,world_id_num)
skyboxgeolist.append(create[0])
skybox = skybox_list[skybox2_list.currentRow()]
skyboxlight = skybox_light_list[skybox2_list.currentRow()]
skyboxangle = skybox_angle_list[skybox2_list.currentRow()]
try:
currentlight = currentlight.replace("world_idnum",str(world_id_num))
currentlight = currentlight.replace("CURRENT_LIGHT",skyboxlight)
currentlight = currentlight.replace("CURRENT_ANGLE",skyboxangle)
except:
QMessageBox.critical(self, "Error", "Please choose a skybox.")
self.change_skybox()
entity_list[0][levels] = currentlight
latest_path = latest_path.replace(".ezm",".vmf")
if not bsp:
name = QFileDialog.getSaveFileName(self, "Export .vmf", latest_path, "Valve Map File (*.vmf)")
file = open(name[0], "w+")
import export
wholething = export.execute(totalblocks, entity_list, levels, skybox,skyboxgeolist)
file.write(wholething)
file.close()
popup = QMessageBox(self, "File Exported",
"The .vmf has been outputted to %s" %(name[0]) + " Open it in hammer to compile as a .bsp. Check out the wiki (https://github.com/baldengineers/easytf2_mapper/wiki/Texture-bug) for fixing errors with textures.")
popup.setWindowTitle("File Exported")
popup.setText("The .vmf has been outputted to %s" %(name[0]))
popup.setInformativeText(" Open it in hammer to compile as a .bsp and/or make some changes.")
hammerButton = popup.addButton("Open Hammer",QMessageBox.ActionRole)
exitButton = popup.addButton("OK",QMessageBox.ActionRole)
popup.exec_()
if popup.clickedButton() == hammerButton:
self.open_hammer(1,name[0])
if popup.clickedButton() == exitButton:
popup.deleteLater()
cur_vmf_location = name[0]
print('not bsp vmf part done')
else:
file = open('output/tf2mapperoutput.vmf','w+')
import export
wholething = export.execute(totalblocks, entity_list, levels, skybox,skyboxgeolist)
file.write(wholething)
file.close()
cur_vmf_location = 'output/tf2mapperoutput.vmf'
print('bsp vmf part done')
def file_export_bsp(self):
global cur_vmf_location
self.file_export(True)
try:
tf2BinLoc = open('startupcache/vbsp.su','r+')
tf2BinLocFile = tf2BinLoc.readlines()[0].replace('\\','/')
tf2BinLoc.close()
subprocess.call('"'+tf2BinLocFile+'/vbsp.exe" "'+cur_vmf_location+'"')
subprocess.call('"'+tf2BinLocFile+'/vvis.exe" '+cur_vmf_location.replace('.vmf','.bsp')+'"')
subprocess.call('"'+tf2BinLocFile+'/vrad.exe" '+cur_vmf_location.replace('.vmf','.bsp')+'"')
shutil.copyfile(cur_vmf_location.replace('.vmf','.bsp'),tf2BinLocFile.replace('/bin','/tf/maps/tf2mapperoutput.bsp'))
popup = QMessageBox(self)
popup.setWindowTitle("File Exported")
popup.setText("The .vmf has been outputted to %s" %(tf2BinLocFile.replace('/bin','/tf/maps/tf2mapperoutput.bsp')))
popup.setInformativeText("Open TF2 and in load up 'tf2mapperoutput.bsp'! You can do this by typing 'map tf2mapperoutput' or by creating a server with that map.\n\nThere also is a .vmf file of your map stored in output/tf2mapperoutput.vmf.")
hammerButton = popup.addButton("Open TF2",QMessageBox.ActionRole)
exitButton = popup.addButton("OK",QMessageBox.ActionRole)
popup.exec_()
if popup.clickedButton() == hammerButton:
subprocess.Popen('"'+tf2BinLocFile.replace('steamapps/common/Team Fortress 2/bin','')+'steam.exe" "steam://run/440"')
if popup.clickedButton() == exitButton:
popup.deleteLater()
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(exc_type, fname, exc_tb.tb_lineno)
try:
tf2BinLoc = open('startupcache/vbsp.su', 'w+')
tf2BinLocFile = QFileDialog.getExistingDirectory(self,'LOCATE Team Fortress 2/bin, NOT IN DEFAULT LOCATION!')
tf2BinLocFile = str(tf2BinLocFile.replace('\\','/'))
tf2BinLoc.write(tf2BinLocFile)