add 'Scripts' menu page

This commit is contained in:
MihailRis 2025-01-05 22:45:43 +03:00
parent 136c35591c
commit 48aad8d974
5 changed files with 52 additions and 0 deletions

View File

@ -1,5 +1,6 @@
<panel size='400' color='0' interval='1' context='menu'>
<button onclick='menu.page="worlds"'>@Worlds</button>
<button onclick='menu.page="scripts"'>@Scripts</button>
<button onclick='menu.page="settings"'>@Settings</button>
<button onclick='menu.page="content_menu"'>@Contents Menu</button>
<button onclick='core.quit()'>@Quit</button>

View File

@ -0,0 +1,7 @@
<panel size='400' color='0' context='menu'>
<label>@Scripts</label>
<panel id="list" size='400' interval='1' color='#00000030' max-length='300'>
<!-- content is generated in script -->
</panel>
<button onclick='menu:back()'>@Back</button>
</panel>

View File

@ -0,0 +1,40 @@
function run_script(path)
debug.log("starting application script "..path)
local code = file.read(path)
local chunk, err = loadstring(code, path)
if chunk == nil then
error(err)
end
setfenv(chunk, setmetatable({app=__vc_app}, {__index=_G}))
start_coroutine(chunk, path)
end
local function refresh()
document.list:clear()
local available = pack.get_available()
local infos = pack.get_info(available)
for _, name in ipairs(available) do
local info = infos[name]
local scripts_dir = info.path.."/scripts/app"
if not file.exists(scripts_dir) then
goto continue
end
local files = file.list(scripts_dir)
for _, filename in ipairs(files) do
if file.ext(filename) == "lua" then
document.list:add(gui.template("script", {
pack=name,
name=file.stem(filename),
path=filename
}))
end
end
::continue::
end
end
function on_open()
refresh()
end

View File

@ -0,0 +1,3 @@
<button color='#10305080' hover-color='#10305040' onclick='run_script("%{path}")'>
%{name} [%{pack}]
</button>

View File

@ -34,6 +34,7 @@ graphics.dense-render.tooltip=Включает прозрачность блок
menu.Apply=Применить
menu.Audio=Звук
menu.Back to Main Menu=Вернуться в Меню
menu.Scripts=Сценарии
menu.Content Error=Ошибка Контента
menu.Content=Контент
menu.Continue=Продолжить