ADD show health option
This commit is contained in:
4
main.py
4
main.py
@@ -7,6 +7,7 @@ def main():
|
|||||||
pygame.init()
|
pygame.init()
|
||||||
screen = pygame.display.set_mode((720, 720))
|
screen = pygame.display.set_mode((720, 720))
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
|
pygame.display.set_caption("CS2 Demo Viewer")
|
||||||
|
|
||||||
states = {}
|
states = {}
|
||||||
context = {
|
context = {
|
||||||
@@ -15,7 +16,8 @@ def main():
|
|||||||
"font": pygame.font.Font(None, 36),
|
"font": pygame.font.Font(None, 36),
|
||||||
"small_font": pygame.font.Font(None, 15),
|
"small_font": pygame.font.Font(None, 15),
|
||||||
"options": {
|
"options": {
|
||||||
"show_yaw": True
|
"show_yaw": True,
|
||||||
|
"show_health": True
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,5 +82,6 @@ class PlayerRenderer:
|
|||||||
|
|
||||||
if self.options["show_yaw"]:
|
if self.options["show_yaw"]:
|
||||||
self._render_yaw(player, team)
|
self._render_yaw(player, team)
|
||||||
|
|
||||||
self._render_health(player)
|
if self.options["show_health"]:
|
||||||
|
self._render_health(player)
|
||||||
@@ -14,7 +14,7 @@ class Game(GameState):
|
|||||||
match_data_path = f"maps/{self.match.map_name}.json"
|
match_data_path = f"maps/{self.match.map_name}.json"
|
||||||
match_image_path = f"maps/{self.match.map_name}.png"
|
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)
|
self.map_coord_controller = MapCoordConverter(self.screen.get_width(), self.screen.get_height(), match_data_path, match_image_path)
|
||||||
|
|
||||||
# Renderers
|
# Renderers
|
||||||
|
|||||||
@@ -14,12 +14,16 @@ class SettingsMenu(GameState):
|
|||||||
self.show_yaw_text = self.font.render("Show Yaw: ", True, (255, 255, 255))
|
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_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):
|
def handle_events(self, events):
|
||||||
"""Handles user inputs."""
|
"""Handles user inputs."""
|
||||||
for event in events:
|
for event in events:
|
||||||
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
|
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
|
||||||
self.switch_state("start_menu")
|
self.switch_state("start_menu")
|
||||||
self.show_yaw_button.handle_event(event)
|
self.show_yaw_button.handle_event(event)
|
||||||
|
self.show_health_button.handle_event(event)
|
||||||
self.back_button.handle_event(event)
|
self.back_button.handle_event(event)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
@@ -29,6 +33,11 @@ class SettingsMenu(GameState):
|
|||||||
else:
|
else:
|
||||||
self.options["show_yaw"] = False
|
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
|
# Save settings to context
|
||||||
self.context["options"] = self.options
|
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.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.y))
|
||||||
self.show_yaw_button.draw(self.screen)
|
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)
|
self.back_button.draw(self.screen)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class HorizontalSlider:
|
|||||||
|
|
||||||
self.background_colour = (255, 255, 255)
|
self.background_colour = (255, 255, 255)
|
||||||
self.knob_colour = (255, 0, 0)
|
self.knob_colour = (255, 0, 0)
|
||||||
|
self.rect_radius = 5
|
||||||
|
|
||||||
self.knob_radius = 10
|
self.knob_radius = 10
|
||||||
self.knob_x = self.x
|
self.knob_x = self.x
|
||||||
@@ -39,10 +40,10 @@ class HorizontalSlider:
|
|||||||
Draw the slider on the screen
|
Draw the slider on the screen
|
||||||
"""
|
"""
|
||||||
if self.fill:
|
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.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))
|
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:
|
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)
|
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):
|
def set_value(self, value):
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class Switch:
|
|||||||
self.is_toggled = default_value
|
self.is_toggled = default_value
|
||||||
self.background_colour = (211,211,211)
|
self.background_colour = (211,211,211)
|
||||||
self.foreground_colour = (150, 150, 150)
|
self.foreground_colour = (150, 150, 150)
|
||||||
|
self.active_border_colour = (255, 0, 0)
|
||||||
self.border_width = 1
|
self.border_width = 1
|
||||||
self.border_radius = 3
|
self.border_radius = 3
|
||||||
self.toggle_speed = 5
|
self.toggle_speed = 5
|
||||||
@@ -78,7 +79,7 @@ class Switch:
|
|||||||
self.rect_offset -= self.toggle_speed
|
self.rect_offset -= self.toggle_speed
|
||||||
elif self.is_toggled:
|
elif self.is_toggled:
|
||||||
# Draw border
|
# 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.y-self.border_width,
|
||||||
self.width+(self.border_width*2),
|
self.width+(self.border_width*2),
|
||||||
self.height+(self.border_width*2)),
|
self.height+(self.border_width*2)),
|
||||||
|
|||||||
Reference in New Issue
Block a user