forked from quasar098/midi-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigpage.py
352 lines (304 loc) · 15.2 KB
/
configpage.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
from utils import *
import pygame
import pygame_gui as pgui
from os import listdir, system
import webbrowser
class ConfigPage:
@property
def made_with_pgui_rect(self):
return self.made_with_pgui_surf.get_rect(bottomleft=(30, Config.SCREEN_HEIGHT-30))
def __init__(self):
self.active = False
self.made_with_pgui_surf = get_font("./assets/poppins-regular.ttf").render("Config page made with pygame_gui library", True, (255, 255, 255))
# pygame_gui stuff
self.ui_manager = pgui.UIManager((Config.SCREEN_WIDTH, Config.SCREEN_HEIGHT))
self.back_button = pgui.elements.UIButton(
relative_rect=pygame.Rect((Config.SCREEN_WIDTH-120, 30, 90, 30)),
text="Back",
manager=self.ui_manager
)
# all attributes matching /s_.+/ are "s"ettings
self.s_camera_mode = pgui.elements.UIDropDownMenu(
["Center", "Lazy", "Smoothed (Default)", "Predictive"],
relative_rect=pygame.Rect((300, 30, 300, 30)),
starting_option=["Center", "Lazy", "Smoothed (Default)", "Predictive"][Config.camera_mode],
manager=self.ui_manager
)
self.s_camera_mode_label = pgui.elements.UILabel(
relative_rect=pygame.Rect((30, 30, 240, 30)),
text="Camera mode:",
manager=self.ui_manager
)
self.s_seed = pgui.elements.UITextEntryLine(
relative_rect=pygame.Rect((300, 90, 300, 30)),
placeholder_text="Default is random number",
manager=self.ui_manager
)
self.s_seed.set_allowed_characters('numbers')
self.s_seed.set_text(str(Config.seed if Config.seed is not None else ''))
self.s_seed_label = pgui.elements.UILabel(
relative_rect=pygame.Rect((30, 90, 240, 30)),
text="RNG seed:",
manager=self.ui_manager
)
self.s_start_playing_delay = pgui.elements.UIHorizontalSlider(
relative_rect=pygame.Rect((300, 150, 300, 30)),
start_value=Config.start_playing_delay,
value_range=(1000, 5000),
manager=self.ui_manager
)
self.s_start_playing_delay_label = pgui.elements.UILabel(
relative_rect=pygame.Rect((30, 150, 240, 30)),
text=f"Starting time delay ({self.s_start_playing_delay.get_current_value()}ms):",
manager=self.ui_manager
)
self.s_max_notes = pgui.elements.UITextEntryLine(
relative_rect=pygame.Rect((300, 210, 300, 30)),
placeholder_text="Default is infinity",
manager=self.ui_manager
)
self.s_max_notes.set_allowed_characters('numbers')
self.s_max_notes.set_text(str(Config.max_notes if Config.max_notes is not None else ''))
self.s_max_notes_label = pgui.elements.UILabel(
relative_rect=pygame.Rect((30, 210, 240, 30)),
text="Max notes to generate:",
manager=self.ui_manager
)
self.s_bounce_min_spacing = pgui.elements.UIHorizontalSlider(
relative_rect=pygame.Rect((300, 270, 300, 30)),
start_value=Config.bounce_min_spacing,
value_range=(5, 50),
manager=self.ui_manager
)
self.s_bounce_min_spacing_label = pgui.elements.UILabel(
relative_rect=pygame.Rect((30, 270, 240, 30)),
text=f"Bounce min spacing ({Config.bounce_min_spacing}ms):",
manager=self.ui_manager
)
self.s_square_speed = pgui.elements.UIHorizontalSlider(
relative_rect=pygame.Rect((300, 330, 300, 30)),
start_value=Config.square_speed,
value_range=(100, 2000),
manager=self.ui_manager
)
self.s_square_speed_label = pgui.elements.UILabel(
relative_rect=pygame.Rect((30, 330, 240, 30)),
text=f"Square speed ({Config.square_speed} pixels/s):",
manager=self.ui_manager
)
self.s_music_offset = pgui.elements.UIHorizontalSlider(
relative_rect=pygame.Rect((300, 390, 300, 30)),
start_value=Config.music_offset,
value_range=(-500, 500),
manager=self.ui_manager
)
self.s_music_offset_label = pgui.elements.UILabel(
relative_rect=pygame.Rect((30, 390, 240, 30)),
text=f"Music offset ({Config.music_offset}ms):",
manager=self.ui_manager
)
self.s_direction_change_chance = pgui.elements.UIHorizontalSlider(
relative_rect=pygame.Rect((300, 450, 300, 30)),
start_value=Config.direction_change_chance,
value_range=(0, 100),
manager=self.ui_manager
)
self.s_direction_change_chance_label = pgui.elements.UILabel(
relative_rect=pygame.Rect((30, 450, 240, 30)),
text=f"Change dir chance ({Config.direction_change_chance}%):",
manager=self.ui_manager
)
self.s_hp_drain_rate = pgui.elements.UIHorizontalSlider(
relative_rect=pygame.Rect((300, 510, 300, 30)),
start_value=Config.hp_drain_rate,
value_range=(3, 20),
manager=self.ui_manager
)
self.s_hp_drain_rate_label = pgui.elements.UILabel(
relative_rect=pygame.Rect((30, 510, 240, 30)),
text=f"HP drain rate ({Config.hp_drain_rate}/s):",
manager=self.ui_manager
)
# audio and general settings
self.s_game_volume = pgui.elements.UIHorizontalSlider(
relative_rect=pygame.Rect((930, 30, 300, 30)),
start_value=Config.volume,
value_range=(0, 100),
manager=self.ui_manager
)
self.s_game_volume_label = pgui.elements.UILabel(
relative_rect=pygame.Rect((630, 30, 240, 30)),
text=f"Music volume ({Config.volume}%):",
manager=self.ui_manager
)
self.s_color_theme = pgui.elements.UIDropDownMenu(
[theme for theme in Config.color_themes],
relative_rect=pygame.Rect((930, 90, 300, 30)),
starting_option=Config.theme,
manager=self.ui_manager
)
self.s_color_theme_label = pgui.elements.UILabel(
relative_rect=pygame.Rect((630, 90, 240, 30)),
text="Color theme:",
manager=self.ui_manager
)
self.s_theatre_mode = pgui.elements.UIDropDownMenu(
["Off", "On"],
relative_rect=pygame.Rect((930, 150, 300, 30)),
starting_option=["Off", "On"][int(Config.theatre_mode)],
manager=self.ui_manager
)
self.s_theatre_mode_label = pgui.elements.UILabel(
relative_rect=pygame.Rect((630, 150, 240, 30)),
text="Theatre mode:",
manager=self.ui_manager
)
self.s_particle_trail = pgui.elements.UIDropDownMenu(
["Off", "On"],
relative_rect=pygame.Rect((930, 210, 300, 30)),
starting_option=["Off", "On"][int(Config.particle_trail)],
manager=self.ui_manager
)
self.s_particle_trail_label = pgui.elements.UILabel(
relative_rect=pygame.Rect((630, 210, 240, 30)),
text="Particle trail:",
manager=self.ui_manager
)
self.s_shader = pgui.elements.UIDropDownMenu(
[_ for _ in listdir("./assets/shaders/") if _.endswith(".glsl")],
relative_rect=pygame.Rect((930, 270, 300, 30)),
starting_option=Config.shader_file_name,
manager=self.ui_manager
)
self.s_shader_label = pgui.elements.UILabel(
relative_rect=pygame.Rect(630, 270, 240, 30),
text="Shader (requires restart):",
manager=self.ui_manager
)
# reset button
self.s_reset_button = pgui.elements.UIButton(
relative_rect=pygame.Rect((Config.SCREEN_WIDTH-330, Config.SCREEN_HEIGHT-60, 300, 30)),
text="Reset to default",
manager=self.ui_manager
)
def handle_event(self, event: pygame.event.Event):
if not self.active:
return
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
if self.made_with_pgui_rect.collidepoint(pygame.mouse.get_pos()):
webbrowser.open("https://github.com/MyreMylar/pygame_gui")
if event.type == pgui.UI_BUTTON_PRESSED:
if event.ui_element == self.back_button:
play_sound("wood.wav")
return True
if event.ui_element == self.s_reset_button:
# todo: rework this
Config.theme = "dark"
self.s_color_theme.selected_option = "dark"
self.s_color_theme.current_state.finish()
self.s_color_theme.current_state.selected_option = "dark"
self.s_color_theme.current_state.start()
Config.shader_file_name = "none.glsl"
self.s_shader.selected_option = "none.glsl"
self.s_shader.current_state.finish()
self.s_shader.current_state.selected_option = "none.glsl"
self.s_shader.current_state.start()
Config.seed = None
self.s_seed.set_text("")
Config.camera_mode = 2
self.s_camera_mode.selected_option = "Smoothed (Default)"
self.s_camera_mode.current_state.finish()
self.s_camera_mode.current_state.selected_option = "Smoothed (Default)"
self.s_camera_mode.current_state.start()
Config.start_playing_delay = 3000
self.s_start_playing_delay.set_current_value(3000)
self.s_start_playing_delay_label.set_text(f"Starting time delay ({self.s_start_playing_delay.get_current_value()}ms):")
Config.max_notes = None
self.s_max_notes.set_text("")
Config.bounce_min_spacing = 30
self.s_bounce_min_spacing.set_current_value(30)
self.s_bounce_min_spacing_label.set_text(f"Bounce min spacing ({Config.bounce_min_spacing}ms):")
Config.square_speed = 600
self.s_square_speed.set_current_value(600)
self.s_square_speed_label.set_text(f"Square speed ({Config.square_speed} pixels/s):")
Config.volume = 70
pygame.mixer.music.set_volume(70/100)
self.s_game_volume.set_current_value(70)
self.s_game_volume_label.set_text(f"Music volume ({Config.volume}%):")
Config.music_offset = -300
self.s_music_offset.set_current_value(-300)
self.s_music_offset_label.set_text(f"Music offset ({Config.music_offset}ms):")
Config.direction_change_chance = 30
self.s_direction_change_chance.set_current_value(30)
self.s_direction_change_chance_label.set_text(f"Change dir chance ({Config.direction_change_chance}%):")
Config.hp_drain_rate = 10
self.s_hp_drain_rate.set_current_value(10)
self.s_hp_drain_rate_label.set_text(f"HP drain rate ({Config.hp_drain_rate}/s):")
Config.theatre_mode = False
self.s_theatre_mode.selected_option = "Off"
self.s_theatre_mode.current_state.finish()
self.s_theatre_mode.current_state.selected_option = "Off"
self.s_theatre_mode.current_state.start()
Config.particle_trail = True
self.s_particle_trail.selected_option = "On"
self.s_particle_trail.current_state.finish()
self.s_particle_trail.current_state.selected_option = "On"
self.s_particle_trail.current_state.start()
play_sound("wood.wav")
if event.type == pgui.UI_DROP_DOWN_MENU_CHANGED:
play_sound("wood.wav")
if event.ui_element == self.s_camera_mode:
Config.camera_mode = "CLSP".index(event.text[0])
if event.ui_element == self.s_color_theme:
Config.theme = event.text
if event.ui_element == self.s_theatre_mode:
Config.theatre_mode = bool("fn".index(event.text[1]))
if event.ui_element == self.s_particle_trail:
Config.particle_trail = bool("fn".index(event.text[1]))
if event.ui_element == self.s_shader:
Config.shader_file_name = event.text
if event.type == pgui.UI_TEXT_ENTRY_CHANGED:
if event.ui_element == self.s_seed:
text: str = event.text
if text.isnumeric() and len(text):
Config.seed = int(text)
else:
Config.seed = None
if event.ui_element == self.s_max_notes:
text: str = event.text
if text.isnumeric() and len(text):
Config.max_notes = int(text)
else:
Config.max_notes = None
if event.type == pgui.UI_HORIZONTAL_SLIDER_MOVED:
if event.ui_element == self.s_start_playing_delay:
self.s_start_playing_delay_label.set_text(f"Starting time delay ({event.value}ms):")
Config.start_playing_delay = event.value
if event.ui_element == self.s_bounce_min_spacing:
self.s_bounce_min_spacing_label.set_text(f"Bounce min spacing ({event.value}ms):")
Config.bounce_min_spacing = event.value
if event.ui_element == self.s_square_speed:
rounded = round(event.value, -2)
self.s_square_speed_label.set_text(f"Square speed ({rounded} pixels/s):")
Config.square_speed = rounded
if event.ui_element == self.s_game_volume:
self.s_game_volume_label.set_text(f"Music volume ({event.value}%):")
Config.volume = event.value
pygame.mixer.music.set_volume(event.value/100)
if event.ui_element == self.s_music_offset:
self.s_music_offset_label.set_text(f"Music offset ({event.value}ms):")
Config.music_offset = event.value
if event.ui_element == self.s_direction_change_chance:
self.s_direction_change_chance_label.set_text(f"Change dir chance ({event.value}%):")
Config.direction_change_chance = event.value
if event.ui_element == self.s_hp_drain_rate:
self.s_hp_drain_rate_label.set_text(f"HP drain rate ({event.value}/s):")
Config.hp_drain_rate = event.value
self.ui_manager.process_events(event)
def draw(self, screen: pygame.Surface):
if not self.active:
return
self.ui_manager.update(1/FRAMERATE) # supposed to use dt but whatever
self.ui_manager.draw_ui(screen)
screen.blit(self.made_with_pgui_surf, self.made_with_pgui_rect)