def create_message_window(self): self.button_response_timer.tick() self.message_window = UIMessageWindow( rect=pygame.Rect( (random.randint(0, self.options.resolution[0] - 300), random.randint(0, self.options.resolution[1] - 200)), (300, 250)), window_title='Test Message Window', html_message='<font color=normal_text>' 'This is a <a href="test">test</a> message to see if ' 'this box <a href=actually_link>actually</a> works.' '' 'In <i>bibendum</i> orci et velit</b> gravida lacinia.<br><br><br> ' 'In hac a habitasse to platea dictumst.<br>' ' <font color=#4CD656 size=4>Vivamus I interdum mollis lacus nec ' 'porttitor.<br> Morbi' ' accumsan, lectus at' ' tincidunt to dictum, neque <font color=#879AF6>erat tristique' ' blob</font>,' ' sed a tempus for <b>nunc</b> dolor in nibh.<br>' ' Suspendisse in viverra dui <i>fringilla dolor laoreet</i>, sit amet ' 'on pharetra a ante' ' sollicitudin.</font>' '<br><br>' 'In <i>bibendum</i> orci et velit</b> gravida lacinia.<br><br><br> ' 'In hac a habitasse to platea dictumst.<br>' ' <font color=#4CD656 size=4>Vivamus I interdum mollis lacus nec ' 'porttitor.<br> Morbi' ' accumsan, lectus at' ' tincidunt to dictum, neque <font color=#879AF6>erat tristique ' 'erat</font>,' ' sed a tempus for <b>nunc</b> dolor in nibh.<br>' ' Suspendisse in viverra dui <i>fringilla dolor laoreet</i>, sit amet ' 'on pharetra a ante' ' sollicitudin.</font>' '<br><br>' 'In <i>bibendum</i> orci et velit</b> gravida lacinia.<br><br><br> ' 'In hac a habitasse to platea dictumst.<br>' ' <font color=#4CD656 size=4>Vivamus I interdum mollis lacus nec ' 'porttitor.<br> Morbi' ' accumsan, lectus at' ' tincidunt to dictum, neque <font color=#879AF6>erat tristique ' 'erat</font>,' ' sed a tempus for <b>nunc</b> dolor in nibh.<br>' ' Suspendisse in viverra dui <i>fringilla dolor laoreet</i>, ' 'sit amet on pharetra a ante' ' sollicitudin.</font>' '</font>', manager=self.ui_manager) time_taken = self.button_response_timer.tick() / 1000.0 # currently taking about 0.35 seconds down from 0.55 to create # an elaborately themed message window. # still feels a little slow but it's better than it was. print("Time taken to create message window: " + str(time_taken))
def __init__(self, tiled_level, hud_rect, all_square_sprites, ui_manager): self.editing_layer = 0 self.tiled_level = tiled_level self.hud_rect = hud_rect self.all_square_sprites = all_square_sprites self.ui_manager = ui_manager self.current_levels = [ file for file in os.listdir("data/levels/") if os.path.isfile(os.path.join("data/levels/", file)) ] self.left_mouse_held = False self.right_mouse_held = False self.need_to_refresh_tiles = True self.default_tile = [ pygame.Rect(0, 0, 0, 0), self.tiled_level.tile_map[0][0], "grass_tile", True, None ] self.held_tile_data = self.default_tile self.held_ai_spawn = None self.held_turret_square = None self.rect_of_tile = None self.hovered_rec = None self.rotate_selected_tile_left = False self.rotate_selected_tile_right = False self.all_palette_tile_sprites = pygame.sprite.Group() self.all_ai_spawn_sprites = pygame.sprite.Group() self.palette_page = 0 self.should_increase_palette_page = False self.should_decrease_palette_page = False self.remove_turret_square_icon = None self.place_turret_square_icon = None self.remove_waypoint_icon = None self.place_waypoint_icon = None self.right_click_mode = "place_tile" self.palette_tiles = [] self.palette_ai_spawns = [] self.num_ai_spawns = 3 self.tiles_per_page = 26 all_tiles_and_ai = len( self.tiled_level.all_tile_data.keys()) + self.num_ai_spawns self.max_pages = int(math.ceil(all_tiles_and_ai / self.tiles_per_page)) self.refresh_palette_tiles() self.left_scroll_held = False self.right_scroll_held = False self.up_scroll_held = False self.down_scroll_held = False self.map_scroll_speed = 256.0 self.map_start_pos = self.tiled_level.find_player_start() self.map_position = [self.map_start_pos[0], self.map_start_pos[1]] # self.map_editor_instructions = MapEditorInstructionsWindow([362, 100, 300, 250], fonts) instructions_message = ( "Arrow keys to scroll map <br>" "Left mouse click to select tile from palette<br>" "Right mouse click to place tile<br>" "'>' and '<' to rotate selected tile<br>" "F5 or quit to save map<br>") self.instruction_message_window = UIMessageWindow( pygame.Rect((362, 100), (300, 250)), "Instructions", instructions_message, self.ui_manager) self.level_name_label = UILabel(pygame.Rect((462, 8), (100, 34)), self.tiled_level.level_name, self.ui_manager, object_id="#screen_text") self.make_new_button = UIButton( pygame.Rect(870, self.hud_rect[1] + 24, 100, 20), "Make New", self.ui_manager) self.tile_set_button = UIButton( pygame.Rect(870, self.hud_rect[1] + 49, 100, 20), "Switch Tiles", self.ui_manager) self.playable_area_display = PlayableAreaDisplay() self.visible_way_point_circles = [] self.refresh_visible_waypoint_circles()
def process_event(self, event: pygame.event.Event) -> bool: if (event.type == pygame.USEREVENT and event.user_type == pygame_gui.UI_DROP_DOWN_MENU_CHANGED and event.ui_element == self.year_drop_down_menu): if self.settings["year"] != event.text: self.settings["year"] = event.text self.setting_changed['yrs'] = True self.any_settings_changed = True if (event.type == pygame.USEREVENT and event.user_type == pygame_gui.UI_DROP_DOWN_MENU_CHANGED and event.ui_element == self.lang_drop_down): if self.settings["language"] != event.text.lower(): self.settings["language"] = event.text.lower() self.setting_changed['lng'] = True self.any_settings_changed = True if (event.type == pygame.USEREVENT and event.user_type == pygame_gui.UI_DROP_DOWN_MENU_CHANGED and event.ui_element == self.resol_drop_down): resolution = self.make_res_tuple(event.text) if (self.settings["resolution"]['width'] != resolution[0] and self.settings["resolution"]['height'] != resolution[1]): self.settings["resolution"]['width'] = resolution[0] self.settings["resolution"]['height'] = resolution[1] self.setting_changed['res'] = True self.any_settings_changed = True if (event.type == pygame.USEREVENT and event.user_type == pygame_gui.UI_DROP_DOWN_MENU_CHANGED and event.ui_element == self.scr_mode_menu): self.settings = read_json() self.in_fullscreen = self.settings['in_fullscreen'] if self.in_fullscreen == "true": self.in_fullscreen = True else: self.in_fullscreen = False new_scr_mode = SettingsWindow.change_scr_for_lang( self.settings['language'], "turkce", event) print(new_scr_mode) if self.settings['screen_mode'] != new_scr_mode: self.settings['screen_mode'] = new_scr_mode screen_mode = self.settings['screen_mode'] if screen_mode == "borderless": if self.in_fullscreen: warning_rect = pygame.Rect((0, 0), (300, 300)) warning_rect.center = self.window_surface.get_rect( ).center self.warning_screen = UIMessageWindow( warning_rect, lang.strings["html_message_error_01"], self.manager, window_title=lang.strings['error'], object_id='#error_01') self.warning_screen.dismiss_button.text = lang.strings[ "dismiss"] self.warning_screen.dismiss_button.tool_tip_text = lang.strings[ 'dismiss_tip'] self.warning_screen.dismiss_button.rebuild() self.warning_screen.set_blocking(True) elif self.special_flags != pygame.NOFRAME: self.special_flags = pygame.NOFRAME self.setting_changed['scr'] = True self.any_settings_changed = True elif screen_mode == "windowed": if self.in_fullscreen: warning_rect = pygame.Rect((0, 0), (300, 300)) warning_rect.center = self.window_surface.get_rect( ).center self.warning_screen = UIMessageWindow( warning_rect, lang.strings["html_message_error_01"], self.manager, window_title=lang.strings['error'], object_id='#error_01') self.warning_screen.dismiss_button.text = lang.strings[ "dismiss"] self.warning_screen.dismiss_button.tool_tip_text = lang.strings[ 'dismiss_tip'] self.warning_screen.set_blocking(True) elif self.special_flags != 0: self.special_flags = 0 self.setting_changed['scr'] = True self.any_settings_changed = True if (event.type == pygame.USEREVENT and event.user_type == pygame_gui.UI_BUTTON_PRESSED and event.ui_object_id == '#settings_window.#keep_changes'): if self.any_settings_changed == True: if self.setting_changed['res'] == True: write_to(self.settings) pygame.event.post(GUI_WINDOW_RESOLUTION_CHANGED) elif self.setting_changed['lng'] == True: write_to(self.settings) pygame.event.post(GUI_LANUAGE_CHANGED) elif self.setting_changed['yrs'] == True: write_to(self.settings) elif self.setting_changed['fll'] == True: write_to(self.settings) pygame.event.post(GUI_TOGGLE_FULLSCREEN) elif self.setting_changed['scr'] == True: if self.special_flags == 0: write_to(self.settings) POST_SPECIAL_FLAG_CHANGE(self.special_flags) else: write_to(self.settings) POST_SPECIAL_FLAG_CHANGE(self.special_flags) lang.strings = lang.change_strings() saved_changes = False if self.setting_changed['res'] == True or self.setting_changed[ 'scr'] == True: saved_changes = True for key in self.setting_changed: if self.setting_changed[key] == True: self.setting_changed[key] = False self.any_settings_changed = False if saved_changes: pygame.event.post(GUI_CHANGES_MADE_TO_SETTINGS) else: print("no change to keep")
class MapEditor: def __init__(self, tiled_level, hud_rect, all_square_sprites, ui_manager): self.editing_layer = 0 self.tiled_level = tiled_level self.hud_rect = hud_rect self.all_square_sprites = all_square_sprites self.ui_manager = ui_manager self.current_levels = [ file for file in os.listdir("data/levels/") if os.path.isfile(os.path.join("data/levels/", file)) ] self.left_mouse_held = False self.right_mouse_held = False self.need_to_refresh_tiles = True self.default_tile = [ pygame.Rect(0, 0, 0, 0), self.tiled_level.tile_map[0][0], "grass_tile", True, None ] self.held_tile_data = self.default_tile self.held_ai_spawn = None self.held_turret_square = None self.rect_of_tile = None self.hovered_rec = None self.rotate_selected_tile_left = False self.rotate_selected_tile_right = False self.all_palette_tile_sprites = pygame.sprite.Group() self.all_ai_spawn_sprites = pygame.sprite.Group() self.palette_page = 0 self.should_increase_palette_page = False self.should_decrease_palette_page = False self.remove_turret_square_icon = None self.place_turret_square_icon = None self.remove_waypoint_icon = None self.place_waypoint_icon = None self.right_click_mode = "place_tile" self.palette_tiles = [] self.palette_ai_spawns = [] self.num_ai_spawns = 3 self.tiles_per_page = 26 all_tiles_and_ai = len( self.tiled_level.all_tile_data.keys()) + self.num_ai_spawns self.max_pages = int(math.ceil(all_tiles_and_ai / self.tiles_per_page)) self.refresh_palette_tiles() self.left_scroll_held = False self.right_scroll_held = False self.up_scroll_held = False self.down_scroll_held = False self.map_scroll_speed = 256.0 self.map_start_pos = self.tiled_level.find_player_start() self.map_position = [self.map_start_pos[0], self.map_start_pos[1]] # self.map_editor_instructions = MapEditorInstructionsWindow([362, 100, 300, 250], fonts) instructions_message = ( "Arrow keys to scroll map <br>" "Left mouse click to select tile from palette<br>" "Right mouse click to place tile<br>" "'>' and '<' to rotate selected tile<br>" "F5 or quit to save map<br>") self.instruction_message_window = UIMessageWindow( pygame.Rect((362, 100), (300, 250)), "Instructions", instructions_message, self.ui_manager) self.level_name_label = UILabel(pygame.Rect((462, 8), (100, 34)), self.tiled_level.level_name, self.ui_manager, object_id="#screen_text") self.make_new_button = UIButton( pygame.Rect(870, self.hud_rect[1] + 24, 100, 20), "Make New", self.ui_manager) self.tile_set_button = UIButton( pygame.Rect(870, self.hud_rect[1] + 49, 100, 20), "Switch Tiles", self.ui_manager) self.playable_area_display = PlayableAreaDisplay() self.visible_way_point_circles = [] self.refresh_visible_waypoint_circles() def end(self): if self.tile_set_button is not None: self.tile_set_button.kill() self.tile_set_button = None if self.make_new_button is not None: self.make_new_button.kill() self.make_new_button = None if self.level_name_label is not None: self.level_name_label.kill() self.level_name_label = None if self.instruction_message_window is not None: self.instruction_message_window.kill() self.instruction_message_window = None for circle in self.visible_way_point_circles: circle.kill() def refresh_visible_waypoint_circles(self): for circle in self.visible_way_point_circles: circle.kill() del circle self.visible_way_point_circles[:] = [] traversal_order = 1 if self.tiled_level.monster_walk_path.start_waypoint is not None: self.visible_way_point_circles.append( DrawableWaypointCircle( self.tiled_level.monster_walk_path.waypoint_radius, self.tiled_level.monster_walk_path.start_waypoint, self.ui_manager, traversal_order)) traversal_order += 1 for waypoint in self.tiled_level.monster_walk_path.waypoints: self.visible_way_point_circles.append( DrawableWaypointCircle( self.tiled_level.monster_walk_path.waypoint_radius, waypoint, self.ui_manager, traversal_order)) traversal_order += 1 def display_turret_placement_squares(self, screen): self.all_square_sprites.draw(screen) def increase_palette_pos(self, x_pos, y_pos): x_pos += self.tiled_level.tile_size[0] + 8 if x_pos > 800: x_pos = 40 y_pos += self.tiled_level.tile_size[1] + 8 return x_pos, y_pos def refresh_palette_tiles(self): self.all_palette_tile_sprites.empty() self.palette_tiles[:] = [] self.palette_ai_spawns[:] = [] x_pos = 40 y_pos = 40 sorted_tile_keys = sorted(self.tiled_level.all_tile_data.keys()) display_tile = self.palette_page * self.tiles_per_page max_tile = (self.palette_page * self.tiles_per_page) + self.tiles_per_page min_tile = len(sorted_tile_keys) + self.num_ai_spawns while display_tile < min_tile and display_tile < max_tile: if display_tile < len(sorted_tile_keys): tile_data = sorted_tile_keys[display_tile] self.palette_tiles.append( Tile([self.hud_rect[0] + x_pos, self.hud_rect[1] + y_pos], 0, self.tiled_level.all_tile_data[tile_data], self.editing_layer)) display_tile += 1 else: self.remove_turret_square_icon = RemoveTurretSquareIcon( [self.hud_rect[0] + x_pos, self.hud_rect[1] + y_pos], self.all_palette_tile_sprites) x_pos, y_pos = self.increase_palette_pos(x_pos, y_pos) display_tile += 1 self.place_turret_square_icon = PlaceTurretSquareIcon( [self.hud_rect[0] + x_pos, self.hud_rect[1] + y_pos], self.all_palette_tile_sprites) x_pos, y_pos = self.increase_palette_pos(x_pos, y_pos) display_tile += 1 self.remove_waypoint_icon = RemoveWaypointIcon( [self.hud_rect[0] + x_pos, self.hud_rect[1] + y_pos], self.all_palette_tile_sprites) x_pos, y_pos = self.increase_palette_pos(x_pos, y_pos) display_tile += 1 self.place_waypoint_icon = PlaceWaypointIcon( [self.hud_rect[0] + x_pos, self.hud_rect[1] + y_pos], self.all_palette_tile_sprites) x_pos, y_pos = self.increase_palette_pos(x_pos, y_pos) display_tile += 1 display_tile += self.num_ai_spawns x_pos, y_pos = self.increase_palette_pos(x_pos, y_pos) for tile in self.palette_tiles: self.all_palette_tile_sprites.add(tile) # for aiSpawn in self.paletteAISpawns: # self.allPaletteTileSprites.add(aiSpawn.sprite) def run(self, screen, background, all_tile_sprites, hud_rect, time_delta): running = True for event in pygame.event.get(): self.ui_manager.process_events(event) if event.type == USEREVENT: if event.user_type == "ui_button_pressed": if event.ui_element == self.make_new_button: new_level_num = len(self.current_levels) + 1 new_level_name = "Level " + str(new_level_num) self.tiled_level.change_level_name_and_save( new_level_name) self.level_name_label.set_text( self.tiled_level.level_name) elif event.ui_element == self.tile_set_button: self.tiled_level.toggle_tile_map() for tile in self.palette_tiles: tile.reload_tile_image_from_data( self.tiled_level.all_tile_data) if event.type == QUIT: self.tiled_level.save_tiles() running = False if event.type == MOUSEBUTTONDOWN: if event.button == 1: self.left_mouse_held = True if event.button == 3: self.right_mouse_held = True if event.type == MOUSEBUTTONUP: if event.button == 1: self.left_mouse_held = False if event.button == 3: self.right_mouse_held = False if event.type == KEYDOWN: if event.key == K_ESCAPE: self.tiled_level.save_tiles() running = False if event.key == K_F5: self.tiled_level.save_tiles() if event.key == K_PERIOD: self.rotate_selected_tile_right = True if event.key == K_COMMA: self.rotate_selected_tile_left = True if event.key == K_UP: self.up_scroll_held = True if event.key == K_DOWN: self.down_scroll_held = True if event.key == K_LEFT: self.left_scroll_held = True if event.key == K_RIGHT: self.right_scroll_held = True if event.key == K_1: self.editing_layer = 1 if event.key == K_0: self.editing_layer = 0 if event.key == K_RIGHTBRACKET: self.should_increase_palette_page = True if event.key == K_LEFTBRACKET: self.should_decrease_palette_page = True if event.type == KEYUP: if event.key == K_UP: self.up_scroll_held = False if event.key == K_DOWN: self.down_scroll_held = False if event.key == K_LEFT: self.left_scroll_held = False if event.key == K_RIGHT: self.right_scroll_held = False self.ui_manager.update(time_delta) if self.should_increase_palette_page: self.should_increase_palette_page = False if self.palette_page < self.max_pages - 1: self.palette_page += 1 else: self.palette_page = 0 # loop back round self.refresh_palette_tiles() if self.should_decrease_palette_page: self.should_decrease_palette_page = False if self.palette_page > 0: self.palette_page -= 1 else: self.palette_page = self.max_pages - 1 # loop back round self.refresh_palette_tiles() if self.up_scroll_held: self.map_position[1] -= self.map_scroll_speed * time_delta if self.map_position[1] < self.tiled_level.initial_screen_offset[1]: self.map_position[1] = self.tiled_level.initial_screen_offset[ 1] if self.down_scroll_held: self.map_position[1] += self.map_scroll_speed * time_delta y_limit = self.tiled_level.level_pixel_size[ 1] - self.tiled_level.initial_screen_offset[1] + self.hud_rect[ 1] if self.map_position[1] > y_limit: self.map_position[1] = y_limit if self.left_scroll_held: self.map_position[0] -= self.map_scroll_speed * time_delta if self.map_position[0] < self.tiled_level.initial_screen_offset[0]: self.map_position[0] = self.tiled_level.initial_screen_offset[ 0] if self.right_scroll_held: self.map_position[0] += self.map_scroll_speed * time_delta max_x = self.tiled_level.level_pixel_size[ 0] - self.tiled_level.initial_screen_offset[0] if self.map_position[0] > max_x: self.map_position[0] = max_x if self.rotate_selected_tile_right and self.held_tile_data[ 4] is not None: self.rotate_selected_tile_right = False self.held_tile_data[4].rotate_tile_right() self.need_to_refresh_tiles = True if self.rotate_selected_tile_left and self.held_tile_data[ 4] is not None: self.rotate_selected_tile_left = False self.held_tile_data[4].rotate_tile_left() self.need_to_refresh_tiles = True if self.left_mouse_held: click_pos = pygame.mouse.get_pos() if self.is_inside_hud(click_pos, hud_rect): self.held_tile_data = self.get_palette_tile_data_at_pos( click_pos) if self.held_tile_data is None: if self.remove_turret_square_icon.is_inside(click_pos): self.right_click_mode = "remove_turret_square" elif self.place_turret_square_icon.is_inside(click_pos): self.right_click_mode = "place_turret_square" elif self.remove_waypoint_icon.is_inside(click_pos): self.right_click_mode = "remove_waypoint" elif self.place_waypoint_icon.is_inside(click_pos): self.right_click_mode = "place_waypoint" else: self.right_click_mode = "place_tile" else: self.held_tile_data = self.tiled_level.get_tile_data_at_pos( click_pos, self.editing_layer) if self.right_mouse_held: click_pos = pygame.mouse.get_pos() if self.is_inside_hud(click_pos, hud_rect): pass else: angle = 0 if self.right_click_mode == "place_tile" and self.held_tile_data is not None: if self.held_tile_data[4] is not None: angle = self.held_tile_data[4].angle self.rect_of_tile = self.tiled_level.set_tile_at_pos( click_pos, self.held_tile_data[2], angle, self.editing_layer) elif self.right_click_mode == "place_ai" and self.held_ai_spawn is not None: self.tiled_level.add_ai_spawn_at_pos( click_pos, self.held_ai_spawn) elif self.right_click_mode == "remove_ai": self.tiled_level.remove_ai_spawn_at_pos(click_pos) elif self.right_click_mode == "remove_turret_square": self.tiled_level.remove_turret_square_at_pos(click_pos) elif self.right_click_mode == "place_turret_square": self.tiled_level.place_turret_square_at_pos(click_pos) elif self.right_click_mode == "remove_waypoint": self.tiled_level.remove_waypoint_at_pos(click_pos) self.refresh_visible_waypoint_circles() elif self.right_click_mode == "place_waypoint": if self.tiled_level.place_waypoint_at_pos(click_pos): self.refresh_visible_waypoint_circles() if self.tiled_level.update_offset_position(self.map_position, all_tile_sprites): self.need_to_refresh_tiles = True self.all_ai_spawn_sprites.empty() for ai_spawn in self.tiled_level.ai_spawns: self.all_ai_spawn_sprites.add(ai_spawn) self.hovered_rec = self.tiled_level.get_tile_data_at_pos( pygame.mouse.get_pos(), self.editing_layer)[0] screen.blit(background, (0, 0)) # draw the background all_tile_sprites.draw(screen) self.all_ai_spawn_sprites.draw(screen) self.playable_area_display.draw(screen, self.tiled_level.position_offset) self.display_turret_placement_squares(screen) for waypoint_circles in self.visible_way_point_circles: waypoint_circles.update_offset_position( self.tiled_level.position_offset) waypoint_circles.draw(screen) if self.held_tile_data is not None: if not self.held_tile_data[3]: pygame.draw.rect(screen, pygame.Color("#FF6464"), self.held_tile_data[0], 1) if self.hovered_rec is not None: pygame.draw.rect(screen, pygame.Color("#FFE164"), self.hovered_rec, 1) # draw the hud pygame.draw.rect(screen, pygame.Color("#3C3C3C"), hud_rect, 0) self.all_palette_tile_sprites.draw(screen) if self.held_tile_data is not None: if self.held_tile_data[3]: pygame.draw.rect(screen, pygame.Color("#FF6464"), self.held_tile_data[0], 1) self.ui_manager.draw_ui(screen) return running @staticmethod def is_inside_hud(pos, hud_rect): if hud_rect[0] <= pos[0] and hud_rect[1] <= pos[1]: if hud_rect[0] + hud_rect[2] > pos[ 0] and hud_rect[1] + hud_rect[3] > pos[1]: return True return False def get_palette_tile_data_at_pos(self, click_pos): for tile in self.palette_tiles: x_min = tile.rect[0] x_max = tile.rect[0] + tile.rect[2] y_min = tile.rect[1] y_max = tile.rect[1] + tile.rect[3] if x_min <= click_pos[0] < x_max: if y_min <= click_pos[1] < y_max: return [tile.rect, tile.image, tile.tile_id, True, None] return None def get_ai_spawn_data_at_pos(self, click_pos): for ai_spawn in self.palette_ai_spawns: x_min = ai_spawn.rect[0] x_max = ai_spawn.rect[0] + ai_spawn.rect[2] y_min = ai_spawn.rect[1] y_max = ai_spawn.rect[1] + ai_spawn.rect[3] if x_min <= click_pos[0] < x_max: if y_min <= click_pos[1] < y_max: return ai_spawn return None
class SettingsWindow(UIWindow): """ Bu tüm ayarların yapıldığı pencere olucak... Tüm ayarlar derken takım numarasının girildiği, led renklerinin değiştirildiği, kullanılan kameranın değiştirildiği(?) yer.. :param rect: koordinat ve ekran büyüklüğü :param manager: ui yöneticisi muhtemelen tüm arayüzün yöneticisi olucak burdaki :param window_surface: ana ekranın pygame.surface'i buna hata penceresini ortalamak için ihtiyacımız var sodkfsedfkjsplofk """ def __init__(self, rect, manager, window_surface): super().__init__(rect, manager, lang.strings['settings_window'], 'SettingsWindow', '#settings_window', resizable=True) self.manager = manager self.settings = read_json() self.window_surface = window_surface self.warning_screen = None self.in_fullscreen = False self.special_flags = self.settings['screen_mode'] self.any_settings_changed = False self.setting_changed = { 'res': False, # resolution of screen 'fll': False, # screen made fullscreen # i removed fll from the settings window and made fullscreen toggleable from a button on the main menu but, didn't change this because I'm too lazy to debug it afterwards 'scr': False, # screen mode changed (other than fullscreen) 'lng': False, # language changed 'yrs': False # year changed } # resolution ↓↓ resol_label_rect = pygame.Rect( (12, 32), ((len(lang.strings['resolution_label']) * 10) - 36, 19)) self.resol_label = UILabel(resol_label_rect, lang.strings['resolution_label'], self.manager, self, self, '#res_menu_label') resol_drop_down_rect = pygame.Rect((12, 56), (94, 24)) resol_drop_down_rect.topleft = resol_label_rect.bottomleft self.res_selections = [ "600x500", "800x600", "900x650", "1000x700", "1200x700", "1240x740" ] current_res = self.settings["resolution"] self.resol_drop_down = UIDropDownMenu( self.res_selections, f"{current_res['width']}x{current_res['height']}", resol_drop_down_rect, self.manager, self, self, '#resolution_menu') # screen mode ↓↓ scr_mode_label_rect = pygame.Rect( (200, 32), ((len(lang.strings['screen_mode_label']) * 10) - 19, 19)) self.scr_mode_label = UILabel(scr_mode_label_rect, lang.strings['screen_mode_label'], self.manager, self, self, '#screen_mode_label') scr_mode_menu_rect = pygame.Rect((200, 56), (106, 24)) scr_mode_menu_rect.topleft = scr_mode_label_rect.bottomleft self.scr_mode_selections = lang.strings['screen_mode_list'] current_screen_mode = self.settings['screen_mode'] if self.settings['screen_mode'] == "windowed" and self.settings[ 'language'] == "turkce": current_screen_mode = self.scr_mode_selections[0] elif self.settings['screen_mode'] == "borderless" and self.settings[ 'language'] == "turkce": current_screen_mode = self.scr_mode_selections[1] elif self.settings['screen_mode'] == "fullscreen" and self.settings[ 'language'] == "turkce": current_screen_mode = self.scr_mode_selections[2] self.scr_mode_menu = UIDropDownMenu(self.scr_mode_selections, current_screen_mode.capitalize(), scr_mode_menu_rect, self.manager, self, self, '#screen_menu') # sene seçme ↓↓ year_label_rect = pygame.Rect( (12, 132), ((len(lang.strings['year_label']) * 10) - 19, 19)) self.year_label = UILabel(year_label_rect, lang.strings['year_label'], self.manager, self, self, '#year_menu_label') year_drop_down_rect = pygame.Rect((12, 156), (84, 24)) year_drop_down_rect.topleft = year_label_rect.bottomleft self.year_selections = ['2018', '2017', '2016'] self.year_drop_down_menu = UIDropDownMenu(self.year_selections, self.settings["year"], year_drop_down_rect, self.manager, self, self, object_id='#year_menu') # dil seçme ↓↓ lang_label_rect = pygame.Rect( (200, 132), ((len(lang.strings['language_label']) * 10) - 24, 19)) self.lang_label = UILabel(lang_label_rect, lang.strings['language_label'], self.manager, self, self, '#lang_menu_label') lang_drop_down_rect = pygame.Rect((200, 156), (84, 24)) lang_drop_down_rect.topleft = lang_label_rect.bottomleft self.lang_drop_down = UIDropDownMenu( GUI_LANGUAGES, self.settings["language"].capitalize(), lang_drop_down_rect, self.manager, self, self, '#lang_menu') # keep changes? ↓↓ save_button_x_size = ((len(lang.strings['keep_changes']) * 10) - 18) save_button_rect = pygame.Rect((-16 - save_button_x_size, -16 - 24), (save_button_x_size, 24)) self.save_button = UIButton(save_button_rect, lang.strings['keep_changes'], self.manager, self, lang.strings['keep_changes_hover'], parent_element=self, object_id='#keep_changes', anchors=GUI_ANCHORS_BOTTOM_RIGHT) def process_event(self, event: pygame.event.Event) -> bool: if (event.type == pygame.USEREVENT and event.user_type == pygame_gui.UI_DROP_DOWN_MENU_CHANGED and event.ui_element == self.year_drop_down_menu): if self.settings["year"] != event.text: self.settings["year"] = event.text self.setting_changed['yrs'] = True self.any_settings_changed = True if (event.type == pygame.USEREVENT and event.user_type == pygame_gui.UI_DROP_DOWN_MENU_CHANGED and event.ui_element == self.lang_drop_down): if self.settings["language"] != event.text.lower(): self.settings["language"] = event.text.lower() self.setting_changed['lng'] = True self.any_settings_changed = True if (event.type == pygame.USEREVENT and event.user_type == pygame_gui.UI_DROP_DOWN_MENU_CHANGED and event.ui_element == self.resol_drop_down): resolution = self.make_res_tuple(event.text) if (self.settings["resolution"]['width'] != resolution[0] and self.settings["resolution"]['height'] != resolution[1]): self.settings["resolution"]['width'] = resolution[0] self.settings["resolution"]['height'] = resolution[1] self.setting_changed['res'] = True self.any_settings_changed = True if (event.type == pygame.USEREVENT and event.user_type == pygame_gui.UI_DROP_DOWN_MENU_CHANGED and event.ui_element == self.scr_mode_menu): self.settings = read_json() self.in_fullscreen = self.settings['in_fullscreen'] if self.in_fullscreen == "true": self.in_fullscreen = True else: self.in_fullscreen = False new_scr_mode = SettingsWindow.change_scr_for_lang( self.settings['language'], "turkce", event) print(new_scr_mode) if self.settings['screen_mode'] != new_scr_mode: self.settings['screen_mode'] = new_scr_mode screen_mode = self.settings['screen_mode'] if screen_mode == "borderless": if self.in_fullscreen: warning_rect = pygame.Rect((0, 0), (300, 300)) warning_rect.center = self.window_surface.get_rect( ).center self.warning_screen = UIMessageWindow( warning_rect, lang.strings["html_message_error_01"], self.manager, window_title=lang.strings['error'], object_id='#error_01') self.warning_screen.dismiss_button.text = lang.strings[ "dismiss"] self.warning_screen.dismiss_button.tool_tip_text = lang.strings[ 'dismiss_tip'] self.warning_screen.dismiss_button.rebuild() self.warning_screen.set_blocking(True) elif self.special_flags != pygame.NOFRAME: self.special_flags = pygame.NOFRAME self.setting_changed['scr'] = True self.any_settings_changed = True elif screen_mode == "windowed": if self.in_fullscreen: warning_rect = pygame.Rect((0, 0), (300, 300)) warning_rect.center = self.window_surface.get_rect( ).center self.warning_screen = UIMessageWindow( warning_rect, lang.strings["html_message_error_01"], self.manager, window_title=lang.strings['error'], object_id='#error_01') self.warning_screen.dismiss_button.text = lang.strings[ "dismiss"] self.warning_screen.dismiss_button.tool_tip_text = lang.strings[ 'dismiss_tip'] self.warning_screen.set_blocking(True) elif self.special_flags != 0: self.special_flags = 0 self.setting_changed['scr'] = True self.any_settings_changed = True if (event.type == pygame.USEREVENT and event.user_type == pygame_gui.UI_BUTTON_PRESSED and event.ui_object_id == '#settings_window.#keep_changes'): if self.any_settings_changed == True: if self.setting_changed['res'] == True: write_to(self.settings) pygame.event.post(GUI_WINDOW_RESOLUTION_CHANGED) elif self.setting_changed['lng'] == True: write_to(self.settings) pygame.event.post(GUI_LANUAGE_CHANGED) elif self.setting_changed['yrs'] == True: write_to(self.settings) elif self.setting_changed['fll'] == True: write_to(self.settings) pygame.event.post(GUI_TOGGLE_FULLSCREEN) elif self.setting_changed['scr'] == True: if self.special_flags == 0: write_to(self.settings) POST_SPECIAL_FLAG_CHANGE(self.special_flags) else: write_to(self.settings) POST_SPECIAL_FLAG_CHANGE(self.special_flags) lang.strings = lang.change_strings() saved_changes = False if self.setting_changed['res'] == True or self.setting_changed[ 'scr'] == True: saved_changes = True for key in self.setting_changed: if self.setting_changed[key] == True: self.setting_changed[key] = False self.any_settings_changed = False if saved_changes: pygame.event.post(GUI_CHANGES_MADE_TO_SETTINGS) else: print("no change to keep") def update(self, time_delta): super().update(time_delta) def make_res_tuple(self, r_string): self.res_settings = self.settings['resolution'] self.res_selections = [ "600x500", "800x600", "900x650", "1000x700", "1200x700", "1240x740" ] if r_string == "600x500": self.res_settings['width'] = 600 self.res_settings['height'] = 500 elif r_string == "800x600": self.res_settings['width'] = 800 self.res_settings['height'] = 600 elif r_string == "900x650": self.res_settings['width'] = 900 self.res_settings['height'] = 650 elif r_string == "1000x700": self.res_settings['width'] = 1000 self.res_settings['height'] = 700 elif r_string == "1200x700": self.res_settings['width'] = 1200 self.res_settings['height'] = 700 elif r_string == "1240x740": self.res_settings['width'] = 1240 self.res_settings['height'] = 740 else: self.res_settings['width'] = 800 self.res_settings['height'] = 600 tuple_res = (self.res_settings['width'], self.res_settings['height']) return tuple_res @staticmethod def change_scr_for_lang(language_settings, language_name: str, event): new_data = event.text.lower() if language_settings == language_name: if event.text == lang.strings['screen_mode_list'][0]: new_data = "windowed" elif event.text == lang.strings['screen_mode_list'][1]: new_data = "borderless" return new_data