From da7b557d21982e8a8109675def770526c2de5e44 Mon Sep 17 00:00:00 2001 From: Vincent Poulailleau Date: Fri, 12 Apr 2024 11:43:50 +0200 Subject: [PATCH] display server info --- space_collector/viewer/constants.py | 4 ++-- space_collector/viewer/score.py | 19 +++++++++++++++---- space_collector/viewer/viewer.py | 2 +- space_collector/viewer/window.py | 8 ++++---- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/space_collector/viewer/constants.py b/space_collector/viewer/constants.py index 8ce4738..3e68280 100644 --- a/space_collector/viewer/constants.py +++ b/space_collector/viewer/constants.py @@ -28,7 +28,7 @@ def resize(self, small_window: bool): self.SCORE_WIDTH = 500 self.SCORE_MARGIN = 100 self.SCORE_FONT_SIZE = 24 - self.SCORE_TEAM_SIZE = 200 + self.SCORE_TEAM_SIZE = 190 self.MAP_MARGIN = 170 else: self.SCREEN_WIDTH = 800 @@ -36,7 +36,7 @@ def resize(self, small_window: bool): self.SCORE_WIDTH = 300 self.SCORE_MARGIN = 50 self.SCORE_FONT_SIZE = 20 - self.SCORE_TEAM_SIZE = 100 + self.SCORE_TEAM_SIZE = 105 self.MAP_MARGIN = 50 self.SCORE_TIME_MARGIN = 100 diff --git a/space_collector/viewer/score.py b/space_collector/viewer/score.py index 9e1cc62..84a0438 100644 --- a/space_collector/viewer/score.py +++ b/space_collector/viewer/score.py @@ -52,11 +52,13 @@ class TeamData: class Score: - def __init__(self): + def __init__(self, addr: str, port: int): self.sprite_list = arcade.SpriteList() self.teams_data: list[TeamData] = [] self.time = 0 self.nb_planets = None + self.port = port + self.addr = addr def setup(self) -> None: font_file = files("space_collector.viewer").joinpath("images/Sportrop.ttf") @@ -81,6 +83,15 @@ def draw(self) -> None: 2, size=constants.SCORE_FONT_SIZE, ) + draw_text( + f"{self.addr}:{self.port}", + constants.SCORE_MARGIN, + constants.SCORE_HEIGHT + - constants.SCORE_TIME_MARGIN + - constants.SCORE_TEAM_SIZE // 4, + 1, + size=constants.SCORE_FONT_SIZE, + ) for index, team_data in enumerate( sorted(self.teams_data, key=lambda td: td.score) ): @@ -97,7 +108,7 @@ def draw(self) -> None: draw_text( "BLOCKED", constants.SCORE_MARGIN, - team_offset - constants.SCORE_TEAM_SIZE // 5, + team_offset - constants.SCORE_TEAM_SIZE // 4, team_data.team, size=constants.SCORE_FONT_SIZE - 5, ) @@ -105,14 +116,14 @@ def draw(self) -> None: draw_text( f"Score: {team_data.score}", constants.SCORE_MARGIN, - team_offset - constants.SCORE_TEAM_SIZE // 5, + team_offset - constants.SCORE_TEAM_SIZE // 4, team_data.team, size=constants.SCORE_FONT_SIZE - 5, ) draw_text( f"Planets: {team_data.nb_saved_planets}/{team_data.nb_planets}", constants.SCORE_MARGIN, - team_offset - 2 * constants.SCORE_TEAM_SIZE // 5, + team_offset - 2 * constants.SCORE_TEAM_SIZE // 4, team_data.team, size=constants.SCORE_FONT_SIZE - 5, ) diff --git a/space_collector/viewer/viewer.py b/space_collector/viewer/viewer.py index 70caee8..6948781 100644 --- a/space_collector/viewer/viewer.py +++ b/space_collector/viewer/viewer.py @@ -26,4 +26,4 @@ def __init__(self, server_addr: str, port: int) -> None: logging.info("Start network") Thread(target=network_thread, daemon=True, args=[server_addr, port]).start() logging.info("Start GUI") - gui_thread() + gui_thread(server_addr, port) diff --git a/space_collector/viewer/window.py b/space_collector/viewer/window.py index abbf7cd..3f45b2e 100644 --- a/space_collector/viewer/window.py +++ b/space_collector/viewer/window.py @@ -13,13 +13,13 @@ class Window(arcade.Window): - def __init__(self) -> None: + def __init__(self, addr: str, port: int) -> None: super().__init__( constants.SCREEN_WIDTH, constants.SCREEN_HEIGHT, constants.SCREEN_TITLE ) arcade.set_background_color(arcade.csscolor.BLACK) self.background = SpaceBackground() - self.score = Score() + self.score = Score(addr, port) self.players: list[Player] = [Player(team) for team in range(4)] def setup(self) -> None: @@ -49,8 +49,8 @@ def on_draw(self): self.score.draw() -def gui_thread() -> None: - window = Window() +def gui_thread(addr: str, port: int) -> None: + window = Window(addr, port) try: window.setup() arcade.run()