diff --git a/NOTE.md b/NOTE.md index 503f05c..25dd9f6 100644 --- a/NOTE.md +++ b/NOTE.md @@ -1,3 +1,13 @@ +A faire : +Widgets: +- Slider +- Checkbox +- Grille (bataille navale) + + + +Réseau : + - Connexion entre les joueurs - Envoie des paramètres à l'autre joueur (largeur longueur du plateau, nombre de bateau et leur taille, ...) - Phase de placement des bateaux diff --git a/main.pyw b/main.pyw index 3e431d1..73d06ad 100644 --- a/main.pyw +++ b/main.pyw @@ -95,7 +95,7 @@ class TestScene2(Scene): # Create a new window -window = Window(resizable=True, vsync=False) +window = Window(resizable=True, vsync=True) window.add_scene(MainMenu) # Start the event loop diff --git a/source/gui/scene/MainMenu.py b/source/gui/scene/MainMenu.py index 72c7765..1a0dc90 100644 --- a/source/gui/scene/MainMenu.py +++ b/source/gui/scene/MainMenu.py @@ -21,7 +21,7 @@ class MainMenu(Scene): self.background = self.add_widget( Image, - x=0, y=0, width=1, height=1, + x=0.0, y=0.0, width=1.0, height=1.0, image=texture_background ) diff --git a/source/gui/scene/RoomJoin.py b/source/gui/scene/RoomJoin.py index 1c7a7a0..fc6e6cf 100644 --- a/source/gui/scene/RoomJoin.py +++ b/source/gui/scene/RoomJoin.py @@ -23,7 +23,7 @@ class RoomJoin(Scene): self.back = self.add_widget( Button, - x=0.02, y=0.02, width=0.2, height=0.1, + x=20, y=20, width=0.2, height=0.1, label_text="Retour", @@ -39,7 +39,7 @@ class RoomJoin(Scene): Input, x=0.4, y=0.5, width=0.13, height=0.1, - regex=r"\d{1,3}(.\d{1,3}){3}", + regex=r"\d{1,3}(\.\d{1,3}){3}", texture_normal=texture_input_normal, texture_active=texture_input_active, diff --git a/source/gui/widget/abc/BoxWidget.py b/source/gui/widget/abc/BoxWidget.py index 3884cc6..68ffcd5 100644 --- a/source/gui/widget/abc/BoxWidget.py +++ b/source/gui/widget/abc/BoxWidget.py @@ -2,7 +2,7 @@ from abc import ABC from typing import TYPE_CHECKING, Optional from source.gui.widget.abc import Widget -from source.type import Percentage +from source.type import Distance, Percentage from source.utils import in_bbox if TYPE_CHECKING: @@ -15,10 +15,10 @@ class BoxWidget(Widget, ABC): """ def __init__(self, scene: "Scene", - x: Percentage = 0, - y: Percentage = 0, - width: Percentage = None, - height: Percentage = None): + x: Distance = 0, + y: Distance = 0, + width: Distance = None, + height: Distance = None): super().__init__(scene) # memorize the value with a percent value @@ -33,37 +33,52 @@ class BoxWidget(Widget, ABC): # property + def _getter_distance(self, max_distance: int, raw_distance: Distance) -> int: + """ + Return the true distance in pixel from a more abstract distance + :param max_distance: the max value the distance in pixel should have + :param raw_distance: the distance object to convert to pixel + :return: the true distance in pixel + """ + + if isinstance(raw_distance, Percentage): return int(max_distance * raw_distance) + if isinstance(raw_distance, int): return raw_distance + if callable(raw_distance): return raw_distance(self) + if raw_distance is None: return 0 + + raise TypeError(f"Invalid type for the distance : {type(raw_distance)}") + @property def x(self) -> int: - return self.scene.window.width * self._p_x + return self._getter_distance(self.scene.window.width, self._x) @x.setter - def x(self, x: Percentage): - self._p_x = x + def x(self, x: Distance): + self._x = x @property def y(self) -> int: - return self.scene.window.height * self._p_y + return self._getter_distance(self.scene.window.height, self._y) @y.setter - def y(self, y: Percentage): - self._p_y = y + def y(self, y: Distance): + self._y = y @property def width(self) -> int: - return 0 if self._p_width is None else self.scene.window.width * self._p_width + return self._getter_distance(self.scene.window.width, self._width) @width.setter - def width(self, width: Optional[Percentage]): - self._p_width = width + def width(self, width: Optional[Distance]): + self._width = width @property def height(self) -> int: - return 0 if self._p_height is None else self.scene.window.height * self._p_height + return self._getter_distance(self.scene.window.height, self._height) @height.setter - def height(self, height: Optional[Percentage]): - self._p_height = height + def height(self, height: Optional[Distance]): + self._height = height @property def xy(self) -> tuple[int, int]: diff --git a/source/type.py b/source/type.py index f169c90..52b2fb1 100644 --- a/source/type.py +++ b/source/type.py @@ -1,3 +1,9 @@ +from typing import Union, Callable, Any + Point2D = tuple[int, int] BBox = tuple[int, int, int, int] -Percentage = float +Percentage = float # a percentage, represented as a number between 0 and 1 + +DistanceFunction = Callable[[Any], int] # a function that return a distance +# a distance, represented either by a whole number, a percentage or a function +Distance = Union[Percentage, int, DistanceFunction]