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, size: int = 50,
color: pygame.Color = pygame.Color(255, 255, 255), color: pygame.Color = pygame.Color(255, 255, 255),
position: Vec2 = Vec2(0), position: Vec2 = Vec2(0),
order: float = -1.0,
origin: Vec2 = Vec2(0), origin: Vec2 = Vec2(0),
): ):
self.text = text self.text = text
self.size = size self.size = size
self.color = color self.color = color
self.position = position self.position = position
self.order = order
self.origin = origin self.origin = origin
@ -47,6 +49,7 @@ def __render_texts(world: World):
else: else:
entity[Sprite] = Sprite(texture) entity[Sprite] = Sprite(texture)
entity[Sprite].position = text.position entity[Sprite].position = text.position
entity[Sprite].order = text.order
entity[Sprite].origin = text.origin entity[Sprite].origin = text.origin

View file

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

View file

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

View file

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