ecs #58
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -25,17 +25,19 @@ 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
|
||||
):
|
||||
text.text += key
|
||||
if text.text == "...":
|
||||
text.text = key
|
||||
else:
|
||||
text.text += key
|
||||
|
||||
|
||||
PLUGIN = Scene(
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue