omp_gdk/scripting/textlabels/
mod.rs1pub mod functions;
2
3use std::ffi::c_void;
4
5use crate::{players::Player, types::colour::Colour, types::vector::Vector3, vehicles::Vehicle};
6
7pub use functions::load_functions;
8
9pub struct TextLabel {
10 handle: *const c_void,
11}
12
13impl TextLabel {
14 pub fn get_handle(&self) -> *const c_void {
15 self.handle
16 }
17 pub fn new(handle: *const c_void) -> Self {
18 Self { handle }
19 }
20 pub fn create(
22 text: &str,
23 colour: Colour,
24 position: Vector3,
25 drawDistance: f32,
26 virtualWorld: i32,
27 los: bool,
28 ) -> Option<TextLabel> {
29 let mut _id = 0;
30 functions::TextLabel_Create(
31 text,
32 colour.rgba(),
33 position.x,
34 position.y,
35 position.z,
36 drawDistance,
37 virtualWorld,
38 los,
39 &mut _id,
40 )
41 }
42 pub fn delete(&self) -> bool {
44 functions::TextLabel_Destroy(self)
45 }
46 pub fn attach_to_player(&self, player: &Player, offset: Vector3) -> bool {
48 functions::TextLabel_AttachToPlayer(self, player, offset.x, offset.y, offset.z)
49 }
50 pub fn attach_to_vehicle(&self, vehicle: &Vehicle, offset: Vector3) -> bool {
52 functions::TextLabel_AttachToVehicle(self, vehicle, offset.x, offset.y, offset.z)
53 }
54 pub fn update_text(&self, colour: Colour, text: &str) -> bool {
56 functions::TextLabel_UpdateText(self, colour.rgba(), text)
57 }
58 pub fn is_streamed_in(&self, player: &Player) -> bool {
60 functions::TextLabel_IsStreamedIn(player, self)
61 }
62 pub fn get_text(&self) -> String {
64 let mut output = String::new();
65 functions::TextLabel_GetText(self, &mut output, 64);
66 output
67 }
68 pub fn get_color(&self) -> Colour {
70 Colour::from_rgba(functions::TextLabel_GetColor(self))
71 }
72 pub fn get_pos(&self) -> Vector3 {
74 let mut out = Vector3::default();
75 functions::TextLabel_GetPos(self, &mut out.x, &mut out.y, &mut out.z);
76 out
77 }
78 pub fn set_draw_distance(&self, distance: f32) -> bool {
80 functions::TextLabel_SetDrawDistance(self, distance)
81 }
82 pub fn get_draw_distance(&self) -> f32 {
84 functions::TextLabel_GetDrawDistance(self)
85 }
86 pub fn get_los(&self) -> bool {
88 functions::TextLabel_GetLOS(self)
89 }
90 pub fn set_los(&self, status: bool) -> bool {
92 functions::TextLabel_SetLOS(self, status)
93 }
94 pub fn get_virtual_world(&self) -> i32 {
96 functions::TextLabel_GetVirtualWorld(self)
97 }
98 pub fn set_virtual_world(&self, world: i32) -> bool {
100 functions::TextLabel_SetVirtualWorld(self, world)
101 }
102 pub fn get_attached_data(&self) -> TextLabelAttachmentData {
104 let mut data = TextLabelAttachmentData::default();
105 functions::TextLabel_GetAttachedData(self, &mut data.playerID, &mut data.vehicleID);
106 data
107 }
108 pub fn get_id(&self) -> i32 {
109 functions::TextLabel_GetID(self)
110 }
111 pub fn from_id(id: i32) -> Option<TextLabel> {
112 functions::TextLabel_FromID(id)
113 }
114}
115
116#[derive(Clone, Copy)]
117pub struct PlayerTextLabel {
118 handle: *const c_void,
119 pub player: Player,
120}
121
122impl PlayerTextLabel {
123 pub fn get_handle(&self) -> *const c_void {
124 self.handle
125 }
126 pub fn new(handle: *const c_void, player: Player) -> Self {
127 Self { handle, player }
128 }
129
130 pub fn update_text(&self, colour: Colour, text: &str) -> bool {
132 functions::PlayerTextLabel_UpdateText(&self.player, self, colour.rgba(), text)
133 }
134 pub fn get_text(&self) -> String {
136 let mut output = String::new();
137 functions::PlayerTextLabel_GetText(&self.player, self, &mut output, 64);
138 output
139 }
140 pub fn get_color(&self) -> Colour {
142 let mut colourint = 0;
143 functions::PlayerTextLabel_GetColor(&self.player, self, &mut colourint);
144 Colour::from_rgba(colourint)
145 }
146 pub fn get_pos(&self) -> Vector3 {
148 let mut out = Vector3::default();
149 functions::PlayerTextLabel_GetPos(&self.player, self, &mut out.x, &mut out.y, &mut out.z);
150 out
151 }
152 pub fn set_draw_distance(&self, distance: f32) -> bool {
153 functions::PlayerTextLabel_SetDrawDistance(&self.player, self, distance)
154 }
155 pub fn get_draw_distance(&self) -> f32 {
157 functions::PlayerTextLabel_GetDrawDistance(&self.player, self)
158 }
159 pub fn get_los(&self) -> bool {
161 functions::PlayerTextLabel_GetLOS(&self.player, self)
162 }
163 pub fn set_los(&self, status: bool) -> bool {
164 functions::PlayerTextLabel_SetLOS(&self.player, self, status)
165 }
166 pub fn get_attached_data(&self) -> TextLabelAttachmentData {
168 let mut data = TextLabelAttachmentData::default();
169 functions::PlayerTextLabel_GetAttachedData(
170 &self.player,
171 self,
172 &mut data.playerID,
173 &mut data.vehicleID,
174 );
175 data
176 }
177 pub fn get_id(&self) -> i32 {
178 functions::PlayerTextLabel_GetID(&self.player, self)
179 }
180 pub fn get_from_id(id: i32, player: &Player) -> Option<PlayerTextLabel> {
181 functions::PlayerTextLabel_FromID(player, id)
182 }
183}
184
185#[repr(C)]
186#[derive(Default, PartialEq, Clone, Copy, Debug)]
187pub struct TextLabelAttachmentData {
188 pub playerID: i32,
189 pub vehicleID: i32,
190}