omp_gdk/scripting/menus/
mod.rs

1pub mod events;
2pub mod functions;
3
4use std::ffi::c_void;
5
6pub use functions::load_functions;
7
8use crate::{players::Player, types::vector::Vector2};
9
10pub struct Menu {
11    handle: *const c_void,
12}
13
14impl Menu {
15    pub fn get_handle(&self) -> *const c_void {
16        self.handle
17    }
18
19    pub fn new(handle: *const c_void) -> Self {
20        Self { handle }
21    }
22
23    /// Creates a menu
24    pub fn create(
25        title: &str,
26        columns: u32,
27        position: Vector2,
28        column1_widthh: f32,
29        column2_width: f32,
30    ) -> Option<Menu> {
31        let mut _id = 0;
32        functions::Menu_Create(
33            title,
34            columns,
35            position.x,
36            position.y,
37            column1_widthh,
38            column2_width,
39            &mut _id,
40        )
41    }
42
43    /// Destroys a menu
44    pub fn destroy(&self) -> bool {
45        functions::Menu_Destroy(self)
46    }
47
48    /// Add item to menu
49    pub fn add_item(&self, column: u8, text: &str) -> i32 {
50        functions::Menu_AddItem(self, column, text)
51    }
52
53    /// Sets the caption of a column in a menu.
54    pub fn set_column_header(&self, column: u8, header_title: &str) -> bool {
55        functions::Menu_SetColumnHeader(self, column, header_title)
56    }
57
58    /// Shows the menu to a player
59    pub fn show_for_player(&self, player: &Player) -> bool {
60        functions::Menu_ShowForPlayer(self, player)
61    }
62
63    /// Hides the menu from a player
64    pub fn hide_for_player(&self, player: &Player) -> bool {
65        functions::Menu_HideForPlayer(self, player)
66    }
67
68    /// Disable a menu, same as destroying it
69    pub fn disable(&self) -> bool {
70        functions::Menu_Disable(self)
71    }
72
73    /// Disable a particular row in menu
74    pub fn disable_row(&self, row: u8) -> bool {
75        functions::Menu_DisableRow(self, row)
76    }
77
78    /// Checks if a menu disabled or not
79    pub fn is_disabled(&self) -> bool {
80        functions::Menu_IsDisabled(self)
81    }
82
83    /// Checks if a row in menu is disabled or not
84    pub fn is_row_disabled(&self, row: i32) -> bool {
85        functions::Menu_IsRowDisabled(self, row)
86    }
87
88    /// Get the number of active columns.
89    pub fn get_columns(&self) -> i32 {
90        functions::Menu_GetColumns(self)
91    }
92
93    /// Get the number of rows in the given column.
94    pub fn get_items(&self, column: i32) -> i32 {
95        functions::Menu_GetItems(self, column)
96    }
97
98    /// Get position of the menu
99    pub fn get_pos(&self) -> Vector2 {
100        let mut pos = Vector2::default();
101        functions::Menu_GetPos(self, &mut pos.x, &mut pos.y);
102        pos
103    }
104
105    /// Get the column width of menu
106    pub fn get_column_width(&self) -> (f32, f32) {
107        let (mut column1_width, mut column2_width) = (0.0, 0.0);
108        functions::Menu_GetColumnWidth(self, &mut column1_width, &mut column2_width);
109        (column1_width, column2_width)
110    }
111
112    /// Get caption of the menu
113    pub fn get_column_header(&self, column: i32) -> String {
114        let mut header = String::new();
115        functions::Menu_GetColumnHeader(self, column, &mut header, 32);
116        header
117    }
118
119    /// Get an item at particular row and column in menu
120    pub fn get_item(&self, column: i32, row: i32) -> String {
121        let mut title = String::new();
122        functions::Menu_GetItem(self, column, row, &mut title, 32);
123        title
124    }
125
126    /// Get the id of the menu object
127    pub fn get_id(&self) -> i32 {
128        functions::Menu_GetID(self)
129    }
130
131    /// Get menu instance from id
132    pub fn from_id(id: i32) -> Option<Menu> {
133        functions::Menu_FromID(id)
134    }
135}