add 'Scripts' menu page
This commit is contained in:
parent
136c35591c
commit
48aad8d974
@ -1,5 +1,6 @@
|
|||||||
<panel size='400' color='0' interval='1' context='menu'>
|
<panel size='400' color='0' interval='1' context='menu'>
|
||||||
<button onclick='menu.page="worlds"'>@Worlds</button>
|
<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="settings"'>@Settings</button>
|
||||||
<button onclick='menu.page="content_menu"'>@Contents Menu</button>
|
<button onclick='menu.page="content_menu"'>@Contents Menu</button>
|
||||||
<button onclick='core.quit()'>@Quit</button>
|
<button onclick='core.quit()'>@Quit</button>
|
||||||
|
|||||||
7
res/layouts/pages/scripts.xml
Normal file
7
res/layouts/pages/scripts.xml
Normal 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>
|
||||||
40
res/layouts/pages/scripts.xml.lua
Normal file
40
res/layouts/pages/scripts.xml.lua
Normal 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
|
||||||
3
res/layouts/templates/script.xml
Normal file
3
res/layouts/templates/script.xml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<button color='#10305080' hover-color='#10305040' onclick='run_script("%{path}")'>
|
||||||
|
%{name} [%{pack}]
|
||||||
|
</button>
|
||||||
@ -34,6 +34,7 @@ graphics.dense-render.tooltip=Включает прозрачность блок
|
|||||||
menu.Apply=Применить
|
menu.Apply=Применить
|
||||||
menu.Audio=Звук
|
menu.Audio=Звук
|
||||||
menu.Back to Main Menu=Вернуться в Меню
|
menu.Back to Main Menu=Вернуться в Меню
|
||||||
|
menu.Scripts=Сценарии
|
||||||
menu.Content Error=Ошибка Контента
|
menu.Content Error=Ошибка Контента
|
||||||
menu.Content=Контент
|
menu.Content=Контент
|
||||||
menu.Continue=Продолжить
|
menu.Continue=Продолжить
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user