-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1960 lines (1684 loc) · 58.9 KB
/
index.html
File metadata and controls
1960 lines (1684 loc) · 58.9 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
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>角色编队工具</title>
<style>
body {
font-family: sans-serif;
padding: 20px;
background: #f7f7f7;
}
h1 {
font-size: 24px;
}
h2 {
margin-top: 30px;
font-size: 20px;
}
.pool-group {
margin-bottom: 20px;
}
.character-pool,
.team-row {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin: 15px 0;
justify-content: center;
}
.character,
.slot {
width: 70px;
height: 70px;
border: 2px dashed #ccc;
border-radius: 10px;
background-color: white;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
box-sizing: border-box;
}
.character img,
.slot img {
max-width: 100%;
max-height: 100%;
}
.character.dragging {
opacity: 0.5;
}
.used {
opacity: 0.3;
pointer-events: none;
}
.team-container {
margin-bottom: 20px;
padding: 10px;
background: #fff;
border: 1px solid #ccc;
border-radius: 6px;
}
.team-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
flex-wrap: wrap;
}
.team-label {
font-weight: bold;
outline: none;
}
button {
margin-left: 6px;
cursor: pointer;
}
#filters button {
margin-right: 4px;
}
.character-pool {
max-height: 400px;
overflow-y: auto;
border: 1px solid #ccc;
padding: 5px;
background: #fff;
}
.team-container.dragging {
opacity: 0.5;
border: 2px dashed #888;
}
#overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.4);
display: none;
z-index: 998;
}
#eligibleSelector {
z-index: 999;
width: 80%;
}
#eligibleList {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
gap: 10px;
}
#filters button.active {
background: #007bff;
color: white;
border: 2px solid #0056b3;
}
.drag-handle {
width: 28px;
height: 100%;
min-width: 18px;
min-height: 18px;
display: flex;
align-items: center;
justify-content: center;
cursor: grab;
background: none;
border: none;
padding: 0 2px;
margin-right: 10px;
opacity: 0.65;
transition: background 0.2s, box-shadow 0.2s, opacity 0.2s;
user-select: none;
z-index: 2;
}
.drag-handle:hover,
.drag-handle:active,
.drag-handle:focus {
background: #eaf4ff;
box-shadow: 0 2px 8px #007bff22;
opacity: 1;
}
.drag-handle svg {
display: block;
width: 18px;
height: 18px;
}
.dragging {
opacity: 0.7;
box-shadow: 0 4px 16px #007bff33;
}
.chosen {
border: 2px solid #007bff;
}
/* 主区域布局 */
#main-layout {
display: flex;
gap: 20px;
align-items: flex-start;
flex-wrap: wrap;
}
/* ✅ 移动端优化 */
@media (max-width: 768px) {
body {
padding: 0;
}
h1 {
font-size: 20px;
}
h2 {
font-size: 16px;
margin-top: 16px;
}
#main-layout {
flex-direction: column;
gap: 12px;
}
#main-layout>div {
width: 100% !important;
flex: none !important;
}
/* 图标缩小 */
.character,
.slot {
width: 45px;
height: 45px;
}
.character-pool,
.team-row {
gap: 6px;
justify-content: center;
}
/* 标题字体 */
.team-label {
font-size: 14px;
max-width: 60%;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
/* 按钮紧凑 */
.team-header button {
font-size: 12px;
padding: 1px 5px;
margin-left: 4px;
}
/* 筛选条滚动 */
#filters {
overflow-x: auto;
white-space: nowrap;
padding-bottom: 8px;
font-size: 16px;
margin-bottom: 0;
}
#filters button {
display: inline-block;
font-size: 13px;
padding: 4px 8px;
}
#eligibleSelector {
width: 95% !important;
max-height: 85vh;
top: 5%;
left: 50%;
transform: translateX(-50%);
padding: 10px;
font-size: 14px;
}
#eligibleList img {
width: 50px !important;
height: 50px !important;
}
#eligibleList {
grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
gap: 6px;
justify-content: center;
}
#eligibleList img {
width: 48px;
height: 48px;
}
#eligibleList label {
/* flex-direction: column; */
align-items: center;
font-size: 12px;
}
#eligibleList input[type="checkbox"] {
margin-bottom: 4px;
}
.character-pool {
max-height: 240px;
padding: 4px;
}
.team-container {
padding: 6px;
padding-bottom: 0;
margin-bottom: 5px;
}
.drag-handle {
justify-content: flex-start;
}
}
.team-controls {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 10px;
align-items: center;
}
/* ✅ 移动端样式优化 */
@media (max-width: 768px) {
.team-controls {
flex-direction: column;
align-items: stretch;
}
.team-controls button,
.team-controls input[type="file"] {
font-size: 15px;
padding: 0;
width: 100%;
margin: 0;
}
}
.filters {
margin-bottom: 12px;
}
.filters-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 6px;
}
.toggle-filters {
font-size: 14px;
padding: 4px 10px;
}
.filters-body {
display: none;
flex-direction: column;
gap: 8px;
}
.filters.show .filters-body {
display: flex;
}
.filter-row {
display: flex;
flex-wrap: wrap;
align-items: center;
}
.filter-label {
flex: 0 0 70px;
font-weight: bold;
margin-bottom: 4px;
}
.filter-buttons {
flex: 1;
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.filter-buttons.full-width {
width: 100%;
justify-content: center;
gap: 12px;
margin-left: 0;
/* 去除之前的 left margin */
}
/* ✅ 移动端优化 */
@media (max-width: 768px) {
.filter-label {
flex: 0 0 64px;
font-size: 14px;
}
.filter-buttons.full-width {
margin-top: 10px;
}
.filter-buttons button {
font-size: 13px;
padding: 4px 8px;
}
.toggle-filters {
font-size: 13px;
}
/* .filters-body {
display: none;
} */
}
/* 顶部布局:标题左、语言下拉右 */
.app-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
/* 和下面内容保持距离 */
}
/* (可选)让下拉框和按钮尺寸更合适 */
.app-header select {
padding: 4px 8px;
font-size: 14px;
}
:root {
--primary: #007bff;
--primary-hover: #0056b3;
--border-light: #ccc;
--bg-card: #fff;
--shadow: rgba(0, 0, 0, 0.1);
}
/* 全局按钮风格 */
button,
.toggle-filters {
padding: 6px 12px;
border: 1px solid var(--border-light);
background: var(--bg-card);
border-radius: 4px;
font-size: 14px;
transition: background 0.2s, color 0.2s, border-color 0.2s;
}
button:hover,
.toggle-filters:hover {
background: var(--primary);
color: #fff;
border-color: var(--primary-hover);
}
button:active {
background: var(--primary-hover);
}
.team-container {
background: var(--bg-card);
border: 1px solid var(--border-light);
border-radius: 8px;
box-shadow: 0 2px 6px var(--shadow);
transition: box-shadow 0.2s;
}
.team-container:hover {
box-shadow: 0 4px 12px var(--shadow);
}
.slot,
.character {
border: 1px solid var(--border-light);
border-radius: 8px;
transition: transform 0.15s;
}
.slot:hover,
.character:hover {
transform: scale(1.05);
}
.filters-header {
padding: 8px;
background: var(--bg-card);
border: 1px solid var(--border-light);
border-radius: 4px 4px 0 0;
}
.filters-body {
padding: 10px;
background: var(--bg-card);
border: 1px solid var(--border-light);
border-top: none;
border-radius: 0 0 4px 4px;
}
.filter-row {
margin-bottom: 8px;
}
.filter-label {
width: 80px;
}
.filter-buttons button {
margin: 0 4px 4px 0;
}
body {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background: #f3f4f6;
}
.app-header {
padding-bottom: 20px;
border-bottom: 1px solid var(--border-light);
margin-bottom: 20px;
}
#main-layout {
gap: 30px;
}
.pool-group h2 {
margin-bottom: 10px;
font-size: 18px;
}
.team-controls {
gap: 12px;
}
body {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background: #f3f4f6;
}
.app-header {
padding-bottom: 20px;
border-bottom: 1px solid var(--border-light);
margin-bottom: 20px;
}
#main-layout {
gap: 30px;
}
.pool-group h2 {
margin-bottom: 10px;
font-size: 18px;
}
.team-controls {
gap: 12px;
}
.team-container {
flex: 1;
}
@media (max-width: 768px) {
/* 隐藏左侧的冒险者/支援者池 */
.pool-group {
display: none;
}
#main-layout {
gap: 0;
}
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 8px 12px;
border-bottom: 1px solid #ccc;
}
.modal-close {
border: none;
background: transparent;
font-size: 18px;
line-height: 1;
cursor: pointer;
}
/* 只在手机端(≤768px)生效 */
@media (max-width: 768px) {
/* 确保 slot 里没有 img 的才显示加号 */
.slot:empty::after {
content: "+";
/* 加号提示 */
font-size: 1.5rem;
/* 大小可调 */
color: #ccc;
/* 颜色可调 */
display: flex;
align-items: center;
justify-content: center;
pointer-events: none;
/* 不影响点击事件 */
}
}
/* ✅ 让弹窗里的筛选区始终可见 */
#eligibleFiltersContainer{
display:flex!important;
flex-direction:column;
gap:8px;
border: none;
}
/* 弹窗筛选行的按钮高亮色 */
#eligibleFiltersContainer button.active {
background: var(--primary);
color:#fff;
}
/* 让过滤行之间有点间距,看着不堆 */
#eligibleFiltersContainer .filter-row:not(:last-child) {
margin-bottom: 8px;
}
/* 让按钮别太窄 */
#eligibleFiltersContainer .filter-buttons button {
min-width: 48px;
}
</style>
<script>
const i18n = {
zh: {
title: "角色编队工具",
filterLabel: "筛选:",
rarity: "稀有度:",
attribute: "属性:",
roleType: "定位:",
reset: "重置",
eligible: "🎮 设置可上场角色",
addTeam: "添加新队伍",
export: "📤 导出",
deleteTeam: "删除队伍",
clear: "清空",
import: "导入配置",
save: "✅ 保存",
close: "❌ 关闭",
expandFilter: "展开筛选",
collapseFilter: "收起筛选",
team: name => `队伍 ${name}`,
conflictAlert: name => `该小组中不能出现重复角色:${name}`,
dropConflict: "拖拽后会导致同组出现重复角色,操作被取消!",
clearConfirm: name => `确定清空 ${name}?`,
deleteConfirm: name => `确定删除 ${name}?`,
adventurerLabel: "冒险者",
supporterLabel: "支援者",
teamBuilderLabel: "队伍编队",
setupYourPool: "设置你的角色池",
eligibleListMissing: "找不到可选列表元素,请检查 HTML 是否正确插入!",
import: "导入配置",
attribute_FIRE: "火",
attribute_WIND: "风",
attribute_EARTH: "土",
attribute_ELECTRIC: "雷",
attribute_WATER: "水",
roleType_ATTACK: "攻击",
roleType_DEFENSE: "防御",
roleType_SPEED: "速度",
roleType_SUPPORT: "辅助",
allLabel: "全部",
},
en: {
title: "Team Builder",
filterLabel: "Filters:",
rarity: "Rarity:",
attribute: "Attribute:",
roleType: "Role:",
reset: "Reset",
eligible: "🎮 Select Eligible Characters",
addTeam: "Add Team",
export: "📤 Export",
deleteTeam: "Delete Team",
clear: "Clear",
import: "Import Config",
save: "✅ Save",
close: "❌ Close",
expandFilter: "Expand Filters",
collapseFilter: "Collapse Filters",
team: name => `Team ${name}`,
conflictAlert: name => `Duplicate character in group: ${name}`,
dropConflict: "This move would create a duplicate character. Action cancelled.",
clearConfirm: name => `Clear ${name}?`,
deleteConfirm: name => `Delete ${name}?`,
adventurerLabel: "Adventurers",
supporterLabel: "Supporters",
teamBuilderLabel: "Team Formation",
setupYourPool: "Setup Your Character Pool",
eligibleListMissing: "Cannot find eligibleList container—please check your HTML.",
import: "Import Config",
attribute_FIRE: "Fire",
attribute_WIND: "Wind",
attribute_EARTH: "Earth",
attribute_ELECTRIC: "Electric",
attribute_WATER: "Water",
roleType_ATTACK: "Attack",
roleType_DEFENSE: "Defense",
roleType_SPEED: "Speed",
roleType_SUPPORT: "Support",
allLabel: "All",
},
ja: {
title: "編成ツール",
filterLabel: "フィルター:",
rarity: "レアリティ:",
attribute: "属性:",
roleType: "役割:",
reset: "リセット",
eligible: "🎮 使用可能キャラ設定",
addTeam: "チーム追加",
export: "📤 エクスポート",
deleteTeam: "チーム削除",
clear: "クリア",
import: "インポート",
save: "✅ 保存",
close: "❌ 閉じる",
expandFilter: "フィルターを展開",
collapseFilter: "フィルターを折りたたむ",
team: name => `チーム ${name}`,
conflictAlert: name => `同じキャラクターが含まれています:${name}`,
dropConflict: "同じキャラがいるため、この操作はキャンセルされました。",
adventurerLabel: "冒険者",
supporterLabel: "サポーター",
teamBuilderLabel: "チーム編成",
setupYourPool: "使用キャラの設定",
eligibleListMissing: "eligibleList 要素が見つかりません。HTML 挿入を確認してください。",
import: "インポート",
attribute_FIRE: "火",
attribute_WIND: "風",
attribute_EARTH: "土",
attribute_ELECTRIC: "雷",
attribute_WATER: "水",
roleType_ATTACK: "攻撃",
roleType_DEFENSE: "防御",
roleType_SPEED: "スピード",
roleType_SUPPORT: "サポート",
clearConfirm: name => `${name} をクリアしますか?`,
deleteConfirm: name => `${name} を削除しますか?`,
allLabel: "すべて",
}
};
</script>
</head>
<body>
<header class="app-header">
<h1 data-t-key="title"></h1>
<select id="languageSelector" onchange="changeLanguage(this.value)">
<option value="zh">中文</option>
<option value="en">English</option>
<option value="ja">日本語</option>
</select>
</header>
<!-- <select id="languageSelector" onchange="changeLanguage(this.value)">
<option value="zh">中文</option>
<option value="en">English</option>
<option value="ja">日本語</option>
</select>
<h1>角色编队工具</h1> -->
<!-- ▶︎ 主筛选 + 折叠外壳 -->
<div id="filters" class="filters">
<div class="filters-header">
<strong data-t-key="filterLabel"></strong>
<button class="toggle-filters"
data-t-key="expandFilter"
onclick="toggleFilterPanel()"></button>
</div>
<!-- 真正渲染按钮的容器 -->
<div id="mainFilters" class="filters-body"></div>
</div>
<div id="overlay" onclick="closeEligibleSelector()"></div>
<div id="eligibleSelector"
style="display:none; background:#fff; border:1px solid #ccc;
padding:10px; position:fixed; top:10%; left:50%;
transform:translateX(-50%); max-height:80vh; overflow:auto; z-index:999;">
<h3 data-t-key="setupYourPool">设置你的角色池</h3>
<div id="eligibleFiltersContainer" class="filters-body"></div>
<!-- 角色网格 -->
<div id="eligibleList"></div>
</div>
<div id="main-layout">
<div style="flex: 1;">
<div class="pool-group">
<h2 data-t-key="adventurerLabel">冒险者</h2>
<div class="character-pool" id="adventurers"></div>
</div>
<div class="pool-group">
<h2 data-t-key="supporterLabel">支援者</h2>
<div class="character-pool" id="supporters"></div>
</div>
</div>
<div style="flex: 1;">
<h2 data-t-key="teamBuilderLabel">队伍编队</h2>
<div id="teams"></div>
<div class="team-controls" style="margin-top: 10px;">
<button onclick="addTeam()" data-t-key="addTeam">添加新队伍</button>
<button onclick="exportConfig()" data-t-key="export">📤 导出</button>
<!-- <input type="file" accept="application/json" onchange="importConfig(event)" /> -->
<button onclick="fileInput.click()" data-t-key="import">📂 导入</button>
<input id="fileInput" type="file" accept="application/json" style="display:none"
onchange="importConfig(event)" />
</div>
</div>
</div>
<script src="https://unpkg.com/drag-drop-touch/DragDropTouch.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.2/Sortable.min.js"></script>
<script>
new Sortable(document.getElementById('teams'), {
animation: 180,
handle: '.drag-handle',
ghostClass: 'dragging',
chosenClass: 'chosen',
onEnd: function (evt) {
// evt.oldIndex, evt.newIndex,队伍顺序已自动调整
saveToLocal(); // 自己的存储逻辑
}
});
</script>
<script src="character-pool.js"></script>
<script>
let teamCounter = 0;
const availableTeamNumbers = [];
const usedNames = new Set();
const slotMap = new Map();
const rarityOrder = ['UR', 'SSR', 'SR', 'R'];
let pendingInsert = null;
let selectorMode = 'eligible'; // 或 'slot'
const activeFilters = { rarity: null, attribute: null, roleType: null };
/* === 弹窗内部筛选状态 === */
const eligibleFilters = {
role: 'all', // all | adventurer | supporter
rarity: null,
attribute: null,
roleType: null,
};
/************* ① 配置:定义所有筛选选项 *****************/
const FILTER_CONFIG = {
role: {
popupOnly: true, // ← 新增
labelKey: 'filterLabel',
buttons: [
{ value: 'all', textKey: 'allLabel' },
{ value: 'adventurer', textKey: 'adventurerLabel' },
{ value: 'supporter', textKey: 'supporterLabel' }
],
},
rarity: { // 仍然用固定文本
labelKey: 'rarity',
buttons: ['SR','SSR','UR'].map(v=>({value:v, text:v}))
},
attribute: { // ➜ 使用翻译键
labelKey: 'attribute',
buttons: ['FIRE','WIND','EARTH','ELECTRIC','WATER']
.map(v=>({value:v, textKey:`attribute_${v}`}))
},
roleType: { // ➜ 使用翻译键
labelKey: 'roleType',
buttons: [
{ value:'ATTACK', textKey:'roleType_ATTACK' },
{ value:'DEFENSE', textKey:'roleType_DEFENSE' },
{ value:'SPEED', textKey:'roleType_SPEED' },
{ value:'SUPPORT', textKey:'roleType_SUPPORT' },
],
},
};
/************* ② 渲染函数:任意容器、任意 scope *********/
function renderFilterUI(targetId, scope){
const isMain = scope === 'main';
const container = document.getElementById(targetId);
container.innerHTML = ''; // 清空
Object.entries(FILTER_CONFIG).forEach(([group, cfg])=>{
if (cfg.popupOnly && isMain) return; // 主界面跳过 role 行
const row = document.createElement('div'); row.className = 'filter-row';
// label
const label = document.createElement('span');
label.className='filter-label';
label.dataset.tKey = cfg.labelKey;
label.textContent = t(cfg.labelKey);
row.appendChild(label);
// buttons
const btnBox = document.createElement('div'); btnBox.className='filter-buttons';
cfg.buttons.forEach(btnCfg=>{
const btn=document.createElement('button');
btn.textContent = btnCfg.textKey ? t(btnCfg.textKey) : btnCfg.text;
if (btnCfg.textKey) btn.dataset.tKey = btnCfg.textKey;
btn.dataset.group = group;
btn.dataset.value = btnCfg.value;
btn.onclick = () => toggleFilterGeneric(scope, group, btnCfg.value);
btnBox.appendChild(btn);
});
row.appendChild(btnBox);
container.appendChild(row);
});
// 额外行:重置 / Eligible 只在主界面出现
if(isMain){
const extra = document.createElement('div'); extra.className='filter-row';
extra.innerHTML = `
<div class="filter-buttons full-width">
<button onclick="resetFilters()" data-t-key="reset">${t('reset')}</button>
<button onclick="openEligibleSelector()" data-t-key="eligible">${t('eligible')}</button>
</div>`;
container.appendChild(extra);
}
}
/************* ③ 通用切换函数(替换以前两个函数) *********/
function toggleFilterGeneric(scope, type, val){
const cfg = scope==='main'
? { state: activeFilters, render: renderPool, selector:'#mainFilters' }
: { state: eligibleFilters, render: renderEligibleList, selector:'#eligibleFiltersContainer' };
cfg.state[type] = cfg.state[type]===val ? null : val;
document.querySelectorAll(`${cfg.selector} [data-group="${type}"]`)
.forEach(btn=>{
btn.classList.toggle(
'active',
btn.dataset.value === cfg.state[type]
);
});
cfg.render();
}
// 判断一个角色是否应该显示
function filterFunc(char) {
if (eligibleCharacters.size > 0 && !eligibleCharacters.has(char.name)) return false;
if (activeFilters.rarity && char.rarity !== activeFilters.rarity) return false;
if (activeFilters.attribute && char.attribute !== activeFilters.attribute) return false;
if (activeFilters.roleType && char.roleType !== activeFilters.roleType) return false;
return true;
}
// 按稀有度+名字排序
function sortFunc(a, b) {
const ra = rarityOrder.indexOf(a.rarity), rb = rarityOrder.indexOf(b.rarity);
if (ra !== rb) return ra - rb;
return (a.baseName || a.name).localeCompare(b.baseName || b.name, currentLang);
}
document.addEventListener('DOMContentLoaded', ()=>{
renderFilterUI('mainFilters','main');
renderFilterUI('eligibleFiltersContainer','eligible');
renderPool();
loadFromLocal();
document.getElementById('languageSelector').value = currentLang;
applyTranslations();
});
function toggleFilter(type, value) {
const prevValue = activeFilters[type];
activeFilters[type] = prevValue === value ? null : value;
// 更新按钮状态
document.querySelectorAll(`#filters button[data-type="${type}"]`).forEach(btn => {
btn.classList.toggle("active", btn.dataset.value === activeFilters[type]);
});
renderPool();
}