h2-mod/data/cdata/ui_scripts/mods/loading.lua

108 lines
2.5 KiB
Lua
Raw Normal View History

2022-01-29 20:04:58 -05:00
function createdivider(menu, text)
local element = LUI.UIElement.new( {
leftAnchor = true,
rightAnchor = true,
left = 0,
right = 0,
topAnchor = true,
bottomAnchor = false,
top = 0,
bottom = 33.33
})
element.scrollingToNext = true
element:addElement(LUI.MenuBuilder.BuildRegisteredType("h1_option_menu_titlebar", {
2022-03-19 19:57:07 -04:00
title_bar_text = Engine.ToUpperCase(text)
2022-01-29 20:04:58 -05:00
}))
2022-04-28 16:41:29 -04:00
element.text = element:getFirstChild():getFirstChild():getNextSibling()
2022-01-29 20:04:58 -05:00
menu.list:addElement(element)
2022-04-22 19:59:38 -04:00
return element
2022-01-29 20:04:58 -05:00
end
function string:truncate(length)
2022-03-19 19:57:07 -04:00
if (#self <= length) then
return self
end
2022-01-29 20:04:58 -05:00
2022-03-19 19:57:07 -04:00
return self:sub(1, length - 3) .. "..."
2022-01-29 20:04:58 -05:00
end
2022-01-30 16:55:21 -05:00
LUI.addmenubutton("main_campaign", {
2022-03-19 19:57:07 -04:00
index = 6,
text = "@MENU_MODS",
description = Engine.Localize("@MENU_MODS_DESC"),
callback = function()
LUI.FlowManager.RequestAddMenu(nil, "mods_menu")
end
2022-01-30 16:55:21 -05:00
})
2022-01-29 20:04:58 -05:00
2022-01-30 18:13:55 -05:00
function getmodname(path)
2023-02-15 12:24:35 -05:00
local modinfo = mods.getinfo(path)
if (not modinfo.isvalid) then
2023-02-28 13:07:57 -05:00
local desc = Engine.Localize("LUA_MENU_MOD_DESC_DEFAULT", string.el(path))
2023-02-15 12:24:35 -05:00
return path, desc
else
2023-02-28 13:07:57 -05:00
local desc = Engine.Localize("@LUA_MENU_MOD_DESC", string.el(modinfo.description), string.el(modinfo.author), string.el(modinfo.version))
2023-02-15 12:24:35 -05:00
return modinfo.name, desc
2022-03-19 19:57:07 -04:00
end
2022-01-30 18:13:55 -05:00
end
2022-04-22 19:59:38 -04:00
LUI.MenuBuilder.registerType("mods_menu", function(a1)
2022-03-19 19:57:07 -04:00
local menu = LUI.MenuTemplate.new(a1, {
menu_title = "@MENU_MODS",
exclusiveController = 0,
menu_width = 400,
menu_top_indent = LUI.MenuTemplate.spMenuOffset,
2022-07-17 13:21:24 -04:00
showTopRightSmallBar = true,
uppercase_title = true
2022-03-19 19:57:07 -04:00
})
2022-01-29 20:04:58 -05:00
2022-03-19 19:57:07 -04:00
local modfolder = game:getloadedmod()
if (modfolder ~= "") then
2022-04-20 18:06:10 -04:00
local name = getmodname(modfolder)
2023-02-28 13:07:57 -05:00
createdivider(menu, Engine.Localize("@LUA_MENU_LOADED_MOD", string.el(name:truncate(24))))
2022-03-19 19:57:07 -04:00
menu:AddButton("@LUA_MENU_UNLOAD", function()
2022-04-28 16:41:29 -04:00
Engine.Exec("unloadmod")
2022-03-19 19:57:07 -04:00
end, nil, true, nil, {
desc_text = Engine.Localize("@LUA_MENU_UNLOAD_DESC")
})
end
createdivider(menu, Engine.Localize("@LUA_MENU_AVAILABLE_MODS"))
2023-02-15 12:24:35 -05:00
local contentpresent = false
local mods = mods.getlist()
for i = 1, #mods do
contentpresent = true
local name, desc = getmodname(mods[i])
if (mods[i] ~= modfolder) then
2023-02-28 13:07:57 -05:00
menu:AddButton(string.el(name), function()
2023-02-15 12:24:35 -05:00
Engine.Exec("loadmod " .. mods[i])
end, nil, true, nil, {
desc_text = desc
})
2022-03-19 19:57:07 -04:00
end
end
menu:AddBackButton(function(a1)
Engine.PlaySound(CoD.SFX.MenuBack)
LUI.FlowManager.RequestLeaveMenu(a1)
end)
LUI.Options.InitScrollingList(menu.list, nil)
menu:CreateBottomDivider()
2023-02-15 12:24:35 -05:00
if (contentpresent) then
menu.optionTextInfo = LUI.Options.AddOptionTextInfo(menu)
end
2022-03-19 19:57:07 -04:00
return menu
2022-04-22 19:59:38 -04:00
end)