-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
1706 lines (1378 loc) · 69.1 KB
/
main.py
File metadata and controls
1706 lines (1378 loc) · 69.1 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
#easy cs:go mapper: counter-strike: global offensive port of the easy tf2 mapper
#
#in development, not at a working stage.
#DIFFERENCES:
#more prefabrications
#more sections (subsections?)
#improved UI
#improved file count
#multi-game system
# program boots up and variables are set which change what game the program utilizes
# (set up after dialog with radio button + grid size is chosen)
# grid size of createprefab, how skybox renderings, skybox textures, light vars, window titles, file directories, etc.
#move all prefabs on grid
# if we can make a new grid system widget
#
#important:
#move all variable definitions that need changing based off game selection
#to a separate function which runs after dialog
#make the grid size dialog run before everything else. make it its own separate class that
#runs before mainwindow
import sys
#move this to after initial dialog
import os.path
import os
from PySide.QtCore import *
from PySide.QtGui import *
import importlib
import createPrefab
import pf
from PIL import Image
from PIL.ImageQt import ImageQt
import generateSkybox
import light_create
import export
import subprocess
import pickle
import pprint
import random
import glob
import webbrowser
import wave
import zipfile
import shutil
import winsound
import GridWidget
class GridBtn(QWidget):
def __init__(self, parent, x, y, btn_id):
super(GridBtn, self).__init__()
self.button = QPushButton("", parent)
self.x,self.y = x,y
self.btn_id = btn_id
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.installEventFilter(self)
self.button.show()
self.icons = None
parent.progress += 100/(parent.grid_x*parent.grid_y)
parent.progressBar.setValue(parent.progress)
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_moduleName and h_icon and h_rot are used when undoing/redoing
current_list = eval('parent.tile_list%s' % str(parent.list_tab_widget.currentIndex()+1))
#format | history.append((x,y,moduleName,self.icon,level))
if clicked:
parent.redo_history=[]
if self.icons:
moduleName = eval(parent.prefab_list[parent.list_tab_widget.currentIndex()][parent.current_list.currentRow()])
templist=[(x,y,moduleName,self.icons,None)]
else:
templist=[(x,y,None,None,None)]
def clear_btn(btn_id):
self.button.setIcon(QIcon())
for l in [parent.totalblocks,parent.entity_list,parent.stored_info_list]:
l[btn_id] = ''
parent.iconlist[btn_id] = ('','')
self.icons = None
if self.checkForCtrl(clicked):
clear_btn(btn_id)
else:
if clicked:
if parent.ymin == None or parent.xmin == None:
parent.ymin,parent.xmin = y,x
else:
if y < parent.ymin:
parent.ymin = y
if x < parent.xmin:
parent.xmin = x
if y > parent.ymax:
parent.ymax = y
if x > parent.xmax:
parent.xmax = x
moduleName = eval(parent.prefab_list[parent.list_tab_widget.currentIndex()][parent.current_list.currentRow()])
else:
moduleName = h_moduleName if h_moduleName != None else clear_btn(btn_id)
if h_moduleName != None:
if clicked:
icon = parent.cur_icon
else:
icon = h_icon
self.button.setIcon(QIcon(icon))
self.button.setIconSize(QSize(32,32))
parent.iconlist[btn_id] = [icon]
parent.stored_info_list[btn_id] = [moduleName,x,y,parent.id_num,parent.world_id_num,parent.entity_num,parent.placeholder_list,parent.rotation]
self.icons = icon
else:
parent.stored_info_list[btn_id] = ""
if "*" not in parent.windowTitle():
parent.setWindowTitle("Easy "+parent.gameVar+" Mapper* - ["+parent.currentfilename+"]")
if clicked:
templist.append((x,y,moduleName,self.icons,None))
parent.history.append(templist)
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):
super(MainWindow, self).__init__()
#QApplication.setStyle(QStyleFactory.create("Cleanlooks")) #comment out if unwanted
#define some variables used throughout the class
self.level = 0
self.levels = 0
self.id_num = 1
self.world_id_num = 2
self.rotation = 0
self.entity_num = 1
self.btn_id_count = 0
self.grid_list=[]
self.totalblocks = []
self.skybox_list=[]
self.last_tuple = 'First'
self.skybox_light_list=[]
self.iconlist = []
self.cur_icon = ""
self.rotation_icon_list=[]
self.skybox_angle_list=[]
self.skybox_icon_list=[]
self.gridsize = []
self.count_btns = 0
self.entity_list=[]
self.save_dict = {}
self.load_dict = {}
self.stored_info_list=[]
#tabs should be more reusable
#for example: the following lists should be this instead:
#self.prefab_list = [[] for i in self.tabs] where self.tabs is the # of tabs
#i.e. We should be able to create new tabs whenever we want, just by
#changing the self.tabs variable.
self.prefab_list = [[],[],[]]
self.prefab_text_list = [[],[],[]]
self.prefab_icon_list = [[],[],[]]
self.openblocks=[]
self.placeholder_list = []
self.history = []
self.redo_history = []
self.currentfilename='Untitled'
self.file_loaded = False
self.current_loaded = ''
self.latest_path='/'
self.isTF = True
self.TLBool = False
self.SLBool = False
self.BRBool = False
#initial startup/gridchange window
initWindow = GridChangeWindow(self, True)
values = initWindow.returnVal()
#tell which game was chosen on launch
if self.isTF:
self.gameVar,self.gameDirVar = "TF2","tf2/"
else:
self.gameVar,self.gameDirVar = "CS:GO","csgo/"
self.TFFormat() if self.isTF else self.CSFormat()
util_list = [createPrefab,light_create,generateSkybox,export]
for util in util_list:
util.setGameDirVar(self.gameDirVar)
#create the main window
self.setGeometry(100, 25, 875, 750)
self.setWindowTitle("Easy "+self.gameVar+" Mapper")
self.setWindowIcon(QIcon("icons\icon.ico"))
#removed for now to see how gui looks without it
## if self.isTF:
## namelist = ['gravelpit','2fort','upward','mvm']
## palette = QPalette()
## palette.setBrush(QPalette.Background,QBrush(QPixmap(self.gameDirVar+"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 Mapper 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(self.grid_change)
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))
gridAction = QAction("&Set Grid Size", self)
gridAction.setShortcut("Ctrl+G")
gridAction.setStatusTip("Set Grid Height and Width. RESETS ALL BLOCKS.")
gridAction.triggered.connect(self.grid_change) #change so it just makes grid bigger/smaller, not erase all blocks, or else it would just do the same exact thing as making a new file
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)
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu("&File")
editMenu = mainMenu.addMenu("&Edit")
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()
editMenu.addAction(undoAction)
editMenu.addAction(redoAction)
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)
#create the status bar
self.status = QStatusBar(self)
self.setStatusBar(self.status)
#perform some necessary functions for startup of program
self.home()
self.grid_change_func(values[0], values[1], values[2])
#self.change_skybox()
#self.level_select()
def TFFormat(self):
print('TF2 version of the mapper loading!')
sys.path.append(self.gameDirVar+"prefabs/")
self.currentlight = '''
entity
{
"id" "world_idnum"
"classname" "light_environment"
"_ambient" "255 255 255 100"
"_ambientHDR" "-1 -1 -1 1"
"_AmbientScaleHDR" "1"
"_light" "CURRENT_LIGHT"
"_lightHDR" "-1 -1 -1 1"
"_lightscaleHDR" "1"
"angles" "CURRENT_ANGLE"
"pitch" "0"
"SunSpreadAngle" "0"
"origin" "0 0 73"
editor
{
"color" "220 30 220"
"visgroupshown" "1"
"visgroupautoshown" "1"
"logicalpos" "[0 500]"
}
}
'''
#skybox default needs to be based off game chosen
self.skybox = 'sky_tf2_04'
#skyboxlight = '255 255 255 200'
#skyboxangle = '0 0 0'
#if the user does not change the lighting, it sticks with this.
#if the user does not choose a skybox it sticks with this
#self.prefab_file = open(self.gameDirVar+"prefab_template/prefab_list.txt")
#self.prefab_text_file = open(self.gameDirVar+"prefab_template/prefab_text_list.txt")
#self.prefab_icon_file = open(self.gameDirVar+"prefab_template/prefab_icon_list.txt")
self.prefab_file = pickle.load(open(self.gameDirVar+"prefabs/pfinfo.ezmd","rb"))
self.skybox_file = open(self.gameDirVar+"prefab_template/skybox_list.txt")
self.skybox_icon = open(self.gameDirVar+"prefab_template/skybox_icons.txt")
self.skybox_light = open(self.gameDirVar+"prefab_template/skybox_light.txt")
self.skybox_angle = open(self.gameDirVar+"prefab_template/skybox_angle.txt")
for main_index,file in enumerate(["prefab_list","prefab_icon_list","prefab_text_list"]):
for index,line in enumerate(self.prefab_file[main_index+1]):
eval("self."+file+"""[int(self.prefab_file[0][index])].append(line)""")# need to do this because reading the file generates a \n after every line
section = 0
self.rotation_icon_list = []
self.index_section_list = [0]
self.rotation_icon_list.append([])
#print(rotation_icon_list)
for line in self.skybox_file.readlines():
self.skybox_list.append(line[:-1] if line.endswith("\n") else line)# need to do this because reading the file generates a \n after every line
for line in self.skybox_icon.readlines():
self.skybox_icon_list.append(line[:-1] if line.endswith("\n") else line)
for line in self.skybox_light.readlines():
self.skybox_light_list.append(line[:-1] if line.endswith("\n") else line)
for line in self.skybox_angle.readlines():
self.skybox_angle_list.append(line[:-1] if line.endswith("\n") else line)
for file in [self.skybox_file,self.skybox_icon,self.skybox_angle,self.skybox_light]:
file.close()
print(self.prefab_list)
#imports that need prefab_list to be defined
for sec in self.prefab_list:
for item in sec:
if item:
globals()[item] = importlib.import_module(item)
print("import", item)
self.save_dict[item]=eval(item)
self.load_dict[eval(item)]=item
logo = open('logo.log','r+')
logo_f = logo.readlines()
for i in logo_f:
print(i[:-1])
logo.close()
print("\n~~~~~~~~~~~~~~~~~~~~~\nMapper loaded! You may have to alt-tab to find the input values dialog.\n")
def CSFormat(self):
#for cs area
pass
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:
if os.path.isfile(self.fileloaded[1]):
if loaded == 1:
subprocess.Popen(self.fileloaded[1] + " "+file)
else:
subprocess.Popen(self.fileloaded[1])
else:
print(str(e))
self.notFound = QMessageBox().setText("ERROR!")
self.notFound.setInformativeText("Hammer executable/batch moved or renamed! (or something else went wrong...)")
self.notFound.exec_()
self.file.close()
os.remove(gameDirVar+"startupcache/startup.su")
self.open_hammer(0,"null")
def open_file(self,reloc = False):
if reloc:
os.remove(self.gameDirVar+"startupcache/startup.su")
if os.path.isfile(self.gameDirVar+"startupcache/startup.su"):
self.file = open(self.gameDirVar+"startupcache/startup.su", "r+")
else:
self.file = open(self.gameDirVar+"startupcache/startup.su", "w+")
self.fileloaded = self.file.readlines()
self.files = "".join(self.fileloaded)
def closeEvent(self, event):
#closeEvent runs close_application when the x button is pressed
event.ignore()
self.close_application()
def home(self):
global levels, current_list
self.xmin = None
self.ymin = None
self.xmax = 0
self.ymax = 0
self.central_widget = QWidget()
self.setCentralWidget(self.central_widget)
self.scrollArea = QScrollArea()
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.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.rotateCCW)
self.button_rotate_layout.addWidget(self.current)
self.button_rotate_layout.addWidget(self.rotateCW)
self.button_rotate_layout.addStretch(1)
#add the main tool bar
self.skyboxAction = QAction(QIcon('icons/sky.png'), "Change Skybox", self)
self.skyboxAction.triggered.connect(self.loadSkyboxList)
self.tileListAction = QAction(QIcon('icons/tile_list.png'), "Re-open Tile list", self)
self.tileListAction.triggered.connect(self.loadTileList)
self.rotateDockAction = QAction(QIcon('icons/rotate_dock.png'), "Re-open Rotation Dock", self)
self.rotateDockAction.triggered.connect(self.loadButtonRotate)
self.mainToolBar = self.addToolBar("Main")
self.mainToolBar.addAction(self.skyboxAction)
self.mainToolBar.addAction(self.tileListAction)
self.mainToolBar.addAction(self.rotateDockAction)
#add the many sections of the tile_list
self.tile_list1 = QListWidget()
self.tile_list2 = QListWidget()
self.tile_list3 = QListWidget()
self.current_list = self.tile_list1
for l in [self.tile_list1, self.tile_list2, self.tile_list3]:
l.setDragEnabled(True)
self.gui_skybox_list = QListWidget()
#print(self.skybox_icon_list)
self.gui_skybox_list.setIconSize(QSize(140, 20))
self.gui_skybox_list.setMaximumWidth(160)
for index, text in enumerate(self.skybox_list):
item = QListWidgetItem(QIcon(self.gameDirVar+self.skybox_icon_list[index]),'')
self.gui_skybox_list.addItem(item)
self.list_tab_widget = QTabWidget()
self.list_tab_widget.setMaximumWidth(200)
self.list_tab_widget.addTab(self.tile_list1,'Geometry')
self.list_tab_widget.addTab(self.tile_list2,'Map Layout')
self.list_tab_widget.addTab(self.tile_list3,'Fun')
self.list_tab_widget.currentChanged.connect(self.changeCurrentList)
print("len:", self.list_tab_widget.count())
#add the prefab tools
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.current_list.currentRow()))
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()
for t in [self.up_tool_btn,self.down_tool_btn,self.del_tool_btn,self.add_tool_btn]:
self.tile_toolbar.addWidget(t)
self.tile_toolbar.addSeparator()
for index, text in enumerate(self.prefab_text_list):
for ind, indiv in enumerate(text):
curr_list = eval("self.tile_list%d" % (index+1))
item = QListWidgetItem(QIcon(self.gameDirVar+self.prefab_icon_list[index][ind]), indiv)
curr_list.addItem(item)
for i in range(self.list_tab_widget.count()):
eval("self.tile_list%d" %(i+1)).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.list_tab_widget)
#self.tile_list_layout.addWidget(self.toolsLabel)
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)
self.button_rotate_widget = QWidget()
self.button_rotate_widget.setLayout(self.button_rotate_layout)
self.tile_list_widget = QWidget()
self.tile_list_widget.setLayout(self.tile_list_layout)
self.loadTileList(True)
self.loadSkyboxList(True)
self.loadButtonRotate(True)
self.column = QHBoxLayout()
self.column.addWidget(self.scrollArea)
self.row = QVBoxLayout(self.central_widget)
self.row.addLayout(self.column)
#TESTING
from classes import PrefabItem, ListGroup
#grid for placing prefabs
self.grid = GridWidget.GridWidget(20,20,self)
self.grid_container = GridWidget.GridWidgetContainer(self.grid)
self.grid_dock = QDockWidget("Grid", self)
self.grid_dock.setWidget(self.grid_container)
self.grid_dock.setFloating(True)
#define various lists
self.tile_list1 = QListWidget()
self.tile_list2 = QListWidget()
self.tile_list3 = QListWidget()
#add items to self.tab_dict and everything will update
self.tab_dict = {"Geometry":self.tile_list1, "Map Layout":self.tile_list2, "Fun/Other":self.tile_list3}
self.list_group = ListGroup([l for _, l in self.tab_dict.items()])
def set_cur_prefab(item):
self.grid.cur_prefab = item.prefab
for _, tile_list in self.tab_dict.items():
tile_list.itemClicked.connect(set_cur_prefab)
#add prefabs to the lists
with open("tf2/prefabs.dat", "rb") as f:
l = pickle.load(f)
for p in l:
prefab = pf.Prefab(p)
self.tab_dict[prefab.section].addItem(PrefabItem(prefab))
#create tabwidget for the lists
self.list_tab_widget = QTabWidget()
self.list_tab_widget.addTab(self.tab_dict['Geometry'],'Geometry')
self.list_tab_widget.addTab(self.tab_dict['Map Layout'],'Map Layout')
self.list_tab_widget.addTab(self.tab_dict['Fun/Other'],'Fun/Other')
#create dock for the tab widget
self.prefab_dock = QDockWidget("Prefabs", self)
self.prefab_dock.setWidget(self.list_tab_widget)
self.prefab_dock.setFloating(True)
#create buttons for the tools
self.grid_tools_ag = QActionGroup(self)
self.add_prefab_action = QAction(QIcon("icons/add_prefab.png"), "Add a prefab to the grid", self.grid_tools_ag)
self.add_prefab_action.toggled.connect(self.grid.enableAddPrefab)
self.select_action = QAction(QIcon("icons/select_move.png"), "Select Prefabs", self.grid_tools_ag)
self.select_action.toggled.connect(self.grid.enableSelect)
self.grid_tools = QToolBar()
self.grid_tools.setOrientation(Qt.Vertical)
self.addToolBar(Qt.LeftToolBarArea, self.grid_tools)
for act in [self.add_prefab_action,self.select_action]:
act.setCheckable(True)
self.grid_tools.addAction(act)
self.add_prefab_action.setChecked(True) #set the default button checked
def file_export():
for p in self.grid.prefabs:
p.prefab.create(p.posx, p.posy, self.grid.prefab_scale, self.rotataion)
## self.grid_tool_dock = QDockWidget("Tools", self)
## self.grid_tool_dock.setWidget(self.grid_tools)
## self.grid_tool_dock.setFloating(True)
self.addDockWidget(Qt.LeftDockWidgetArea, self.skybox_list_dock)
#END TESTING
if os.path.isfile(self.gameDirVar+'startupcache/firsttime.su'):
f = open(self.gameDirVar+'startupcache/firsttime.su', 'r+')
lines = f.readlines()
else:
f = open(self.gameDirVar+'startupcache/firsttime.su','w+')
lines = f.readlines()
if "startup" not in lines:
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()
#WILL ONLY WORK IN REDIST FORM
else:
pass
self.show()
def loadSkyboxList(self,startup=False):
if not self.SLBool:
self.skybox_list_dock = QDockWidget("Skybox List", self)
self.skybox_list_dock.visibilityChanged.connect(self.toggleSLBool)
self.skybox_list_dock.setWidget(self.gui_skybox_list)
self.skybox_list_dock.setFloating(False)
self.addDockWidget(Qt.LeftDockWidgetArea, self.skybox_list_dock)
def toggleSLBool(self):
if self.SLBool:
self.SLBool = False
else:
self.SLBool = True
def loadTileList(self,startup=False):
if not self.TLBool:
self.tile_list_dock = QDockWidget("Prefab List", self)
self.tile_list_dock.visibilityChanged.connect(self.toggleTLBool)
self.tile_list_dock.setWidget(self.tile_list_widget)
self.tile_list_dock.setFloating(False)
self.addDockWidget(Qt.RightDockWidgetArea, self.tile_list_dock)
#if startup:
#self.TLBool = True
def toggleTLBool(self):
if self.TLBool:
self.TLBool = False
else:
self.TLBool = True
def loadButtonRotate(self,startup = False):
if not self.BRBool:
self.button_rotate_dock = QDockWidget("Current Prefab", self)
self.button_rotate_dock.visibilityChanged.connect(self.toggleBRBool)
self.button_rotate_dock.setWidget(self.button_rotate_widget)
self.button_rotate_dock.setFloating(False)
self.addDockWidget(Qt.LeftDockWidgetArea,self.button_rotate_dock)
#if startup:
#self.BRBool = True
#i am.... the top dock
# ^
# |
#this comment is perfect and i will leave it in because the pun is wasted because it's no longer on the top dock widget area
def toggleBRBool(self):
if self.BRBool:
self.BRBool = False
else:
self.BRBool = True
def changeCurrentList(self):
print("current list: tile_list%s" % str(self.list_tab_widget.currentIndex()+1))
self.current_list = eval('self.tile_list%s' % str(self.list_tab_widget.currentIndex()+1))
def rotateCW_func(self):
if self.rotation < 3:
self.rotation = self.rotation + 1
else:
self.rotation = 0
self.changeIcon()
def rotateCCW_func(self):
if self.rotation == 0:
self.rotation = 3
else:
self.rotation = self.rotation - 1
self.changeIcon()
def prefab_list_up(self):
self.current_list = eval('self.tile_list%s' % str(self.list_tab_widget.currentIndex()+1))
currentRow = self.current_list.currentRow()
if currentRow > 0:
currentItem = self.current_list.takeItem(currentRow)
self.current_list.insertItem(currentRow - 1, currentItem)
self.current_list.setCurrentRow(currentRow - 1)
self.update_list_file(currentRow, currentRow - 1)
self.changeIcon()
def prefab_list_down(self):
self.current_list = eval('self.tile_list%s' % str(self.list_tab_widget.currentIndex()+1))
currentRow = self.current_list.currentRow()
if currentRow < self.current_list.count() - 1:
currentItem = self.current_list.takeItem(currentRow)
self.current_list.insertItem(currentRow + 1, currentItem)
self.current_list.setCurrentRow(currentRow + 1)
self.update_list_file(currentRow, currentRow + 1)
self.changeIcon()
def update_list_file(self, old_index, new_index):
file_list = [self.gameDirVar+"prefab_template/prefab_list.txt", self.gameDirVar+"prefab_template/prefab_icon_list.txt", self.gameDirVar+"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(self.gameDirVar+"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):
#NEEDS TO BE REDONE based off what mode
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[self.list_tab_widget.currentIndex()][currentprefab]),
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if choice == QMessageBox.Yes:
text_list = [self.gameDirVar+'prefab_template/prefab_text_list.txt',self.gameDirVar+'prefab_template/rot_prefab_list.txt',
self.gameDirVar+'prefab_template/prefab_list.txt', self.gameDirVar+'prefab_template/prefab_icon_list.txt']
for cur in text_list:
file = open(cur, 'r+')
cur_list = file.readlines()
file.seek(0)
file.truncate()
print(cur_list[index_section_list[self.list_tab_widget.currentIndex()]+currentprefab+1])
del cur_list[index_section_list[self.list_tab_widget.currentIndex()]+currentprefab+1]
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)
#needs to be redone-- final redist will not be called easytf2mapper as it is no longer just that
if choice.exec_() == 0:
if os.path.isfile('EasyTF2Mapper.exe'):
subprocess.Popen('EasyTF2Mapper.exe')
else:
subprocess.Popen('python main.py')
sys.exit()
else:
pass
else:
del choice
def changeIcon(self):
pixmap = QPixmap(self.gameDirVar+self.prefab_icon_list[self.list_tab_widget.currentIndex()][self.current_list.currentRow()])
transform = QTransform().rotate(90*self.rotation)
self.cur_icon = pixmap.transformed(transform, Qt.SmoothTransformation)
self.current.setIcon(QIcon(self.cur_icon))
self.current.setIconSize(QSize(32,32))
def file_open(self, tmp = False, first = False):
global stored_info_list, totalblocks,entity_list, currentfilename, file_loaded, latest_path,save_dict,load_dict
if not tmp:
name = QFileDialog.getOpenFileName(self, "Open File", latest_path,"*.ezm")
latest_path,file = str(name[0]),open(name[0], "rb")
self.level = 0
self.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_func(openlines[0],openlines[1],openlines[2])
#print('grid changed')
elif "stored_info_list" in header:
stored_info_list=[]
stored_info_list_temp=[]
openlines = pickle.load(file)
for item in openlines:
stored_info_list_temp.append(item)
for index,lvl in enumerate(stored_info_list_temp):
stored_info_list.append([])
for info in lvl:
try:
temp = save_dict[info[0]]
info[0] = temp
stored_info_list[index].append(info)
except:
stored_info_list[index].append('')
elif "icon_list" in header:
self.iconlist=[]
openlines = pickle.load(file)
for item in openlines:
self.iconlist.append(item)
elif "GSList" in header:
openlines = pickle.load(file)
self.gui_skybox_list.setCurrentRow(openlines)
else:
break
for i in range(levelcountload):
file = open(self.gameDirVar+"leveltemp/level" + str(i)+".tmp", "wb")
pickle.dump(self.iconlist[i], file)
file.close()
#self.change_skybox()
file.close()
self.setWindowTitle("Easy "+gameVar+" Mapper - [" + str(name[0]) + "]")
currentfilename = str(name[0])
file_loaded = True
self.upd_icns()
else:
file = open(self.gameDirVar+"leveltemp/level.tmp", "rb")
self.iconlist = pickle.load(file)
file.close()
for index, icon in enumerate(self.iconlist):
self.grid_list[index].button.setIcon(QIcon(icon))
self.grid_list[index].button.setIconSize(QSize(32,32))
def upd_icns(self):
for index, icon in enumerate(self.iconlist[0]):
#if "icons" in icon:
#print(grid_list)
if icon != '':
#print("index: "+str(index)+" icon name: "+icon[0])
ptrans = QTransform().rotate(90*icon[1])
pmap = QPixmap(icon[0]).transformed(ptrans,Qt.SmoothTransformation)
self.grid_list[index].button.setIcon(QIcon(pmap))
self.grid_list[index].button.setIconSize(QSize(32,32))