finished the history menu
This commit is contained in:
parent
f3ee475c2e
commit
3df01c695c
3 changed files with 96 additions and 6 deletions
26
source/gui/scene/HistoryGame.py
Normal file
26
source/gui/scene/HistoryGame.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from source.gui import widget
|
||||
from source.gui.scene.abc import Scene
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from source.gui.window import Window
|
||||
|
||||
|
||||
class HistoryGame(Scene):
|
||||
def __init__(self, window: "Window", history_path: Path, **kwargs):
|
||||
super().__init__(window, **kwargs)
|
||||
|
||||
self.history_path = history_path
|
||||
|
||||
self.add_widget(
|
||||
widget.Text,
|
||||
|
||||
x=0.5, y=0.5,
|
||||
|
||||
anchor_x="center", anchor_y="center",
|
||||
|
||||
text=str(history_path)
|
||||
)
|
|
@ -1,3 +1,5 @@
|
|||
import math
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from source import path_history
|
||||
|
@ -10,22 +12,83 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
class HistoryMenu(Scene):
|
||||
PAGE_SIZE: int = 10
|
||||
PAGE_SIZE: int = 8
|
||||
|
||||
def __init__(self, window: "Window", page: int = 0, **kwargs):
|
||||
super().__init__(window, **kwargs)
|
||||
|
||||
for i, path in enumerate(
|
||||
list(path_history.iterdir())
|
||||
[page*self.PAGE_SIZE:(page+1)*self.PAGE_SIZE]
|
||||
):
|
||||
self.back = self.add_widget(
|
||||
widget.Button,
|
||||
x=20, y=20, width=0.2, height=0.1,
|
||||
|
||||
label_text="Retour",
|
||||
|
||||
style=texture.Button.Style1
|
||||
)
|
||||
|
||||
from source.gui.scene import MainMenu
|
||||
self.back.add_listener("on_click_release", lambda *_: self.window.set_scene(MainMenu))
|
||||
|
||||
# génère les boutons des sauvegardes
|
||||
paths: list[Path] = list(path_history.iterdir())
|
||||
page_max: int = math.ceil(len(paths) / self.PAGE_SIZE)
|
||||
|
||||
self.title = self.add_widget(
|
||||
widget.Text,
|
||||
|
||||
x=0.5, y=0.80,
|
||||
|
||||
anchor_x="center",
|
||||
|
||||
text=f"Page {page+1}/{page_max}",
|
||||
font_size=50
|
||||
)
|
||||
|
||||
for i, path in enumerate(paths[page*self.PAGE_SIZE:(page+1)*self.PAGE_SIZE]):
|
||||
button = self.add_widget(
|
||||
widget.Button,
|
||||
|
||||
x=0.2, y=1.0 - ((i+1) * 0.1), width=0.6, height=0.1,
|
||||
x=0.25, y=0.75 - ((i+1) * 0.09), width=0.5, height=0.08,
|
||||
|
||||
label_text=path.stem,
|
||||
|
||||
style=texture.Button.Style1
|
||||
)
|
||||
|
||||
from source.gui.scene import HistoryGame
|
||||
button.add_listener(
|
||||
"on_click_release",
|
||||
(lambda path: (lambda *_: self.window.set_scene(HistoryGame, history_path=path)))(path)
|
||||
)
|
||||
|
||||
if page > 0:
|
||||
# si nous ne sommes pas à la première page, ajoute un bouton "précédent".
|
||||
self.previous = self.add_widget(
|
||||
widget.Button,
|
||||
x=0.1, y=0.45, width=0.1, height=0.1,
|
||||
|
||||
label_text="Précédent",
|
||||
|
||||
style=texture.Button.Style1
|
||||
)
|
||||
|
||||
self.previous.add_listener(
|
||||
"on_click_release",
|
||||
lambda *_: self.window.set_scene(self.__class__, page=page-1)
|
||||
)
|
||||
|
||||
if page < page_max - 1:
|
||||
# si nous ne sommes pas à la dernière page, ajoute un bouton "suivant".
|
||||
self.next = self.add_widget(
|
||||
widget.Button,
|
||||
x=0.80, y=0.45, width=0.1, height=0.1,
|
||||
|
||||
label_text="Suivant",
|
||||
|
||||
style=texture.Button.Style1
|
||||
)
|
||||
|
||||
self.next.add_listener(
|
||||
"on_click_release",
|
||||
lambda *_: self.window.set_scene(self.__class__, page=page+1)
|
||||
)
|
||||
|
|
|
@ -10,5 +10,6 @@ from .RoomHost import RoomHost
|
|||
from .RoomJoin import RoomJoin
|
||||
from .RoomCreate import RoomCreate
|
||||
from .HistoryMenu import HistoryMenu
|
||||
from .HistoryGame import HistoryGame
|
||||
|
||||
from .MainMenu import MainMenu
|
||||
|
|
Loading…
Reference in a new issue