forked from christianbomholt/dayz_loot_editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
1230 lines (1110 loc) · 45.5 KB
/
app.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
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
from tkinter import Tk, Menu, IntVar, Frame, Label, StringVar, Entry, Listbox
from tkinter import END, OptionMenu, Checkbutton, Button, Radiobutton
from tkinter import ttk, VERTICAL, HORIZONTAL, LabelFrame, simpledialog
from sqlalchemy.sql.expression import or_
from config import ConfigManager
import os.path
from database.dao import Dao
from model.item import Item, Ammobox, init_database
from ui.db import DB
from ui.linkitems import LinkItem
from ui.new_items import NewItems
from ui.setprices import TraderEditor
from xml_manager.xml_writer import XMLWriter
import tkinter.filedialog as filedialog
import webbrowser
import re
import json
from utility import (
assign_rarity,
assign_NotInCE,
distribute_nominal,
column_definition,
categoriesDict,
categoriesNamalskDict,
)
from utility import (
distribute_mags_and_bullets,
apipush,
apipull,
exportSpawnable,
writeToJSONFile,
)
class GUI(object):
def __init__(self, main_container: Tk):
#
self.config = ConfigManager("config.xml")
self.database = Dao(self.config.get_database())
self.database.upgradeDB()
self.gridItems = []
#
self.window = main_container
self.window.grid_rowconfigure(0, weight=1)
self.window.grid_columnconfigure(1, weight=1)
self.menu_bar = Menu(self.window)
self.selected_mods = []
self.moddict = {}
self.modcount = 0
self.moddlist = []
self.import_mods = self.config.get_import_mod()
self.selected_hive = []
self.hivedict = {}
self.hivecount = 0
self.hivelist = []
self.totalWeaponDisplayed = IntVar()
self.totalNumDisplayed = IntVar()
self.nomVars = []
self.weaponNomTypes = {
"ranged": 0,
"ammo": 0,
"optic": 0,
"mag": 0,
"attachment": 0,
}
self.distributorValue = StringVar()
self.weapondistributorValue = StringVar()
self.searchName = StringVar()
self.worldName = StringVar()
self.worldName.set("world")
#
self.__create_menu_bar()
self.__create_entry_frame()
self.__create_tree_view()
self.__create_side_bar()
self.__initiate_items()
self.__create_nominal_info()
self.makeExpansionDir()
#
self.tree.bind("<ButtonRelease-1>", self.__fill_entry_frame)
self.window.wm_title(
"CE-Editor v0.13.0 - "
+ self.config.get_database()
+ " used for maptype: "
+ self.database.get_mapselectValue(1).mapselectvalue
)
def initializeapp(self):
self.__create_tree_view()
self.__create_side_bar()
self.database = Dao(self.config.get_database())
items = self.database.session.query(Item).filter(
Item.mod.in_(self.selected_mods)
)
self.gridItems = items
self.__populate_items(self.gridItems)
self.__initiate_items()
self.__create_nominal_info()
self.window.wm_title("CE-Editor v0.13.0 - New database - restart")
self.makeExpansionDir()
def deselectAllMods(self):
for k in self.moddict:
self.moddict[k].set(0)
self.__selectmodsfunction___()
def selectAllMods(self):
for k in self.moddict:
self.moddict[k].set(1)
self.__selectmodsfunction___()
def initAllMods(self, menu):
for mod in self.database.get_all_types("mod"):
if mod != "all":
self.modcount += 1
int_var = IntVar(value=1)
menu.add_checkbutton(
label=mod, variable=int_var, command=self.__selectmodsfunction___
)
self.moddict[mod] = int_var
self.selected_mods.append(mod)
def deselectAllHive(self):
for k in self.hivedict:
self.hivedict[k].set(0)
self.__selecthivefunction___()
def selectAllHive(self):
for k in self.hivedict:
self.hivedict[k].set(1)
self.__selecthivefunction___()
def initAllHive(self, menu):
for hive in self.database.get_all_types("hive"):
if hive != "all":
self.hivecount += 1
int_var = IntVar(value=1)
menu.add_checkbutton(
label=hive, variable=int_var, command=self.__selecthivefunction___
)
self.hivedict[hive] = int_var
self.selected_hive.append(hive)
def makeExpansionDir(self):
try:
os.mkdir("Expansion")
os.mkdir("Expansion/Traders")
os.mkdir("Expansion/TraderZones")
os.mkdir("Expansion/Market")
except Exception:
pass
def updateAllMods(self, menu):
for i in range(self.modcount + 3):
if i > 2:
menu.delete(i)
for mod in self.database.get_all_types("mod"):
if mod != "all":
int_var = IntVar(value=1)
menu.add_checkbutton(
label=mod, variable=int_var, command=self.__selectmodsfunction___
)
self.moddict[mod] = int_var
self.selected_mods.append(mod)
def updateAllHive(self, menu):
for i in range(self.hivecount + 3):
if i > 2:
menu.delete(i)
for hive in self.database.get_all_types("hive"):
if hive != "all":
int_var = IntVar(value=1)
menu.add_checkbutton(
label=hive, variable=int_var, command=self.__selecthivefunction___
)
self.hivedict[hive] = int_var
self.selected_hive.append(hive)
def __create_menu_bar(self):
# file menus builder
file_menu = Menu(self.menu_bar, tearoff=0)
file_menu.add_command(label="Setup Database", command=self.__open_db_window)
file_menu.add_command(
label="Import attachfile", command=self.__import_link_window
)
file_menu.add_separator()
file_menu.add_command(label="Add Items", command=self.__open_items_window)
file_menu.add_separator()
file_menu.add_command(
label="Export Selected Mod_XML", command=self.export_mod_xml
)
file_menu.add_command(label="Export XML File", command=self.export_xml_normal)
file_menu.add_command(
label="Export Namalsk XML File", command=self.export_xml_Namalsk
)
file_menu.add_separator()
file_menu.add_command(
label="Export Spawnable Types", command=self.writespawnabletypes
)
file_menu.add_separator()
file_menu.add_command(label="Exit", command=self.window.destroy)
# database menus builder
# help menus builder
help_menu = Menu(self.menu_bar, tearoff=0)
help_menu.add_command(label="Watch the video....", command=self.demovideo)
# tools menus builder
tools_menu = Menu(self.menu_bar, tearoff=0)
tools_menu.add_command(
label="Derive types and subtypes", command=self.derivetypessubtypes
)
tools_menu.add_command(
label="Assign Rarity from nominal", command=self.func2assign_raritiy
)
tools_menu.add_separator()
tools_menu.add_command(label="Dump database to sql file", command=self.dump2sql)
tools_menu.add_separator()
tools_menu.add_command(label="Derive ammobox table", command=self.deriveammobox)
tools_menu.add_command(
label="Distribute gun,mag and bullet", command=self.testdist
)
tools_menu.add_command(
label="TestFunction for (Dev)", command=self.testfunction
)
# tools_menu.add_command(label="APIPull (Dev)", command=self.apipull)
# tools_menu.add_command(label="APIPush (Dev)", command=self.apipush)
# initializing mods menu
self.mods_menu = Menu(self.menu_bar, tearoff=0)
self.mods_menu.add_command(label="Deselect All", command=self.deselectAllMods)
self.mods_menu.add_command(label="Select All", command=self.selectAllMods)
self.mods_menu.add_separator()
self.initAllMods(self.mods_menu)
# initializing hive menu
self.hive_menu = Menu(self.menu_bar, tearoff=0)
self.hive_menu.add_command(label="Deselect All", command=self.deselectAllHive)
self.hive_menu.add_command(label="Select All", command=self.selectAllHive)
self.hive_menu.add_separator()
self.initAllHive(self.hive_menu)
# building menu bar
self.menu_bar.add_cascade(label="File", menu=file_menu)
self.menu_bar.add_cascade(label="Mods In Use", menu=self.mods_menu)
self.menu_bar.add_cascade(label="Hive In Use", menu=self.hive_menu)
self.menu_bar.add_cascade(label="Help", menu=help_menu)
self.menu_bar.add_cascade(label="Tools", menu=tools_menu)
# configuring menu bar
self.window.config(menu=self.menu_bar)
def export_mod_xml(self):
self.__export_mod_xml()
def export_xml_normal(self):
self.__export_xml("Normal")
def export_xml_Namalsk(self):
self.__export_xml("Namalsk")
# Create Left side entry frame *************************************************
def __create_entry_frame(self):
self.entryFrameHolder = Frame(self.window)
self.entryFrameHolder.grid(row=0, column=0, sticky="nw")
self.entryFrame = Frame(self.entryFrameHolder)
self.entryFrame.grid(padx=8, pady=6)
# labels
Label(self.entryFrame, text="Name").grid(row=0, column=0, sticky="w", pady=5)
Label(self.entryFrame, text="Nominal").grid(row=1, column=0, sticky="w", pady=5)
Label(self.entryFrame, text="Min").grid(row=2, column=0, sticky="w", pady=5)
Label(self.entryFrame, text="QMin").grid(row=3, column=0, sticky="w", pady=5)
Label(self.entryFrame, text="QMax").grid(row=4, column=0, sticky="w", pady=5)
Label(self.entryFrame, text="Restock").grid(row=5, column=0, sticky="w", pady=5)
Label(self.entryFrame, text="Lifetime").grid(
row=6, column=0, sticky="w", pady=5
)
Label(self.entryFrame, text="Usages").grid(row=7, column=0, sticky="w", pady=5)
Label(self.entryFrame, text="Tiers").grid(row=8, column=0, sticky="w", pady=5)
Label(self.entryFrame, text="Category").grid(
row=9, column=0, sticky="w", pady=5
)
Label(self.entryFrame, text="Type").grid(row=10, column=0, sticky="w", pady=5)
Label(self.entryFrame, text="Sub Type").grid(
row=11, column=0, sticky="w", pady=5
)
Label(self.entryFrame, text="Rarity").grid(row=12, column=0, sticky="w", pady=5)
Label(self.entryFrame, text="Mod").grid(row=13, column=0, sticky="w", pady=5)
Label(self.entryFrame, text="Trader").grid(row=14, column=0, sticky="w", pady=5)
Label(self.entryFrame, text="Hive").grid(row=15, column=0, sticky="w", pady=5)
# input variables
self.id = IntVar()
self.name = StringVar()
self.nominal = IntVar()
self.min = IntVar()
self.qmin = IntVar()
self.qmax = IntVar()
self.restock = IntVar()
self.lifetime = IntVar()
self.usages = StringVar()
self.tiers = StringVar()
self.cat_type = StringVar()
self.item_type = StringVar()
self.sub_type = StringVar()
self.rarity = StringVar()
self.mod = StringVar()
self.trader = StringVar()
self.dynamic_event = IntVar()
self.count_in_cargo = IntVar()
self.count_in_hoarder = IntVar()
self.count_in_player = IntVar()
self.count_in_map = IntVar()
self.hive = StringVar()
# form fields
self.nameField = Entry(self.entryFrame, textvariable=self.name)
self.nameField.grid(row=0, column=1, sticky="w")
self.nominalField = Entry(self.entryFrame, textvariable=self.nominal)
self.nominalField.grid(row=1, column=1, sticky="w")
self.minField = Entry(self.entryFrame, textvariable=self.min)
self.minField.grid(row=2, column=1, sticky="w")
self.qminField = Entry(self.entryFrame, textvariable=self.qmin)
self.qminField.grid(row=3, column=1, sticky="w")
self.qmaxField = Entry(self.entryFrame, textvariable=self.qmax)
self.qmaxField.grid(row=4, column=1, sticky="w")
self.restockField = Entry(self.entryFrame, textvariable=self.restock)
self.restockField.grid(row=5, column=1, sticky="w")
self.lifetimeField = Entry(self.entryFrame, textvariable=self.lifetime)
self.lifetimeField.grid(row=6, column=1, sticky="w")
self.usagesListBox = Listbox(
self.entryFrame,
height=4,
selectmode="multiple",
exportselection=False,
)
self.usagesListBox.grid(row=7, column=1, pady=5, sticky="w")
usages = self.config.get_usages()
for i in usages:
self.usagesListBox.insert(END, i)
self.tiersListBox = Listbox(
self.entryFrame,
height=4,
selectmode="multiple",
exportselection=False,
)
self.tiersListBox.grid(row=8, column=1, pady=5, sticky="w")
tiers = self.config.get_tiers()
for i in tiers:
self.tiersListBox.insert(END, i)
self.cat_typeOption = OptionMenu(
self.entryFrame,
self.cat_type,
*self.database.get_all_types("cat_type")[:-1],
)
self.cat_typeOption.grid(row=9, column=1, sticky="w", pady=5)
self.itemtypeAutoComp = ttk.Combobox(
self.entryFrame,
textvariable=self.item_type,
values=self.database.get_all_types("item_type")[:-1],
)
self.itemtypeAutoComp.grid(row=10, column=1, sticky="w", pady=5)
self.subtypeAutoComp = ttk.Combobox(
self.entryFrame,
textvariable=self.sub_type,
values=self.database.get_all_types("sub_type")[:-1],
)
self.subtypeAutoComp.grid(row=11, column=1, sticky="w", pady=5)
self.rarityOption = OptionMenu(
self.entryFrame, self.rarity, *self.config.get_rarities()
)
self.rarityOption.grid(row=12, column=1, sticky="w", pady=5)
self.mod_select_list = list(
set(self.import_mods + self.database.get_all_types("mod")[:-1])
)
self.modOption = OptionMenu(self.entryFrame, self.mod, *self.mod_select_list)
self.modOption.grid(row=13, column=1, sticky="w", pady=5)
self.traderOption = OptionMenu(
self.entryFrame, self.trader, *self.config.get_traders()
)
self.traderOption.grid(row=14, column=1, sticky="w", pady=5)
self.hiveOption = OptionMenu(
self.entryFrame, self.hive, *self.config.get_hive()
)
self.hiveOption.grid(row=15, column=1, sticky="w", pady=5)
self.checkBoxFrame = Frame(self.entryFrameHolder)
self.checkBoxFrame.grid(row=1, column=0, columnspan=2, sticky="w")
self.dynamic_event_check = Checkbutton(
self.checkBoxFrame,
text="Dynamic Event",
variable=self.dynamic_event,
onvalue=1,
offvalue=0,
)
self.dynamic_event_check.grid(row=0, column=0, sticky="w")
self.count_in_hoarder_check = Checkbutton(
self.checkBoxFrame,
text="Count in Hoarder",
variable=self.count_in_hoarder,
onvalue=1,
offvalue=0,
)
self.count_in_hoarder_check.grid(row=1, column=0, sticky="w")
self.count_in_cargo_check = Checkbutton(
self.checkBoxFrame,
text="Count in Cargo",
variable=self.count_in_cargo,
onvalue=1,
offvalue=0,
)
self.count_in_cargo_check.grid(row=2, column=0, sticky="w")
self.count_in_player_check = Checkbutton(
self.checkBoxFrame,
text="Count in Player",
variable=self.count_in_player,
onvalue=1,
offvalue=0,
)
self.count_in_player_check.grid(row=3, column=0, sticky="w")
self.count_in_map_check = Checkbutton(
self.checkBoxFrame,
text="Count in Map",
variable=self.count_in_map,
onvalue=1,
offvalue=0,
)
self.count_in_map_check.grid(row=4, column=0, sticky="w")
Button(
self.checkBoxFrame, text="Update", width=8, command=self.__update_item
).grid(row=5, column=0, pady=5, sticky="w")
Button(
self.checkBoxFrame, text="Delete", width=8, command=self.__delete_item
).grid(row=5, column=1, pady=5, sticky="w")
# **********************Create tree view ************************************************************
#
def fixed_map(self, style, option):
return [
elm
for elm in style.map("Treeview", query_opt=option)
if elm[:2] != ("!disabled", "!selected")
]
def __create_tree_view(self):
style = ttk.Style()
style.configure("Treeview", background="#97FFFF", foreground="black")
self.treeFrame = Frame(self.window)
self.treeFrame.grid(row=0, column=1, sticky="nsew")
self.treeFrame.grid_rowconfigure(0, weight=1)
self.treeFrame.grid_columnconfigure(1, weight=1)
self.tree = ttk.Treeview(
self.treeFrame,
columns=[col.get("text") for col in column_definition],
height=40,
)
style.map(
"Treeview",
foreground=self.fixed_map(style, "foreground"),
background=self.fixed_map(style, "background"),
)
for col in column_definition:
self.tree.heading(
col.get("col_id"),
text=col.get("text"),
command=lambda _col=col.get("text"): self.tree_view_sort_column(
self.tree, _col, False
),
)
self.tree.column(
col.get("col_id"), width=col.get("width"), stretch=col.get("stretch")
)
self.tree.grid(row=0, column=0, sticky="nsew")
self.tree.heading("#0", text="ID")
self.tree.column("#0", width="60", stretch="NO")
self.treeView = self.tree
vertical = ttk.Scrollbar(self.treeFrame, orient=VERTICAL)
horizontal = ttk.Scrollbar(self.treeFrame, orient=HORIZONTAL)
vertical.grid(row=0, column=1, sticky="ns")
horizontal.grid(row=1, column=0, sticky="we")
self.tree.config(yscrollcommand=vertical.set)
self.tree.config(xscrollcommand=horizontal.set)
vertical.config(command=self.tree.yview)
horizontal.config(command=self.tree.xview)
def __create_side_bar(self):
self.filterFrameHolder = Frame(self.window)
self.filterFrameHolder.grid(row=0, column=2, sticky="n")
self.filterFrame = LabelFrame(self.filterFrameHolder, width=14, text="Filter")
self.filterFrame.grid(row=1, column=1, pady=5)
Label(self.filterFrame, text="Category").grid(row=1, column=0, sticky="w")
Label(self.filterFrame, text="Item type").grid(row=2, column=0, sticky="w")
Label(self.filterFrame, text="Sub type").grid(row=3, column=0, sticky="w")
self.__create_distribution_block()
cat_filter = self.database.get_all_types("cat_type")
type_filter = self.database.get_all_types("item_type")
subtype_filter = self.database.get_all_types("sub_type")
def update_options_type(*args):
if self.cat_type_for_filter.get() == "all":
type_filter = self.database.get_all_types("item_type")
else:
type_filter = self.database.get_filter_types(
self.cat_type_for_filter.get()
)
self.type_for_filter.set("all")
menu = self.type_option_m["menu"]
menu.delete(0, "end")
for types in type_filter:
menu.add_command(
label=types,
command=lambda nation=types: self.type_for_filter.set(nation),
)
def update_options_subtype(*args):
if self.type_for_filter.get() == "all":
sub_type_for_filter = self.database.get_all_types("sub_type")
else:
sub_type_for_filter = self.database.get_filter_subtypes(
self.type_for_filter.get()
)
self.sub_type_for_filter.set("all")
menu = self.suptype_option_m["menu"]
menu.delete(0, "end")
for elem in sub_type_for_filter:
menu.add_command(
label=elem,
command=lambda nation=elem: self.sub_type_for_filter.set(nation),
)
# Category
self.cat_type_for_filter = StringVar()
self.cat_type_for_filter.set("all")
self.cat_option_m = OptionMenu(
self.filterFrame,
self.cat_type_for_filter,
*cat_filter,
command=self.__CatFilter__,
).grid(row=1, column=1, sticky="w", padx=5)
self.cat_type_for_filter.trace("w", update_options_type)
# Item_type
self.type_for_filter = StringVar()
self.type_for_filter.set("all")
self.type_option_m = OptionMenu(
self.filterFrame,
self.type_for_filter,
*type_filter,
command=self.__TypeFilter__,
)
self.type_option_m.grid(row=2, column=1, sticky="w", padx=5)
self.type_for_filter.trace("w", update_options_subtype)
# Sub_type
self.sub_type_for_filter = StringVar()
self.sub_type_for_filter.set("all")
self.suptype_option_m = OptionMenu(
self.filterFrame,
self.sub_type_for_filter,
*subtype_filter,
command=self.__SubTypeFilter__,
)
self.suptype_option_m.grid(row=3, column=1, sticky="w", padx=5)
# Usage_Flag
self.usage_for_filter = StringVar(value=self.database.get_all_usage("usage"))
self.LB_usage_filter = Listbox(
self.filterFrame,
height=4,
listvariable=self.usage_for_filter,
selectmode="extended",
exportselection=False,
)
self.LB_usage_filter.grid(row=4, columnspan=2, sticky="w", padx=5)
# Tiers_Filter
self.tier_for_filter = StringVar(value=self.database.get_all_tier("tier"))
self.LB_tier_filter = Listbox(
self.filterFrame,
height=4,
listvariable=self.tier_for_filter,
selectmode="extended",
exportselection=False,
)
self.LB_tier_filter.grid(row=5, columnspan=2, sticky="w", padx=5)
Button(
self.filterFrame, text="Filter", width=12, command=self.__filter_items
).grid(row=6, columnspan=2, pady=5, padx=10, sticky="nesw")
# Search like name
Entry(self.filterFrame, textvariable=self.searchName, width=14).grid(
row=7, columnspan=2, pady=5, padx=10, sticky="nesw"
)
Button(
self.filterFrame,
text="Search like Name",
width=14,
command=self.__search_like_name,
).grid(row=8, columnspan=2, pady=5, padx=10, sticky="nesw")
#
# This is were we have the test button
#
Button(
self.filterFrame,
text="Trader Editor",
width=14,
command=self.openTraderEditor,
).grid(row=9, columnspan=2, pady=5, padx=10, sticky="nesw")
Entry(self.filterFrame, textvariable=self.worldName, width=14).grid(
row=10, columnspan=2, pady=5, padx=10, sticky="nesw"
)
Button(
self.filterFrame,
text="Expansion Trader",
width=14,
command=self.expansionTrader,
).grid(row=11, columnspan=2, pady=5, padx=10, sticky="nesw")
Button(
self.filterFrame,
text="Donate !",
width=14,
command=self.donate,
).grid(row=12, columnspan=2, pady=5, padx=10, sticky="nesw")
# Normal Distribution block
def __create_distribution_block(self):
self.distribution = LabelFrame(
self.filterFrameHolder, width=14, text="Nominal Distribution"
)
self.distribution.grid(row=2, column=1, pady=5)
Label(self.distribution, text="By Displayed Items").grid(row=0, columnspan=2)
Label(self.distribution, text="Target Nominal").grid(row=1, columnspan=2)
self.desiredNomEntry = Entry(
self.distribution, textvariable=self.totalNumDisplayed, width=14
).grid(row=2, columnspan=2, pady=7)
self.distributorValue.set("Use Rarity")
Radiobutton(
self.distribution,
text="Use Rarity",
variable=self.distributorValue,
value="Use Rarity",
).grid(row=3, column=0, sticky="w")
Radiobutton(
self.distribution,
text="Use Nominal",
variable=self.distributorValue,
value="Use Nominal",
).grid(row=4, column=0, sticky="w")
Button(
self.distribution,
text="Distribute",
width=12,
command=self.__distribute_nominal,
).grid(row=5, columnspan=2, pady=10)
def readexpansionworld(self, newworld):
try:
# with open("./Expansion/TraderZones/World.json") as f:
with open(f"./Expansion/TraderZones/{newworld}.json") as f:
world = json.load(f)
return world
except Exception:
world = dict()
world["m_Version"] = 4
world["m_FileName"] = newworld
world["m_ZoneName"] = newworld
world["DisplayName"] = newworld + " Trading Zone"
world["Position"] = [7500.0, 0.0, 7500.0]
world["Radius"] = 50000.0
world["Stock"] = dict()
writeToJSONFile("./Expansion/TraderZones", newworld, world)
return world
def expansionTrader(self):
newworld = str(self.worldName.get()).lower()
world = self.readexpansionworld(newworld)
TRADER_NAME = simpledialog.askstring(
title="Trader Name", prompt="What's the name of the Trader?: "
)
trader = dict()
trader["m_Version"] = 4
trader["m_FileName"] = TRADER_NAME.upper()
trader["TraderName"] = TRADER_NAME.upper()
trader["DisplayName"] = "#STR_EXPANSION_MARKET_" + TRADER_NAME.upper()
trader["Currencies"] = [
"expansiongoldbar",
"expansiongoldnugget",
"expansionsilverbar",
"expansionsilvernugget",
]
# trader['Items'] = []
trader["Items"] = dict()
to_append = dict()
to_append["Stock"] = dict()
for items in self.treeView.selection():
item = self.treeView.item(items)
item_name = item["values"][0]
trader["Items"].update({item_name: 1})
to_append["Stock"].update({item_name: 250})
writeToJSONFile("./Expansion/Traders", TRADER_NAME.upper(), trader)
world["Stock"].update(to_append["Stock"])
writeToJSONFile("./Expansion/TraderZones", newworld, world)
def donate(self):
new = 2
url = "https://www.paypal.com/paypalme/Luskerne"
webbrowser.open(url, new=new)
def demovideo(self):
new = 2
url = "https://youtu.be/3Jxva7KCNSk"
webbrowser.open(url, new=new)
def dump2sql(self):
self.database.sql_dbDump()
def testfunction(self):
print("DEBUG : test function")
print(type(self.type_option_m))
def apipull(self):
apipull(self.database.session)
def apipush(self):
apipush(self.database.session)
def testdist(self):
self.deriveammobox
distribute_mags_and_bullets(self.database.session, self.gridItems)
def writespawnabletypes(self):
exportSpawnable(self.database.session, self.gridItems)
def func2assign_raritiy(self):
items = self.database.session.query(Item).filter(Item.nominal > 0).all()
assign_rarity(items, self.database.session)
print("First part done")
items = self.database.session.query(Item).filter(Item.nominal == 0).all()
assign_NotInCE(items, self.database.session)
def derivetypessubtypes(self):
if self.database.get_mapselectValue(1).mapselectvalue == "Namalsk":
for Item in self.gridItems:
try:
for item_type, subtypes in categoriesNamalskDict.get(
Item.cat_type
).items():
for subtype, substrings in subtypes.items():
for item_substring in substrings:
if (
item_substring in Item.name.lower()
and item_substring != ""
):
Item.item_type = item_type
Item.sub_type = subtype
if Item.cat_type in {"rifles", "pistols"}:
Item.cat_type = "weapons"
except Exception:
print("DEBUG item category not found :", Item.cat_type, Item.name)
else:
for Item in self.gridItems:
try:
for item_type, subtypes in categoriesDict.get(
Item.cat_type
).items():
for subtype, substrings in subtypes.items():
for item_substring in substrings:
if (
item_substring in Item.name.lower()
and item_substring != ""
):
Item.item_type = item_type
Item.sub_type = subtype
except Exception:
print("DEBUG item category not found :", Item.cat_type, Item.name)
self.database.session.commit()
def __CatFilter__(self, selection):
if selection != "all":
self.type_for_filter.set("all")
self.sub_type_for_filter.set("all")
def __TypeFilter__(self, selection):
if selection != "all":
self.cat_type_for_filter.set("all")
self.sub_type_for_filter.set("all")
def __SubTypeFilter__(self, selection):
print("Debug: subtypefilter: " + selection)
if selection != "all":
self.cat_type_for_filter.set("all")
self.type_for_filter.set("all")
def __selectmodsfunction___(self):
values = [(mod, var.get()) for mod, var in self.moddict.items()]
self.moddlist = values
self.selected_mods = [x[0] for x in self.moddlist if x[1] == 1]
items = self.database.session.query(Item).filter(
Item.mod.in_(self.selected_mods)
)
self.gridItems = items
self.__populate_items(self.gridItems)
self.__create_nominal_info()
self.type_for_filter.set("all")
self.sub_type_for_filter.set("all")
self.cat_type_for_filter.set("all")
def __selecthivefunction___(self):
values = [(hive, var.get()) for hive, var in self.hivedict.items()]
self.hivelist = values
self.selected_hive = [x[0] for x in self.hivelist if x[1] == 1]
items = self.database.session.query(Item).filter(
Item.hive.in_(self.selected_hive)
)
self.gridItems = items
self.__populate_items(self.gridItems)
self.__create_nominal_info()
self.type_for_filter.set("all")
self.sub_type_for_filter.set("all")
self.cat_type_for_filter.set("all")
# Updated to loop through selected items in the grid.
def __update_item(self):
# get filter values from UI
def __update_helper(item, field, default_value):
value_from_update_form = getattr(self, field).get()
if value_from_update_form != default_value:
# print("__update_item :", value_from_update_form, default_value)
setattr(item, field, value_from_update_form)
for items in self.treeView.selection():
item = self.treeView.item(items)
id_of_interest = item["text"]
item_to_update = self.database.session.query(Item).get(id_of_interest)
__update_helper(item_to_update, "nominal", -1)
__update_helper(item_to_update, "min", -1)
__update_helper(item_to_update, "qmin", -1)
__update_helper(item_to_update, "qmax", -1)
__update_helper(item_to_update, "restock", -1)
__update_helper(item_to_update, "lifetime", -1)
__update_helper(item_to_update, "rarity", "")
__update_helper(item_to_update, "cat_type", "")
__update_helper(item_to_update, "item_type", "")
__update_helper(item_to_update, "sub_type", "")
__update_helper(item_to_update, "mod", "")
__update_helper(item_to_update, "trader", "")
__update_helper(item_to_update, "hive", "")
__update_helper(item_to_update, "dynamic_event", -1)
__update_helper(item_to_update, "count_in_hoarder", -1)
__update_helper(item_to_update, "count_in_cargo", -1)
__update_helper(item_to_update, "count_in_player", -1)
__update_helper(item_to_update, "count_in_map", -1)
usages = self.usagesListBox.curselection()
usage_values = [self.usagesListBox.get(i) for i in usages]
usages = ",".join(usage_values)
if usages != "" and usages != "None":
setattr(item_to_update, "usage", usages)
elif usages == "None":
setattr(item_to_update, "usage", "")
tiers = self.tiersListBox.curselection()
tier_values = [self.tiersListBox.get(i) for i in tiers]
tiers = ",".join(tier_values)
print(tiers)
if tiers != "" and tiers != "None":
setattr(item_to_update, "tier", tiers)
elif tiers == "None":
setattr(item_to_update, "tier", "")
self.database.session.commit()
self.__populate_items(self.gridItems)
self.__filter_items()
self.__create_entry_frame()
self.__reset_entry_frame()
# self.__init__(window)
def __delete_item(self):
for items in self.treeView.selection():
item = self.treeView.item(items)
itemid = item["text"]
self.database.delete_item(itemid)
self.__populate_items(self.gridItems)
def __initiate_items(self, items=None):
items = self.database.session.query(Item).filter(
Item.mod.in_(self.selected_mods)
)
self.gridItems = items
self.__populate_items(items.all())
def __populate_items(self, items):
if self.tree.get_children() != ():
self.tree.delete(*self.tree.get_children())
for idx, i in enumerate(items):
if idx % 2 == 0:
self.tree.insert(
"",
"end",
text=i.id,
value=[
i.name,
i.nominal,
i.min,
i.qmin,
i.qmax,
i.restock,
i.lifetime,
i.usage,
i.tier,
i.rarity,
i.cat_type,
i.item_type,
i.sub_type,
i.mod,
i.trader,
i.dynamic_event,
i.count_in_hoarder,
i.count_in_cargo,
i.count_in_player,
i.count_in_map,
],
tags=("evenrow",),
)
else:
self.tree.insert(
"",
"end",
text=i.id,
value=[
i.name,
i.nominal,
i.min,
i.qmin,
i.qmax,
i.restock,
i.lifetime,
i.usage,
i.tier,
i.rarity,
i.cat_type,
i.item_type,
i.sub_type,
i.mod,
i.trader,
i.dynamic_event,
i.count_in_hoarder,
i.count_in_cargo,
i.count_in_player,
i.count_in_map,
],
tags=("oddrow",),
)
self.tree.tag_configure("oddrow", background="#FFFFFF")
self.tree.tag_configure("evenrow", background="#F5F5F5")
def __search_like_name(self):
searchname = str(self.searchName.get()).lower()
if searchname != "":
print(searchname)
items = self.database.search_like_name(searchname)
self.__populate_items(items)
self.gridItems = items
def __filter_usage_items(self):