diff --git a/NOTE.md b/NOTE.md index 148df70..df0861f 100644 --- a/NOTE.md +++ b/NOTE.md @@ -1,22 +1,5 @@ A faire : -Widgets: -- 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 -- Confirmer l'emplacement des bateaux (envoie des données signalant la confirmation) - -- Joueur 1 sélectionne une case (envoie des données à l'autre joueur) -- Joueur 2 envoie la valeur de retour de board.bomb après les données de joueur 1 -- Joueur 2 sélectionne une case -- Joueur 1 envoie la valeur de retour également -... - -- Joueur 1 gagne (envoie des données de victoire à l'autre joueur) -- Joueur 1 et Joueur 2 s'envoie mutuellement leurs plateaux pour voir les cases restantes de l'autre -- Proposition de rejouer ? \ No newline at end of file +- Optimiser les textures dans un dictionnaires +- Optimiser les textures similaire dans un atlas +- Toutes les scènes devrait proposer un compteur de fps +- Permettre de forcer la taille de la fenêtre à un ratio diff --git a/main.pyw b/main.pyw index 36c8cf5..dae6b4e 100644 --- a/main.pyw +++ b/main.pyw @@ -1,11 +1,11 @@ import pyglet from source.gui.scene import MainMenu -from source.gui.window import Window +from source.gui.window import GameWindow # Create a new window -window = Window(resizable=True, vsync=True) +window = GameWindow(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 a88f986..eb18f94 100644 --- a/source/gui/scene/MainMenu.py +++ b/source/gui/scene/MainMenu.py @@ -4,7 +4,6 @@ import pyglet from source.gui.scene.abc import Scene from source.gui import widget, scene -from source.gui.widget.debug import FPSDisplay if TYPE_CHECKING: from source.gui.window import Window @@ -77,13 +76,9 @@ class MainMenu(Scene): self.settings.add_listener("on_click_release", lambda *_: self.window.set_scene(scene.Settings)) - self.fps_display = self.add_widget(FPSDisplay, color=(255, 255, 255, 180)) - def on_draw(self): self.background.draw() self.title.draw() self.game_create.draw() self.game_join.draw() self.settings.draw() - - self.fps_display.draw() diff --git a/source/gui/scene/abc/Scene.py b/source/gui/scene/abc/Scene.py index 735d954..b0ec6ea 100644 --- a/source/gui/scene/abc/Scene.py +++ b/source/gui/scene/abc/Scene.py @@ -24,9 +24,9 @@ class Scene(ABC): def add_widget(self, widget_class: Type["Widget"], **widget_kwargs): """ Add a widget to the scene. - :widget_class: the class of the widget to add. - :widget_args: args for the creation of the widget object. - :widget_kwargs: kwargs for the creation of the widget object. + :param widget_class: the class of the widget to add. + :param widget_args: args for the creation of the widget object. + :param widget_kwargs: kwargs for the creation of the widget object. :return: the new created widget. """ @@ -37,7 +37,7 @@ class Scene(ABC): def remove_widget(self, widget: "Widget") -> None: """ Remove a widget from the scene. - :scene: the widget to remove. + :param scene: the widget to remove. """ self._widgets.remove(widget) diff --git a/source/gui/widget/debug/FPSDisplay.py b/source/gui/widget/debug/FPSDisplay.py deleted file mode 100644 index eda298f..0000000 --- a/source/gui/widget/debug/FPSDisplay.py +++ /dev/null @@ -1,22 +0,0 @@ -from source.gui.widget.abc import Widget - -from typing import TYPE_CHECKING - -import pyglet - -if TYPE_CHECKING: - from source.gui.scene.abc import Scene - - -class FPSDisplay(Widget): - """ - A widget that display the current FPS of the scene's window - """ - - def __init__(self, scene: "Scene", **kwargs): - super().__init__(scene) - - self.fps_display = pyglet.window.FPSDisplay(scene.window, **kwargs) - - def draw(self): - self.fps_display.draw() diff --git a/source/gui/widget/debug/__init__.py b/source/gui/widget/debug/__init__.py deleted file mode 100644 index 292fa2b..0000000 --- a/source/gui/widget/debug/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .FPSDisplay import FPSDisplay diff --git a/source/gui/window/GameWindow.py b/source/gui/window/GameWindow.py new file mode 100644 index 0000000..65ff7fa --- /dev/null +++ b/source/gui/window/GameWindow.py @@ -0,0 +1,24 @@ +import pyglet.window + +from source.gui.window import Window +from source.type import Color + + +class GameWindow(Window): # NOQA + """ + Similar to the normal Window, but add small feature useful for a game like a fps counter. + """ + + def __init__(self, + + fps_color: Color = (255, 255, 255, 200), + fps_enable: bool = True, + + *args, **kwargs): + super().__init__(*args, **kwargs) + + self._fps_counter = pyglet.window.FPSDisplay(self, color=fps_color) + self.fps_enable = fps_enable + + def on_draw_after(self): + if self.fps_enable: self._fps_counter.draw() diff --git a/source/gui/window/Window.py b/source/gui/window/Window.py index ac78683..18fbecf 100644 --- a/source/gui/window/Window.py +++ b/source/gui/window/Window.py @@ -76,15 +76,24 @@ class Window(pyglet.window.Window): # NOQA :return: une fonction appelant l'événement original ainsi que ceux des scènes. """ + # try to get the original function func = None try: func = super().__getattribute__(item) except AttributeError: pass + # try to get a function that would get executed after everything else + func_after = None + try: func_after = super().__getattribute__(item + "_after") + except AttributeError: pass + def _func(*args, **kwargs) -> None: if func is not None: func(*args, **kwargs) + for scene in self._scenes: getattr(scene, item)(*args, **kwargs) + if func_after is not None: func_after(*args, **kwargs) + return _func def __getattribute__(self, item: str) -> Any: diff --git a/source/gui/window/__init__.py b/source/gui/window/__init__.py index 262037f..2275442 100644 --- a/source/gui/window/__init__.py +++ b/source/gui/window/__init__.py @@ -1 +1,2 @@ from .Window import Window +from .GameWindow import GameWindow diff --git a/source/type.py b/source/type.py index 52b2fb1..c3c929d 100644 --- a/source/type.py +++ b/source/type.py @@ -3,7 +3,8 @@ from typing import Union, Callable, Any Point2D = tuple[int, int] BBox = tuple[int, int, int, int] Percentage = float # a percentage, represented as a number between 0 and 1 +Color = tuple[int, int, int, int] 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] +Distance = Union[Percentage, int, DistanceFunction] \ No newline at end of file