united custom Sprite and Label in better_pyglet, they now have a default_kwargs. "Century Gothic Bold" is now the default font
This commit is contained in:
parent
e64439b622
commit
316de05525
14 changed files with 39 additions and 12 deletions
7
main.pyw
7
main.pyw
|
@ -4,6 +4,13 @@ from source.gui.scene import MainMenu
|
||||||
from source.gui.window import GameWindow
|
from source.gui.window import GameWindow
|
||||||
|
|
||||||
|
|
||||||
|
from source import path_font
|
||||||
|
from source.gui.better_pyglet import Label
|
||||||
|
|
||||||
|
pyglet.font.add_directory(path_font)
|
||||||
|
Label.default_kwargs["font_name"] = "Century Gothic" # NOQA: Label à un "default_kwargs" avec la metaclass
|
||||||
|
|
||||||
|
|
||||||
# Create a new window
|
# Create a new window
|
||||||
window = GameWindow(resizable=True, vsync=False, caption="Bataille Navale")
|
window = GameWindow(resizable=True, vsync=False, caption="Bataille Navale")
|
||||||
window.set_minimum_size(720, 480)
|
window.set_minimum_size(720, 480)
|
||||||
|
|
8
source/gui/better_pyglet/Label.py
Normal file
8
source/gui/better_pyglet/Label.py
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
import pyglet
|
||||||
|
|
||||||
|
from source.gui.better_pyglet.abc import Element
|
||||||
|
|
||||||
|
|
||||||
|
class Label(Element, pyglet.text.Label):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **(self.default_kwargs | kwargs))
|
|
@ -1,13 +1,15 @@
|
||||||
import pyglet
|
import pyglet
|
||||||
|
|
||||||
|
from source.gui.better_pyglet.abc import Element
|
||||||
|
|
||||||
class Sprite(pyglet.sprite.Sprite):
|
|
||||||
|
class Sprite(Element, pyglet.sprite.Sprite):
|
||||||
"""
|
"""
|
||||||
Same as the pyglet sprite, but allow to set a width and height easier
|
Same as the pyglet sprite, but allow to set a width and height easier
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, width: int = None, height: int = None, *args, **kwargs):
|
def __init__(self, width: int = None, height: int = None, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **(self.default_kwargs | kwargs))
|
||||||
|
|
||||||
self._orig_width: int = self.width
|
self._orig_width: int = self.width
|
||||||
self._orig_height: int = self.height
|
self._orig_height: int = self.height
|
|
@ -1 +1,2 @@
|
||||||
from .Sprite import Sprite
|
from .Sprite import Sprite
|
||||||
|
from .Label import Label
|
7
source/gui/better_pyglet/abc/Element.py
Normal file
7
source/gui/better_pyglet/abc/Element.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
from abc import ABC
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
class Element(ABC):
|
||||||
|
def __init_subclass__(cls, **kwargs):
|
||||||
|
cls.default_kwargs: dict[str, Any] = {} # all subclasses will have their own "default_kwargs" dict
|
1
source/gui/better_pyglet/abc/__init__.py
Normal file
1
source/gui/better_pyglet/abc/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
from .Element import Element
|
|
@ -2,7 +2,7 @@ from typing import TYPE_CHECKING, Type
|
||||||
|
|
||||||
import pyglet
|
import pyglet
|
||||||
|
|
||||||
from source.gui.sprite import Sprite
|
from source.gui.better_pyglet import Sprite, Label
|
||||||
from source.gui.texture.abc import Style
|
from source.gui.texture.abc import Style
|
||||||
from source.gui.widget.abc import BoxWidget
|
from source.gui.widget.abc import BoxWidget
|
||||||
from source.type import Distance
|
from source.type import Distance
|
||||||
|
@ -38,7 +38,7 @@ class Button(BoxWidget):
|
||||||
**dict_filter_prefix("background_", kwargs)
|
**dict_filter_prefix("background_", kwargs)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.label = pyglet.text.Label(
|
self.label = Label(
|
||||||
width=None, height=None,
|
width=None, height=None,
|
||||||
anchor_x="center", anchor_y="center",
|
anchor_x="center", anchor_y="center",
|
||||||
batch=self.scene.batch,
|
batch=self.scene.batch,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from typing import TYPE_CHECKING, Type
|
from typing import TYPE_CHECKING, Type
|
||||||
|
|
||||||
from source.gui.sprite import Sprite
|
from source.gui.better_pyglet import Sprite
|
||||||
from source.gui.texture.abc import Style
|
from source.gui.texture.abc import Style
|
||||||
from source.gui.widget.abc import BoxWidget
|
from source.gui.widget.abc import BoxWidget
|
||||||
from source.type import Distance
|
from source.type import Distance
|
||||||
|
|
|
@ -7,7 +7,7 @@ import pyglet.shapes
|
||||||
from source.core import Board, Boat
|
from source.core import Board, Boat
|
||||||
from source.core.enums import Orientation, BombState
|
from source.core.enums import Orientation, BombState
|
||||||
from source.core.error import InvalidBoatPosition
|
from source.core.error import InvalidBoatPosition
|
||||||
from source.gui.sprite import Sprite
|
from source.gui.better_pyglet import Sprite
|
||||||
from source.gui.texture.abc import Style
|
from source.gui.texture.abc import Style
|
||||||
from source.gui.widget.abc import BoxWidget
|
from source.gui.widget.abc import BoxWidget
|
||||||
from source.type import Distance, ColorRGB, Point2D
|
from source.type import Distance, ColorRGB, Point2D
|
||||||
|
|
|
@ -2,7 +2,7 @@ from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import pyglet.image
|
import pyglet.image
|
||||||
|
|
||||||
from source.gui.sprite import Sprite
|
from source.gui.better_pyglet import Sprite
|
||||||
from source.gui.widget.abc import BoxWidget
|
from source.gui.widget.abc import BoxWidget
|
||||||
from source.type import Distance
|
from source.type import Distance
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ from typing import TYPE_CHECKING, Optional, Type
|
||||||
|
|
||||||
import pyglet.image
|
import pyglet.image
|
||||||
|
|
||||||
from source.gui.sprite import Sprite
|
from source.gui.better_pyglet import Sprite, Label
|
||||||
from source.gui.texture.abc import Style
|
from source.gui.texture.abc import Style
|
||||||
from source.gui.widget.abc import BoxWidget
|
from source.gui.widget.abc import BoxWidget
|
||||||
from source.type import Distance
|
from source.type import Distance
|
||||||
|
@ -46,7 +46,7 @@ class Input(BoxWidget):
|
||||||
**dict_filter_prefix("background_", kwargs)
|
**dict_filter_prefix("background_", kwargs)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.label = pyglet.text.Label(
|
self.label = Label(
|
||||||
width=None, height=None,
|
width=None, height=None,
|
||||||
anchor_x="center", anchor_y="center",
|
anchor_x="center", anchor_y="center",
|
||||||
batch=self.scene.batch,
|
batch=self.scene.batch,
|
||||||
|
|
|
@ -2,7 +2,7 @@ from typing import TYPE_CHECKING, Callable, Any, Type
|
||||||
|
|
||||||
import pyglet.image
|
import pyglet.image
|
||||||
|
|
||||||
from source.gui.sprite import Sprite
|
from source.gui.better_pyglet import Sprite, Label
|
||||||
from source.gui.texture.abc import Style
|
from source.gui.texture.abc import Style
|
||||||
from source.gui.widget.abc import BoxWidget
|
from source.gui.widget.abc import BoxWidget
|
||||||
from source.type import Distance
|
from source.type import Distance
|
||||||
|
@ -54,7 +54,7 @@ class Scroller(BoxWidget):
|
||||||
**dict_filter_prefix("cursor_", kwargs)
|
**dict_filter_prefix("cursor_", kwargs)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.label = pyglet.text.Label(
|
self.label = Label(
|
||||||
anchor_x="center", anchor_y="center",
|
anchor_x="center", anchor_y="center",
|
||||||
batch=self.scene.batch,
|
batch=self.scene.batch,
|
||||||
**dict_filter_prefix("label_", kwargs)
|
**dict_filter_prefix("label_", kwargs)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
from source.gui.better_pyglet import Label
|
||||||
from source.gui.widget.abc import BoxWidget
|
from source.gui.widget.abc import BoxWidget
|
||||||
|
|
||||||
import pyglet
|
import pyglet
|
||||||
|
@ -25,7 +26,7 @@ class Text(BoxWidget):
|
||||||
**kwargs):
|
**kwargs):
|
||||||
super().__init__(scene, x, y, width, height)
|
super().__init__(scene, x, y, width, height)
|
||||||
|
|
||||||
self.label = pyglet.text.Label(
|
self.label = Label(
|
||||||
x=self.x, y=self.y, width=self.width, height=self.height,
|
x=self.x, y=self.y, width=self.width, height=self.height,
|
||||||
batch=self.scene.batch,
|
batch=self.scene.batch,
|
||||||
**kwargs
|
**kwargs
|
||||||
|
|
Loading…
Reference in a new issue