Cleanup ui scripts

This commit is contained in:
Federico Cecchetto 2022-03-20 00:57:07 +01:00
parent 769d2c74cb
commit 2f5eaa8298
5 changed files with 267 additions and 266 deletions

View File

@ -1,3 +1,14 @@
game:addlocalizedstring("MENU_MODS", "MODS")
game:addlocalizedstring("MENU_MODS_DESC", "Load installed mods.")
game:addlocalizedstring("LUA_MENU_MOD_DESC_DEFAULT", "Load &&1.")
game:addlocalizedstring("LUA_MENU_MOD_DESC", "&&1\nAuthor: &&2\nVersion: &&3")
game:addlocalizedstring("LUA_MENU_OPEN_STORE", "Open store")
game:addlocalizedstring("LUA_MENU_OPEN_STORE_DESC", "Download and install mods.")
game:addlocalizedstring("LUA_MENU_LOADED_MOD", "Loaded mod: ^3&&1")
game:addlocalizedstring("LUA_MENU_AVAILABLE_MODS", "Available mods")
game:addlocalizedstring("LUA_MENU_UNLOAD", "Unload")
game:addlocalizedstring("LUA_MENU_UNLOAD_DESC", "Unload the currently loaded mod.")
function createdivider(menu, text)
local element = LUI.UIElement.new( {
leftAnchor = true,
@ -12,7 +23,7 @@ function createdivider(menu, text)
element.scrollingToNext = true
element:addElement(LUI.MenuBuilder.BuildRegisteredType("h1_option_menu_titlebar", {
title_bar_text = Engine.ToUpperCase(Engine.Localize(text))
title_bar_text = Engine.ToUpperCase(text)
}))
menu.list:addElement(element)
@ -28,8 +39,8 @@ end
LUI.addmenubutton("main_campaign", {
index = 6,
text = "$_MODS",
description = "Load installed mods.",
text = "@MENU_MODS",
description = Engine.Localize("@MENU_MODS_DESC"),
callback = function()
LUI.FlowManager.RequestAddMenu(nil, "mods_menu")
end
@ -37,13 +48,13 @@ LUI.addmenubutton("main_campaign", {
function getmodname(path)
local name = path
local desc = "Load " .. name
local desc = Engine.Localize("@LUA_MENU_MOD_DESC_DEFAULT", name)
local infofile = path .. "/info.json"
if (io.fileexists(infofile)) then
pcall(function()
local data = json.decode(io.readfile(infofile))
desc = string.format("%s\nAuthor: %s\nVersion: %s",
desc = Engine.Localize("@LUA_MENU_MOD_DESC",
data.description, data.author, data.version)
name = data.name
end)
@ -54,33 +65,33 @@ end
LUI.MenuBuilder.m_types_build["mods_menu"] = function(a1)
local menu = LUI.MenuTemplate.new(a1, {
menu_title = "$_MODS",
menu_title = "@MENU_MODS",
exclusiveController = 0,
menu_width = 400,
menu_top_indent = LUI.MenuTemplate.spMenuOffset,
showTopRightSmallBar = true
})
menu:AddButton("$_OPEN STORE", function()
menu:AddButton("@LUA_MENU_OPEN_STORE", function()
if (LUI.MenuBuilder.m_types_build["mod_store_menu"]) then
LUI.FlowManager.RequestAddMenu(nil, "mod_store_menu")
end
end, nil, true, nil, {
desc_text = "Download and install mods."
desc_text = Engine.Localize("@LUA_MENU_OPEN_STORE_DESC")
})
local modfolder = game:getloadedmod()
if (modfolder ~= "") then
createdivider(menu, "$_Loaded mod: ^3" .. getmodname(modfolder):truncate(20))
createdivider(menu, Engine.Localize("@LUA_MENU_LOADED_MOD", getmodname(modfolder):truncate(24)))
menu:AddButton("$_UNLOAD", function()
menu:AddButton("@LUA_MENU_UNLOAD", function()
game:executecommand("unloadmod")
end, nil, true, nil, {
desc_text = "Unload the currently loaded mod."
desc_text = Engine.Localize("@LUA_MENU_UNLOAD_DESC")
})
end
createdivider(menu, "$_Available mods")
createdivider(menu, Engine.Localize("@LUA_MENU_AVAILABLE_MODS"))
if (io.directoryexists("mods")) then
local mods = io.listfiles("mods/")
@ -89,7 +100,8 @@ LUI.MenuBuilder.m_types_build["mods_menu"] = function(a1)
local name, desc = getmodname(mods[i])
if (mods[i] ~= modfolder) then
menu:AddButton("$_" .. name, function()
game:addlocalizedstring(name, name)
menu:AddButton(name, function()
game:executecommand("loadmod " .. mods[i])
end, nil, true, nil, {
desc_text = desc
@ -110,14 +122,3 @@ LUI.MenuBuilder.m_types_build["mods_menu"] = function(a1)
return menu
end
local localize = Engine.Localize
Engine.Localize = function(...)
local args = {...}
if (type(args[1]) == "string" and args[1]:sub(1, 2) == "$_") then
return args[1]:sub(3, -1)
end
return localize(table.unpack(args))
end

View File

@ -1,4 +1,4 @@
game:addlocalizedstring("MENU_GENERAL", "General")
game:addlocalizedstring("MENU_GENERAL", "GENERAL")
game:addlocalizedstring("MENU_GENERAL_DESC", "Set the client's settings.")
game:addlocalizedstring("LUA_MENU_AUTO_UPDATE", "Automatic updates")
game:addlocalizedstring("LUA_MENU_CHECK_UPDATES", "Check for updates")
@ -46,7 +46,7 @@ end
LUI.addmenubutton("pc_controls", {
index = 4,
text = "@MENU_GENERAL",
description = "@MENU_GENERAL_DESC",
description = Engine.Localize("@MENU_GENERAL_DESC"),
callback = function()
LUI.FlowManager.RequestAddMenu(nil, "settings_menu")
end