added popup alongside scene

This commit is contained in:
Faraphel 2023-03-03 13:06:08 +01:00
parent 0872883a5c
commit 16e88462a1
9 changed files with 40 additions and 20 deletions

View file

@ -12,7 +12,6 @@ A faire :
- Voir si les event listener intégré à pyglet sont plus pratique que l'event propagation (?) - Voir si les event listener intégré à pyglet sont plus pratique que l'event propagation (?)
- Faire une scène incluant par défaut les boutons "Retour" (?) - Faire une scène incluant par défaut les boutons "Retour" (?)
- Faire des scènes "pop-up" (?)
Bug : Bug :

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

View file

@ -5,12 +5,13 @@ import pyglet.clock
from source.gui import texture, widget from source.gui import texture, widget
from source.gui.event import StopEvent from source.gui.event import StopEvent
from source.gui.scene.abc import Scene from source.gui.scene.abc import Scene
from source.gui.scene.abc.Popup import Popup
if TYPE_CHECKING: if TYPE_CHECKING:
from source.gui.window import Window from source.gui.window import Window
class Result(Scene): class Result(Popup):
def __init__(self, window: "Window", won: bool, **kwargs): def __init__(self, window: "Window", won: bool, **kwargs):
super().__init__(window, **kwargs) super().__init__(window, **kwargs)
@ -25,9 +26,3 @@ class Result(Scene):
from source.gui.scene import MainMenu from source.gui.scene import MainMenu
pyglet.clock.schedule_once(lambda dt: self.window.set_scene(MainMenu), 5.0) pyglet.clock.schedule_once(lambda dt: self.window.set_scene(MainMenu), 5.0)
def on_mouse_press_after(self, x: int, y: int, button: int, modifiers: int):
raise StopEvent()
def on_mouse_motion_after(self, x: int, y: int, button: int, modifiers: int):
raise StopEvent()

View file

@ -1,17 +1,24 @@
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from source.gui.event import StopEvent
from source.gui.scene.abc import Scene
from source.gui import widget, texture from source.gui import widget, texture
from source.gui.scene.abc.Popup import Popup
if TYPE_CHECKING: if TYPE_CHECKING:
from source.gui.window import Window from source.gui.window import Window
class Settings(Scene): class Settings(Popup):
def __init__(self, window: "Window", **kwargs): def __init__(self, window: "Window", **kwargs):
super().__init__(window, **kwargs) super().__init__(window, **kwargs)
self.background = self.add_widget(
widget.Image,
x=0, y=0, width=1.0, height=1.0,
image=texture.Popup.Style1.background
)
self.back = self.add_widget( self.back = self.add_widget(
widget.Button, widget.Button,
x=20, y=20, width=0.2, height=0.1, x=20, y=20, width=0.2, height=0.1,
@ -43,9 +50,3 @@ class Settings(Scene):
text_transform=lambda value: round(value, 2) text_transform=lambda value: round(value, 2)
) )
def on_mouse_press_after(self, x: int, y: int, button: int, modifiers: int):
raise StopEvent()
def on_mouse_motion_after(self, x: int, y: int, button: int, modifiers: int):
raise StopEvent()

View file

@ -0,0 +1,16 @@
from abc import ABC
from source.gui.event import StopEvent
from source.gui.scene.abc import Scene
class Popup(Scene, ABC):
"""
Similaire à une Scène, mais empêche les interactions avec les scènes en arrière-plan.
"""
def on_mouse_press_after(self, x: int, y: int, button: int, modifiers: int):
raise StopEvent()
def on_mouse_motion_after(self, x: int, y: int, button: int, modifiers: int):
raise StopEvent()

View file

@ -0,0 +1,10 @@
from . import path
from .abc import Style
from .type import Texture
path = path / "popup"
class Popup:
class Style1(Style):
background = Texture(path / "background.png")

View file

@ -2,6 +2,7 @@ from pathlib import Path
path: Path = Path("./assets/image") path: Path = Path("./assets/image")
from .Popup import Popup
from .Background import Background from .Background import Background
from .Button import Button from .Button import Button
from .Checkbox import Checkbox from .Checkbox import Checkbox

View file

@ -38,7 +38,7 @@ class Image(BoxWidget):
# refresh # refresh
def _refresh_size(self): def _refresh_size(self):
self.image.width, self.image.height = self.size self.image.x, self.image.y, self.image.width, self.image.height = self.bbox
# event # event

View file

@ -121,8 +121,6 @@ class Input(BoxWidget):
self.trigger_event("on_enter") self.trigger_event("on_enter")
def on_text(self, char: str): def on_text(self, char: str):
print("on_text")
if not self.activated: return # ignore si ce widget est désactivé / non sélectionné if not self.activated: return # ignore si ce widget est désactivé / non sélectionné
if not self.label.multiline and char in "\r\n": return # si le texte est sur une ligne, ignore les retours if not self.label.multiline and char in "\r\n": return # si le texte est sur une ligne, ignore les retours