-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
1081 lines (858 loc) · 38.4 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
import tkinter as tk
from tkinter import messagebox
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from tkinter import font
from tkinter import *
from ttkbootstrap import Style
from PIL import Image, ImageTk
from ttkbootstrap.scrolled import ScrolledFrame
import os
from tkinter import PhotoImage
import sqlite3
from tkinter import Tk, filedialog
import shutil
def setup_database():
conn = sqlite3.connect('clash_royale.db')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS categories (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
directory TEXT NOT NULL
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS images (
id INTEGER PRIMARY KEY AUTOINCREMENT,
category_id INTEGER,
filename TEXT,
FOREIGN KEY (category_id) REFERENCES categories (id)
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS profilecards (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
rarity TEXT,
elixir INTEGER,
card_type TEXT,
arena TEXT,
description TEXT,
hitpoints INTEGER,
damage INTEGER,
card_range INTEGER,
stun_duration REAL,
shield TEXT,
movement_speed TEXT,
radius REAL,
image_path TEXT,
property TEXT
)
''')
conn.commit()
conn.close()
setup_database()
window = ttk.Window(themename='solar')
window.title("ClashPedia")
top_frame = tk.Frame(window, bg='#c3c3c3')
top_frame.pack(side=tk.TOP)
top_frame.pack_propagate(False)
top_frame.configure(height='150' , width='1925')
lb = tk.Label(top_frame , text= 'ClashPedia (Clash Royale Encyclopedia)', font=('Showcard Gothic', 36, 'bold'))
lb.place(x=20 , y = 10)
lb.pack(padx=10 ,pady=20)
options_frame = tk.Frame(window, bg='#c3c3c3')
options_frame.pack(side=tk.LEFT)
options_frame.pack_propagate(False)
options_frame.configure(height='800' , width='175')
main_frame = tk.Frame(window)
main_frame.pack(side=LEFT)
main_frame.pack_propagate(False)
main_frame.configure(height='1000' ,width='1750')
logo_dir = "design_photo"
logo_filename = "logo.png"
logo_path = os.path.join(logo_dir, logo_filename)
logo_img = Image.open(logo_path)
logo_img = logo_img.resize((160, 150), Image.LANCZOS)
logo_photo = ImageTk.PhotoImage(logo_img)
logo_label = tk.Label(top_frame, image=logo_photo, bg='#c3c3c3')
logo_label.place(x=10, y=20)
def hide_switch_page():
welcome_switch_page.config(bg='#c3c3c3')
categories_switch_page.config(bg='#c3c3c3')
deck_builder_switch_page.config(bg='#c3c3c3')
profile_maker_switch_page.config(bg='#c3c3c3')
def delete_page():
for frame in main_frame.winfo_children():
frame.destroy()
def switch_page(lb ,page):
hide_switch_page()
lb.configure(bg='#158aff')
delete_page()
page()
def welcome_page():
welcome_frame = ScrolledFrame(main_frame, padding=5, height=10, autohide=True)
welcome_frame.pack(fill=BOTH, expand=YES)
text_label = tk.Label(welcome_frame, text='Welcome to ClashPedia, your ultimate guide to Clash Royale!\nExplore cards, strategies, updates, and much more.', font=('Showcard Gothic', 23, 'bold'))
text_label.pack(pady=10)
banner_path = "design_photo/banner.png"
image = Image.open(banner_path)
image = ImageTk.PhotoImage(image)
image_label = tk.Label(welcome_frame, image=image)
image_label.image = image
image_label.pack()
tutorial_of_cards_label = tk.Label(welcome_frame, text='What is "CLASH ROYALE?"', font=('Rockwell Extra Bold', 15, 'bold'))
tutorial_of_cards_label.pack(pady=10, anchor='w', padx=20)
tutorial_of_cards_text = """
Winning Battles:
- Get more Crowns than your opponent by destroying their Crown Towers.
- Destroying the opponent's King's Tower instantly gives you 3 Crowns and wins the game.
- If no King's Tower is destroyed, the player with more Crowns at the end of the 3-minute period wins.
- If neither player has more Crowns, the game goes into Overtime.
- Overtime ends if a Crown Tower is destroyed, deciding the winner.
- If all towers have identical health, a tiebreaker occurs where towers rapidly lose health until one is destroyed.
Trophies and Rewards:
- Winning earns Trophies, while losing loses them.
- Trophies unlock new Arenas and higher Leagues.
- New Arenas offer new Cards and better rewards.
- Victory in Challenges and Tournaments earns rewards and progresses in the event.
Clan Wars:
- In a stalemate, a coin flip decides the winner.
- Trophies contribute to Clan War standings and rewards.1. Troops: These are units that can move and attack.
2. Spells: These are temporary effects that can be cast anywhere on the battlefield.
3. Buildings: These are stationary structures that decay over time.
4. Tower Troops: These are troops that stay on your Crown Towers and attack enemy troops.
"""
tutorial_of_cards_info = tk.Label(welcome_frame, text=tutorial_of_cards_text, justify='left')
tutorial_of_cards_info.pack(pady=5, anchor='w', padx=40)
types_frame = tk.Frame(welcome_frame, bg="white", bd=2, relief=tk.GROOVE)
types_frame.pack(pady=10, padx=20, fill=tk.BOTH, expand=True)
tutorial_of_cards_label = tk.Label(types_frame, text='Types of Cards:', font=('Rockwell Extra Bold', 15, 'bold'))
tutorial_of_cards_label.pack(pady=10, anchor='w', padx=20)
tutorial_of_cards_text = """
1. Troops: These are units that can move and attack.
2. Spells: These are temporary effects that can be cast anywhere on the battlefield.
3. Buildings: These are stationary structures that decay over time.
4. Tower Troops: These are troops that stay on your Crown Towers and attack enemy troops.
"""
tutorial_of_cards_info = tk.Label(types_frame, text=tutorial_of_cards_text, justify='left')
tutorial_of_cards_info.pack(pady=5, anchor='w', padx=40)
rarities_frame = tk.Frame(welcome_frame, bg="white", bd=2, relief=tk.GROOVE)
rarities_frame.pack(pady=10, padx=20, fill=tk.BOTH, expand=True)
rarities_and_levels_label = tk.Label(rarities_frame, text='Rarities and Levels:', font=('Rockwell Extra Bold', 15, 'bold'))
rarities_and_levels_label.pack(pady=10, anchor='w', padx=20)
rarities_and_levels_text = """
- Common: Levels 1 to 15
- Rare: Levels 3 to 15
- Epic: Levels 6 to 15
- Legendary: Levels 9 to 15
- Champion: Levels 11 to 15
"""
rarities_and_levels_info = tk.Label(rarities_frame, text=rarities_and_levels_text, justify='left')
rarities_and_levels_info.pack(pady=5, anchor='w', padx=40)
champion_frame = tk.Frame(welcome_frame, bg="white", bd=2, relief=tk.GROOVE)
champion_frame.pack(pady=10, padx=20, fill=tk.BOTH, expand=True)
champion_cards_label = tk.Label(champion_frame, text='Champion Cards:', font=('Rockwell Extra Bold', 15, 'bold'))
champion_cards_label.pack(pady=10, anchor='w', padx=20)
champion_cards_text = """
- Unique troops with special abilities.
- Can be activated by tapping an icon on the screen, costing Elixir.
- Abilities have a cooldown after use.
- Not affected by regular card cycle rules.
- Only one Champion card allowed in a deck.
- Mirror cannot spawn Champions.
- Cloned Champions can't use abilities.
"""
champion_cards_info = tk.Label(champion_frame, text=champion_cards_text, justify='left')
champion_cards_info.pack(pady=5, anchor='w', padx=40)
ranges_frame = tk.Frame(welcome_frame, bg="white", bd=2, relief=tk.GROOVE)
ranges_frame.pack(pady=10, padx=20, fill=tk.BOTH, expand=True)
ranges_label = tk.Label(ranges_frame, text='Ranges:', font=('Rockwell Extra Bold', 15, 'bold'))
ranges_label.pack(pady=10, anchor='w', padx=20)
ranges_text = """
- Melee: Short (0.8 tiles or less)
- Melee: Medium (1.2 tiles)
- Melee: Long (1.6 tiles)
- Ranged (2 or more tiles)
"""
ranges_info = tk.Label(ranges_frame, text=ranges_text, justify='left')
ranges_info.pack(pady=5, anchor='w', padx=40)
welcome_frame.pack()
def get_data_from_db(query, param=None):
conn = sqlite3.connect('clash_royale.db')
cursor = conn.cursor()
if param:
cursor.execute(query, (param,))
else:
cursor.execute(query)
data = cursor.fetchall()
conn.close()
return data
def clear_main_frame(frame=None):
if frame:
for widget in frame.winfo_children():
widget.destroy()
else:
for widget in main_frame.winfo_children():
widget.destroy()
def show_categories(category):
clear_main_frame()
if category == 'elixir':
query = """
SELECT elixir, image_path FROM profile_cards
ORDER BY
CASE
WHEN elixir = '1' THEN 1
WHEN elixir = '2' THEN 2
WHEN elixir = '3' THEN 3
WHEN elixir = '4' THEN 4
WHEN elixir = '5' THEN 5
WHEN elixir = '6' THEN 6
WHEN elixir = '7' THEN 7
WHEN elixir = '8' THEN 8
WHEN elixir = '9' THEN 9
WHEN elixir = '10' THEN 10
END
"""
data = get_data_from_db(query)
titles = ["Elixir_1",
"Elixir_2",
"Elixir_3",
"Elixir_4",
"Elixir_5",
"Elixir_6",
"Elixir_7",
"Elixir_8",
"Elixir_9",
"Elixir_10"
]
elif category == 'arena':
query = """
SELECT arena, image_path FROM profile_cards
ORDER BY
CASE
WHEN arena = '0' THEN 1
WHEN arena = '1' THEN 2
WHEN arena = '2' THEN 3
WHEN arena = '3' THEN 4
WHEN arena = '4' THEN 5
WHEN arena = '5' THEN 6
WHEN arena = '6' THEN 7
WHEN arena = '7' THEN 8
WHEN arena = '8' THEN 9
WHEN arena = '9' THEN 10
WHEN arena = '10' THEN 11
WHEN arena = '11' THEN 12
WHEN arena = '12' THEN 13
WHEN arena = '13' THEN 14
WHEN arena = '14' THEN 15
WHEN arena = '15' THEN 16
WHEN arena = '16' THEN 17
WHEN arena = '17' THEN 18
WHEN arena = '18' THEN 19
END
"""
data = get_data_from_db(query)
titles = ["Arena 0",
"Arena 1",
"Arena 2",
"Arena 3",
"Arena 4",
"Arena 5",
"Arena 6",
"Arena 7",
"Arena 8",
"Arena 9",
"Arena 10",
"Arena 11",
"Arena 12",
"Arena 13",
"Arena 14",
"Arena 15",
"Arena 16",
"Arena 17",
"Arena 18",]
elif category == 'type':
query = """
SELECT type, filename FROM images
ORDER BY
CASE
WHEN type = 'Spells' THEN 1
WHEN type = 'Troop' THEN 2
WHEN type = 'Buildings' THEN 3
END
"""
data = get_data_from_db(query)
titles = ["Spells",
"Troop",
"Buildings"]
elif category == 'rarity':
query = """
SELECT rarity, image_path FROM profile_cards
ORDER BY
CASE
WHEN rarity = 'common' THEN 1
WHEN rarity = 'rare' THEN 2
WHEN rarity = 'epic' THEN 3
WHEN rarity = 'legendary' THEN 4
WHEN rarity = 'champion' THEN 5
WHEN rarity = 'funny' THEN 6
END
"""
data = get_data_from_db(query)
titles = ["common",
"rare",
"epic",
"legendary",
"champion",
"funny"]
button_frame = tk.Frame(main_frame)
button_frame.pack(fill=tk.X, padx=10, pady=5)
type_button = ttk.Button(button_frame, text='Type', command=lambda: show_categories('type'))
type_button.pack(side=tk.LEFT, padx=5)
arena_button = ttk.Button(button_frame, text='Arena', command=lambda: show_categories('arena'))
arena_button.pack(side=tk.LEFT, padx=5)
elixir_button = ttk.Button(button_frame, text='Elixir', command=lambda: show_categories('elixir'))
elixir_button.pack(side=tk.LEFT, padx=5)
rarity_button = ttk.Button(button_frame, text='Rarity', command=lambda: show_categories('rarity'))
rarity_button.pack(side=tk.LEFT, padx=5)
category_frame = ScrolledFrame(main_frame, autohide=True)
category_frame.pack(fill=tk.BOTH, expand=tk.YES, padx=10, pady=10)
current_title = None
row = 0
col = 0
for title, filename in data:
if title != current_title:
if current_title is not None:
row += 1
current_title = title
title_label = tk.Label(category_frame, text=current_title, font=("Showcard Gothic", 16, "bold"))
title_label.grid(row=row, column=0, columnspan=13, pady=(10, 0), sticky="w")
row += 1
col = 0
img_path = os.path.join("clash-royale-card-elixir", filename)
if os.path.isfile(img_path):
img = Image.open(img_path)
img = img.resize((90, 120), Image.LANCZOS)
img = ImageTk.PhotoImage(img)
panel = tk.Label(category_frame, image=img, compound=tk.LEFT, bd=0, padx=5, pady=5)
panel.image = img
panel.grid(row=row, column=col, sticky="w")
panel.bind("<Button-1>", lambda event, img_path=img_path: show_image(event, img_path))
col += 1
if col >= 13:
row += 1
col = 0
def categories_page(category=None):
clear_main_frame()
button_frame = tk.Frame(main_frame)
button_frame.pack(fill=tk.X, padx=10, pady=5)
type_button = ttk.Button(button_frame, text='Type', command=lambda: show_categories('type'))
type_button.pack(side=tk.LEFT, padx=5)
arena_button = ttk.Button(button_frame, text='Arena', command=lambda: show_categories('arena'))
arena_button.pack(side=tk.LEFT, padx=5)
elixir_button = ttk.Button(button_frame, text='Elixir', command=lambda: show_categories('elixir'))
elixir_button.pack(side=tk.LEFT, padx=5)
rarity_button = ttk.Button(button_frame, text='Rarity', command=lambda: show_categories('rarity'))
rarity_button.pack(side=tk.LEFT, padx=5)
if category:
show_categories(category)
else:
show_categories('rarity')
def show_image(event, image_path):
print(f"Image path: {image_path}")
image_window = tk.Toplevel()
image_window.title("Card Image")
image_window.geometry("600x900")
img = Image.open(image_path)
img = img.resize((150, 200), Image.LANCZOS)
img = ImageTk.PhotoImage(img)
image_label = tk.Label(image_window, image=img)
image_label.image = img
image_label.pack(pady=10)
card_details_frame = ttk.Frame(image_window)
card_details_frame.pack(padx=20, pady=(0, 20), fill=tk.X)
conn = sqlite3.connect('clash_royale.db')
cursor = conn.cursor()
cursor.execute('''
SELECT name, rarity, elixir, card_type, arena, description, hitpoints, damage,
card_range, stun_duration, shield, movement_speed, radius
FROM profile_cards
WHERE image_path = ?
''', (os.path.basename(image_path),))
card_data = cursor.fetchone()
conn.close()
print(f"Card data: {card_data}")
label_font = ("Showcard Gothic", 8)
value_font = ("Arial", 8, "bold")
if card_data:
labels = [
"Name", "Rarity", "Elixir", "Card Type", "Arena", "Description",
"Hitpoints", "Damage", "Card Range", "Stun Duration", "Shield",
"Movement Speed", "Radius"
]
for i, (label, value) in enumerate(zip(labels, card_data)):
label_widget = ttk.Label(card_details_frame, text=f"{label}:", font=label_font)
label_widget.grid(row=i*2, column=0, sticky="w", padx=(0, 10), pady=5)
if label == "Description":
value_widget = ttk.Label(card_details_frame, text=value, font=value_font, wraplength=400) # Adjust wraplength as needed
else:
value_widget = ttk.Label(card_details_frame, text=value, font=value_font)
value_widget.grid(row=i*2, column=1, sticky="w", padx=(0, 10), pady=5)
# Add a separator line
separator = ttk.Separator(card_details_frame, orient='horizontal')
separator.grid(row=i*2 + 1, column=0, columnspan=2, sticky='ew', pady=(5, 5))
else:
error_label = ttk.Label(card_details_frame, text="No data found for this card.", font=label_font)
error_label.grid(row=0, column=0, sticky="w", padx=(0, 10), pady=5)
# Global dictionary to store image paths for each deck
decks = {f"Deck_{i+1}": [] for i in range(10)}
boxes = []
def update_deck_display(container_frame, selected_images):
for widget in container_frame.winfo_children():
if isinstance(widget, tk.Frame) and not any(isinstance(w, tk.Label) for w in widget.winfo_children()):
widget.destroy()
row_frame = tk.Frame(container_frame)
row_frame.pack(pady=5)
col = 0
for img_path in selected_images:
img = Image.open(img_path)
img = img.resize((90, 120), Image.LANCZOS)
img = ImageTk.PhotoImage(img)
box = tk.Frame(row_frame, width=90, height=120, bg='lightgray', borderwidth=1, relief='solid')
box.pack(side='left', padx=5)
box.pack_propagate(False)
label = tk.Label(box, image=img)
label.image = img
label.pack(expand=True)
col += 1
if col >= 4:
row_frame = tk.Frame(container_frame)
row_frame.pack(pady=5)
col = 0
def on_box_click(deck_label, selected_images):
new_window = tk.Toplevel(window, width=1000, height=1925)
build_deck_page(new_window, selected_images, deck_label['text'].replace(" ", "_"), deck_label.master)
def deck_builder_page():
deck_builder_frame = ScrolledFrame(main_frame, autohide=True)
deck_builder_frame.pack(fill=BOTH, expand=YES, padx=10, pady=10)
box_frame = tk.Frame(deck_builder_frame)
box_frame.pack(pady=10, padx=10)
for i in range(10):
container_frame = tk.Frame(box_frame, width=500, height=400, bg='white', borderwidth=1, relief='solid')
container_frame.grid(row=i//3, column=i%3, padx=5, pady=5)
container_frame.pack_propagate(False)
deck_label = tk.Label(container_frame, text=f'Deck {i+1}', font=('Showcard Gothic', 16, 'bold'))
deck_label.pack(side='top', pady=10)
selected_images = decks[deck_label['text'].replace(" ", "_")] # Reference the correct list for the deck
deck_label.bind("<Button-1>", lambda e, deck_label=deck_label, selected_images=selected_images: on_box_click(deck_label, selected_images))
# Update the deck display initially
update_deck_display(container_frame, selected_images)
result_button = tk.Button(container_frame, text=f'Result {i+1}', width=10, height=1, bg='gray', fg='white')
result_button.pack(side='bottom', pady=20)
result_button.bind("<Button-1>", lambda e, result_name=f'Result_{i+1}': result_page(result_name))
def result_page(result_name):
result_window = tk.Toplevel(window)
result_window.title(f'{result_name} - Result')
result_window.geometry('1200x1000')
def get_card_properties(image_paths):
conn = sqlite3.connect('clash_royale.db')
cursor = conn.cursor()
card_properties = {}
for path in image_paths:
cursor.execute("""
SELECT
property,
(CASE
WHEN property IN ('win_conditions') THEN 'Win Conditions'
WHEN property IN ('spells') THEN 'Spells'
WHEN property IN ('buildings') THEN 'Buildings'
WHEN property IN ('mini_tanks') THEN 'Mini Tanks'
WHEN property IN ('damage_units') THEN 'Damage Units'
END) as category,
elixir
FROM profile_cards
WHERE image_path=?""", (os.path.basename(path),))
result = cursor.fetchone()
if result:
card_properties[path] = (result[1], result[2])
conn.close()
return card_properties
selected_image_paths = results[result_name]
card_properties = get_card_properties(selected_image_paths)
categories = {
'Win Conditions': [],
'Spells': [],
'Buildings': [],
'Mini Tanks': [],
'Damage Units': []
}
elixir_values = []
for path, (category, elixir) in card_properties.items():
if category in categories:
categories[category].append(path)
elixir_values.append(elixir)
frames = {}
# Evaluation of the deck
evaluation = {
'Win Conditions': (1, 2),
'Spells': (1, 3),
'Mini Tanks': (0, 2),
'Buildings': (0, 2),
'Damage Units': (2, 4)
}
evaluations = {}
for category, (min_count, max_count) in evaluation.items():
count = len(categories[category])
result = "- Good" if min_count <= count <= max_count else "- Bad"
evaluations[category] = result
for category in categories:
frame = tk.Frame(result_window)
frame.pack(fill=tk.X, pady=5)
title_frame = tk.Frame(frame)
title_frame.pack(fill=tk.X)
title = tk.Label(title_frame, text=category, font=("Showcard Gothic", 16, "bold"))
title.pack(side=tk.LEFT, anchor="w", padx=10)
result_label = tk.Label(title_frame, text=f"{evaluations[category]}", font=("Showcard Gothic", 12, "bold"))
result_label.pack(side=tk.LEFT, padx=10)
frames[category] = frame
for category, paths in categories.items():
row_frame = tk.Frame(frames[category])
row_frame.pack(pady=5)
col = 0
if not paths:
# Add a blank space if there are no images for this category
blank_space = tk.Label(row_frame, text=" \n\n\n\n")
blank_space.pack(side=tk.LEFT, padx=5)
else:
for path in paths:
img = Image.open(path)
img = img.resize((90, 120), Image.LANCZOS)
img = ImageTk.PhotoImage(img)
panel = tk.Label(row_frame, image=img, compound=tk.LEFT, bd=0, padx=5, pady=5)
panel.image = img
panel.pack(side=tk.LEFT, padx=5)
col += 1
if col >= 8:
row_frame = tk.Frame(frames[category])
row_frame.pack(pady=5)
col = 0
if elixir_values:
average_elixir = sum(elixir_values) / len(elixir_values)
avg_elixir_label = tk.Label(result_window, text=f"Average Elixir: {average_elixir:.2f}", font=("Showcard Gothic", 16, "bold"))
avg_elixir_label.pack(pady=10)
else:
avg_elixir_label = tk.Label(result_window, text="Average Elixir: N/A", font=("Showcard Gothic", 16, "bold"))
avg_elixir_label.pack(pady=10)
# Global dictionary to store image paths for each result page
results = {f"Result_{i+1}": [] for i in range(10)}
def build_deck_page(new_window, selected_image_paths, deck_name, container_frame, category=None):
new_window.geometry("1250x800")
new_window.transient(window)
def clear_frame(frame):
for widget in frame.winfo_children():
widget.destroy()
def show_categories(frame, category):
clear_frame(frame)
if category == 'elixir':
query = """
SELECT elixir, image_path FROM profile_cards
ORDER BY
CASE
WHEN elixir = '1' THEN 1
WHEN elixir = '2' THEN 2
WHEN elixir = '3' THEN 3
WHEN elixir = '4' THEN 4
WHEN elixir = '5' THEN 5
WHEN elixir = '6' THEN 6
WHEN elixir = '7' THEN 7
WHEN elixir = '8' THEN 8
WHEN elixir = '9' THEN 9
WHEN elixir = '10' THEN 10
END
"""
data = get_data_from_db(query)
elif category == 'arena':
query = """
SELECT arena, image_path FROM profile_cards
ORDER BY
CASE
WHEN arena = '0' THEN 1
WHEN arena = '1' THEN 2
WHEN arena = '2' THEN 3
WHEN arena = '3' THEN 4
WHEN arena = '4' THEN 5
WHEN arena = '5' THEN 6
WHEN arena = '6' THEN 7
WHEN arena = '7' THEN 8
WHEN arena = '8' THEN 9
WHEN arena = '9' THEN 10
WHEN arena = '10' THEN 11
WHEN arena = '11' THEN 12
WHEN arena = '12' THEN 13
WHEN arena = '13' THEN 14
WHEN arena = '14' THEN 15
WHEN arena = '15' THEN 16
WHEN arena = '16' THEN 17
WHEN arena = '17' THEN 18
WHEN arena = '18' THEN 19
END
"""
data = get_data_from_db(query)
elif category == 'type':
query = """
SELECT card_type, image_path FROM profile_cards
ORDER BY
CASE
WHEN card_type = 'Spell' THEN 1
WHEN card_type = 'Troop' THEN 2
WHEN card_type = 'Building' THEN 3
END
"""
data = get_data_from_db(query)
elif category == 'rarity':
query = """
SELECT rarity, image_path FROM profile_cards
ORDER BY
CASE
WHEN rarity = 'common' THEN 1
WHEN rarity = 'rare' THEN 2
WHEN rarity = 'epic' THEN 3
WHEN rarity = 'legendary' THEN 4
WHEN rarity = 'champion' THEN 5
WHEN rarity = 'funny' THEN 6
END
"""
data = get_data_from_db(query)
button_frame = tk.Frame(frame)
button_frame.pack(fill=tk.X, padx=10, pady=5)
type_button = ttk.Button(button_frame, text='Type', command=lambda: show_categories(frame, 'type'))
type_button.pack(side=tk.LEFT, padx=5)
arena_button = ttk.Button(button_frame, text='Arena', command=lambda: show_categories(frame, 'arena'))
arena_button.pack(side=tk.LEFT, padx=5)
elixir_button = ttk.Button(button_frame, text='Elixir', command=lambda: show_categories(frame, 'elixir'))
elixir_button.pack(side=tk.LEFT, padx=5)
rarity_button = ttk.Button(button_frame, text='Rarity', command=lambda: show_categories(frame, 'rarity'))
rarity_button.pack(side=tk.LEFT, padx=5)
category_frame = ScrolledFrame(frame, autohide=True)
category_frame.pack(fill=tk.BOTH, expand=tk.YES, padx=10, pady=10)
current_title = None
row = 0
col = 0
for title, filename in data:
if title != current_title:
if current_title is not None:
row += 1
current_title = title
title_label = tk.Label(category_frame, text=current_title, font=("Showcard Gothic", 16, "bold"))
title_label.grid(row=row, column=0, columnspan=13, pady=(10, 0), sticky="w")
row += 1
col = 0
img_path = os.path.join("clash-royale-card-elixir", filename)
if os.path.isfile(img_path):
img = Image.open(img_path)
img = img.resize((90, 120), Image.LANCZOS)
img = ImageTk.PhotoImage(img)
panel = tk.Label(category_frame, image=img, compound=tk.LEFT, bd=0, padx=5, pady=5)
panel.image = img
panel.grid(row=row, column=col, sticky="w")
panel.bind("<Button-1>", lambda event, img_path=img_path: on_image_click(event, img_path))
col += 1
if col >= 13:
row += 1
col = 0
def on_image_click(event, img_path):
if img_path not in selected_image_paths:
if len(selected_image_paths) < 8:
selected_image_paths.append(img_path)
row, col = 0, 0
clear_frame(deck_frame)
for img_path in selected_image_paths:
img = Image.open(img_path)
img = img.resize((90, 120), Image.LANCZOS)
img = ImageTk.PhotoImage(img)
panel = tk.Label(deck_frame, image=img, compound=tk.LEFT, bd=0, padx=5, pady=5)
panel.image = img
panel.grid(row=row, column=col)
col += 1
if col >= 13:
col = 0
row += 1
panel.bind("<Button-1>", lambda event, img_path=img_path: remove_image_from_deck(event, img_path))
else:
messagebox.showwarning("Limit Reached", "You can only choose 8 cards.")
else:
messagebox.showwarning("Repeated Card", "You have already chosen this card.")
def remove_image_from_deck(event, img_path):
selected_image_paths.remove(img_path)
row, col = 0, 0
clear_frame(deck_frame)
for img_path in selected_image_paths:
img = Image.open(img_path)
img = img.resize((90, 120), Image.LANCZOS)
img = ImageTk.PhotoImage(img)
panel = tk.Label(deck_frame, image=img, compound=tk.LEFT, bd=0, padx=5, pady=5)
panel.image = img
panel.grid(row=row, column=col)
col += 1
if col >= 13:
col = 0
row += 1
panel.bind("<Button-1>", lambda event, img_path=img_path: remove_image_from_deck(event, img_path))
def save_deck():
if len(selected_image_paths) != 8:
messagebox.showwarning("Invalid Deck", "You must choose exactly 8 cards.")
return
decks[deck_name] = list(selected_image_paths)
result_name = f"Result_{deck_name.split('_')[1]}"
results[result_name] = list(selected_image_paths)
messagebox.showinfo("Success", f"{deck_name} has been saved with {len(selected_image_paths)} cards.")
update_deck_display(container_frame, selected_image_paths)
def clear_deck():
selected_image_paths.clear()
clear_frame(deck_frame)
deck_frame = tk.Frame(new_window)
deck_frame.pack(side=BOTTOM, fill=X)
save_button = tk.Button(button_frame, text="Save", command=save_deck)
save_button.pack(side=RIGHT, padx=10)
clear_button = tk.Button(button_frame, text='Clear', command=clear_deck)
clear_button.pack(side=RIGHT, padx=10)
if category:
show_categories(new_window, category)
else:
show_categories(new_window, 'rarity')
def save_card_to_file(name, rarity, elixir, card_type, arena, description, hitpoints, damage, card_range, stun_duration, shield, movement_speed, radius, image_path):
if not name or not rarity or not elixir or not card_type or not arena or not description:
messagebox.showwarning("Input Error", "Name, Rarity, Elixir, Type, Arena, and Description are required fields.")
return
try:
elixir = int(elixir)
hitpoints = int(hitpoints)
damage = int(damage)
card_range = int(card_range)
stun_duration = float(stun_duration)
radius = float(radius)
except ValueError:
messagebox.showwarning("Input Error", "Elixir, Hitpoints, Damage, Range, Stun Duration, and Radius must be numbers.")
return
image_path = os.path.basename(image_path)
conn = sqlite3.connect('clash_royale.db')
cursor = conn.cursor()
cursor.execute('''
INSERT INTO profile_cards (name, rarity, elixir, card_type, arena, description, hitpoints, damage, card_range, stun_duration, shield, movement_speed, radius, image_path)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', (name, rarity, elixir, card_type, arena, description.strip(), hitpoints, damage, card_range, stun_duration, shield, movement_speed, radius, image_path))
conn.commit()
conn.close()
messagebox.showinfo("Success", "Card saved successfully.")
def upload_image(image_path_var):
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename(title="Select an image", filetypes=[('Image files', '*.png *.jpg *.jpeg')])
root.destroy()
if file_path:
save_dir = 'clash-royale-card-elixir'
if not os.path.exists(save_dir):
os.makedirs(save_dir)
file_name = os.path.basename(file_path)
save_path = os.path.join(save_dir, file_name)
shutil.copy(file_path, save_path)
image_path_var.set(save_path)
def profile_maker_page():
profile_maker_frame = ScrolledFrame(main_frame, padding=5, height=10, autohide=True)
profile_maker_frame.pack(fill=BOTH, expand=YES)
title_label = tk.Label(profile_maker_frame, text="Profile Maker", font=('Showcard Gothic', 25, 'bold'))
title_label.pack(pady=10)
form_frame = tk.Frame(profile_maker_frame)
form_frame.pack(pady=10, padx=10)
name_label = tk.Label(form_frame, text="Card Name:")
name_label.grid(row=0, column=0, padx=5, pady=5)
name_entry = tk.Entry(form_frame)
name_entry.grid(row=0, column=1, padx=5, pady=5)
rarity_label = tk.Label(form_frame, text="Rarity:")
rarity_label.grid(row=1, column=0, padx=5, pady=5)
rarity_entry = tk.Entry(form_frame)
rarity_entry.grid(row=1, column=1, padx=5, pady=5)
elixir_label = tk.Label(form_frame, text="Elixir Cost:")
elixir_label.grid(row=2, column=0, padx=5, pady=5)
elixir_entry = tk.Entry(form_frame)
elixir_entry.grid(row=2, column=1, padx=5, pady=5)
type_label = tk.Label(form_frame, text="Card Type:")
type_label.grid(row=3, column=0, padx=5, pady=5)
type_entry = tk.Entry(form_frame)
type_entry.grid(row=3, column=1, padx=5, pady=5)
arena_label = tk.Label(form_frame, text="Arena:")
arena_label.grid(row=4, column=0, padx=5, pady=5)
arena_entry = tk.Entry(form_frame)
arena_entry.grid(row=4, column=1, padx=5, pady=5)
description_label = tk.Label(form_frame, text="Description:")
description_label.grid(row=5, column=0, padx=5, pady=5)
description_text = tk.Text(form_frame, height=5, width=40)
description_text.grid(row=5, column=1, padx=5, pady=5)
hitpoints_label = tk.Label(form_frame, text="Hitpoints:")
hitpoints_label.grid(row=6, column=0, padx=5, pady=5)
hitpoints_entry = tk.Entry(form_frame)