position now use a css like distance system
This commit is contained in:
parent
e1b575efc9
commit
d574703e90
22 changed files with 204 additions and 135 deletions
1
NOTE.md
1
NOTE.md
|
@ -17,6 +17,7 @@ Bug :
|
||||||
- (incertain) Dans de rare cas (souvent en fermant brutalement la fenêtre) le processus ne s'arrête pas
|
- (incertain) Dans de rare cas (souvent en fermant brutalement la fenêtre) le processus ne s'arrête pas
|
||||||
- Quitter pendant que l'on décide de si l'on doit charger ou non une ancienne sauvegarde fait crash l'adversaire
|
- Quitter pendant que l'on décide de si l'on doit charger ou non une ancienne sauvegarde fait crash l'adversaire
|
||||||
- Les champs invalides n'empêchent pas de faire l'action
|
- Les champs invalides n'empêchent pas de faire l'action
|
||||||
|
- Si le port est déjà utilisé, le jeu n'indique par l'erreur à l'hote
|
||||||
|
|
||||||
Autre :
|
Autre :
|
||||||
- Tester sur Linux
|
- Tester sur Linux
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
from typing import Callable
|
|
||||||
|
|
||||||
|
|
||||||
# pourcentage
|
|
||||||
|
|
||||||
|
|
||||||
def w_percent(value: float) -> Callable: # positionne en pourcentage la largeur
|
|
||||||
return lambda widget: int(widget.scene.window.width * (value / 100))
|
|
||||||
|
|
||||||
|
|
||||||
def h_percent(value: float) -> Callable: # positionne en pourcentage la hauteur
|
|
||||||
return lambda widget: int(widget.scene.window.height * (value / 100))
|
|
||||||
|
|
||||||
|
|
||||||
# pixel
|
|
||||||
|
|
||||||
|
|
||||||
def right(px: int) -> Callable: # positionne depuis la droite
|
|
||||||
return lambda widget: widget.scene.window.width - px
|
|
||||||
|
|
||||||
|
|
||||||
def up(px: int) -> Callable: # positionne depuis le haut
|
|
||||||
return lambda widget: widget.scene.window.height - px
|
|
||||||
|
|
||||||
|
|
||||||
def right_content(px: int) -> Callable: # positionne depuis la droite avec la taille du widget compris
|
|
||||||
return lambda widget: widget.scene.window.width - widget.width - px
|
|
||||||
|
|
||||||
|
|
||||||
def up_content(px: int) -> Callable: # positionne depuis le haut avec la taille du widget compris
|
|
||||||
return lambda widget: widget.scene.window.height - widget.height - px
|
|
||||||
|
|
||||||
|
|
||||||
# raccourci
|
|
||||||
|
|
||||||
w_full = w_percent(100)
|
|
||||||
h_full = h_percent(100)
|
|
29
source/gui/position/Unit.py
Normal file
29
source/gui/position/Unit.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
from typing import Callable, TYPE_CHECKING
|
||||||
|
|
||||||
|
from source.gui.position import Value
|
||||||
|
from source.type import DistanceFunc
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Unit:
|
||||||
|
"""
|
||||||
|
Cette classe représente une unité de position (px, vw, ...).
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, converter: Callable[[float], DistanceFunc]):
|
||||||
|
self.converter = converter
|
||||||
|
|
||||||
|
def __mul__(self, other: float): # opérateur *
|
||||||
|
"""
|
||||||
|
Lorsque que cet object est multiplié avec une valeur, renvoie un objet Value
|
||||||
|
utilisant le convertisseur de l'unité.
|
||||||
|
:param other: l'autre élément utilisé dans la multiplication.
|
||||||
|
:return: l'objet Value
|
||||||
|
"""
|
||||||
|
|
||||||
|
return Value(self.converter(other))
|
||||||
|
|
||||||
|
def __rmul__(self, other): # opérateur *, lorsque cet objet est situé à droite de l'opération
|
||||||
|
return self.__mul__(other)
|
47
source/gui/position/Value.py
Normal file
47
source/gui/position/Value.py
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
from source.type import DistanceFunc
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from source.gui.widget.abc import BoxWidget
|
||||||
|
|
||||||
|
|
||||||
|
class Value:
|
||||||
|
"""
|
||||||
|
Une valeur utilisée pour calculer la position des objets.
|
||||||
|
Elle utilise une fonction permettant à partir d'un widget, d'obtenir une position dans la fenêtre
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, calc: DistanceFunc):
|
||||||
|
self.calc = calc # fonction calculant la position depuis la taille d'un widget
|
||||||
|
|
||||||
|
def __add__(self, other) -> "Value": # opérateur +
|
||||||
|
"""
|
||||||
|
Créer un nouvel objet Value correspondant à l'addition des deux opérandes
|
||||||
|
:param other: l'autre élément utilisé dans la multiplication.
|
||||||
|
:return: le nouvel objet Value
|
||||||
|
"""
|
||||||
|
return self.__class__(lambda widget: self.calc(widget) + other.calc(widget))
|
||||||
|
|
||||||
|
def __radd__(self, other): # opérateur +, lorsque cet objet est situé à droite de l'opération
|
||||||
|
return self.__add__(other)
|
||||||
|
|
||||||
|
def __sub__(self, other) -> "Value": # opérateur -
|
||||||
|
"""
|
||||||
|
Créer un nouvel objet Value correspondant à la soustraction des deux opérandes
|
||||||
|
:param other: l'autre élément utilisé dans la multiplication.
|
||||||
|
:return: le nouvel objet Value
|
||||||
|
"""
|
||||||
|
return self.__class__(lambda widget: self.calc(widget) - other.calc(widget))
|
||||||
|
|
||||||
|
def __rsub__(self, other): # opérateur -, lorsque cet objet est situé à droite de l'opération
|
||||||
|
# similaire à __sub__, mais c'est cette valeur qui est soustraite à l'autre
|
||||||
|
return self.__class__(lambda widget: other.calc(widget) - self.calc(widget))
|
||||||
|
|
||||||
|
def __call__(self, widget: "BoxWidget") -> int: # lorsque cet objet est appelé comme une fonction
|
||||||
|
"""
|
||||||
|
Calcul pour le widget en paramètre la valeur associé.
|
||||||
|
:param widget: Le widget à utiliser pour les calculs
|
||||||
|
:return: la position correspondant à ce widget.
|
||||||
|
"""
|
||||||
|
return self.calc(widget)
|
31
source/gui/position/__init__.py
Normal file
31
source/gui/position/__init__.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
from .Value import Value
|
||||||
|
from .Unit import Unit
|
||||||
|
|
||||||
|
px = Unit(lambda value: (lambda widget: value)) # PiXel
|
||||||
|
vw = Unit(lambda value: (lambda widget: int(widget.scene.window.width * (value / 100)))) # Viewport Width
|
||||||
|
vh = Unit(lambda value: (lambda widget: int(widget.scene.window.height * (value / 100)))) # Viewport Height
|
||||||
|
ww = Unit(lambda value: (lambda widget: int(widget.width * (value / 100)))) # Widget Width
|
||||||
|
wh = Unit(lambda value: (lambda widget: int(widget.height * (value / 100)))) # Widget Height
|
||||||
|
|
||||||
|
|
||||||
|
vw_full, vh_full = 100*vw, 100*vh
|
||||||
|
vw_center, vh_center = 50*vw, 50*vh
|
||||||
|
|
||||||
|
ww_full, wh_full = 100*ww, 100*wh
|
||||||
|
ww_center, wh_center = 50*ww, 50*wh
|
||||||
|
|
||||||
|
|
||||||
|
def real_right(value: Value) -> Value: # positionne depuis la droite avec la taille du widget compris
|
||||||
|
return vw_full - value
|
||||||
|
|
||||||
|
|
||||||
|
def real_top(value: Value) -> Value: # positionne depuis le haut avec la taille du widget compris
|
||||||
|
return vh_full - value
|
||||||
|
|
||||||
|
|
||||||
|
def right(value: Value) -> Value: # positionne depuis la droite
|
||||||
|
return real_right(value) - ww_full
|
||||||
|
|
||||||
|
|
||||||
|
def top(value: Value) -> Value: # positionne depuis le haut
|
||||||
|
return real_top(value) - wh_full
|
|
@ -4,7 +4,7 @@ from datetime import datetime, timedelta
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import TYPE_CHECKING, Optional
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from source.gui.position import w_percent, h_percent
|
from source.gui.position import vw, vh
|
||||||
from source.path import path_save, path_history
|
from source.path import path_save, path_history
|
||||||
from source.core.enums import BombState
|
from source.core.enums import BombState
|
||||||
from source.core.error import InvalidBombPosition, PositionAlreadyShot
|
from source.core.error import InvalidBombPosition, PositionAlreadyShot
|
||||||
|
@ -50,7 +50,7 @@ class Game(BaseGame):
|
||||||
self.chat_log = self.add_widget(
|
self.chat_log = self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=10, y=45, width=w_percent(40),
|
x=10, y=45, width=40*vw,
|
||||||
|
|
||||||
text="",
|
text="",
|
||||||
anchor_x="left", anchor_y="bottom",
|
anchor_x="left", anchor_y="bottom",
|
||||||
|
@ -60,7 +60,7 @@ class Game(BaseGame):
|
||||||
self.chat_input = self.add_widget(
|
self.chat_input = self.add_widget(
|
||||||
widget.Input,
|
widget.Input,
|
||||||
|
|
||||||
x=10, y=10, width=w_percent(50), height=30,
|
x=10, y=10, width=50*vw, height=30,
|
||||||
|
|
||||||
type_regex=".{0,60}",
|
type_regex=".{0,60}",
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ class Game(BaseGame):
|
||||||
self.button_save = self.add_widget(
|
self.button_save = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
|
|
||||||
x=w_percent(70), y=0, width=w_percent(15), height=h_percent(10),
|
x=70*vw, y=0, width=15*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Sauvegarder",
|
label_text="Sauvegarder",
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ class Game(BaseGame):
|
||||||
self.label_state = self.add_widget(
|
self.label_state = self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=w_percent(50), y=h_percent(15),
|
x=50*vw, y=15*vh,
|
||||||
|
|
||||||
anchor_x="center",
|
anchor_x="center",
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from source.gui import widget, texture
|
from source.gui import widget, texture
|
||||||
from source.gui.position import w_full, h_percent, w_percent, right_content
|
from source.gui.position import vw_full, vw_center, vh_center, right, px, vw, vh
|
||||||
from source.gui.scene.abc import Scene
|
from source.gui.scene.abc import Scene
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ class GameError(Scene):
|
||||||
self.label = self.add_widget(
|
self.label = self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=w_percent(50), y=h_percent(50), width=w_full,
|
x=vw_center, y=vh_center, width=vw_full,
|
||||||
|
|
||||||
anchor_x="center",
|
anchor_x="center",
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ class GameError(Scene):
|
||||||
self.back = self.add_widget(
|
self.back = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
|
|
||||||
x=right_content(20), y=20, width=w_percent(20), height=h_percent(10),
|
x=right(20*px), y=20, width=20*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Retour",
|
label_text="Retour",
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ from pathlib import Path
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from source.gui import widget, texture
|
from source.gui import widget, texture
|
||||||
from source.gui.position import w_percent, w_full, h_percent, right_content
|
from source.gui.position import vw_full, vw, vh, right, px, vw_center, vh_center
|
||||||
from source.gui.scene.abc import Scene
|
from source.gui.scene.abc import Scene
|
||||||
from source.network import Host
|
from source.network import Host
|
||||||
from source.utils import path_ctime_str
|
from source.utils import path_ctime_str
|
||||||
|
@ -20,7 +20,7 @@ class GameLoad(Scene):
|
||||||
self.label = self.add_widget(
|
self.label = self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=w_percent(50), y=h_percent(50), width=w_full,
|
x=vw_center, y=vh_center, width=vw_full,
|
||||||
|
|
||||||
anchor_x="center",
|
anchor_x="center",
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ class GameLoad(Scene):
|
||||||
self.refuse = self.add_widget(
|
self.refuse = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
|
|
||||||
x=20, y=20, width=w_percent(20), height=h_percent(10),
|
x=20, y=20, width=20*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Refuser",
|
label_text="Refuser",
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class GameLoad(Scene):
|
||||||
self.accept = self.add_widget(
|
self.accept = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
|
|
||||||
x=right_content(20), y=20, width=w_percent(20), height=h_percent(10),
|
x=right(20*px), y=20, width=20*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Accepter",
|
label_text="Accepter",
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from source.gui import widget, texture
|
from source.gui import widget, texture
|
||||||
from source.gui.position import w_full, h_full, w_percent, h_percent
|
from source.gui.position import vw_full, vh_full, vh_center, vw_center, vw, vh
|
||||||
from source.gui.scene.abc.Popup import Popup
|
from source.gui.scene.abc.Popup import Popup
|
||||||
from source.network.packet import PacketQuit
|
from source.network.packet import PacketQuit
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ class GameQuit(Popup):
|
||||||
self.background = self.add_widget(
|
self.background = self.add_widget(
|
||||||
widget.Image,
|
widget.Image,
|
||||||
|
|
||||||
x=0, y=0, width=w_full, height=h_full,
|
x=0, y=0, width=vw_full, height=vh_full,
|
||||||
|
|
||||||
image=texture.Popup.Style1.background
|
image=texture.Popup.Style1.background
|
||||||
)
|
)
|
||||||
|
@ -27,7 +27,7 @@ class GameQuit(Popup):
|
||||||
self.text = self.add_widget(
|
self.text = self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=w_percent(50), y=h_percent(50), width=w_full,
|
x=vw_center, y=vh_center, width=vw_full,
|
||||||
|
|
||||||
anchor_x="center",
|
anchor_x="center",
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ class GameQuit(Popup):
|
||||||
|
|
||||||
self.cancel = self.add_widget(
|
self.cancel = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
x=w_percent(20), y=h_percent(20), width=w_percent(20), height=h_percent(10),
|
x=20*vw, y=20*vh, width=20*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Annuler",
|
label_text="Annuler",
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ class GameQuit(Popup):
|
||||||
|
|
||||||
self.confirm = self.add_widget(
|
self.confirm = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
x=w_percent(60), y=h_percent(20), width=w_percent(20), height=h_percent(10),
|
x=60*vw, y=20*vh, width=20*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Confirmer",
|
label_text="Confirmer",
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ from typing import TYPE_CHECKING
|
||||||
import pyglet.clock
|
import pyglet.clock
|
||||||
|
|
||||||
from source.gui import texture, widget, sound
|
from source.gui import texture, widget, sound
|
||||||
from source.gui.position import w_full, h_full
|
from source.gui.position import vw_full, vh_full
|
||||||
from source.gui.scene.abc.Popup import Popup
|
from source.gui.scene.abc.Popup import Popup
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
@ -20,7 +20,7 @@ class GameResult(Popup):
|
||||||
self.image = self.add_widget(
|
self.image = self.add_widget(
|
||||||
widget.Image,
|
widget.Image,
|
||||||
|
|
||||||
x=0, y=0, width=w_full, height=h_full,
|
x=0, y=0, width=vw_full, height=vh_full,
|
||||||
image=texture.Result.Style1.get("victory" if won else "defeat")
|
image=texture.Result.Style1.get("victory" if won else "defeat")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from source.gui import widget, texture
|
from source.gui import widget, texture
|
||||||
from source.gui.position import h_full, w_full, w_percent, h_percent
|
from source.gui.position import vh_full, vw_full, vw, vh
|
||||||
from source.gui.scene.abc.Popup import Popup
|
from source.gui.scene.abc.Popup import Popup
|
||||||
from source.network.packet import PacketResponseSave
|
from source.network.packet import PacketResponseSave
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ class GameSave(Popup):
|
||||||
self.background = self.add_widget(
|
self.background = self.add_widget(
|
||||||
widget.Image,
|
widget.Image,
|
||||||
|
|
||||||
x=0, y=0, width=w_full, height=h_full,
|
x=0, y=0, width=vw_full, height=vh_full,
|
||||||
|
|
||||||
image=texture.Popup.Style1.background
|
image=texture.Popup.Style1.background
|
||||||
)
|
)
|
||||||
|
@ -27,7 +27,7 @@ class GameSave(Popup):
|
||||||
self.text = self.add_widget(
|
self.text = self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=w_percent(50), y=h_percent(50),
|
x=50*vw, y=50*vh,
|
||||||
|
|
||||||
anchor_x="center",
|
anchor_x="center",
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class GameSave(Popup):
|
||||||
|
|
||||||
self.refuse = self.add_widget(
|
self.refuse = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
x=w_percent(20), y=h_percent(20), width=w_percent(20), height=h_percent(10),
|
x=20*vw, y=20*vh, width=20*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Refuser",
|
label_text="Refuser",
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ class GameSave(Popup):
|
||||||
|
|
||||||
self.accept = self.add_widget(
|
self.accept = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
x=w_percent(60), y=h_percent(20), width=w_percent(20), height=h_percent(10),
|
x=60*vw, y=20*vh, width=20*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Accepter",
|
label_text="Accepter",
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ from pathlib import Path
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from source.gui import widget
|
from source.gui import widget
|
||||||
from source.gui.position import w_percent, h_percent, w_full
|
from source.gui.position import vw_full, vh, vw
|
||||||
from source.gui.scene.abc import Scene
|
from source.gui.scene.abc import Scene
|
||||||
from source.utils import path_ctime_str
|
from source.utils import path_ctime_str
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ class GameWaitLoad(Scene):
|
||||||
self.label = self.add_widget(
|
self.label = self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=w_percent(50), y=h_percent(50), width=w_full,
|
x=50*vw, y=50*vh, width=vw_full,
|
||||||
|
|
||||||
anchor_x="center",
|
anchor_x="center",
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ from pathlib import Path
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from source.gui import widget, texture
|
from source.gui import widget, texture
|
||||||
from source.gui.position import h_percent, w_percent
|
from source.gui.position import vw, vh, vw_center
|
||||||
from source.gui.scene.abc import BaseGame
|
from source.gui.scene.abc import BaseGame
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
@ -41,7 +41,7 @@ class HistoryGame(BaseGame):
|
||||||
|
|
||||||
self.previous = self.add_widget(
|
self.previous = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
x=w_percent(20), y=h_percent(10), width=w_percent(20), height=h_percent(10),
|
x=20*vw, y=10*vh, width=20*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Précédent",
|
label_text="Précédent",
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ class HistoryGame(BaseGame):
|
||||||
|
|
||||||
self.next = self.add_widget(
|
self.next = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
x=w_percent(60), y=h_percent(10), width=w_percent(20), height=h_percent(10),
|
x=60*vw, y=10*vh, width=20*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Suivant",
|
label_text="Suivant",
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ class HistoryGame(BaseGame):
|
||||||
|
|
||||||
self.text_move = self.add_widget(
|
self.text_move = self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
x=w_percent(50), y=h_percent(12),
|
x=vw_center, y=12*vh,
|
||||||
|
|
||||||
anchor_x="center",
|
anchor_x="center",
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import math
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from source.gui.position import w_percent, h_percent
|
from source.gui.position import vw, vh, top
|
||||||
from source.path import path_history
|
from source.path import path_history
|
||||||
from source.gui import widget, texture
|
from source.gui import widget, texture
|
||||||
from source.gui.scene.abc import Scene
|
from source.gui.scene.abc import Scene
|
||||||
|
@ -20,7 +20,7 @@ class HistoryMenu(Scene):
|
||||||
|
|
||||||
self.back = self.add_widget(
|
self.back = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
x=20, y=20, width=w_percent(20), height=h_percent(10),
|
x=20, y=20, width=20*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Retour",
|
label_text="Retour",
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ class HistoryMenu(Scene):
|
||||||
self.title = self.add_widget(
|
self.title = self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=w_percent(50), y=h_percent(80),
|
x=50*vw, y=80*vh,
|
||||||
|
|
||||||
anchor_x="center",
|
anchor_x="center",
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ class HistoryMenu(Scene):
|
||||||
button = self.add_widget(
|
button = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
|
|
||||||
x=w_percent(25), y=h_percent(75 - ((i+1) * 9)), width=w_percent(50), height=h_percent(8),
|
x=25*vw, y=top((25 + (i*9))*vh), width=50*vw, height=8*vh,
|
||||||
|
|
||||||
label_text=path.stem,
|
label_text=path.stem,
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ class HistoryMenu(Scene):
|
||||||
# si nous ne sommes pas à la première page, ajoute un bouton "précédent".
|
# si nous ne sommes pas à la première page, ajoute un bouton "précédent".
|
||||||
self.previous = self.add_widget(
|
self.previous = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
x=w_percent(10), y=h_percent(45), width=w_percent(10), height=h_percent(10),
|
x=10*vw, y=45*vh, width=10*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Précédent",
|
label_text="Précédent",
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ class HistoryMenu(Scene):
|
||||||
# si nous ne sommes pas à la dernière page, ajoute un bouton "suivant".
|
# si nous ne sommes pas à la dernière page, ajoute un bouton "suivant".
|
||||||
self.next = self.add_widget(
|
self.next = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
x=w_percent(80), y=h_percent(45), width=w_percent(10), height=h_percent(10),
|
x=80*vw, y=45*vh, width=10*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Suivant",
|
label_text="Suivant",
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from source.gui.position import w_full, h_full, h_percent, w_percent
|
from source.gui.position import vw_full, vh_full, vw, vh
|
||||||
from source.gui.scene.abc import Scene
|
from source.gui.scene.abc import Scene
|
||||||
from source.gui import widget, scene, texture
|
from source.gui import widget, scene, texture
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ class MainMenu(Scene):
|
||||||
self.background = self.add_widget(
|
self.background = self.add_widget(
|
||||||
widget.Image,
|
widget.Image,
|
||||||
|
|
||||||
x=0, y=0, width=w_full, height=h_full,
|
x=0, y=0, width=vw_full, height=vh_full,
|
||||||
|
|
||||||
image=texture.Background.main
|
image=texture.Background.main
|
||||||
)
|
)
|
||||||
|
@ -23,7 +23,7 @@ class MainMenu(Scene):
|
||||||
self.title = self.add_widget(
|
self.title = self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=50, y=h_percent(85),
|
x=50, y=85*vh,
|
||||||
|
|
||||||
text="Bataille Navale",
|
text="Bataille Navale",
|
||||||
font_size=50
|
font_size=50
|
||||||
|
@ -31,7 +31,7 @@ class MainMenu(Scene):
|
||||||
|
|
||||||
self.game_create = self.add_widget(
|
self.game_create = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
x=50, y=h_percent(50), width=w_percent(30), height=h_percent(10),
|
x=50, y=50*vh, width=30*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Créer une salle",
|
label_text="Créer une salle",
|
||||||
label_font_size=20,
|
label_font_size=20,
|
||||||
|
@ -44,7 +44,7 @@ class MainMenu(Scene):
|
||||||
self.game_join = self.add_widget(
|
self.game_join = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
|
|
||||||
x=50, y=h_percent(35), width=w_percent(30), height=h_percent(10),
|
x=50, y=35*vh, width=30*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Rejoindre une salle",
|
label_text="Rejoindre une salle",
|
||||||
label_font_size=20,
|
label_font_size=20,
|
||||||
|
@ -57,7 +57,7 @@ class MainMenu(Scene):
|
||||||
self.history = self.add_widget(
|
self.history = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
|
|
||||||
x=50, y=h_percent(20), width=w_percent(30), height=h_percent(10),
|
x=50, y=20*vh, width=30*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Historique",
|
label_text="Historique",
|
||||||
label_font_size=20,
|
label_font_size=20,
|
||||||
|
@ -70,7 +70,7 @@ class MainMenu(Scene):
|
||||||
self.settings = self.add_widget(
|
self.settings = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
|
|
||||||
x=50, y=h_percent(5), width=w_percent(30), height=h_percent(10),
|
x=50, y=5*vh, width=30*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Paramètres",
|
label_text="Paramètres",
|
||||||
label_font_size=20,
|
label_font_size=20,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from source.gui import widget, texture, regex
|
from source.gui import widget, texture, regex
|
||||||
from source.gui.position import w_percent, h_percent, right_content
|
from source.gui.position import vw, vh, right, px
|
||||||
from source.gui.scene import RoomHost
|
from source.gui.scene import RoomHost
|
||||||
from source.gui.scene.abc import Scene
|
from source.gui.scene.abc import Scene
|
||||||
from source.network.packet import PacketSettings
|
from source.network.packet import PacketSettings
|
||||||
|
@ -16,7 +16,7 @@ class RoomCreate(Scene):
|
||||||
|
|
||||||
self.back = self.add_widget(
|
self.back = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
x=20, y=20, width=w_percent(20), height=h_percent(10),
|
x=20, y=20, width=20*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Retour",
|
label_text="Retour",
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class RoomCreate(Scene):
|
||||||
self.add_widget(
|
self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=w_percent(10), y=h_percent(65),
|
x=10*vw, y=65*vh,
|
||||||
|
|
||||||
anchor_x="center", anchor_y="center",
|
anchor_x="center", anchor_y="center",
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ class RoomCreate(Scene):
|
||||||
self.input_port = self.add_widget(
|
self.input_port = self.add_widget(
|
||||||
widget.Input,
|
widget.Input,
|
||||||
|
|
||||||
x=w_percent(20), y=h_percent(60), width=w_percent(15), height=h_percent(10),
|
x=20*vw, y=60*vh, width=15*vw, height=10*vh,
|
||||||
|
|
||||||
style=texture.Input.Style1,
|
style=texture.Input.Style1,
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ class RoomCreate(Scene):
|
||||||
self.add_widget(
|
self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=w_percent(10), y=h_percent(50),
|
x=10*vw, y=50*vh,
|
||||||
|
|
||||||
anchor_x="center", anchor_y="center",
|
anchor_x="center", anchor_y="center",
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ class RoomCreate(Scene):
|
||||||
self.input_username = self.add_widget(
|
self.input_username = self.add_widget(
|
||||||
widget.Input,
|
widget.Input,
|
||||||
|
|
||||||
x=w_percent(20), y=h_percent(45), width=w_percent(15), height=h_percent(10),
|
x=20*vw, y=45*vh, width=15*vw, height=10*vh,
|
||||||
|
|
||||||
type_regex=regex.username_type,
|
type_regex=regex.username_type,
|
||||||
check_regex=regex.username_check,
|
check_regex=regex.username_check,
|
||||||
|
@ -81,7 +81,7 @@ class RoomCreate(Scene):
|
||||||
self.add_widget(
|
self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=w_percent(10), y=h_percent(90),
|
x=10*vw, y=90*vh,
|
||||||
anchor_x="center", anchor_y="center",
|
anchor_x="center", anchor_y="center",
|
||||||
text=f"Largeur de la grille"
|
text=f"Largeur de la grille"
|
||||||
)
|
)
|
||||||
|
@ -89,7 +89,7 @@ class RoomCreate(Scene):
|
||||||
self.input_width = self.add_widget(
|
self.input_width = self.add_widget(
|
||||||
widget.Input,
|
widget.Input,
|
||||||
|
|
||||||
x=w_percent(20), y=h_percent(86), width=w_percent(10), height=h_percent(8),
|
x=20*vw, y=86*vh, width=10*vw, height=8*vh,
|
||||||
|
|
||||||
type_regex=regex.number(min_length=0, max_length=4),
|
type_regex=regex.number(min_length=0, max_length=4),
|
||||||
check_regex=regex.number(min_length=1, max_length=4),
|
check_regex=regex.number(min_length=1, max_length=4),
|
||||||
|
@ -102,7 +102,7 @@ class RoomCreate(Scene):
|
||||||
self.add_widget(
|
self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=w_percent(10), y=h_percent(80),
|
x=10*vw, y=80*vh,
|
||||||
anchor_x="center", anchor_y="center",
|
anchor_x="center", anchor_y="center",
|
||||||
text=f"Longueur de la grille"
|
text=f"Longueur de la grille"
|
||||||
)
|
)
|
||||||
|
@ -110,7 +110,7 @@ class RoomCreate(Scene):
|
||||||
self.input_height = self.add_widget(
|
self.input_height = self.add_widget(
|
||||||
widget.Input,
|
widget.Input,
|
||||||
|
|
||||||
x=w_percent(20), y=h_percent(76), width=w_percent(10), height=h_percent(8),
|
x=20*vw, y=76*vh, width=10*vw, height=8*vh,
|
||||||
|
|
||||||
type_regex=regex.number(min_length=0, max_length=4),
|
type_regex=regex.number(min_length=0, max_length=4),
|
||||||
check_regex=regex.number(min_length=1, max_length=4),
|
check_regex=regex.number(min_length=1, max_length=4),
|
||||||
|
@ -125,7 +125,7 @@ class RoomCreate(Scene):
|
||||||
self.checkbox_host_start = self.add_widget(
|
self.checkbox_host_start = self.add_widget(
|
||||||
widget.Checkbox,
|
widget.Checkbox,
|
||||||
|
|
||||||
x=w_percent(40), y=h_percent(80), width=w_percent(5), height=h_percent(10),
|
x=40*vw, y=80*vh, width=5*vw, height=10*vh,
|
||||||
|
|
||||||
style=texture.Checkbox.Style1,
|
style=texture.Checkbox.Style1,
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ class RoomCreate(Scene):
|
||||||
self.add_widget(
|
self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=w_percent(46), y=h_percent(85),
|
x=46*vw, y=85*vh,
|
||||||
|
|
||||||
anchor_y="center",
|
anchor_y="center",
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ class RoomCreate(Scene):
|
||||||
self.button_boat_size_previous = self.add_widget(
|
self.button_boat_size_previous = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
|
|
||||||
x=w_percent(70), y=h_percent(80), width=w_percent(3), height=h_percent(10),
|
x=70*vw, y=80*vh, width=3*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="<",
|
label_text="<",
|
||||||
label_font_size=25,
|
label_font_size=25,
|
||||||
|
@ -176,7 +176,7 @@ class RoomCreate(Scene):
|
||||||
self.label_boat_size = self.add_widget(
|
self.label_boat_size = self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=w_percent(80), y=h_percent(85),
|
x=80*vw, y=85*vh,
|
||||||
|
|
||||||
anchor_x="center", anchor_y="center"
|
anchor_x="center", anchor_y="center"
|
||||||
)
|
)
|
||||||
|
@ -184,7 +184,7 @@ class RoomCreate(Scene):
|
||||||
self.button_boat_size_next = self.add_widget(
|
self.button_boat_size_next = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
|
|
||||||
x=w_percent(87), y=h_percent(80), width=w_percent(3), height=h_percent(10),
|
x=87*vw, y=80*vh, width=3*vw, height=10*vh,
|
||||||
|
|
||||||
label_text=">",
|
label_text=">",
|
||||||
label_font_size=25,
|
label_font_size=25,
|
||||||
|
@ -201,7 +201,7 @@ class RoomCreate(Scene):
|
||||||
self.input_boat_amount = self.add_widget(
|
self.input_boat_amount = self.add_widget(
|
||||||
widget.Input,
|
widget.Input,
|
||||||
|
|
||||||
x=w_percent(70), y=h_percent(68), width=w_percent(20), height=h_percent(8),
|
x=70*vw, y=68*vh, width=20*vw, height=8*vh,
|
||||||
|
|
||||||
type_regex=regex.number(min_length=0, max_length=4),
|
type_regex=regex.number(min_length=0, max_length=4),
|
||||||
check_regex=regex.number(min_length=1, max_length=4),
|
check_regex=regex.number(min_length=1, max_length=4),
|
||||||
|
@ -228,7 +228,7 @@ class RoomCreate(Scene):
|
||||||
self.label_boat_recap = self.add_widget(
|
self.label_boat_recap = self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=w_percent(70), y=h_percent(60), width=w_percent(20), height=h_percent(10),
|
x=70*vw, y=60*vh, width=20*vw, height=10*vh,
|
||||||
|
|
||||||
multiline=True
|
multiline=True
|
||||||
)
|
)
|
||||||
|
@ -239,7 +239,7 @@ class RoomCreate(Scene):
|
||||||
|
|
||||||
self.start = self.add_widget(
|
self.start = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
x=right_content(20), y=20, width=w_percent(20), height=h_percent(10),
|
x=right(20*px), y=20, width=20*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Continuer",
|
label_text="Continuer",
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ from typing import TYPE_CHECKING
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from source import network
|
from source import network
|
||||||
from source.gui.position import w_percent, h_percent
|
from source.gui.position import vw, vh
|
||||||
from source.gui.scene.abc import Scene
|
from source.gui.scene.abc import Scene
|
||||||
from source.gui import widget, texture
|
from source.gui import widget, texture
|
||||||
from source.utils.thread import in_pyglet_context, StoppableThread
|
from source.utils.thread import in_pyglet_context, StoppableThread
|
||||||
|
@ -23,7 +23,7 @@ class RoomHost(Scene):
|
||||||
|
|
||||||
self.back = self.add_widget(
|
self.back = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
x=20, y=20, width=w_percent(20), height=h_percent(10),
|
x=20, y=20, width=20*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Retour",
|
label_text="Retour",
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ class RoomHost(Scene):
|
||||||
self.label_ip = self.add_widget(
|
self.label_ip = self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=w_percent(50), y=h_percent(55),
|
x=50*vw, y=55*vh,
|
||||||
|
|
||||||
anchor_x="center", anchor_y="center",
|
anchor_x="center", anchor_y="center",
|
||||||
font_size=20
|
font_size=20
|
||||||
|
@ -44,7 +44,7 @@ class RoomHost(Scene):
|
||||||
self.description = self.add_widget(
|
self.description = self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=w_percent(50), y=h_percent(45),
|
x=50*vw, y=45*vh,
|
||||||
|
|
||||||
anchor_x="center", anchor_y="center",
|
anchor_x="center", anchor_y="center",
|
||||||
text="En attente d'un second joueur..."
|
text="En attente d'un second joueur..."
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from typing import TYPE_CHECKING, Optional
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from source import network
|
from source import network
|
||||||
from source.gui.position import w_percent, h_percent
|
from source.gui.position import vw, vh
|
||||||
from source.gui.scene.abc import Scene
|
from source.gui.scene.abc import Scene
|
||||||
from source.gui import widget, texture, regex
|
from source.gui import widget, texture, regex
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ class RoomJoin(Scene):
|
||||||
|
|
||||||
self.back = self.add_widget(
|
self.back = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
x=20, y=20, width=w_percent(20), height=h_percent(10),
|
x=20, y=20, width=20*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Retour",
|
label_text="Retour",
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ class RoomJoin(Scene):
|
||||||
|
|
||||||
self.entry_username = self.add_widget(
|
self.entry_username = self.add_widget(
|
||||||
widget.Input,
|
widget.Input,
|
||||||
x=w_percent(40), y=h_percent(55), width=w_percent(20), height=h_percent(10),
|
x=40*vw, y=55*vh, width=20*vw, height=10*vh,
|
||||||
|
|
||||||
type_regex=regex.username_type,
|
type_regex=regex.username_type,
|
||||||
check_regex=regex.username_check,
|
check_regex=regex.username_check,
|
||||||
|
@ -42,7 +42,7 @@ class RoomJoin(Scene):
|
||||||
|
|
||||||
self.entry_ip = self.add_widget(
|
self.entry_ip = self.add_widget(
|
||||||
widget.Input,
|
widget.Input,
|
||||||
x=w_percent(40), y=h_percent(45), width=w_percent(13), height=h_percent(10),
|
x=40*vw, y=45*vh, width=13*vw, height=10*vh,
|
||||||
|
|
||||||
type_regex=regex.ipv4_type,
|
type_regex=regex.ipv4_type,
|
||||||
check_regex=regex.ipv4_check,
|
check_regex=regex.ipv4_check,
|
||||||
|
@ -54,7 +54,7 @@ class RoomJoin(Scene):
|
||||||
|
|
||||||
self.entry_port = self.add_widget(
|
self.entry_port = self.add_widget(
|
||||||
widget.Input,
|
widget.Input,
|
||||||
x=w_percent(53), y=h_percent(45), width=w_percent(7), height=h_percent(10),
|
x=53*vw, y=45*vh, width=7*vw, height=10*vh,
|
||||||
|
|
||||||
type_regex=regex.port_type,
|
type_regex=regex.port_type,
|
||||||
check_regex=regex.port_check,
|
check_regex=regex.port_check,
|
||||||
|
@ -66,7 +66,7 @@ class RoomJoin(Scene):
|
||||||
|
|
||||||
self.connect = self.add_widget(
|
self.connect = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
x=w_percent(40), y=h_percent(35), width=w_percent(20), height=h_percent(10),
|
x=40*vw, y=35*vh, width=20*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Se connecter",
|
label_text="Se connecter",
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ class RoomJoin(Scene):
|
||||||
|
|
||||||
self.status = self.add_widget(
|
self.status = self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
x=w_percent(50), y=h_percent(25),
|
x=50*vw, y=25*vh,
|
||||||
|
|
||||||
anchor_x="center",
|
anchor_x="center",
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from source.gui import widget, texture
|
from source.gui import widget, texture
|
||||||
from source.gui.position import w_full, h_full, w_percent, h_percent
|
from source.gui.position import vw_full, vh_full, vw, vh
|
||||||
from source.gui.scene.abc.Popup import Popup
|
from source.gui.scene.abc.Popup import Popup
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
@ -15,14 +15,14 @@ class Settings(Popup):
|
||||||
self.background = self.add_widget(
|
self.background = self.add_widget(
|
||||||
widget.Image,
|
widget.Image,
|
||||||
|
|
||||||
x=0, y=0, width=w_full, height=h_full,
|
x=0, y=0, width=vw_full, height=vh_full,
|
||||||
|
|
||||||
image=texture.Popup.Style1.background
|
image=texture.Popup.Style1.background
|
||||||
)
|
)
|
||||||
|
|
||||||
self.back = self.add_widget(
|
self.back = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
x=20, y=20, width=w_percent(20), height=h_percent(10),
|
x=20, y=20, width=20*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Retour",
|
label_text="Retour",
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ class Settings(Popup):
|
||||||
self.checkbox = self.add_widget(
|
self.checkbox = self.add_widget(
|
||||||
widget.Checkbox,
|
widget.Checkbox,
|
||||||
|
|
||||||
x=w_percent(45), y=h_percent(45), width=w_percent(10), height=h_percent(10),
|
x=45*vw, y=45*vh, width=10*vw, height=10*vh,
|
||||||
|
|
||||||
style=texture.Checkbox.Style1
|
style=texture.Checkbox.Style1
|
||||||
)
|
)
|
||||||
|
@ -45,7 +45,7 @@ class Settings(Popup):
|
||||||
self.scroller = self.add_widget(
|
self.scroller = self.add_widget(
|
||||||
widget.Scroller,
|
widget.Scroller,
|
||||||
|
|
||||||
x=w_percent(30), y=h_percent(20), width=w_percent(30), height=h_percent(10),
|
x=30*vw, y=20*vh, width=30*vw, height=10*vh,
|
||||||
|
|
||||||
style=texture.Scroller.Style1,
|
style=texture.Scroller.Style1,
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ from abc import ABC
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from source.gui import widget, texture
|
from source.gui import widget, texture
|
||||||
from source.gui.position import right_content, h_percent, w_percent, w_full, h_full
|
from source.gui.position import right, vw, vh, vw_full, vh_full, px
|
||||||
from source.gui.scene.abc import Scene
|
from source.gui.scene.abc import Scene
|
||||||
from source.type import Point2D
|
from source.type import Point2D
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ class BaseGame(Scene, ABC):
|
||||||
self.background = self.add_widget(
|
self.background = self.add_widget(
|
||||||
widget.Image,
|
widget.Image,
|
||||||
|
|
||||||
x=0, y=0, width=w_full, height=h_full,
|
x=0, y=0, width=vw_full, height=vh_full,
|
||||||
|
|
||||||
image=texture.Background.game,
|
image=texture.Background.game,
|
||||||
)
|
)
|
||||||
|
@ -43,7 +43,7 @@ class BaseGame(Scene, ABC):
|
||||||
self.grid_ally = self.add_widget(
|
self.grid_ally = self.add_widget(
|
||||||
widget.GameGrid,
|
widget.GameGrid,
|
||||||
|
|
||||||
x=75, y=h_percent(25), width=w_percent(35), height=h_percent(50),
|
x=75, y=25*vh, width=35*vw, height=50*vh,
|
||||||
|
|
||||||
boats_length=self.boats_length,
|
boats_length=self.boats_length,
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ class BaseGame(Scene, ABC):
|
||||||
self.grid_enemy = self.add_widget(
|
self.grid_enemy = self.add_widget(
|
||||||
widget.GameGrid,
|
widget.GameGrid,
|
||||||
|
|
||||||
x=right_content(75), y=h_percent(25), width=w_percent(35), height=h_percent(50),
|
x=right(75*px), y=25*vh, width=35*vw, height=50*vh,
|
||||||
|
|
||||||
grid_style=texture.Grid.Style1,
|
grid_style=texture.Grid.Style1,
|
||||||
boat_style=texture.Grid.Boat.Style1,
|
boat_style=texture.Grid.Boat.Style1,
|
||||||
|
@ -69,7 +69,7 @@ class BaseGame(Scene, ABC):
|
||||||
self.add_widget(
|
self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=w_percent(27), y=h_percent(99.5),
|
x=27*vw, y=99.5*vh,
|
||||||
|
|
||||||
text=self.name_ally,
|
text=self.name_ally,
|
||||||
font_size=20,
|
font_size=20,
|
||||||
|
@ -79,7 +79,7 @@ class BaseGame(Scene, ABC):
|
||||||
self.add_widget(
|
self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=w_percent(73), y=h_percent(99.5),
|
x=73*vw, y=99.5*vh,
|
||||||
|
|
||||||
text=self.name_enemy,
|
text=self.name_enemy,
|
||||||
font_size=20,
|
font_size=20,
|
||||||
|
@ -89,7 +89,7 @@ class BaseGame(Scene, ABC):
|
||||||
self.score_ally = self.add_widget(
|
self.score_ally = self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=w_percent(44), y=h_percent(99.5),
|
x=44*vw, y=99.5*vh,
|
||||||
|
|
||||||
text="0",
|
text="0",
|
||||||
font_size=25,
|
font_size=25,
|
||||||
|
@ -99,7 +99,7 @@ class BaseGame(Scene, ABC):
|
||||||
self.score_enemy = self.add_widget(
|
self.score_enemy = self.add_widget(
|
||||||
widget.Text,
|
widget.Text,
|
||||||
|
|
||||||
x=w_percent(56), y=h_percent(99.5),
|
x=56*vw, y=99.5*vh,
|
||||||
|
|
||||||
text="0",
|
text="0",
|
||||||
font_size=25,
|
font_size=25,
|
||||||
|
@ -109,7 +109,7 @@ class BaseGame(Scene, ABC):
|
||||||
self.button_quit = self.add_widget(
|
self.button_quit = self.add_widget(
|
||||||
widget.Button,
|
widget.Button,
|
||||||
|
|
||||||
x=w_percent(85), y=0, width=w_percent(15), height=h_percent(10),
|
x=85*vw, y=0, width=15*vw, height=10*vh,
|
||||||
|
|
||||||
label_text="Quitter",
|
label_text="Quitter",
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ from abc import ABC
|
||||||
from typing import TYPE_CHECKING, Optional
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from source.gui.widget.abc import Widget
|
from source.gui.widget.abc import Widget
|
||||||
from source.type import Distance, Percentage
|
from source.type import Distance
|
||||||
from source.utils import in_bbox
|
from source.utils import in_bbox
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
@ -33,15 +33,13 @@ class BoxWidget(Widget, ABC):
|
||||||
|
|
||||||
# property
|
# property
|
||||||
|
|
||||||
def _getter_distance(self, max_distance: int, raw_distance: Distance) -> int:
|
def _getter_distance(self, raw_distance: Distance) -> int:
|
||||||
"""
|
"""
|
||||||
Return the true distance in pixel from a more abstract distance
|
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
|
:param raw_distance: the distance object to convert to pixel
|
||||||
:return: the true distance in 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 isinstance(raw_distance, int): return raw_distance
|
||||||
if callable(raw_distance): return raw_distance(self)
|
if callable(raw_distance): return raw_distance(self)
|
||||||
if raw_distance is None: return 0
|
if raw_distance is None: return 0
|
||||||
|
@ -50,7 +48,7 @@ class BoxWidget(Widget, ABC):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def x(self) -> int:
|
def x(self) -> int:
|
||||||
return self._getter_distance(self.scene.window.width, self._x)
|
return self._getter_distance(self._x)
|
||||||
|
|
||||||
@x.setter
|
@x.setter
|
||||||
def x(self, x: Distance):
|
def x(self, x: Distance):
|
||||||
|
@ -58,7 +56,7 @@ class BoxWidget(Widget, ABC):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def y(self) -> int:
|
def y(self) -> int:
|
||||||
return self._getter_distance(self.scene.window.height, self._y)
|
return self._getter_distance(self._y)
|
||||||
|
|
||||||
@y.setter
|
@y.setter
|
||||||
def y(self, y: Distance):
|
def y(self, y: Distance):
|
||||||
|
@ -82,7 +80,7 @@ class BoxWidget(Widget, ABC):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def width(self) -> int:
|
def width(self) -> int:
|
||||||
return self._getter_distance(self.scene.window.width, self._width)
|
return self._getter_distance(self._width)
|
||||||
|
|
||||||
@width.setter
|
@width.setter
|
||||||
def width(self, width: Optional[Distance]):
|
def width(self, width: Optional[Distance]):
|
||||||
|
@ -90,7 +88,7 @@ class BoxWidget(Widget, ABC):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def height(self) -> int:
|
def height(self) -> int:
|
||||||
return self._getter_distance(self.scene.window.height, self._height)
|
return self._getter_distance(self._height)
|
||||||
|
|
||||||
@height.setter
|
@height.setter
|
||||||
def height(self, height: Optional[Distance]):
|
def height(self, height: Optional[Distance]):
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
from typing import Union, Callable, Any
|
from typing import Union, Callable
|
||||||
|
|
||||||
|
|
||||||
Point2D = tuple[int, int] # a 2D point
|
Point2D = tuple[int, int] # a 2D point
|
||||||
BBox = tuple[int, int, int, int] # a boundary box
|
BBox = tuple[int, int, int, int] # a boundary box
|
||||||
Percentage = float # a percentage, represented as a number between 0 and 1
|
|
||||||
ColorRGB = tuple[int, int, int] # a RGB Color
|
ColorRGB = tuple[int, int, int] # a RGB Color
|
||||||
ColorRGBA = tuple[int, int, int, int] # a RGBA Color
|
ColorRGBA = tuple[int, int, int, int] # a RGBA Color
|
||||||
|
|
||||||
DistanceFunction = Callable[[Any], int] # a function that return a distance
|
DistanceFunc = Callable[["BoxWidget"], int] # a function that return a position / distance
|
||||||
Distance = Union[int, Percentage, DistanceFunction] # a distance, represented by a number, a percentage or a function
|
Distance = Union[int, DistanceFunc] # a position / distance, represented by a number or a function
|
||||||
|
|
Loading…
Reference in a new issue