165 lines
3.5 KiB
Lua
Raw Normal View History

2022-03-04 01:39:19 +01:00
menucallbacks = {}
originalmenus = {}
stack = {}
LUI.MenuBuilder.m_types_build["generic_waiting_popup_"] = function (menu, event)
2022-03-09 22:27:12 +01:00
local oncancel = stack.oncancel
2022-03-04 01:39:19 +01:00
local popup = LUI.MenuBuilder.BuildRegisteredType("waiting_popup", {
2022-03-09 22:27:12 +01:00
message_text = stack.text,
isLiveWithCancel = true,
cancel_func = function(...)
local args = {...}
oncancel()
LUI.FlowManager.RequestLeaveMenu(args[1])
end
2022-03-04 01:39:19 +01:00
})
2022-03-09 22:27:12 +01:00
local listchildren = popup:getChildById("LUIHorizontalList"):getchildren()
local children = listchildren[2]:getchildren()
popup.text = children[2]
2022-03-04 01:39:19 +01:00
2022-03-09 22:27:12 +01:00
stack = {
ret = popup
}
2022-03-04 01:39:19 +01:00
2022-03-09 22:27:12 +01:00
return popup
2022-03-04 01:39:19 +01:00
end
LUI.MenuBuilder.m_types_build["generic_yes_no_popup_"] = function()
2022-03-09 22:27:12 +01:00
local callback = stack.callback
local popup = LUI.MenuBuilder.BuildRegisteredType("generic_yesno_popup", {
popup_title = stack.title,
message_text = stack.text,
yes_action = function()
callback(true)
end,
no_action = function()
callback(false)
end
2022-03-04 01:39:19 +01:00
})
2022-03-09 22:27:12 +01:00
stack = {
ret = popup
}
2022-03-04 01:39:19 +01:00
2022-03-09 22:27:12 +01:00
return popup
2022-03-04 01:39:19 +01:00
end
LUI.MenuBuilder.m_types_build["generic_confirmation_popup_"] = function()
2022-03-09 22:27:12 +01:00
local popup = LUI.MenuBuilder.BuildRegisteredType( "generic_confirmation_popup", {
cancel_will_close = false,
popup_title = stack.title,
message_text = stack.text,
button_text = stack.buttontext,
confirmation_action = stack.callback
})
stack = {
ret = popup
}
return stack.ret
2022-03-04 01:39:19 +01:00
end
LUI.onmenuopen = function(name, callback)
2022-03-09 22:27:12 +01:00
if (not LUI.MenuBuilder.m_types_build[name]) then
return
end
2022-03-04 01:39:19 +01:00
2022-03-09 22:27:12 +01:00
if (not menucallbacks[name]) then
menucallbacks[name] = {}
end
2022-03-04 01:39:19 +01:00
2022-03-09 22:27:12 +01:00
table.insert(menucallbacks[name], callback)
2022-03-04 01:39:19 +01:00
2022-03-09 22:27:12 +01:00
if (not originalmenus[name]) then
originalmenus[name] = LUI.MenuBuilder.m_types_build[name]
LUI.MenuBuilder.m_types_build[name] = function(...)
local args = {...}
local menu = originalmenus[name](table.unpack(args))
2022-03-04 01:39:19 +01:00
2022-03-09 22:27:12 +01:00
for k, v in luiglobals.next, menucallbacks[name] do
v(menu, table.unpack(args))
end
2022-03-04 01:39:19 +01:00
2022-03-09 22:27:12 +01:00
return menu
end
end
2022-03-04 01:39:19 +01:00
end
local addoptionstextinfo = LUI.Options.AddOptionTextInfo
LUI.Options.AddOptionTextInfo = function(menu)
2022-03-09 22:27:12 +01:00
local result = addoptionstextinfo(menu)
menu.optionTextInfo = result
return result
2022-03-04 01:39:19 +01:00
end
LUI.addmenubutton = function(name, data)
2022-03-09 22:27:12 +01:00
LUI.onmenuopen(name, function(menu)
if (not menu.list) then
return
end
2022-03-04 01:39:19 +01:00
2022-03-09 22:27:12 +01:00
local button = menu:AddButton(data.text, data.callback, nil, true, nil, {
desc_text = data.description
})
2022-03-04 01:39:19 +01:00
2022-03-09 22:27:12 +01:00
local buttonlist = menu:getChildById(menu.type .. "_list")
2022-03-04 01:39:19 +01:00
2022-03-09 22:27:12 +01:00
if (data.id) then
button.id = data.id
end
2022-03-04 01:39:19 +01:00
2022-03-09 22:27:12 +01:00
if (data.index) then
buttonlist:removeElement(button)
buttonlist:insertElement(button, data.index)
end
2022-03-04 01:39:19 +01:00
2022-03-09 22:27:12 +01:00
local hintbox = menu.optionTextInfo
menu:removeElement(hintbox)
2022-03-04 01:39:19 +01:00
2022-03-09 22:27:12 +01:00
LUI.Options.InitScrollingList(menu.list, nil)
menu.optionTextInfo = LUI.Options.AddOptionTextInfo(menu)
end)
2022-03-04 01:39:19 +01:00
end
LUI.openmenu = function(menu, args)
2022-03-09 22:27:12 +01:00
stack = args
LUI.FlowManager.RequestAddMenu(nil, menu)
return stack.ret
2022-03-04 01:39:19 +01:00
end
LUI.openpopupmenu = function(menu, args)
2022-03-09 22:27:12 +01:00
stack = args
LUI.FlowManager.RequestPopupMenu(nil, menu)
return stack.ret
2022-03-04 01:39:19 +01:00
end
LUI.yesnopopup = function(data)
2022-03-09 22:27:12 +01:00
for k, v in luiglobals.next, data do
stack[k] = v
end
LUI.FlowManager.RequestPopupMenu(nil, "generic_yes_no_popup_")
return stack.ret
2022-03-04 01:39:19 +01:00
end
LUI.confirmationpopup = function(data)
2022-03-09 22:27:12 +01:00
for k, v in luiglobals.next, data do
stack[k] = v
end
LUI.FlowManager.RequestPopupMenu(nil, "generic_confirmation_popup_")
return stack.ret
2022-03-04 01:39:19 +01:00
end
function userdata_:getchildren()
2022-03-09 22:27:12 +01:00
local children = {}
local first = self:getFirstChild()
2022-03-04 01:39:19 +01:00
2022-03-09 22:27:12 +01:00
while (first) do
table.insert(children, first)
first = first:getNextSibling()
end
2022-03-04 01:39:19 +01:00
2022-03-09 22:27:12 +01:00
return children
2022-03-04 01:39:19 +01:00
end