From 93f514f1f22d42aac72b4b19b87238a57f3ef198 Mon Sep 17 00:00:00 2001 From: Luke <39926192+LukeWasTakenn@users.noreply.github.com> Date: Wed, 15 Feb 2023 18:04:11 +0100 Subject: [PATCH 01/18] add radial menu docs --- docs/ox_lib/Interface/Client/radial.md | 120 +++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 docs/ox_lib/Interface/Client/radial.md diff --git a/docs/ox_lib/Interface/Client/radial.md b/docs/ox_lib/Interface/Client/radial.md new file mode 100644 index 00000000..19fbe386 --- /dev/null +++ b/docs/ox_lib/Interface/Client/radial.md @@ -0,0 +1,120 @@ +--- +title: Radial Menu +--- + +### lib.addRadialItem + +Item or array of items added to the global radial menu. + +* id: `string` + * Id that is used for removing options. +* icon: `string` +* label: `string` +* menu?: `string` + * Id of a menu to open. +* onSelect: `function` + +### lib.removeRadialItem + +Id of an item to be removed from the global menu. + +* id: `string` + +### lib.registerRadial + +Registers a radial sub menu with predefined options. + +* id: `string` + * Unique menu id used to open with `menu` prop on an item. +* items: `array` + * icon: `string` + * label: `string` + * menu?: `string` + * Id of a menu to open. + * onSelect?: `function` + +### lib.hideRadial + +Hides the radial menu if one is open. + +### Usage Example + +:::tip + +When adding radial menu items whether they are global or for a sub menu, make sure to stick to short as possible labels +as long labels will look out of place and should not be used with the radial menu because of it's density. +::: + + +Here's a use case example with some global options and an option utilising the lib's points system. + +```lua +lib.registerRadial({ + id = 'police_menu', + items = { + { + label = 'Handcuff', + icon = 'handcuffs', + onSelect = function() + print('Handcuffs') + end + }, + { + label = 'Frisk', + icon = 'hand' + }, + { + label = 'Fingerprint', + icon = 'fingerprint' + }, + { + label = 'Jail', + icon = 'bus' + }, + { + label = 'Search', + icon = 'magnifying-glass', + onSelect = function() + print('Search') + end + } + } +}) + +lib.addRadialItem({ + { + id = 'police', + label = 'Police', + icon = 'shield-halved', + menu = 'police_menu' + }, + { + id = 'business_stuff', + label = 'Business', + icon = 'briefcase', + onSelect = function() + print("Business") + end + } +}) + +local coords = GetEntityCoords(cache.ped) +local point = lib.points.new(coords, 5) + +function point:onEnter() + lib.addRadialItem({ + id = 'garage_access', + icon = 'warehouse', + label = 'Garage', + onSelect = function() + print('Garage') + end + }) +end + +function point:onExit() + lib.removeRadialItem('garage_access') +end +``` +![radial1](https://i.imgur.com/4eYU94s.png) +![radial2](https://i.imgur.com/Czw7mLF.png) From 41a1a7cf1b7db7bff4fa9d04f9fc059a8682d134 Mon Sep 17 00:00:00 2001 From: Luke <39926192+LukeWasTakenn@users.noreply.github.com> Date: Wed, 15 Feb 2023 18:35:29 +0100 Subject: [PATCH 02/18] add radial menu typescript examples --- docs/ox_lib/Interface/Client/radial.md | 137 +++++++++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/docs/ox_lib/Interface/Client/radial.md b/docs/ox_lib/Interface/Client/radial.md index 19fbe386..b0b68df1 100644 --- a/docs/ox_lib/Interface/Client/radial.md +++ b/docs/ox_lib/Interface/Client/radial.md @@ -2,10 +2,30 @@ title: Radial Menu --- +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + ### lib.addRadialItem Item or array of items added to the global radial menu. + + + +```lua +lib.addRadialItem(items) +``` + + + +```ts +import lib from '@overextended/ox_lib/client' + +lib.addRadialItem(items) +``` + + + * id: `string` * Id that is used for removing options. * icon: `string` @@ -18,12 +38,46 @@ Item or array of items added to the global radial menu. Id of an item to be removed from the global menu. + + + +```lua +lib.removeRadialItem(item) +``` + + + +```ts +import lib from '@overextended/ox_lib/client' + +lib.removeRadialItem(item) +``` + + + * id: `string` ### lib.registerRadial Registers a radial sub menu with predefined options. + + + +```lua +lib.registerRadial(radial) +``` + + + +```ts +import lib from '@overextended/ox_lib/client' + +lib.registerRadial(radial) +``` + + + * id: `string` * Unique menu id used to open with `menu` prop on an item. * items: `array` @@ -37,6 +91,23 @@ Registers a radial sub menu with predefined options. Hides the radial menu if one is open. + + + +```lua +lib.hideRadial() +``` + + + +```ts +import lib from '@overextended/ox_lib/client' + +lib.hideRadial() +``` + + + ### Usage Example :::tip @@ -48,6 +119,9 @@ as long labels will look out of place and should not be used with the radial men Here's a use case example with some global options and an option utilising the lib's points system. + + + ```lua lib.registerRadial({ id = 'police_menu', @@ -116,5 +190,68 @@ function point:onExit() lib.removeRadialItem('garage_access') end ``` + + + +:::caution + +Points system in the lib isn't available for the npm package. +::: + +```ts +import lib from '@overextended/ox_lib/client' + +lib.registerRadial({ + id: 'police_menu', + items: [ + { + label: 'Handcuff', + icon: 'handcuffs', + onSelect: () => { + console.log('Handcuffs') + } + }, + { + label: 'Frisk', + icon: 'hand' + }, + { + label: 'Fingerprint', + icon: 'fingerprint' + }, + { + label: 'Jail', + icon: 'bus' + }, + { + label: 'Search', + icon: 'magnifying-glass', + onSelect: () => { + console.log('Search') + } + } + ] +}) + +lib.addRadialItem([ + { + id: 'police', + label: 'Police', + icon: 'shield-halved', + menu: 'police_menu' + }, + { + id: 'business_stuff', + label: 'Business', + icon: 'briefcase', + onSelect: () => { + console.log('Business') + } + } +]) +``` + + + ![radial1](https://i.imgur.com/4eYU94s.png) ![radial2](https://i.imgur.com/Czw7mLF.png) From 9e9f204a35df8f8f8b74c5496bb0b822186076e2 Mon Sep 17 00:00:00 2001 From: Luke <39926192+LukeWasTakenn@users.noreply.github.com> Date: Thu, 16 Feb 2023 14:28:04 +0100 Subject: [PATCH 03/18] improve radial menu information --- docs/ox_lib/Interface/Client/radial.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/ox_lib/Interface/Client/radial.md b/docs/ox_lib/Interface/Client/radial.md index b0b68df1..99db08ad 100644 --- a/docs/ox_lib/Interface/Client/radial.md +++ b/docs/ox_lib/Interface/Client/radial.md @@ -5,6 +5,10 @@ title: Radial Menu import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; +* Radial menu has a global menu that's by default accessed with `z` and only displays when there is at least one item. +* You can add and remove items from the global menu using `lib.addRadialItem` and `lib.removeRadialItem`. +* Use `lib.registerRadial` for creating sub menus and use the `menu` property on the items to open those sub menus. + ### lib.addRadialItem Item or array of items added to the global radial menu. @@ -33,6 +37,7 @@ lib.addRadialItem(items) * menu?: `string` * Id of a menu to open. * onSelect: `function` + * Function that's ran when a user clicks the item. ### lib.removeRadialItem @@ -86,6 +91,7 @@ lib.registerRadial(radial) * menu?: `string` * Id of a menu to open. * onSelect?: `function` + * Function that's ran when a user clicks the item. ### lib.hideRadial From 12d4548d5d0670d0cefb837ccc1f027ae0b29ab6 Mon Sep 17 00:00:00 2001 From: Luke <39926192+LukeWasTakenn@users.noreply.github.com> Date: Thu, 16 Feb 2023 16:31:58 +0100 Subject: [PATCH 04/18] update alert docs --- docs/ox_lib/Interface/Client/alert.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/ox_lib/Interface/Client/alert.md b/docs/ox_lib/Interface/Client/alert.md index dcbb210c..be6c1fe9 100644 --- a/docs/ox_lib/Interface/Client/alert.md +++ b/docs/ox_lib/Interface/Client/alert.md @@ -42,6 +42,8 @@ lib.alertDialog(data) * Centers the dialog vertically and horizontally. * cancel?: `boolean` * Displays a cancel button (ESC is still available if this is not defined). + * size?: `'xs'` or `'sm'` or `'md'` or `'lg'` or `'xl'` + * overflow?: `boolean` * labels?: `table` * Allows you to define the displayed labels for cancel and/or confirm buttons. * cancel?: `string` @@ -108,4 +110,4 @@ console.log(alert) -![alert_dialog](https://i.imgur.com/TnUT3S1.png) +![alert_dialog](https://i.imgur.com/Xlx86aK.png) From 6b4d0429c2304f4a6cbcd437fe8f88886e76494d Mon Sep 17 00:00:00 2001 From: Luke <39926192+LukeWasTakenn@users.noreply.github.com> Date: Thu, 16 Feb 2023 16:32:05 +0100 Subject: [PATCH 05/18] update clipboard docs --- docs/ox_lib/Interface/Client/clipboard.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/ox_lib/Interface/Client/clipboard.md b/docs/ox_lib/Interface/Client/clipboard.md index 83269dab..5b593fe3 100644 --- a/docs/ox_lib/Interface/Client/clipboard.md +++ b/docs/ox_lib/Interface/Client/clipboard.md @@ -5,10 +5,17 @@ title: Clipboard import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; + + ### lib.setClipboard Sets the player's clipboard to the specified string value. +:::caution + +Will not work if focus is already taken by some NUI component. +::: + From 280801e265abb2c91c9f99bc1801791fb01432c2 Mon Sep 17 00:00:00 2001 From: Luke <39926192+LukeWasTakenn@users.noreply.github.com> Date: Thu, 16 Feb 2023 16:34:50 +0100 Subject: [PATCH 06/18] update context docs --- docs/ox_lib/Interface/Client/context.md | 334 +++++++++++++----------- 1 file changed, 187 insertions(+), 147 deletions(-) diff --git a/docs/ox_lib/Interface/Client/context.md b/docs/ox_lib/Interface/Client/context.md index fff65af2..3d8ab797 100644 --- a/docs/ox_lib/Interface/Client/context.md +++ b/docs/ox_lib/Interface/Client/context.md @@ -57,8 +57,9 @@ lib.registerContext(context) * progress?: `number` * Adds a progress bar filled to this percentage * colorScheme?: `string` - * Sets the color scheme of the progress bar. Current options available are: - * `whiteAlpha`, `blackAlpha`, `gray`, `red`, `orange`, `yellow`, `green`, `teal`, `blue`, `cyan`, `purple`, `pink` + * Sets the color scheme of the progress bar. Current options can be found here: + * https://mantine.dev/theming/colors/#default-colors + * For example: `blue` or `teal` * arrow?: `boolean` * Shows an arrow on the right side like `menu` does, useful when you are opening a menu from an event. Can be set to false to hide it. * description?: `string` @@ -67,6 +68,10 @@ lib.registerContext(context) * Url to an image that will be displayed in the button's metadata. * metadata?: `string[]` or `object` or `array` * Information that will display on the side upon hovering a button. + * label: `string` + * value: `any` + * progress?: `number` + * Display a progress bar in the metadata. * event?: `string` * Event that the button is going to trigger. * serverEvent?: `string` @@ -169,182 +174,217 @@ Avoid constantly re-registering a menu that does not depend on any outside value ```lua lib.registerContext({ - id = 'example_menu', - title = 'Example Context', - onExit = function() - print('Hello there') - end, - options = { - {title = 'Empty button'}, - { - title = 'Example button', - description = 'Example button description', - onSelect = function(args) - print('Pressed the button!') - end, - metadata = { - {label = 'Value 1', value = 'Some value'}, - {label = 'Value 2', value = 300}, - } - }, - { - title = 'Menu button', - menu = 'other_example_menu', - description = 'Takes you to another menu!', - metadata = {'It also has metadata support'} - }, - { - title = 'Event button', - description = 'Open a menu and send event data', - arrow = true, - event = 'some_event', - args = {value1 = 300, value2 = 'Other value'} - } + id = 'some_menu', + title = 'Some context menu', + options = { + { + title = 'Empty button', }, { - id = 'other_example_menu', - title = 'Other Context Menu', - menu = 'example_menu', - options = { - ['Nothing here'] = {} - } + title = 'Disabled button', + description = 'This button is disabled', + icon = 'hand', + disabled = true + }, + { + title = 'Example button', + description = 'Example button description', + icon = 'circle', + onSelect = function() + print("Pressed the button!") + end, + metadata = { + {label = 'Value 1', value = 'Some value'}, + {label = 'Value 2', value = 300} + }, + }, + { + title = 'Menu button', + description = 'Takes you to another menu!', + menu = 'other_menu', + icon = 'bars' + }, + { + title = 'Event button', + description = 'Open a menu from the event and send event data', + icon = 'check', + event = 'test_event', + arrow = true, + args = { + someValue = 500 + } } + } }) ``` - -```lua -RegisterCommand('testcontext', function() - lib.showContext('example_menu') -end) -``` - - + + ```ts import lib from '@overextended/ox_lib/client' -``` -```ts -lib.registerContext([ - { - id: 'example_menu', - title: 'Example Context', - onExit: () => { - console.log('Hello there'); +lib.registerContext({ + id: 'some_menu', + title: 'Some context menu', + options: [ + { + title: 'Empty button', }, - options: [ - { title: 'Empty button' }, - { - title: 'Example button', - description: 'Example button description', - onSelect: (args) => { - console.log('Pressed the button!'); - }, - metadata: [ - { label: 'Value 1', value: 'Some value' }, - { label: 'Value 2', value: 300 }, - ], - }, - { - title: 'Menu button', - menu: 'other_example_menu', - description: 'Takes you to another menu!', - metadata: ['It also has metadata support'], - }, - { - title: 'Event button', - description: 'Open a menu and send event data', - arrow: true, - event: 'some_event', - args: { value1: 300, value2: 'Other value' }, - }, - ], - }, - { - id: 'other_example_menu', - title: 'Other Context Menu', - menu: 'example_menu', - options: { - ['Nothing here']: {}, + { + title: 'Disabled button', + description: 'This button is disabled', + icon: 'hand', + disabled: true }, - }, -]); + { + title: 'Example button', + description: 'Example button description', + icon: 'circle', + onSelect: () => { + console.log("Pressed the button!") + }, + metadata: [ + {label: 'Value 1', value: 'Some value'}, + {label: 'Value 2', value: 300} + ], + }, + { + title: 'Menu button', + description: 'Takes you to another menu!', + menu: 'other_menu', + icon: 'bars' + }, + { + title: 'Event button', + description: 'Open a menu from the event and send event data', + icon: 'check', + event: 'test_event', + arrow: true, + args: { + someValue: 500 + } + } + ] +}) ``` - -```ts -RegisterCommand('testcontext', () => { - lib.showContext('example_menu') -}, false) -``` - -To trigger the event from the `Event button` and get it's data we first need to register the event properly: +Then we can also register our second menu called `other_menu` ```lua -RegisterNetEvent('some_event', function(data) - print(json.encode(data, {indent=true})) - lib.registerContext({ - id = 'another_context_menu', - title = 'Event Menu', - menu = 'example_menu', - options = { - ['Menu data'] = { - description = 'Data from the previous menu', - metadata = { - ['Value1'] = data.value1, - ['Value2'] = data.value2 - } - } - } - }) - lib.showContext('another_context_menu') -end) +lib.registerContext({ + id = 'other_menu', + title = 'Other context menu', + menu = 'some_menu', + onBack = function() + print('Went back!') + end, + options = { + { + title = 'Nothing here' + } + } +}) ``` - ```ts -onNet('some_event', () => { - console.log(JSON.stringify(data, null, 2)) - lib.registerContext({ - id: 'another_context_menu', - title: 'Event Menu', - menu: 'example_menu', - options: { - ['Menu data']: { - description: 'Data from the previous menu', - metadata: { - ['Value1']: data.value1, - ['Value2']: data.value2, - }, - }, - }, - }); - lib.showContext('another_context_menu'); -}); +lib.registerContext({ + id: 'other_menu', + title: 'Other context menu', + menu: 'some_menu', + onBack: () => { + console.log('Went back!') + }, + options: [ + { + title: 'Nothing here' + } + ] +}) ``` - -The data from the `args` table in the menu is passed as a first argument to the event you register, in this case that argument is called `data`. +And the event that we are going to run from the `some_menu` menu, which is going to open another menu. + + + + +```lua +RegisterNetEvent('test_event', function(args) + lib.registerContext({ + id = 'event_menu', + title = 'Event menu', + menu = 'some_menu', + options = { + { + title = 'Event value: '..args.someValue, + } + } + }) + + lib.showContext('event_menu') +end) +``` + + + + +```ts +onNet('test_event', (args: {someValue: number}) => { + lib.registerContext({ + id:'event_menu', + title:'Event menu', + menu:'some_menu', + options: [ + { + title: `Event value: ${args.someValue}`, + } + ] + }) + + lib.showContext('event_menu') +}) +``` + + + + +Lastly we register a test command to show the `some_menu` menu. + + + + +```lua +RegisterCommand('testcontext', function() + lib.showContext('some_menu') +end) +``` + + + +```ts +RegisterCommand('testcontext', () => { + lib.showContext('some_menu') +}) +``` + + + +The data from the `args` table in the menu is passed as a first argument to the event you register. Using this event we also register a new context menu with it's own options. -By defining a `menu` param to be the id of the first menu we can get the neat back arrow button next to the menu title that will take us back. +By defining a `menu` param to be the id of the first menu we can get the back arrow button next to the menu title that will take us back. -If we have a button that does not define either event, serverEvent or menu the button will do nothing upon being clicked. - -Of course just registering the event won't do much so we need to display it with the `lib.showContext` function, passing in the menu's id. - -![menu_example](https://i.imgur.com/aJu92dv.png) -![metadata](https://i.imgur.com/kFGSlBF.png) -![event_menu](https://i.imgur.com/r0Ln4VP.png) -![example](https://i.imgur.com/dUsil3p.png) +![menu_example](https://i.imgur.com/TkaH2P9.png) +![metadata](https://i.imgur.com/0mMmwgi.png) +![sub_menu](https://i.imgur.com/RbT1tKX.png) +![event_menu](https://i.imgur.com/zjIiROj.png) From 217ff0a160ce23664b5cb68951444474410a6446 Mon Sep 17 00:00:00 2001 From: Luke <39926192+LukeWasTakenn@users.noreply.github.com> Date: Fri, 17 Feb 2023 11:41:08 +0100 Subject: [PATCH 07/18] interface convar docs --- docs/ox_lib/Interface/index.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 docs/ox_lib/Interface/index.md diff --git a/docs/ox_lib/Interface/index.md b/docs/ox_lib/Interface/index.md new file mode 100644 index 00000000..3d2be019 --- /dev/null +++ b/docs/ox_lib/Interface/index.md @@ -0,0 +1,24 @@ +--- +title: Interface +--- + +If you wish to change the primary colour for the UI to better match your server's theme you can do so easily through the available convars. + +They don't require you to build the UI, just restart the resource. + +Convars: + +```yaml +set ox:primaryColor blue +set ox:primaryShade 8 +``` + +Changing the primary colour will change the colour in elements such as the progress bar/circle, skill check, radial menu center button and hover, +dialog confirm buttons, input field focus, and more. + +You can find the full list of preset colours and shades here: + +https://mantine.dev/theming/colors/#default-colors + +If you wish to create your own pallete I suggest following the guide on that page. +Keep in mind doing so *will* require you to download the source code and build the UI. From a96e80e0dfab430429528a94dbecf740ce8b1182 Mon Sep 17 00:00:00 2001 From: Luke <39926192+LukeWasTakenn@users.noreply.github.com> Date: Fri, 17 Feb 2023 12:59:51 +0100 Subject: [PATCH 08/18] improve input dialog docs --- docs/ox_lib/Interface/Client/input.md | 192 +++++++++++++++++--------- 1 file changed, 128 insertions(+), 64 deletions(-) diff --git a/docs/ox_lib/Interface/Client/input.md b/docs/ox_lib/Interface/Client/input.md index 59ba65c5..0da83214 100644 --- a/docs/ox_lib/Interface/Client/input.md +++ b/docs/ox_lib/Interface/Client/input.md @@ -23,7 +23,7 @@ lib.inputDialog(heading, rows) ```ts import lib from '@overextended/ox_lib/client' -lib.inputDialog(heading, rows) +lib.inputDialog(heading, rows, options) ``` @@ -31,50 +31,130 @@ lib.inputDialog(heading, rows) * heading: `string` * rows: `string[]` or `table` (`array`) - * type: `'input'` or `'number'` or `'checkbox'` or `'select'` or `'slider'` + * type: `'input'` or `'number'` or `'checkbox'` or `'select'` or `'slider'` or `'color'` or `'multi-select'` or `'date'` or `'date-range'` or `'time'` or `'textarea'` +* options?: `table`(`object`) + * allowCancel: `boolean` + * If true the user will not be able to cancel and close the input dialog until submitted. + +Available properties per field type: + +* input * label: `string` * description?: `string` - * If set will show a ? near the label a user can hover over and the description. - * options?: `table` (`array`) - * [ Only used with `'select'` type ] - * value: `string` - * label: `string` - * password?: `boolean` - * Hides input characters with ability to toggle them on. Used only with `'input'` type. - * icon?: `string` - * Used only with `'input'` and `'number'` types. * placeholder?: `string` - * Used only with `'input'` and `'number'` types. + * icon?: `string` + * required? `boolean` * disabled?: `boolean` - * Should the field be disabled from input. - * default?: `string` or `number` - * Default value for the field. + * default?: `string` + * password?: `boolean` + +* number + * label: `string` + * description?: `string` + * placeholder?: `string` + * icon?: `string` + * required? `boolean` + * disabled?: `boolean` + * default?: `number` + * min?: `number` + * max?: `number` + +* checkbox + * label: `string` * checked?: `boolean` - * Whether the checkbox should be checked by default. Used only with `'checkbox'` type. + * disabled?: `boolean` + * required?: `boolean` + +* select and multi-select + * label: `string` + * options: `table`(`array`) + * value: `string` + * label?: `string` + * description?: `string` + * placeholder?: `string` + * icon?: `string` + * required? `boolean` + * disabled?: `boolean` + * default?: `string` + * value of the default option. + * clearable?: `boolean` + +* slider + * label: `string` + * placeholder?: `string` + * icon?: `string` + * required? `boolean` + * disabled?: `boolean` + * default?: `number` * min?: `number` - * Used only with `'slider'` and `'number'` types. * max?: `number` - * Used only with `'slider'` and `'number'` types. * step?: `number` - * Amount of change per slider step. Used only with `'slider'` type. + +* color + * label: `string` + * description?: `string` + * placeholder?: `string` + * icon?: `string` + * required? `boolean` + * disabled?: `boolean` + * default?: `string` + * format?: `'hex'` | `'hexa'` | `'rgb'` | `'rgba'` | `'hsl'` | `'hsla'`; + +* date + * label: `string` + * description?: `string` + * icon?: `string` + * required? `boolean` + * disabled?: `boolean` + * default?: `string` or `true` + * True defaults to current date + * format?: `string` + * Date format to display in the field + * clearable?: `boolean` + +* date-range + * label: `string` + * description?: `string` + * icon?: `string` + * required? `boolean` + * disabled?: `boolean` + * default?: `[string, string]` + * format?: `string` + * Date format to display in the field + * clearable?: `boolean` + +* time + * label: `string` + * description?: `string` + * icon?: `string` + * required? `boolean` + * disabled?: `boolean` + * default?: `string` + * format?: `'12'` or `'24'` + * clearable?: `boolean` + +* textarea + * label: `string` + * description?: `string` + * placeholder?: `string` + * icon?: `string` + * required? `boolean` + * disabled?: `boolean` + * default?: `number` + * min?: `number` + * Minimum amount of rows the text area will take. + * max?: `number` + * Maxmimum amount of rows the text area will take, when exceeded goes into overflow. + * autosize?: `boolean` + * If true text area will grow with content until max rows are reached. The callback data is promise based meaning that the thread will not continue executing until the user either sends the data or exits the popup. The data returned will be a table (array), indexes represent the rows sent to the dialog, so if we want data from the first field that would be index `1` (`0`), if we want data from the third field, that would be index `3` (`2`), etc... -The standard input rows will always return a string, if you want a row to be of number data type, you can use set the `type` to `number`. - -If a user left an input field empty it will return `nil`. - -You can also add checkboxes that will return `true` if checked and `nil` if unchecked. -Look at the *Advanced* example for it's usage. - :::caution -When using the advanced method you can define `icon` and `password` **ONLY** with type `'input'` and `'number'` and -you can define `options` **ONLY** with type `'select'`. - -Doing so otherwise ***will*** result in errors. +Field types such as `date`, `date-range` and `time` return a unix timestamp on the set value. ::: ### lib.closeInputDialog @@ -108,13 +188,10 @@ lib.closeInputDialog() ```lua -local input = lib.inputDialog('Police locker', {'Locker number', 'Locker passcode'}) +local input = lib.inputDialog('Basic dialog', {'First row', 'Second row'}) if not input then return end -local lockerNumber = tonumber(input[1]) -local lockerPasscode = input[2] - -print(lockerNumber, lockerPasscode) +print(input, input[1], input[2]) ``` @@ -126,19 +203,16 @@ This function is **asynchronous** requiring you to do a `.then` callback on the ::: ```ts -const input = await lib.inputDialog('Police locker', ['Locker number', 'Locker passcode']) +const input = await lib.inputDialog('Basic dialog', ['First row', 'Second row']) if (!input) return -const lockerNumber = input[0] as number -const lockerPasscode = input[1] as number - -console.log(lockerNumber, lockerPasscode) +console.log(input, input[0], input[1]) ``` -![Example image](https://i.imgur.com/RvFFZqv.png) +![Example image](https://i.imgur.com/KnZ0sEW.png) ### Advanced @@ -146,20 +220,15 @@ console.log(lockerNumber, lockerPasscode) ```lua -local input = lib.inputDialog('Police locker', { - { type = "input", label = "Locker number", placeholder = "123" }, - { type = "checkbox", label = "Some checkbox" }, - { type = "input", label = "Locker PIN", password = true, icon = 'lock' }, - { type = "checkbox", label = "Some other checkbox", checked = true }, - { type = 'select', label = 'Value select', options = { - { value = 'option1', label = 'Option 1' }, - { value = 'option2', label = 'Option 2' }, - { value = 'option3', label = 'Option 3'}, - }}, - { type = "number", label = "Number counter", default = 12 } +local input = lib.inputDialog('Dialog title', { + {type = 'input', label = 'Text input', description = 'Some input description'}, + {type = 'number', label = 'Number input', description = 'Some number desrciption', icon = 'hashtag'}, + {type = 'checkbox', label = 'Simple checkbox'}, + {type = 'color', label = 'Colour input', default = '#eb4034'}, + {type = 'date', label = 'Date input', icon = {'far', 'calendar'}, default = true, format = "DD/MM/YYYY"} }) -print(json.encode(input, {indent=true})) +print(json.encode(input)) ``` @@ -172,16 +241,11 @@ This function is **asynchronous** requiring you to do a `.then` callback on the ```ts const input = await lib.inputDialog('Police locker', [ - { type: 'input', label: 'Locker number', placeholder: '123' }, - { type: 'checkbox', label: 'Some checkbox' }, - { type: 'input', label: 'Locker PIN', password: true, icon: 'lock' }, - { type: 'checkbox', label: 'Some other checkbox', checked: true }, - { type: 'select', label: 'Value select', options: [ - { value: 'option1', label: 'Option 1' }, - { value: 'option2', label: 'Option 2' }, - { value: 'option3', label: 'Option 3' }, - ]}, - { type: 'number', label: 'Number counter', default: 12 }, + {type: 'input', label: 'Text input', description: 'Some input description'}, + {type: 'number', label: 'Number input', description: 'Some number desrciption', icon: 'hashtag'}, + {type: 'checkbox', label: 'Simple checkbox'}, + {type: 'color', label: 'Colour input', default: '#eb4034'}, + {type: 'date', label: 'Date input', icon: ['far', 'calendar'], default: true, format: "DD/MM/YYYY"} ]); console.log(JSON.stringify(input, null, 2)); @@ -190,4 +254,4 @@ console.log(JSON.stringify(input, null, 2)); -![Example image](https://i.imgur.com/9dBA2d2.png) ![Select example](https://i.imgur.com/ILdFeot.png) +![Example image](https://i.imgur.com/v44YEkC.png) From b87b3b6e925be9a51ad3464b2050145b54a87caf Mon Sep 17 00:00:00 2001 From: Luke <39926192+LukeWasTakenn@users.noreply.github.com> Date: Fri, 17 Feb 2023 13:11:49 +0100 Subject: [PATCH 09/18] update notification docs --- docs/ox_lib/Interface/Client/notify.md | 80 ++++---------------------- 1 file changed, 11 insertions(+), 69 deletions(-) diff --git a/docs/ox_lib/Interface/Client/notify.md b/docs/ox_lib/Interface/Client/notify.md index c8f7711c..b6ea5be8 100644 --- a/docs/ox_lib/Interface/Client/notify.md +++ b/docs/ox_lib/Interface/Client/notify.md @@ -5,7 +5,7 @@ title: Notifications import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; -## lib.notify +### lib.notify Custom notifications with a lot of styling options. @@ -33,9 +33,10 @@ lib.notify(data) * title?: `string` * Must provide if there is no description * description?: `string` - * Must provide if there is no title; has markdown support. + * Must provide if there is no title + * Markdown support * duration?: `number` -* position?: `'top'` or `'top-right'` or `'top-left'` or `'bottom'` or `'bottom-right'` or `'bottom-left'` +* position?: `'top'` or `'top-right'` or `'top-left'` or `'bottom'` or `'bottom-right'` or `'bottom-left'` or `'center-right'` or `'center-left'` * Default: `'top-right'` * type?: `'inform'` or `'error'` or `'success'` * Default: `'inform'` @@ -45,6 +46,11 @@ lib.notify(data) * Font Awesome 6 icon name * iconColor: `string` +:::caution + +Setting `iconColor` will get rid of the contrasted icon colour and it's circular background. +::: + ### Usage Example #### Standard @@ -76,7 +82,7 @@ lib.notify({ -![notification](https://i.imgur.com/cRxJICO.png) +![notification](https://i.imgur.com/HFeBTLg.png) #### Custom @@ -121,68 +127,4 @@ lib.notify({ -![custom_notification](https://i.imgur.com/0EK5APp.png) - -## lib.defaultNotify - -Default notifications provided by Chakra UI. - - - - -```lua -lib.defaultNotify(data) -``` - - - - -```ts -import lib from '@overextended/ox_lib/client' - -lib.defaultNotify(data) -``` - - - - -* id?: `number` - * Same as id in `lib.notify` -* title?: `string` -* description?: `string` -* duration?: `number` -* position?: `'top'` or `'top-right'` or `'top-left'` or `'bottom'` or `'bottom-right'` or `'bottom-left'` -* variant?: `'solid'` or `'subtle'` or `'left-accent'` or `'top-accent'` -* status?: `'info'` or `'warning'` or `'success'` or `'error'` - -### Usage Example - - - - -```lua -lib.defaultNotify({ - title = 'Notification title', - description = 'Notification description', - variant = 'left-accent', - status = 'success' -}) -``` - - - - -```ts -import lib from '@overextended/ox_lib/client' - -lib.defaultNotify({ - title: 'Notification title', - description: 'Notification description', - status: 'success' -}) -``` - - - - -![default_notification](https://i.imgur.com/EIibuY9.png) +![custom_notification](https://i.imgur.com/wcjqIlw.png) From 7a3ecf27b966977e70038e5e6501b75b27dba4be Mon Sep 17 00:00:00 2001 From: Luke <39926192+LukeWasTakenn@users.noreply.github.com> Date: Fri, 17 Feb 2023 13:16:27 +0100 Subject: [PATCH 10/18] update progress images with new design --- docs/ox_lib/Interface/Client/progress.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/ox_lib/Interface/Client/progress.md b/docs/ox_lib/Interface/Client/progress.md index 72094b8b..4f3064a0 100644 --- a/docs/ox_lib/Interface/Client/progress.md +++ b/docs/ox_lib/Interface/Client/progress.md @@ -135,7 +135,7 @@ else console.log('Do stuff when cancelled') -![progress_bar](https://i.imgur.com/7pAwktr.png) +![progress_bar](https://i.imgur.com/7ZJgLjl.png) ## lib.progressCircle @@ -269,7 +269,7 @@ else console.log('Do stuff when cancelled') -![progress_circle](https://i.imgur.com/nETRm5f.png) +![progress_circle](https://i.imgur.com/2tLbgrW.png) ## lib.progressActive From b47092b02a336ec862fdc4eb4811c47cd244f57e Mon Sep 17 00:00:00 2001 From: Luke <39926192+LukeWasTakenn@users.noreply.github.com> Date: Fri, 17 Feb 2023 13:23:59 +0100 Subject: [PATCH 11/18] update textui docs --- docs/ox_lib/Interface/Client/textui.md | 61 ++++++++++++++------------ 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/docs/ox_lib/Interface/Client/textui.md b/docs/ox_lib/Interface/Client/textui.md index 1eb0d0ac..5d5c442f 100644 --- a/docs/ox_lib/Interface/Client/textui.md +++ b/docs/ox_lib/Interface/Client/textui.md @@ -5,11 +5,14 @@ title: TextUI import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; -## lib.showTextUI +### lib.showTextUI Show the TextUI window. -**DO NOT** run this every tick, it's intended to be used as a toggle. +:::danger + +**DO NOT** run this function every tick, it's intented to be used as a toggle. +::: @@ -38,9 +41,32 @@ lib.showTextUI(text, options) * iconColor?: `string` * style?: React.CSSProperties +### lib.hideTextUI + +Hides the currently visible TextUI window + + + + +```lua +lib.hideTextUI() +``` + + + + +```ts +import lib from '@overextended/ox_lib/client' + +lib.hideTextUI() +``` + + + + ### Usage Example -### Basic +#### Basic @@ -61,9 +87,9 @@ lib.showTextUI('[E] - Fuel vehicle') -![basic_example](https://i.imgur.com/3ptQyAq.png) +![basic_example](https://i.imgur.com/uZS40fD.png) -### Custom styling +#### Custom styling @@ -100,27 +126,4 @@ lib.showTextUI('[E] - Pick apple', { -![custom_example](https://i.imgur.com/gNDwPBN.png) - -### lib.hideTextUI - -Hides the currently visible TextUI window - - - - -```lua -lib.hideTextUI() -``` - - - - -```ts -import lib from '@overextended/ox_lib/client' - -lib.hideTextUI() -``` - - - +![custom_example](https://i.imgur.com/sy9lPC0.png) From c897cc2ff3500025780cb7bb77f3eda34edbaa4c Mon Sep 17 00:00:00 2001 From: Luke <39926192+LukeWasTakenn@users.noreply.github.com> Date: Fri, 17 Feb 2023 13:27:13 +0100 Subject: [PATCH 12/18] update skill check docs --- docs/ox_lib/Interface/Client/skillcheck.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/ox_lib/Interface/Client/skillcheck.md b/docs/ox_lib/Interface/Client/skillcheck.md index d967887a..60f6c1b0 100644 --- a/docs/ox_lib/Interface/Client/skillcheck.md +++ b/docs/ox_lib/Interface/Client/skillcheck.md @@ -13,7 +13,7 @@ Runs a skill check with the defined difficulty. ```lua -lib.skillCheck(difficulty) +lib.skillCheck(difficulty, inputs) ``` @@ -22,7 +22,7 @@ lib.skillCheck(difficulty) ```ts import lib from '@overextended/ox_lib/client' -lib.skillCheck(difficulty) +lib.skillCheck(difficulty, inputs) ``` @@ -36,6 +36,8 @@ lib.skillCheck(difficulty) * hard: { areaSize: 25, speedMultiplier: 1.75 } * `areaSize` size of the area in degrees. * Sending an array will chain the checks together and return false if one fails and true if all succeed +* inputs: `string[]` + * Picks a random key from the inputs table to use on each skill check pass. ### Usage Example @@ -43,7 +45,7 @@ lib.skillCheck(difficulty) ```lua -local success = lib.skillCheck({'easy', 'easy', {areaSize = 60, speedMultiplier = 2}, 'hard'}) +local success = lib.skillCheck({'easy', 'easy', {areaSize = 60, speedMultiplier = 2}, 'hard'}, {'w', 'a', 's', 'd'}) ``` @@ -52,10 +54,10 @@ local success = lib.skillCheck({'easy', 'easy', {areaSize = 60, speedMultiplier ```ts import lib from '@overextended/ox_lib/client' -const success = await lib.skillCheck(['easy', 'easy', {areaSize: 60, speedMultiplier: 2}, 'hard']) +const success = await lib.skillCheck(['easy', 'easy', {areaSize: 60, speedMultiplier: 2}, 'hard'], ['w', 'a', 's', 'd']) ``` -![skillcheck_example](https://i.imgur.com/RWSWZ1I.png) +![skillcheck_example](https://i.imgur.com/rgfkn0S.png) From 92095caefb981804481b876a312e11290d4e7a5e Mon Sep 17 00:00:00 2001 From: Luke <39926192+LukeWasTakenn@users.noreply.github.com> Date: Fri, 17 Feb 2023 13:37:15 +0100 Subject: [PATCH 13/18] update list menu image --- docs/ox_lib/Interface/Client/menu.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/ox_lib/Interface/Client/menu.md b/docs/ox_lib/Interface/Client/menu.md index 1d9e6c87..daf13138 100644 --- a/docs/ox_lib/Interface/Client/menu.md +++ b/docs/ox_lib/Interface/Client/menu.md @@ -309,5 +309,4 @@ RegisterCommand('testmenu', () => { -![Example](https://i.imgur.com/eIdWZ4c.png) -![Example2](https://i.imgur.com/GxNetwe.png) +![Example](https://i.imgur.com/2zxbsnN.png) From 2cca23ad7586b0a088a952ce7822a23e7a3810cd Mon Sep 17 00:00:00 2001 From: Luke <39926192+LukeWasTakenn@users.noreply.github.com> Date: Sun, 19 Feb 2023 13:56:53 +0100 Subject: [PATCH 14/18] add icon images support info --- docs/ox_lib/Interface/Client/context.md | 1 + docs/ox_lib/Interface/Client/menu.md | 2 ++ 2 files changed, 3 insertions(+) diff --git a/docs/ox_lib/Interface/Client/context.md b/docs/ox_lib/Interface/Client/context.md index 3d8ab797..66eb3a14 100644 --- a/docs/ox_lib/Interface/Client/context.md +++ b/docs/ox_lib/Interface/Client/context.md @@ -52,6 +52,7 @@ lib.registerContext(context) * Function that's ran when the button is clicked. * icon?: `string` * FontAwesome icon that will be displayed on the left side, works the same as notification and textui icons. + * Also supports image urls, png and webp files but are not recommend to use over font awesome icons. * iconColor?: `string` * Colour of the displayed icon. * progress?: `number` diff --git a/docs/ox_lib/Interface/Client/menu.md b/docs/ox_lib/Interface/Client/menu.md index daf13138..e47ea9b3 100644 --- a/docs/ox_lib/Interface/Client/menu.md +++ b/docs/ox_lib/Interface/Client/menu.md @@ -38,6 +38,8 @@ lib.registerMenu(data, cb) * progress?: `number` * colorScheme?: `string` * icon?: `string` + * FontAwesome icon that will be displayed on the left side, works the same as notification and textui icons. + * Also supports image urls, png and webp files but are not recommend to use over font awesome icons. * iconColor?: `string` * values?: `table` (`Array`) * If provided creates a side scrollable list. From 8ce5644b8c6eba1ce77c32af42906d172514821b Mon Sep 17 00:00:00 2001 From: Luke <39926192+LukeWasTakenn@users.noreply.github.com> Date: Mon, 20 Feb 2023 18:23:17 +0100 Subject: [PATCH 15/18] add package points docs --- docs/ox_lib/Points/JavaScript/Client.md | 46 +++++++++++++++++++++++++ docs/ox_lib/Points/{ => Lua}/Client.md | 0 2 files changed, 46 insertions(+) create mode 100644 docs/ox_lib/Points/JavaScript/Client.md rename docs/ox_lib/Points/{ => Lua}/Client.md (100%) diff --git a/docs/ox_lib/Points/JavaScript/Client.md b/docs/ox_lib/Points/JavaScript/Client.md new file mode 100644 index 00000000..eba3304e --- /dev/null +++ b/docs/ox_lib/Points/JavaScript/Client.md @@ -0,0 +1,46 @@ +# Points + +Simple and centralised distance checking, supporting callbacks when entering, leaving, and standing in-range of set coordinates. + +```ts +Point({coords, distance, onEnter, onExit, nearby, args}) +``` + +* coords: `number[]` +* distance: `number` +* onEnter?: `function` +* onExit?: `function` +* nearby?: `function` +* args?: `T` + +```ts +import { Point, cache } from '@overextended/ox_lib/client' + +function nearby(this: Point<{dunak: string}>) { + // @ts-ignore + DrawMarker(2, this.coords.x, this.coords.y, this.coords.z, 0, 0, 0, 0, 180, 0, 1, 1, 1, 200, 20, 20, 50, false, true, 2, null, null, false, false) + + if (this.currentDistance && this.currentDistance < 1 && IsControlJustReleased(0, 38)) { + console.log('Inside marker', this.id) + console.log(this.args?.dunak) + } +} + +const point = new Point({ + coords: GetEntityCoords(cache.ped, false), + distance: 5, + nearby: nearby, + args: { + dunak: 'nerd' + } +}) + +point.onEnter = () => { + console.log('Entered range of point', point.id) +} + +point.onExit = () => { + console.log('Left range of point', point.id) +} +``` + diff --git a/docs/ox_lib/Points/Client.md b/docs/ox_lib/Points/Lua/Client.md similarity index 100% rename from docs/ox_lib/Points/Client.md rename to docs/ox_lib/Points/Lua/Client.md From b4c985a59f461c45c2dee21b16b67d95f7caaebc Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Wed, 22 Feb 2023 10:25:32 +1100 Subject: [PATCH 16/18] update lib.addCommand --- docs/ox_lib/AddCommand/Server.md | 54 +++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/docs/ox_lib/AddCommand/Server.md b/docs/ox_lib/AddCommand/Server.md index 45991f82..f2c8742a 100644 --- a/docs/ox_lib/AddCommand/Server.md +++ b/docs/ox_lib/AddCommand/Server.md @@ -1,18 +1,50 @@ +Registers commands and simplifies argument validation, permissions, and chat suggestions. + ```lua -lib.addCommand(principal, command, callback, parameters, help) +lib.addCommand(commandName, properties, cb) ``` -* principal: `string` or `string[]` or `false` -* command: `string` -* callback: `function` -* parameters?: `table` (`array`) -* help?: `string` +- commandName: `string` or `string[]` +- properties: `table` or `false` + - help?: `string` + - restricted?: `boolean` or `string` or `string[]` + - params?: `table[]` + - name: `string` + - help?: `string` + - type?: `'number'` or `'playerId'` or `'string'` + - optional?: `boolean` ```lua -lib.addCommand('group.admin', {'additem', 'giveitem'}, function(source, args) - args.item = Items(args.item) - if args.item and args.count > 0 then - Inventory.AddItem(args.target, args.item.name, args.count, args.metatype) +lib.addCommand('giveitem', { + help = 'Gives an item to a player', + params = { + { + name = 'target', + type = 'playerId', + help = 'Target player\'s server id', }, + { + name = 'item', + type = 'string', + help = 'Name of the item to give', + }, + { + name = 'count', + type = 'number', + help = 'Amount of the item to give, or blank to give 1', + optional = true, + }, + { + name = 'metatype', + help = 'Sets the item\'s "metadata.type"', + optional = true, + }, + }, + restricted = 'group.admin' +}, function(source, args, raw) + local item = Items(args.item) + + if item then + Inventory.AddItem(args.target, item.name, args.count or 1, args.metatype) end -end, {'target:number', 'item:string', 'count:number', 'metatype:?string'}) +end) ``` From 3cd716ed7fe5feaa9fa03d42bf3029ca7a2b2d53 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sun, 26 Feb 2023 02:19:52 +1100 Subject: [PATCH 17/18] radial onSelect params --- docs/ox_lib/Interface/Client/radial.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ox_lib/Interface/Client/radial.md b/docs/ox_lib/Interface/Client/radial.md index 99db08ad..149bb17c 100644 --- a/docs/ox_lib/Interface/Client/radial.md +++ b/docs/ox_lib/Interface/Client/radial.md @@ -36,7 +36,7 @@ lib.addRadialItem(items) * label: `string` * menu?: `string` * Id of a menu to open. -* onSelect: `function` +* onSelect: `function(currentMenu: string | nil, itemIndex: number)` * Function that's ran when a user clicks the item. ### lib.removeRadialItem From 1bbf1823a91d95fb96ab67b4872f963da3bedafc Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sun, 26 Feb 2023 02:34:01 +1100 Subject: [PATCH 18/18] radial onSelect using exports --- docs/ox_lib/Interface/Client/radial.md | 28 ++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/docs/ox_lib/Interface/Client/radial.md b/docs/ox_lib/Interface/Client/radial.md index 149bb17c..eb1c018d 100644 --- a/docs/ox_lib/Interface/Client/radial.md +++ b/docs/ox_lib/Interface/Client/radial.md @@ -36,7 +36,7 @@ lib.addRadialItem(items) * label: `string` * menu?: `string` * Id of a menu to open. -* onSelect: `function(currentMenu: string | nil, itemIndex: number)` +* onSelect: `function(currentMenu: string | nil, itemIndex: number)` | `string` * Function that's ran when a user clicks the item. ### lib.removeRadialItem @@ -90,7 +90,7 @@ lib.registerRadial(radial) * label: `string` * menu?: `string` * Id of a menu to open. - * onSelect?: `function` + * onSelect?: `function(currentMenu: string | nil, itemIndex: number)` | `string` * Function that's ran when a user clicks the item. ### lib.hideRadial @@ -129,15 +129,21 @@ Here's a use case example with some global options and an option utilising the l ```lua +exports('myMenuHandler', function(menu, item) + print(menu, item) + + if menu == 'police_menu' and item == 1 then + print('Handcuffs') + end +end) + lib.registerRadial({ id = 'police_menu', items = { { label = 'Handcuff', icon = 'handcuffs', - onSelect = function() - print('Handcuffs') - end + onSelect = 'myMenuHandler' }, { label = 'Frisk', @@ -207,15 +213,21 @@ Points system in the lib isn't available for the npm package. ```ts import lib from '@overextended/ox_lib/client' +exports('myMenuHandler', (menu, item) => { + console.log(menu, item) + + if (menu === 'police_menu' and item === 1) { + console.log('Handcuffs') + } +}) + lib.registerRadial({ id: 'police_menu', items: [ { label: 'Handcuff', icon: 'handcuffs', - onSelect: () => { - console.log('Handcuffs') - } + onSelect: 'myMenuHandler' }, { label: 'Frisk',