diff --git a/main.py b/main.py index 44af99e..5afd4ef 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,7 @@ def main(): pygame.init() screen = pygame.display.set_mode((720, 720)) clock = pygame.time.Clock() + pygame.display.set_caption("CS2 Demo Viewer") states = {} context = { @@ -15,7 +16,8 @@ def main(): "font": pygame.font.Font(None, 36), "small_font": pygame.font.Font(None, 15), "options": { - "show_yaw": True + "show_yaw": True, + "show_health": True } } diff --git a/render/player_renderer.py b/render/player_renderer.py index fe38325..418c749 100644 --- a/render/player_renderer.py +++ b/render/player_renderer.py @@ -82,5 +82,6 @@ class PlayerRenderer: if self.options["show_yaw"]: self._render_yaw(player, team) - - self._render_health(player) \ No newline at end of file + + if self.options["show_health"]: + self._render_health(player) \ No newline at end of file diff --git a/states/game.py b/states/game.py index 63e39a7..3db8165 100644 --- a/states/game.py +++ b/states/game.py @@ -14,7 +14,7 @@ class Game(GameState): match_data_path = f"maps/{self.match.map_name}.json" match_image_path = f"maps/{self.match.map_name}.png" - # Map Coordinate Helper Class, misnamed + # Map Coordinate Helper Class, self.map_coord_controller = MapCoordConverter(self.screen.get_width(), self.screen.get_height(), match_data_path, match_image_path) # Renderers diff --git a/states/settings_menu.py b/states/settings_menu.py index e1fcb96..1a11dd0 100644 --- a/states/settings_menu.py +++ b/states/settings_menu.py @@ -14,12 +14,16 @@ class SettingsMenu(GameState): self.show_yaw_text = self.font.render("Show Yaw: ", True, (255, 255, 255)) self.show_yaw_button = Switch(100, 100, 50, 50, self.options["show_yaw"]) + self.show_health_text = self.font.render("Show Health: ", True, (255, 255, 255)) + self.show_health_button = Switch(100, 150, 50, 50, self.options["show_health"]) + def handle_events(self, events): """Handles user inputs.""" for event in events: if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: self.switch_state("start_menu") self.show_yaw_button.handle_event(event) + self.show_health_button.handle_event(event) self.back_button.handle_event(event) def update(self): @@ -29,6 +33,11 @@ class SettingsMenu(GameState): else: self.options["show_yaw"] = False + if self.show_health_button.get_is_toggled(): + self.options["show_health"] = True + else: + self.options["show_health"] = False + # Save settings to context self.context["options"] = self.options @@ -38,5 +47,11 @@ class SettingsMenu(GameState): self.screen.blit(self.show_yaw_text, (self.show_yaw_button.x + self.show_yaw_button.width + 10, self.show_yaw_button.y)) self.show_yaw_button.draw(self.screen) + + self.screen.blit(self.show_health_text, (self.show_health_button.x + self.show_health_button.width + 10, + self.show_health_button.y)) + self.show_health_button.draw(self.screen) + self.back_button.draw(self.screen) + diff --git a/widgets/slider.py b/widgets/slider.py index ce5a3c2..3e16ef7 100644 --- a/widgets/slider.py +++ b/widgets/slider.py @@ -13,6 +13,7 @@ class HorizontalSlider: self.background_colour = (255, 255, 255) self.knob_colour = (255, 0, 0) + self.rect_radius = 5 self.knob_radius = 10 self.knob_x = self.x @@ -39,10 +40,10 @@ class HorizontalSlider: Draw the slider on the screen """ if self.fill: - pygame.draw.rect(self.screen, self.fill_colour, (self.x, self.y, self.knob_x, self.height)) - pygame.draw.rect(self.screen, self.background_colour, (self.knob_x, self.y, self.width - (self.knob_x - self.x), self.height)) + pygame.draw.rect(self.screen, self.fill_colour, (self.x, self.y, self.knob_x, self.height), border_radius=self.rect_radius) + pygame.draw.rect(self.screen, self.background_colour, (self.knob_x, self.y, self.width - (self.knob_x - self.x), self.height), border_radius=self.rect_radius) else: - pygame.draw.rect(self.screen, self.background_colour, (self.x, self.y, self.width, self.height)) + pygame.draw.rect(self.screen, self.background_colour, (self.x, self.y, self.width, self.height), border_radius=self.rect_radius) pygame.draw.circle(self.screen, self.knob_colour, (int(self.knob_x), self.y + self.height // 2), self.knob_radius) def set_value(self, value): diff --git a/widgets/switch.py b/widgets/switch.py index 7bf1a46..7bc5033 100644 --- a/widgets/switch.py +++ b/widgets/switch.py @@ -12,6 +12,7 @@ class Switch: self.is_toggled = default_value self.background_colour = (211,211,211) self.foreground_colour = (150, 150, 150) + self.active_border_colour = (255, 0, 0) self.border_width = 1 self.border_radius = 3 self.toggle_speed = 5 @@ -78,7 +79,7 @@ class Switch: self.rect_offset -= self.toggle_speed elif self.is_toggled: # Draw border - pygame.draw.rect(screen, (255, 0, 0), (self.x-self.border_width, + pygame.draw.rect(screen, self.active_border_colour, (self.x-self.border_width, self.y-self.border_width, self.width+(self.border_width*2), self.height+(self.border_width*2)),