ADD show health option

This commit is contained in:
2025-04-20 21:45:41 +02:00
parent 40b86ebf86
commit 69cae0044a
6 changed files with 28 additions and 8 deletions

View File

@@ -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
}
}

View File

@@ -83,4 +83,5 @@ class PlayerRenderer:
if self.options["show_yaw"]:
self._render_yaw(player, team)
self._render_health(player)
if self.options["show_health"]:
self._render_health(player)

View File

@@ -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

View File

@@ -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)

View File

@@ -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):

View File

@@ -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)),