ecs #58

Merged
raphael merged 70 commits from ecs into main 2023-11-03 15:29:36 +00:00
4 changed files with 14 additions and 6 deletions
Showing only changes of commit d922afc37e - Show all commits

View file

@ -23,12 +23,14 @@ class Text:
size: int = 50,
color: pygame.Color = pygame.Color(255, 255, 255),
position: Vec2 = Vec2(0),
order: float = -1.0,
origin: Vec2 = Vec2(0),
):
self.text = text
self.size = size
self.color = color
self.position = position
self.order = order
self.origin = origin
@ -47,6 +49,7 @@ def __render_texts(world: World):
else:
entity[Sprite] = Sprite(texture)
entity[Sprite].position = text.position
entity[Sprite].order = text.order
entity[Sprite].origin = text.origin

View file

@ -25,16 +25,18 @@ def __update(world: World):
for entity in world.query(Writing, Text):
text = entity[Text]
for key in pressed:
if text.text == "...":
text.text = ""
if key == "backspace":
text.text = text.text[:-1]
if text.text == "":
text.text = "..."
if key.startswith("["): # pavé numerique
key = key[1]
if (
key in entity[Writing].accepted_chars
and len(text.text) < entity[Writing].max_chars
if key in entity[Writing].accepted_chars and (
text.text == "..." or len(text.text) < entity[Writing].max_chars
):
if text.text == "...":
text.text = key
else:
text.text += key

View file

@ -122,6 +122,7 @@ def __initialize_world(world: World):
150,
text_color,
Vec2(render.WIDTH / 2, 450),
1.0,
Vec2(0.5),
),
Response(),
@ -133,6 +134,7 @@ def __initialize_world(world: World):
150,
text_color,
Vec2(render.WIDTH / 2, 650),
1.0,
Vec2(0.5),
),
Writing("0123456789", 2),

View file

@ -24,6 +24,7 @@ def __create_button(world: World, assets: Assets, i: int, name: str):
Sprite(
assets.error_texture,
Vec2(render.WIDTH / 2, 450 + 150 * i),
1,
origin=Vec2(0.5),
),
HoveredTexture(