174 lines
3.7 KiB
Lua
Raw Normal View History

2022-05-20 21:11:58 +02:00
local menucallbacks = {}
local originalmenus = {}
local stack = {}
function getchildren(element)
local children = {}
local first = element:getFirstChild()
while (first) do
table.insert(children, first)
first = first:getNextSibling()
end
return children
end
function printchildtree(element, indent, last)
indent = indent or ""
print(indent .. "+- " .. element.id .. " " .. (element:getText() or ""))
indent = indent .. (last and " " or "| ")
local children = getchildren(element)
for i = 1, #children do
printchildtree(children[i], indent, i == #children)
end
end
2022-03-04 01:39:19 +01:00
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-05-20 21:11:58 +02:00
popup.text = popup:getLastChild():getPreviousSibling():getPreviousSibling()
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 = {...}
2022-05-20 21:11:58 +02:00
local menu = originalmenus[name](unpack(args))
2022-03-04 01:39:19 +01:00
2022-05-20 21:11:58 +02:00
for k, v in next, menucallbacks[name] do
v(menu, unpack(args))
2022-03-09 22:27:12 +01:00
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-05-20 21:11:58 +02:00
for k, v in next, data do
2022-03-09 22:27:12 +01:00
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-05-20 21:11:58 +02:00
for k, v in next, data do
2022-03-09 22:27:12 +01:00
stack[k] = v
end
LUI.FlowManager.RequestPopupMenu(nil, "generic_confirmation_popup_")
return stack.ret
2022-05-20 21:11:58 +02:00
end