diff --git a/pysamp/textdraw.py b/pysamp/textdraw.py index 2363216..e5497d8 100644 --- a/pysamp/textdraw.py +++ b/pysamp/textdraw.py @@ -22,8 +22,9 @@ text_draw_text_size, text_draw_use_box, select_text_draw, - cancel_select_text_draw + cancel_select_text_draw, ) +from pysamp.event import event class TextDraw: @@ -36,6 +37,7 @@ class TextDraw: To create a new textdraw, use :meth:`TextDraw.create`. """ + def __init__(self, id: int) -> None: self.id = id @@ -75,9 +77,7 @@ def create(cls, x: float, y: float, text: str) -> "TextDraw": - If part of the text is off-screen, the color of the text will\ not show, only the shadow (if enabled) will. """ - return cls( - text_draw_create(x, y, text) - ) + return cls(text_draw_create(x, y, text)) def destroy(self) -> bool: """Destroy the textdraw. @@ -286,11 +286,7 @@ def set_preview_model(self, model_index: int) -> bool: return text_draw_set_preview_model(self.id, model_index) def set_preview_rotation( - self, - rotation_x: float, - rotation_y: float, - rotation_z: float, - zoom: float = 1.0 + self, rotation_x: float, rotation_y: float, rotation_z: float, zoom: float = 1.0 ) -> bool: """Sets the rotation and zoom of a 3D model preview textdraw. @@ -355,5 +351,28 @@ def cancel_select(self, player: "Player") -> bool: """ return cancel_select_text_draw(player.id) + @event("OnPlayerClickTextDraw") + def on_click(cls, player_id: int, clicked_id: int): + """This event is called when a player clicks on the instance of the + TextDraw. + + :param Player player: The player that clicked on the + textdraw. + :returns: No return value. + + .. warning:: + The clickable area is defined by :meth:`TextDraw.text_size()`. + The x and y parameters passed to that function + must not be zero or negative. + Do not use :meth:`TextDraw.cancel_select()` unconditionally + within this event. This results in an infinite loop. + + Wraps: https://open.mp/docs/scripting/callbacks/OnPlayerClickTextDraw + """ + if clicked_id != cls.id: + return + + return Player(player_id) + from .player import Player # noqa