JRS COREالوثائق
مرجع الـ API

menu

The JRS Core menu, themed like the stores, part of jrs_core

Note

جهة الكلاينت

القائمة مبنية داخل jrs_core (modules/menu). ما تحتاج ريسورس إضافي. السكربتات القديمة اللي تستدعي exports.jrs_menu:GetMenuData() تكمل تشتغل لأن jrs_core يوفّر jrs_menu.

GetMenuData#

GetMenuData#

يرجع جدول API القائمة.

returntable

API القائمة: Open، Close، CloseAll، GetOpened، GetOpenedMenus، IsOpen، IsAnyOpen، ReOpen.

lua
local MenuData = exports.jrs_core:GetMenuData()

فتح

Open#

يفتح قائمة ويرجع نسخة القائمة (شوف دوال النسخة). إذا فتحت قائمة بنفس النوع والـ namespace والاسم تتسكّر القديمة أول.

typestringrequired

دائماً "default".

namespacestringrequired

اسم ريسورسك، GetCurrentResourceName().

namestringrequired

اسم فريد لهذي القائمة داخل ريسورسك.

datatablerequired

بيانات القائمة: title، subtext، align، elements (شوف بيانات القائمة).

submitfunction

تتشغّل بـ (data, menu) لما يضغط اللاعب Enter على عنصر. data.current هو العنصر المختار.

cancelfunction

تتشغّل بـ (data, menu) لما يضغط اللاعب Backspace. سكّر القائمة هنا بـ menu.close().

changefunction

تتشغّل بـ (data, menu) لما تتغير قيمة slider.

closefunction

تتشغّل لما تتسكّر القائمة.

returntable | nil

نسخة القائمة، أو nil وسبب (ui_busy:<owner>، unknown_menu_type) إذا ما قدرت تنفتح.

lua
local MenuData = exports.jrs_core:GetMenuData()

MenuData.CloseAll()
MenuData.Open('default', GetCurrentResourceName(), 'shop_menu', {
    title = 'General Store',
    subtext = 'Choose an option',
    align = 'top-left',
    elements = {
        { label = 'Buy bread', value = 'bread', desc = '$0.50' },
        { label = 'Amount', value = 1, type = 'slider', min = 1, max = 10, hop = 1 },
    },
}, function(data, menu)
    if data.current.value == 'bread' then
        print('bought bread')
    end
end, function(data, menu)
    menu.close()
end)

Instance functions#

The table returned by Open (and passed as the second argument of your callbacks).

close#

Closes this menu and calls your close callback.

lua
menu.close()
refresh#

Redraws the menu after you changed the data.

lua
menu.setTitle('New title')
menu.refresh()
setTitle#
titlestringrequired

The new title.

lua
menu.setTitle('New title')
setElement#

Changes one field of one row, then call refresh.

indexnumberrequired

Row index, starting at 1.

keystringrequired

The field name, for example label.

valueanyrequired

The new value.

lua
menu.setElement(1, 'label', 'Sold out')
menu.refresh()
setElements#

Replaces all rows.

lua
menu.setElements({ { label = 'Back', value = 'back' } })
menu.refresh()
update#

Updates every row that matches the query.

querytablerequired

Fields a row must have, for example { value = 'bread' }.

newDatatablerequired

Fields to set on the matching rows.

lua
menu.update({ value = 'bread' }, { label = 'Bread (sold out)' })
menu.refresh()
removeElement#

Removes every row that matches the query.

lua
menu.removeElement({ value = 'bread' })
menu.refresh()
CloseAll#

Closes every open menu.

lua
MenuData.CloseAll()
Close#
typestringrequired

"default".

namespacestringrequired

The resource name.

namestringrequired

The menu name.

lua
MenuData.Close('default', GetCurrentResourceName(), 'shop_menu')
IsOpen#
lua
local open = MenuData.IsOpen('default', GetCurrentResourceName(), 'shop_menu')
IsAnyOpen#
lua
if MenuData.IsAnyOpen() then return end
GetOpened#

Returns the instance of an open menu, or nil.

lua
local menu = MenuData.GetOpened('default', GetCurrentResourceName(), 'shop_menu')
GetOpenedMenus#

Returns the list of all open menu instances.

lua
local list = MenuData.GetOpenedMenus()
ReOpen#

Opens an instance again with its old data and callbacks. The menu does this itself after the pause menu closes.

lua
MenuData.ReOpen(menu)

Controls#

The menu reads the keyboard itself: arrows move, Enter selects, Backspace goes back. The pause menu closes open menus and brings them back afterwards.

RegisterControls and UnregisterControls exist for compatibility with older scripts and do nothing.

الأحداث (Events)

Fired on the client when the first menu opens and when the last one closes. Useful for pausing your own prompts.

lua
AddEventHandler('jrs_menu:openmenu', function() end)
AddEventHandler('jrs_menu:closemenu', function() end)
JRS Core · فريمورك RedM مجاني ومفتوح المصدر · من فريق JRS