جهة الكلاينت
القائمة مبنية داخل jrs_core (modules/menu). ما تحتاج ريسورس إضافي. السكربتات القديمة اللي تستدعي exports.jrs_menu:GetMenuData() تكمل تشتغل لأن jrs_core يوفّر jrs_menu.
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) إذا ما قدرت تنفتح.
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.
menu.close()refresh#
Redraws the menu after you changed the data.
menu.setTitle('New title')
menu.refresh()setTitle#
titlestringrequiredThe new title.
menu.setTitle('New title')setElement#
Changes one field of one row, then call refresh.
indexnumberrequiredRow index, starting at 1.
keystringrequiredThe field name, for example label.
valueanyrequiredThe new value.
menu.setElement(1, 'label', 'Sold out')
menu.refresh()setElements#
Replaces all rows.
menu.setElements({ { label = 'Back', value = 'back' } })
menu.refresh()update#
Updates every row that matches the query.
querytablerequiredFields a row must have, for example { value = 'bread' }.
newDatatablerequiredFields to set on the matching rows.
menu.update({ value = 'bread' }, { label = 'Bread (sold out)' })
menu.refresh()removeElement#
Removes every row that matches the query.
menu.removeElement({ value = 'bread' })
menu.refresh()Menu API functions#
CloseAll#
Closes every open menu.
MenuData.CloseAll()Close#
typestringrequired"default".
namespacestringrequiredThe resource name.
namestringrequiredThe menu name.
MenuData.Close('default', GetCurrentResourceName(), 'shop_menu')IsOpen#
local open = MenuData.IsOpen('default', GetCurrentResourceName(), 'shop_menu')IsAnyOpen#
if MenuData.IsAnyOpen() then return endGetOpened#
Returns the instance of an open menu, or nil.
local menu = MenuData.GetOpened('default', GetCurrentResourceName(), 'shop_menu')ReOpen#
Opens an instance again with its old data and callbacks. The menu does this itself after the pause menu closes.
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.
AddEventHandler('jrs_menu:openmenu', function() end)
AddEventHandler('jrs_menu:closemenu', function() end)