-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsettings.py
More file actions
135 lines (107 loc) · 4.43 KB
/
settings.py
File metadata and controls
135 lines (107 loc) · 4.43 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
import pygame
import pygame_gui
import chess
import pygame.transform
pygame.init()
ICON = pygame.image.load(chess.resource_path("pieces/bp.png"))
screen = pygame.display.set_mode((chess.WIDTH, chess.HEIGHT))
pygame.display.set_caption("Chess")
pygame.display.set_icon(ICON)
clock: pygame.Clock = pygame.time.Clock()
restart_requested = False
if "evil_mode" not in chess.settings:
chess.settings["evil_mode"] = False
theme_file = chess.resource_path("theme.json")
manager = pygame_gui.UIManager((chess.WIDTH, chess.HEIGHT), theme_path=theme_file)
font_big = pygame.font.SysFont("Arial", 40, bold=True)
settings_text = chess.text_outline("Settings", font_size=100, outline_width=4)
settings_rect = settings_text.get_rect(center=(chess.WIDTH//2, chess.HEIGHT//4))
size600_button = pygame_gui.elements.UIButton(
relative_rect=pygame.Rect(chess.WIDTH//2 - 100, chess.HEIGHT//2 - 60, 200, 50),
text="600 x 600",
manager=manager,
)
size800_button = pygame_gui.elements.UIButton(
relative_rect=pygame.Rect(chess.WIDTH//2 - 100, chess.HEIGHT//2 , 200, 50),
text="800 x 800",
manager=manager
)
size1000_button = pygame_gui.elements.UIButton(
relative_rect=pygame.Rect(chess.WIDTH//2 - 100, chess.HEIGHT//2 + 60, 200, 50),
text="1000 x 1000",
manager=manager
)
back_button = pygame_gui.elements.UIButton(
relative_rect=pygame.Rect(chess.WIDTH//2 - 100, chess.HEIGHT//2 + 120, 200, 50),
text="back",
manager=manager,
)
sb = pygame.image.load(chess.resource_path(r"pieces\ws.png"))
soldier_button = pygame.transform.scale(sb, (chess.SQUARE_SIZE, chess.SQUARE_SIZE))
e = pygame.image.load(chess.resource_path(r"pieces\evil.png"))
evil_text = pygame.transform.scale(e, (chess.SQUARE_SIZE * 4, chess.SQUARE_SIZE*2))
evil_rect = evil_text.get_rect(center=(chess.WIDTH // 2, (chess.HEIGHT // 4) + chess.SQUARE_SIZE * 0.79))
def main():
global restart_requested, evil_mode
running = True
# Build bg and blur here
bg = chess.build_bg()
try:
blurred = pygame.transform.box_blur(bg, radius=7)
except AttributeError:
blurred = bg
while running:
time_delta = clock.tick(60) / 1000.0
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
return
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
mouse = pygame.mouse.get_pos()
mx, my = mouse
if mx // chess.SQUARE_SIZE == 0 and my // chess.SQUARE_SIZE == 7:
chess.settings["evil_mode"] = not chess.settings["evil_mode"]
chess.save_settings(chess.settings)
if event.type == pygame_gui.UI_BUTTON_PRESSED:
if event.ui_element == back_button:
import menu
menu.main()
elif event.ui_element == size600_button:
chess.settings["screen_size"] = 600
chess.save_settings(chess.settings)
restart_requested = True
elif event.ui_element == size800_button:
chess.settings["screen_size"] = 800
chess.save_settings(chess.settings)
restart_requested = True
elif event.ui_element == size1000_button:
chess.settings["screen_size"] = 1000
chess.save_settings(chess.settings)
restart_requested = True
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
import menu
menu.main()
manager.process_events(event)
manager.update(time_delta)
screen.blit(blurred)
screen.blit(settings_text, settings_rect)
screen.blit(soldier_button, (0*chess.SQUARE_SIZE,7*chess.SQUARE_SIZE))
manager.draw_ui(screen)
if chess.settings.get("evil_mode"):
screen.blit(evil_text, evil_rect)
pygame.display.flip()
if restart_requested:
running = False
if restart_requested:
pygame.display.quit() # close only the window
chess.restart_program() # never returns
# normal exit back to menu
pygame.display.quit()
return
if __name__ == "__main__":
try:
main()
except pygame.error as e:
if str(e) != "video system not initialized" or str(e) != "Surface is not initialized":
print(e)