-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
2352 lines (2181 loc) · 106 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
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
#encoding:utf-8
import os
import sys
import webbrowser
import zipfile
from copy import deepcopy
from functools import partial
from json import dumps, loads
from re import sub
from sqlite3 import connect
from threading import Thread
from tempfile import mkdtemp
from shutil import rmtree
from PyQt5.QtCore import QRect, QRegExp, Qt, pyqtSignal
from PyQt5.QtGui import QColor, QRegExpValidator, QFont
from PyQt5.QtWidgets import (QAction, QApplication, QComboBox, QFileDialog,
QLabel, QLineEdit, QListWidget, QMainWindow,
QMenuBar, QMessageBox, QPushButton, QTextBrowser,
QWidget, QAbstractItemView)
import about
import calculator
import pic_window
idx_represent_str = ["己方手卡", "己方魔陷_1", "己方魔陷_2", "己方魔陷_3", "己方魔陷_4", "己方魔陷_5", "己方场地", "己方灵摆_1", "己方灵摆_2", "己方怪兽_1", "己方怪兽_2", "己方怪兽_3", "己方怪兽_4", "己方怪兽_5", "己方墓地", "己方除外", "己方额外", "对方手卡", "对方魔陷_1", "对方魔陷_2", "对方魔陷_3", "对方魔陷_4", "对方魔陷_5", "对方场地", "对方灵摆_1", "对方灵摆_2", "对方怪兽_1", "对方怪兽_2", "对方怪兽_3", "对方怪兽_4", "对方怪兽_5", "对方墓地", "对方除外", "对方额外", "额外怪兽区_1", "额外怪兽区_2"]
idx_represent_controller = {"己方": 1, "对方": -1, "额外怪兽区": 0}
cardcolors_dict = {0x2: QColor(10,128,0), 0x4: QColor(235,30,128), 0x10: QColor(168,168,0), 0x40: QColor(108,34,108), 0x80: QColor(16,128,235), 0x2000: QColor(168,168,168), 0x800000: QColor(0,0,0), 0x4000: QColor(98,98,98), 0x4000000: QColor(3,62,116), 0xffffffff: QColor(178,68,0)}
init_field = {"locations":{}, "desp":{}, "LP":[8000,8000], "fields":[]}
for t in range(len(idx_represent_str)):
init_field["fields"].append([])
version_idx = 220
version_name = "v1.22.0"
default_mirror = "Github"
mirror_setting = {
"Github":{
"version": "https://github.com/Wind2009-Louse/DuelEditor/raw/master/version.json",
"release": "https://github.com/Wind2009-Louse/DuelEditor/releases/download/"
},
"wuyanzheshui":{
"version": "https://github.wuyanzheshui.workers.dev/Wind2009-Louse/DuelEditor/raw/master/version.json",
"release": "https://github.wuyanzheshui.workers.dev/Wind2009-Louse/DuelEditor/releases/download/"
},
"cnpmjs": {
"version": "https://github.com.cnpmjs.org/Wind2009-Louse/DuelEditor/raw/master/version.json",
"release": "https://github.com.cnpmjs.org/Wind2009-Louse/DuelEditor/releases/download/"
},
"fastGit": {
"version": "https://hub.fastgit.org/Wind2009-Louse/DuelEditor/raw/master/version.json",
"release": "https://hub.fastgit.org/Wind2009-Louse/DuelEditor/releases/download/"
},
"ghproxy": {
"version": "https://cdn.jsdelivr.net/gh/Wind2009-Louse/DuelEditor@master/version.json",
"release": "https://mirror.ghproxy.com/https://github.com/Wind2009-Louse/DuelEditor/releases/download/"
}
}
class Update_Thread(Thread):
def __init__(self, window, url):
self.window = window
self.url = url
super().__init__()
def run(self):
try:
json_result = loads(about.requests.get(self.url, timeout=5).content.decode("utf-8", errors="ignore"))
if json_result["version"] > version_idx:
self.window.update_signal.emit(json_result["name"])
except Exception as e:
print(e)
class Download_Thread(Thread):
def __init__(self, window, release_url, version_name=None):
self.window = window
self.url = release_url
self.version_name = version_name
super().__init__()
def run(self):
if self.version_name == None:
return
url = ""
filename = ""
if os.name == "nt":
url = "%s%s/DuelEditor.exe"%(self.url, self.version_name)
filename = "DuelEditor %s.exe"%self.version_name
elif os.name == "posix":
url = "%s%s/DuelEditor.out"%(self.url, self.version_name)
filename = "DuelEditor %s.out"%self.version_name
else:
self.window.download_signal.emit("下载失败,找不到对应系统的版本!")
return
try:
length = 0
count = 0
with about.requests.get(url, stream=True) as req:
length = float(req.headers['Content-length'])
with open(filename, 'wb') as f:
for chunk in req.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
count += len(chunk)
self.window.process_signal.emit("%.2f%%"%(count * 100 / length))
self.window.process_signal.emit("")
if count < length:
self.window.download_signal.emit("下载失败,请重试!")
os.remove(filename)
else:
self.window.download_signal.emit("下载成功!")
except Exception as e:
print(e)
self.window.process_signal.emit("")
self.window.download_signal.emit("下载失败!")
finally:
self.version_name = None
class Ui_MainWindow(QMainWindow):
update_signal = pyqtSignal(str)
download_signal = pyqtSignal(str)
process_signal = pyqtSignal(str)
clear_img_signal = pyqtSignal(str)
normal_font = QFont()
bold_font = QFont()
bold_font.setBold(True)
italic_font = QFont()
italic_font.setItalic(True)
bold_italic_font = QFont()
bold_italic_font.setBold(True)
bold_italic_font.setItalic(True)
def placeframe(self):
menu_height = self.menuBar().height()
width = self.width()
height = self.height() - menu_height
# print(width, height)
width_1_1 = 191 * width // self.origin_width
height_1_1 = 143 * height // self.origin_height
if height < self.origin_height:
height_1_1 = 143 - (self.origin_height - height) // 2
xline_1_1 = 10
xline_1_2 = 10 + 200 * width // self.origin_width
xline_1_3 = 10 + 400 * width // self.origin_width
xline_1_4 = 10 + 600 * width // self.origin_width
yline_1_1 = menu_height + 8
yline_1_2 = menu_height + (self.origin_height - 10) * height // self.origin_height - height_1_1
if height < self.origin_height:
yline_1_2 = menu_height + (self.origin_height - 153) - (self.origin_height - height) // 2
# enemy/self place
self.label_enemy_ex.setGeometry(
QRect(xline_1_1, yline_1_1, width_1_1, 20))
self.Enemy_Ex.setGeometry(
QRect(xline_1_1, yline_1_1+22, width_1_1, height_1_1 - 22))
self.label_enemy_hand.setGeometry(
QRect(xline_1_2, yline_1_1, width_1_1, 20))
self.Enemy_Hand.setGeometry(
QRect(xline_1_2, yline_1_1+22, width_1_1, height_1_1 - 22))
self.label_enemy_grave.setGeometry(
QRect(xline_1_3, yline_1_1, width_1_1, 20))
self.Enemy_Grave.setGeometry(
QRect(xline_1_3, yline_1_1+22, width_1_1, height_1_1 - 22))
self.label_enemy_banish.setGeometry(
QRect(xline_1_4, yline_1_1, width_1_1, 20))
self.Enemy_Banish.setGeometry(
QRect(xline_1_4, yline_1_1+22, width_1_1, height_1_1 - 22))
self.label_self_ex.setGeometry(
QRect(xline_1_1, yline_1_2, width_1_1, 20))
self.Self_Ex.setGeometry(
QRect(xline_1_1, yline_1_2+22, width_1_1, height_1_1 - 22))
self.label_self_hand.setGeometry(
QRect(xline_1_2, yline_1_2, width_1_1, 20))
self.Self_Hand.setGeometry(
QRect(xline_1_2, yline_1_2+22, width_1_1, height_1_1 - 22))
self.label_self_grave.setGeometry(
QRect(xline_1_3, yline_1_2, width_1_1, 20))
self.Self_Grave.setGeometry(
QRect(xline_1_3, yline_1_2+22, width_1_1, height_1_1 - 22))
self.label_self_banish.setGeometry(
QRect(xline_1_4, yline_1_2, width_1_1, 20))
self.Self_Banish.setGeometry(
QRect(xline_1_4, yline_1_2+22, width_1_1, height_1_1 - 22))
# field
width_2_0 = 110 * width // self.origin_width
width_2_1 = width_2_0 + 1
height_2_0 = (yline_1_2 - yline_1_1 - height_1_1 - 38) // 5
height_2_1 = height_2_0 + 1
xline_2_1 = 10
xline_2_2 = 10 + 120 * width // self.origin_width
xline_2_3 = 10 + 120 * width // self.origin_width + width_2_0
xline_2_4 = 10 + 120 * width // self.origin_width + width_2_0 * 2
xline_2_5 = 10 + 120 * width // self.origin_width + width_2_0 * 3
xline_2_6 = 10 + 120 * width // self.origin_width + width_2_0 * 4
xline_2_7 = 10 + 680 * width // self.origin_width
yline_2_1 = yline_1_1 + height_1_1 + 30
yline_2_2 = yline_2_1 + height_2_0
yline_2_3 = yline_2_1 + height_2_0 * 2 # 280 * height / self.origin_height
yline_2_4 = yline_2_1 + height_2_0 * 3 # 330 * height / self.origin_height
yline_2_5 = yline_2_1 + height_2_0 * 4 # 380 * height / self.origin_height
yline_2_6 = yline_2_1 + height_2_0 + 25 # 255 * height / self.origin_height
yline_2_7 = yline_2_5 - height_2_0 - 25 # 305 * height / self.origin_height
yline_2_8 = yline_2_5 - 45 # 335 * height / self.origin_height
if height < self.origin_height:
diff = (self.origin_height - height) // 2
height_2_1 = 51
yline_2_0 = 180 + menu_height
yline_2_1 = yline_2_0 - diff
yline_2_2 = yline_2_0 + 50 - diff
yline_2_3 = yline_2_0 + 100 - diff
yline_2_4 = yline_2_0 + 150 - diff
yline_2_5 = yline_2_0 + 200 - diff
yline_2_6 = yline_2_0 + 75 - diff
yline_2_7 = yline_2_0 + 125 - diff
yline_2_8 = yline_2_0 + 155 - diff
self.Enemy_S1.setGeometry(QRect(xline_2_6, yline_2_1, width_2_1, height_2_1))
self.Enemy_S2.setGeometry(QRect(xline_2_5, yline_2_1, width_2_1, height_2_1))
self.Enemy_S3.setGeometry(QRect(xline_2_4, yline_2_1, width_2_1, height_2_1))
self.Enemy_S4.setGeometry(QRect(xline_2_3, yline_2_1, width_2_1, height_2_1))
self.Enemy_S5.setGeometry(QRect(xline_2_2, yline_2_1, width_2_1, height_2_1))
self.Enemy_M1.setGeometry(QRect(xline_2_6, yline_2_2, width_2_1, height_2_1))
self.Enemy_M2.setGeometry(QRect(xline_2_5, yline_2_2, width_2_1, height_2_1))
self.Enemy_M3.setGeometry(QRect(xline_2_4, yline_2_2, width_2_1, height_2_1))
self.Enemy_M4.setGeometry(QRect(xline_2_3, yline_2_2, width_2_1, height_2_1))
self.Enemy_M5.setGeometry(QRect(xline_2_2, yline_2_2, width_2_1, height_2_1))
self.label_enemy_field.setGeometry(QRect(xline_2_7, yline_2_6-22, width_2_1, 20))
self.Enemy_Field.setGeometry(QRect(xline_2_7, yline_2_6, width_2_1, height_2_1))
self.label_enemy_lpen.setGeometry(QRect(xline_2_7, yline_2_1-22, width_2_1, 20))
self.Enemy_P1.setGeometry(QRect(xline_2_7, yline_2_1, width_2_1, height_2_1))
self.label_enemy_rpen.setGeometry(QRect(xline_2_1, yline_2_1-22, width_2_1, 20))
self.Enemy_P2.setGeometry(QRect(xline_2_1, yline_2_1, width_2_1, height_2_1))
self.label_enemy_lp.setGeometry(QRect(xline_2_1, yline_2_6-22, width_2_1, 20))
self.Enemy_LP.setGeometry(QRect(xline_2_1, yline_2_6, width_2_1, 21))
# middle
self.ExM_1.setGeometry(QRect(xline_2_3, yline_2_3, width_2_1, height_2_1))
self.ExM_2.setGeometry(QRect(xline_2_5, yline_2_3, width_2_1, height_2_1))
# self place
self.Self_S1.setGeometry(QRect(xline_2_2, yline_2_5, width_2_1, height_2_1))
self.Self_S2.setGeometry(QRect(xline_2_3, yline_2_5, width_2_1, height_2_1))
self.Self_S3.setGeometry(QRect(xline_2_4, yline_2_5, width_2_1, height_2_1))
self.Self_S4.setGeometry(QRect(xline_2_5, yline_2_5, width_2_1, height_2_1))
self.Self_S5.setGeometry(QRect(xline_2_6, yline_2_5, width_2_1, height_2_1))
self.Self_M1.setGeometry(QRect(xline_2_2, yline_2_4, width_2_1, height_2_1))
self.Self_M2.setGeometry(QRect(xline_2_3, yline_2_4, width_2_1, height_2_1))
self.Self_M3.setGeometry(QRect(xline_2_4, yline_2_4, width_2_1, height_2_1))
self.Self_M4.setGeometry(QRect(xline_2_5, yline_2_4, width_2_1, height_2_1))
self.Self_M5.setGeometry(QRect(xline_2_6, yline_2_4, width_2_1, height_2_1))
self.label_self_lpen.setGeometry(QRect(xline_2_1, yline_2_5-22, width_2_1, 20))
self.Self_P1.setGeometry(QRect(xline_2_1, yline_2_5, width_2_1, height_2_1))
self.label_self_rpen.setGeometry(QRect(xline_2_7, yline_2_5-22, width_2_1, 20))
self.Self_P2.setGeometry(QRect(xline_2_7, yline_2_5, width_2_1, height_2_1))
self.label_self_field.setGeometry(QRect(xline_2_1, yline_2_7-22, width_2_1, 20))
self.Self_Field.setGeometry(QRect(xline_2_1, yline_2_7, width_2_1, height_2_1))
self.label_self_lp.setGeometry(QRect(xline_2_7, yline_2_8-22, width_2_1, 20))
self.Self_LP.setGeometry(QRect(xline_2_7, yline_2_8, width_2_1, 21))
# target/desc
magic_3_1 = 85
width_3_1 = 181 * width // self.origin_width
height_3_1 = 200 * (height - magic_3_1) // (self.origin_height - magic_3_1)
height_3_2 = height - 160 - height_3_1
xline_3_1 = 810 * width // self.origin_width
yline_3_1 = menu_height + height_3_1
self.label_target_list.setGeometry(QRect(xline_3_1, menu_height, width_3_1, 20))
self.Target_list.setGeometry(QRect(xline_3_1, menu_height + 20, width_3_1, height_3_1))
self.Delete_target_button.setGeometry(QRect(xline_3_1, yline_3_1+25, width_3_1, 28))
self.Dest_Box.setGeometry(QRect(xline_3_1, yline_3_1+63, width_3_1, 22))
self.Move_card_button.setGeometry(QRect(xline_3_1, yline_3_1+90, width_3_1, 28))
self.Erase_card_button.setGeometry(QRect(xline_3_1, yline_3_1+120, width_3_1, 28))
self.Target_detail_browser.setGeometry(QRect(xline_3_1, yline_3_1+150, width_3_1, height_3_2 - 32))
self.Target_effect_button.setGeometry(QRect(xline_3_1, yline_3_1 + 150 + height_3_2 - 30, (width_3_1 - 4) // 2, 28))
self.Target_img_button.setGeometry(QRect(xline_3_1 + width_3_1 // 2 + 2, yline_3_1 + 150 + height_3_2 - 30, (width_3_1 - 4) // 2, 28))
# search/operation buttoms
width_4_1 = 181 * width // self.origin_width
height_4_1 = height - 410
xline_4_1 = 1000 * width // self.origin_width
self.label_cardsearch.setGeometry(QRect(xline_4_1, menu_height, width_4_1, 20))
self.NewCard_line.setGeometry(QRect(xline_4_1, menu_height + 20, width_4_1-42, 21))
self.NewCard_button.setGeometry(QRect(xline_4_1+width_4_1-40, menu_height + 20, 40, 21))
self.Newcard_List.setGeometry(QRect(xline_4_1, menu_height + 50, width_4_1, height_4_1))
self.Create_card_button.setGeometry(QRect(xline_4_1, menu_height + height_4_1+55, width_4_1, 28))
self.Rename_button.setGeometry(QRect(xline_4_1, menu_height + height_4_1+85, width_4_1, 28))
self.Comment_Line.setGeometry(QRect(xline_4_1, menu_height + height_4_1+123, width_4_1, 21))
self.Comment_card_button.setGeometry(QRect(xline_4_1, menu_height + height_4_1+150, width_4_1, 28))
self.Comment_button.setGeometry(QRect(xline_4_1, menu_height + height_4_1+180, width_4_1, 28))
self.LPTarget_Box.setGeometry(QRect(xline_4_1, menu_height + height_4_1+220, width_4_1, 22))
self.LP_line.setGeometry(QRect(xline_4_1, menu_height + height_4_1+250, width_4_1, 21))
self.AddLP_button.setGeometry(QRect(xline_4_1, menu_height + height_4_1+280, width_4_1, 28))
self.DecLP_button.setGeometry(QRect(xline_4_1, menu_height + height_4_1+310, width_4_1, 28))
self.CgeLP_button.setGeometry(QRect(xline_4_1, menu_height + height_4_1+340, width_4_1, 28))
self.HalLP_button.setGeometry(QRect(xline_4_1, menu_height + height_4_1+370, width_4_1, 28))
# operation list
width_5_1 = 181 * width // self.origin_width
height_5_1 = 350 * height // self.origin_height
height_5_2 = height - height_5_1 - 175
xline_5_1 = 1190 * width // self.origin_width
self.label_operation_list.setGeometry(QRect(xline_5_1, menu_height, width_5_1, 16))
self.Operator_search.setGeometry(QRect(xline_5_1, menu_height + 20, width_5_1 - 23, 21))
self.Operator_search_button.setGeometry(QRect(xline_5_1 + width_5_1 - 21, menu_height + 20, 21, 21))
self.Operator_list.setGeometry(QRect(xline_5_1, menu_height + 50, width_5_1, height_5_1 - 20))
self.Delete_ope_button.setGeometry(QRect(xline_5_1, menu_height + height_5_1+35, width_5_1, 28))
self.CopyingOpe_list.setGeometry(QRect(xline_5_1, menu_height + height_5_1+70, width_5_1, height_5_2))
self.Copy_ope_button.setGeometry(QRect(xline_5_1, menu_height + height_5_1+height_5_2+75, width_5_1, 28))
self.Paste_ope_button.setGeometry(QRect(xline_5_1, menu_height + height_5_1+height_5_2+105, width_5_1, 28))
self.Delete_copy_button.setGeometry(QRect(xline_5_1, menu_height + height_5_1+height_5_2+135, width_5_1, 28))
def init_frame(self):
'''初始化UI'''
self.origin_width = 1380
self.origin_height = 590
self.mini_width = 960
self.mini_height = 540
self.setMinimumSize(self.mini_width, self.mini_height + self.menuBar().height())
self.centralwidget = QWidget(self)
# for small screen
self.desktop = QApplication.desktop()
self.screen = self.desktop.screenGeometry()
if self.screen.width() < 1380:
self.resize(self.mini_width, self.mini_height + self.menuBar().height())
else:
self.resize(self.origin_width, self.origin_height + self.menuBar().height())
'''初始化label'''
self.label_target_list = QLabel(self.centralwidget)
self.label_target_list.setAlignment(Qt.AlignCenter)
self.label_cardsearch = QLabel(self.centralwidget)
self.label_cardsearch.setAlignment(Qt.AlignCenter)
self.label_operation_list = QLabel(self.centralwidget)
self.label_operation_list.setAlignment(Qt.AlignCenter)
self.label_self_ex = QLabel(self.centralwidget)
self.label_self_ex.setAlignment(Qt.AlignCenter)
self.label_self_hand = QLabel(self.centralwidget)
self.label_self_hand.setAlignment(Qt.AlignCenter)
self.label_self_grave = QLabel(self.centralwidget)
self.label_self_grave.setAlignment(Qt.AlignCenter)
self.label_self_banish = QLabel(self.centralwidget)
self.label_self_banish.setAlignment(Qt.AlignCenter)
self.label_self_lpen = QLabel(self.centralwidget)
self.label_self_lpen.setAlignment(Qt.AlignCenter)
self.label_self_rpen = QLabel(self.centralwidget)
self.label_self_rpen.setAlignment(Qt.AlignCenter)
self.label_self_field = QLabel(self.centralwidget)
self.label_self_field.setAlignment(Qt.AlignCenter)
self.label_self_lp = QLabel(self.centralwidget)
self.label_self_lp.setAlignment(Qt.AlignCenter)
self.label_enemy_ex = QLabel(self.centralwidget)
self.label_enemy_ex.setAlignment(Qt.AlignCenter)
self.label_enemy_hand = QLabel(self.centralwidget)
self.label_enemy_hand.setAlignment(Qt.AlignCenter)
self.label_enemy_grave = QLabel(self.centralwidget)
self.label_enemy_grave.setAlignment(Qt.AlignCenter)
self.label_enemy_banish = QLabel(self.centralwidget)
self.label_enemy_banish.setAlignment(Qt.AlignCenter)
self.label_enemy_lpen = QLabel(self.centralwidget)
self.label_enemy_lpen.setAlignment(Qt.AlignCenter)
self.label_enemy_rpen = QLabel(self.centralwidget)
self.label_enemy_rpen.setAlignment(Qt.AlignCenter)
self.label_enemy_field = QLabel(self.centralwidget)
self.label_enemy_field.setAlignment(Qt.AlignCenter)
self.label_enemy_lp = QLabel(self.centralwidget)
self.label_enemy_lp.setAlignment(Qt.AlignCenter)
self.Target_list = QListWidget(self.centralwidget)
self.Delete_target_button = QPushButton(self.centralwidget)
self.Dest_Box = QComboBox(self.centralwidget)
for i in range(36):
self.Dest_Box.addItem("")
self.Move_card_button = QPushButton(self.centralwidget)
self.Erase_card_button = QPushButton(self.centralwidget)
self.Target_detail_browser = QTextBrowser(self.centralwidget)
self.Target_detail_browser.setOpenExternalLinks(True)
self.Target_detail_browser.setTextInteractionFlags(Qt.TextBrowserInteraction)
self.Target_effect_button = QPushButton(self.centralwidget)
self.Target_img_button = QPushButton(self.centralwidget)
self.Target_img_button.setFocusPolicy(Qt.NoFocus)
self.NewCard_line = QLineEdit(self.centralwidget)
self.NewCard_line.setPlaceholderText("输入卡片名称")
self.NewCard_button = QPushButton(self.centralwidget)
self.Newcard_List = QListWidget(self.centralwidget)
self.Create_card_button = QPushButton(self.centralwidget)
self.Rename_button = QPushButton(self.centralwidget)
self.Rename_button.setEnabled(False)
self.Rename_button.setFocusPolicy(Qt.NoFocus)
self.Comment_Line = QLineEdit(self.centralwidget)
self.Comment_Line.setPlaceholderText("输入注释")
self.Comment_card_button = QPushButton(self.centralwidget)
self.Comment_button = QPushButton(self.centralwidget)
self.LPTarget_Box = QComboBox(self.centralwidget)
self.LPTarget_Box.addItem("")
self.LPTarget_Box.addItem("")
self.LP_line = QLineEdit(self.centralwidget)
regx = QRegExp("^[0-9]{15}$")
validator = QRegExpValidator(regx, self.LP_line)
self.LP_line.setValidator(validator)
self.LP_line.setPlaceholderText("输入基本分变动")
self.AddLP_button = QPushButton(self.centralwidget)
self.DecLP_button = QPushButton(self.centralwidget)
self.CgeLP_button = QPushButton(self.centralwidget)
self.HalLP_button = QPushButton(self.centralwidget)
self.Operator_list = QListWidget(self.centralwidget)
self.Operator_list.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.Operator_search = QLineEdit(self.centralwidget)
self.Operator_search.setPlaceholderText("输入操作内容搜索")
self.Operator_search_button = QPushButton(self.centralwidget)
self.Delete_ope_button = QPushButton(self.centralwidget)
self.CopyingOpe_list = QListWidget(self.centralwidget)
self.CopyingOpe_list.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.Copy_ope_button = QPushButton(self.centralwidget)
self.Paste_ope_button = QPushButton(self.centralwidget)
self.Delete_copy_button = QPushButton(self.centralwidget)
self.Self_Ex = QListWidget(self.centralwidget)
self.Self_Hand = QListWidget(self.centralwidget)
self.Self_Grave = QListWidget(self.centralwidget)
self.Self_Banish = QListWidget(self.centralwidget)
self.Self_S1 = QListWidget(self.centralwidget)
self.Self_S2 = QListWidget(self.centralwidget)
self.Self_S3 = QListWidget(self.centralwidget)
self.Self_S4 = QListWidget(self.centralwidget)
self.Self_S5 = QListWidget(self.centralwidget)
self.Self_M1 = QListWidget(self.centralwidget)
self.Self_M2 = QListWidget(self.centralwidget)
self.Self_M3 = QListWidget(self.centralwidget)
self.Self_M4 = QListWidget(self.centralwidget)
self.Self_M5 = QListWidget(self.centralwidget)
self.Self_P1 = QListWidget(self.centralwidget)
self.Self_P2 = QListWidget(self.centralwidget)
self.Self_Field = QListWidget(self.centralwidget)
self.Self_LP = QLineEdit(self.centralwidget)
self.Self_LP.setText("8000")
self.Self_LP.setEnabled(False)
self.ExM_1 = QListWidget(self.centralwidget)
self.ExM_2 = QListWidget(self.centralwidget)
self.Enemy_Ex = QListWidget(self.centralwidget)
self.Enemy_Hand = QListWidget(self.centralwidget)
self.Enemy_Grave = QListWidget(self.centralwidget)
self.Enemy_Banish = QListWidget(self.centralwidget)
self.Enemy_S1 = QListWidget(self.centralwidget)
self.Enemy_S2 = QListWidget(self.centralwidget)
self.Enemy_S3 = QListWidget(self.centralwidget)
self.Enemy_S4 = QListWidget(self.centralwidget)
self.Enemy_S5 = QListWidget(self.centralwidget)
self.Enemy_M1 = QListWidget(self.centralwidget)
self.Enemy_M2 = QListWidget(self.centralwidget)
self.Enemy_M3 = QListWidget(self.centralwidget)
self.Enemy_M4 = QListWidget(self.centralwidget)
self.Enemy_M5 = QListWidget(self.centralwidget)
self.Enemy_Field = QListWidget(self.centralwidget)
self.Enemy_P1 = QListWidget(self.centralwidget)
self.Enemy_P2 = QListWidget(self.centralwidget)
self.Enemy_LP = QLineEdit(self.centralwidget)
self.Enemy_LP.setText("8000")
self.Enemy_LP.setEnabled(False)
self.placeframe()
self.retranslateUi()
def __init__(self):
super(Ui_MainWindow, self).__init__()
self.init_frame()
# bar init
bar = QMenuBar(self)
self.setMenuBar(bar)
self.new_bar = QAction("新建(&N)",self)
self.new_bar.setShortcut("Ctrl+N")
self.new_bar.triggered.connect(self.newfile)
bar.addAction(self.new_bar)
self.open_bar = QAction("打开(&O)",self)
self.open_bar.setShortcut("Ctrl+O")
self.open_bar.triggered.connect(self.save_and_open_file)
bar.addAction(self.open_bar)
self.recent_bar_list = bar.addMenu("打开…")
self.recent_bar_list.triggered[QAction].connect(self.open_recent_file)
self.save_bar = QAction("保存(&S)",self)
self.save_bar.setShortcut("Ctrl+S")
self.save_bar.triggered.connect(self.savefile)
bar.addAction(self.save_bar)
self.mirror_bar_init(bar)
self.menu_bar_list = bar.addMenu("功能…")
self.calculator_bar = QAction("计算器",self)
self.calculator_bar.triggered.connect(self.open_calculator)
self.menu_bar_list.addAction(self.calculator_bar)
self.export_deck_bar = QAction("导出卡组",self)
self.export_deck_bar.triggered.connect(self.export_deck)
self.menu_bar_list.addAction(self.export_deck_bar)
self.blur_search_bar = QAction("搜索效果文字",self,checkable=True)
self.blur_search_bar.setChecked(True)
self.blur_search_bar.triggered.connect(self.search_card)
self.menu_bar_list.addAction(self.blur_search_bar)
self.coloring_field_card = QAction("按照卡片种类显示颜色",self,checkable=True)
self.coloring_field_card.setChecked(False)
self.coloring_field_card.triggered.connect(self.refresh_color)
self.menu_bar_list.addAction(self.coloring_field_card)
self.about_bar = QAction("关于", self)
self.about_bar.triggered.connect(self.open_about)
bar.addAction(self.about_bar)
self.quit_bar = QAction("退出", self)
self.quit_bar.triggered.connect(self.close)
bar.addAction(self.quit_bar)
self.read_config()
self.img_window_list = []
# 读取卡片数据库
self.card_datas = {}
self.raw_datas = {}
self.monster_datas = {}
self.card_colors = {}
self.id_map_by_name = {}
self.ex_card_id_set = set()
self.token_card_id_set = set()
card_sorted = {}
# 读取Pro1默认cdb
if os.path.exists("cards.cdb"):
self.read_cdb("cards.cdb", card_sorted)
# 读取Pro1扩展包
self.read_cdbs_from_dir("expansions", card_sorted)
# 读取Pro2的cdb目录
self.read_cdbs_from_dir("cdb", card_sorted)
# Windows系统下,读取注册表中Pro2的安装目录
if os.name == "nt":
import winreg
try:
pro2_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows\CurrentVersion\App Paths\YGOPro2.exe", access=winreg.KEY_READ)
if pro2_key:
pro2_path = winreg.QueryValueEx(pro2_key, "path")
if len(pro2_path) > 0:
self.read_cdbs_from_dir(pro2_path[0], card_sorted)
except Exception as e:
pass
try:
pro2_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\YGOPro2.exe", access=winreg.KEY_READ)
if pro2_key:
pro2_path = winreg.QueryValueEx(pro2_key, "path")
if len(pro2_path) > 0:
self.read_cdbs_from_dir(pro2_path[0], card_sorted)
except Exception as e:
pass
self.card_names = list(self.card_datas.keys())
self.card_names.sort(key=lambda x: (card_sorted[x]))
if len(self.card_names) <= 0:
self.Newcard_List.addItem("无数据库")
self.Newcard_List.setEnabled(False)
self.coloring_field_card.setEnabled(False)
# sub windows
self.calculate_window = calculator.Calculator()
self.calculate_window.setdatas(self.monster_datas)
self.about_window = about.UI_About(version_idx, version_name, self.version_url, self)
# 初始化
self.idx_represent_field = [
self.Self_Hand, self.Self_S1, self.Self_S2, self.Self_S3, self.Self_S4, self.Self_S5,
self.Self_Field, self.Self_P1, self.Self_P2, self.Self_M1, self.Self_M2, self.Self_M3, self.Self_M4, self.Self_M5,
self.Self_Grave, self.Self_Banish, self.Self_Ex,
self.Enemy_Hand, self.Enemy_S1, self.Enemy_S2, self.Enemy_S3, self.Enemy_S4, self.Enemy_S5,
self.Enemy_Field, self.Enemy_P1, self.Enemy_P2, self.Enemy_M1, self.Enemy_M2, self.Enemy_M3, self.Enemy_M4, self.Enemy_M5,
self.Enemy_Grave, self.Enemy_Banish, self.Enemy_Ex, self.ExM_1, self.ExM_2
]
self.unsave_changed = False
# 操作部分
self.copying_operation = []
self.Operator_search.textChanged.connect(self.search_operation)
self.Operator_search.returnPressed.connect(self.search_operation_cycle)
self.Operator_search_button.clicked.connect(self.search_operation_cycle)
self.Operator_list.itemSelectionChanged.connect(self.operation_index_changed)
self.Delete_ope_button.clicked.connect(self.remove_operator)
self.Operator_list.doubleClicked.connect(self.copy_ope)
self.Copy_ope_button.clicked.connect(self.copy_ope)
self.CopyingOpe_list.itemSelectionChanged.connect(self.select_copying)
self.CopyingOpe_list.doubleClicked.connect(self.remove_from_copying)
self.Paste_ope_button.clicked.connect(self.paste_operator)
self.Delete_copy_button.clicked.connect(self.remove_from_copying)
# 判断是否有最近打开的文件,若有则尝试打开
if self.fullfilename is not None and len(self.fullfilename) > 0:
fullname = self.fullfilename
temp_id = self.lastest_field_id
self.newfile()
try:
self.openfile(fullname, temp_id)
except Exception as e:
self.fullfilename = ""
else:
self.newfile()
# 对象部分
self.Delete_target_button.clicked.connect(self.remove_from_targets)
self.Target_list.clicked.connect(self.target_index_changed)
self.Target_list.itemSelectionChanged.connect(self.target_index_changed)
self.Target_list.doubleClicked.connect(self.remove_from_targets)
self.Target_effect_button.clicked.connect(self.show_card_effect)
self.Target_img_button.clicked.connect(self.view_pic)
self.Move_card_button.clicked.connect(self.ope_movecards)
# 添加/删除卡片部分
self.NewCard_line.textChanged.connect(self.search_card)
self.NewCard_line.returnPressed.connect(self.create_card)
self.NewCard_button.clicked.connect(self.create_card)
self.Newcard_List.doubleClicked.connect(self.fix_cardname)
self.Newcard_List.clicked.connect(self.show_carddesp)
self.Newcard_List.itemSelectionChanged.connect(self.show_carddesp)
self.Rename_button.clicked.connect(self.card_rename)
self.Create_card_button.clicked.connect(self.create_card)
self.Erase_card_button.clicked.connect(self.erase_targets)
# 基本分变更部分
self.AddLP_button.clicked.connect(self.ope_LPAdd)
self.DecLP_button.clicked.connect(self.ope_LPDec)
self.CgeLP_button.clicked.connect(self.ope_LPCge)
self.HalLP_button.clicked.connect(self.ope_LPHal)
# 注释部分
self.Comment_button.clicked.connect(self.ope_addcomment)
self.Comment_card_button.clicked.connect(self.ope_addcarddesp)
self.Comment_Line.returnPressed.connect(self.comment_enter)
# 场上的卡片
for field_id in range(len(self.idx_represent_field)):
self.idx_represent_field[field_id].itemSelectionChanged.connect(partial(self.select_field, field_id))
self.idx_represent_field[field_id].clicked.connect(partial(self.select_field, field_id))
self.idx_represent_field[field_id].doubleClicked.connect(partial(self.target_field, field_id))
self.update_signal.connect(self.update_hint)
self.download_signal.connect(self.download_hint)
self.process_signal.connect(self.process_hint)
self.clear_img_signal.connect(self.img_cache_clear)
self.update_check()
def update_check(self):
self.update_thread = Update_Thread(self, self.version_url)
self.update_thread.setDaemon(True)
self.update_thread.start()
def keyPressEvent(self, event):
'''键盘事件响应'''
if event.key() == Qt.Key_Delete:
# Delete键删除目标
if self.Target_list.hasFocus():
self.remove_from_targets()
# Delete键删除操作
elif self.Operator_list.hasFocus():
self.remove_operator()
elif self.CopyingOpe_list.hasFocus():
self.remove_from_copying()
# 回车键默认减少LP
if self.LP_line.hasFocus() and (event.key() == Qt.Key_Return or event.key() == Qt.Key_Enter):
self.ope_LPDec()
# 其它事件
QWidget.keyPressEvent(self, event)
def resizeEvent(self, event):
self.centralwidget.resize(self.width(), self.height())
self.placeframe()
def closeEvent(self, event):
'''重写关闭窗口事件
用于退出前确认保存更改'''
if self.unsave_confirm():
event.ignore()
else:
self.calculate_window.close()
self.about_window.close()
self.save_config()
event.accept()
def comment_enter(self):
'''在注释栏回车时触发的事件
根据目标数量确定为为卡片添加注释,或是添加操作备注'''
if len(self.targets) > 0:
self.ope_addcarddesp()
else:
self.ope_addcomment()
def retranslateUi(self):
self.setWindowTitle("DuelEditor")
self.Operator_list.setSortingEnabled(False)
self.label_operation_list.setText("操作列表(0/0)")
self.label_target_list.setText("操作对象(0)")
self.Delete_target_button.setText("对象中删除")
self.Create_card_button.setText("←添加到对象")
self.Move_card_button.setText("移动对象")
self.Comment_card_button.setText("对象注释")
self.Comment_button.setText("操作注释")
self.label_self_ex.setText("己方额外(0)")
self.label_self_hand.setText("己方手卡(0)")
self.label_self_rpen.setText("己方右灵摆")
self.label_self_lpen.setText("己方左灵摆")
self.label_self_field.setText("己方场地")
self.label_self_lp.setText("己方基本分")
self.label_self_grave.setText("己方墓地(0)")
self.label_self_banish.setText("己方除外(0)")
self.label_enemy_rpen.setText("对方右灵摆")
self.label_enemy_field.setText("对方场地")
self.label_enemy_lpen.setText("对方左灵摆")
self.label_enemy_lp.setText("对方基本分")
self.label_enemy_grave.setText("对方墓地(0)")
self.label_enemy_hand.setText("对方手卡(0)")
self.label_enemy_ex.setText("对方额外(0)")
self.label_enemy_banish.setText("对方除外(0)")
self.Erase_card_button.setText("移除对象")
for idx in range(len(idx_represent_str)):
self.Dest_Box.setItemText(idx, idx_represent_str[idx])
self.label_cardsearch.setText("卡片搜索(0)")
self.Delete_ope_button.setText("删除操作")
self.Copy_ope_button.setText("复制操作")
self.Paste_ope_button.setText("粘贴操作")
self.Delete_copy_button.setText("从剪切板删除")
self.LPTarget_Box.setItemText(0, "己方")
self.LPTarget_Box.setItemText(1, "对方")
self.AddLP_button.setText("增加基本分")
self.DecLP_button.setText("减少基本分")
self.CgeLP_button.setText("变成基本分")
self.HalLP_button.setText("基本分减半")
self.Rename_button.setText("未选定卡")
self.NewCard_button.setText("添加")
self.Target_effect_button.setText("效果")
self.Target_img_button.setText("卡图")
self.Operator_search_button.setText("↓")
def maketitle(self, process=""):
'''根据当前正在打开的文件修改窗口标题'''
if process is not None and process != "":
title_name = "(%s)DuelEditor - %s"%(process, self.filename)
else:
title_name = "DuelEditor - %s"%self.filename
if self.unsave_changed:
title_name = "*" + title_name
self.setWindowTitle(title_name)
def newfile(self):
if self.unsave_confirm():
return
self.lastest_field_id = -1
self.operators = {"cardindex":0, "cards":{}, "operations":[]}
self.fields = {0:deepcopy(init_field)}
self.targets = []
self.copying_operation = []
self.filename = "Untitle.json"
self.fullfilename = ""
self.last_text = ""
self.showing_card_id = None
self.unsave_changed = False
self.maketitle()
self.update_rename_buttom()
self.update_operationlist()
self.update_copying()
self.refresh_field()
self.update_targetlist()
self.show_cardinfo()
self.search_card()
def openfile(self, fullname=None, idx=None):
'''打开文件'''
show_error = (fullname == None)
if self.unsave_confirm():
return
if not isinstance(fullname, str):
fullname = str(QFileDialog.getOpenFileName(self, '选择打开的文件', self.fullfilename, filter="*.json")[0])
if len(fullname) == 0:
return
if idx is None:
idx = self.get_recent_index(fullname)
origin_data = deepcopy(self.operators)
try:
with open(fullname,'r',encoding='utf-8') as f:
json_data = f.read()
dict_data = loads(json_data)
self.operators = dict_data
self.make_fields()
self.update_operationlist()
ope_idx = len(self.operators["operations"])-1
if idx is not None:
ope_idx = min(idx, ope_idx)
self.Operator_list.setCurrentRow(ope_idx)
self.filename = os.path.split(fullname)[-1]
self.fullfilename = fullname
self.unsave_changed = False
self.maketitle()
self.update_recent(fullname, self.get_current_operation_index())
return
# 出错时尝试不使用utf-8编码打开文件
except Exception as e:
try:
with open(fullname,'r') as f:
json_data = f.read()
dict_data = loads(json_data)
self.operators = dict_data
self.make_fields()
self.update_operationlist()
ope_idx = len(self.operators["operations"])-1
if idx is not None:
ope_idx = min(idx, ope_idx)
self.Operator_list.setCurrentRow(ope_idx)
self.filename = os.path.split(fullname)[-1]
self.fullfilename = fullname
self.unsave_changed = False
self.maketitle()
self.update_recent(fullname, self.get_current_operation_index())
return
except:
pass
self.operators = origin_data
self.make_fields()
self.update_recent(fullname, -2)
if show_error:
QMessageBox.warning(self, "提示", "打开失败!", QMessageBox.Yes)
def unsave_confirm(self):
'''如果取消动作,则返回True,否则返回False'''
if self.unsave_changed:
reply = QMessageBox.warning(self, '保存', "是否保存当前文件'%s'?"%self.filename, QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel)
if reply == QMessageBox.Yes:
self.savefile()
elif reply == QMessageBox.No:
self.unsave_changed = False
return self.unsave_changed
def savefile(self):
'''保存文件'''
fullname = str(QFileDialog.getSaveFileName(self,'保存为', self.fullfilename,"*.json")[0])
if len(fullname) == 0:
return
self.filename = os.path.split(fullname)[-1]
self.fullfilename = fullname
json_data = dumps(self.operators,indent=2,ensure_ascii=False)
with open(fullname,'w',encoding='utf-8') as f:
f.write(json_data)
QMessageBox.warning(self, "提示", "保存成功!", QMessageBox.Yes)
self.unsave_changed = False
self.maketitle()
self.update_recent(fullname, self.get_current_operation_index())
def make_fields(self, begin_at=0, end_at=None):
'''根据操作生成各操作的场地
若begin_at不大于0,则从初始场地开始生成,否则从第begin_at个动作后开始生成场地'''
# 获取场地
if begin_at <= 0:
begin_at = 0
self.fields.clear()
lastest_field = deepcopy(init_field)
else:
lastest_field = deepcopy(self.fields[min(begin_at-1, len(self.fields) - 1)])
# 遍历操作
if end_at is None:
end_at = len(self.operators["operations"])
else:
end_at = min(len(self.operators["operations"]), end_at+1)
for idx in range(begin_at, end_at):
'''type(str), args(list of int), dest(int), desp(str)'''
operation = self.operators["operations"][idx]
if operation["type"] == "move":
for card_idx in operation["args"]:
lastest_field["locations"][card_idx] = operation["dest"]
elif operation["type"] == "carddesp":
for card_idx in operation["args"]:
lastest_field["desp"][card_idx] = operation["desp"]
elif operation["type"] == "erase":
for card_idx in operation["args"]:
if card_idx in lastest_field["locations"]:
lastest_field["locations"].pop(card_idx)
elif operation["type"] == "LPAdd":
lastest_field["LP"][operation["args"][0]] += operation["args"][1]
elif operation["type"] == "LPDec":
lastest_field["LP"][operation["args"][0]] -= operation["args"][1]
elif operation["type"] == "LPCge":
lastest_field["LP"][operation["args"][0]] = operation["args"][1]
elif operation["type"] == "LPHal":
lastest_field["LP"][operation["args"][0]] = (lastest_field["LP"][operation["args"][0]] + 1) // 2
# 卡片移动时,对场地列表进行更新
if operation["type"] in ["move","erase"]:
for card_idx in operation["args"]:
if idx > 0 and card_idx in self.fields[idx-1]["locations"]:
last_locat = self.fields[idx-1]["locations"][card_idx]
lastest_field["fields"][last_locat].remove(card_idx)
if operation["type"] == "move":
lastest_field["fields"][operation["dest"]].append(card_idx)
# 将场地复制到列表中用以读取
self.fields[idx] = deepcopy(lastest_field)
# 没有操作会导致没有场地被放置到列表中,用以作为初始场地
if len(self.fields) == 0:
self.fields[0] = lastest_field
def get_last_location(self, card_id, ope_id):
'''获取指定卡片在上一个操作中的位置'''
if ope_id <= 0:
return "未知"
field = self.fields[ope_id-1]
if card_id in field["locations"]:
return idx_represent_str[field["locations"][card_id]]
else:
return "未知"
def get_current_field(self):
'''获取当前操作对应的场地信息
场地格式:
locations(dict), desp(dict), LP(list), fields(list of list)'''
ope_id = self.get_current_operation_index()
if ope_id < 0:
ope_id = 0
return self.fields[ope_id]
def insert_operation(self, operation, update=True):
'''插入操作。操作格式:\n\ntype(str), args(list of int), dest(int), desp(str)'''
# 判断是插入或新增
ope_id = self.get_current_operation_index()
self.lastest_field_id = ope_id
if ope_id < 0:
self.operators["operations"].append(operation)
ope_id = 0
else:
ope_id += 1
self.operators["operations"].insert(ope_id, operation)
if update:
# self.make_fields(ope_id)
self.make_fields(self.lastest_field_id, ope_id)
self.lastest_field_id = ope_id
self.update_operationlist()
self.Operator_list.setCurrentRow(ope_id)
self.show_opeinfo()
self.unsave_changed = True
self.maketitle()
self.label_target_list.setText("操作对象(%d)"%len(self.targets))
#self.Operator_list.setFocus()
def show_cardinfo(self, card_id=None):
'''根据card_id,在信息栏显示卡片详情'''
# 清空
if card_id is None:
self.Target_detail_browser.document().clear()
self.Target_detail_browser.setText("")
return
if card_id not in self.operators["cards"]:
return
card_name = self.operators["cards"][card_id]["Name"]
self.showing_card_id = card_id
self.update_rename_buttom()
if QApplication.keyboardModifiers() == Qt.ShiftModifier:
if self.show_card_effect():
return
field = self.get_current_field()
card_locat = "未知"
card_desp = "无"
if card_id in field["locations"]:
card_locat = idx_represent_str[field["locations"][card_id]]
if card_id in field["desp"]:
card_desp = field["desp"][card_id]
result = "[%s]\n位置:%s\n备注:%s"%(card_name, card_locat, card_desp)
self.Target_detail_browser.document().clear()
self.Target_detail_browser.setText(result)
def show_card_effect(self):
'''显示卡片的效果'''
if self.showing_card_id is None:
return False
if self.showing_card_id not in self.operators["cards"]:
return False
card_name = self.operators["cards"][self.showing_card_id]["Name"]
search_list = [card_name, card_name[:-1]]
for name in search_list:
if name in self.card_datas:
text = self.card_datas[name]
self.Target_detail_browser.setHtml(text)
return True
return False
def show_opeinfo(self, idx=None):
'''显示指定操作详情\n\nidx为空时,显示选定操作的详情'''
# 获取操作
self.showing_card_id = None
self.update_rename_buttom()
if idx is None: