launcher_app.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. laptop.register_app("launcher", {
  2. app_name = "Main launcher",
  3. app_info = "Desktop Enviroment",
  4. fullscreen = true,
  5. os_min_version = '5.00',
  6. formspec_func = function(launcher_app, mtos)
  7. -- no system found. Error
  8. if not mtos.sysdata then
  9. local formspec = "size[10,7]background[10,7;0,0;laptop_launcher_insert_floppy.png;true]"..
  10. "listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]"..
  11. "list[nodemeta:"..mtos.pos.x..','..mtos.pos.y..','..mtos.pos.z..";main;2.5,3;1,1;]" ..
  12. "list[current_player;main;0,6.5;8,1;]" ..
  13. "listring[nodemeta:"..mtos.pos.x..','..mtos.pos.y..','..mtos.pos.z..";main]" ..
  14. "listring[current_player;main]"
  15. local idata = mtos.bdev:get_removable_disk()
  16. if idata.stack then
  17. if idata.os_format ~= "boot" then
  18. formspec = formspec .. "label[0,1.7;Disk found but not formatted to boot]"
  19. end
  20. end
  21. return formspec
  22. end
  23. local c_row_count = 4
  24. local i = 0
  25. local out = "size[15,10]"
  26. if mtos.theme.desktop_background then
  27. out = out..'background[15,10;0,0;'..mtos.theme.desktop_background..';true]'
  28. end
  29. local appslist_sorted = {}
  30. for name, def in pairs(laptop.apps) do
  31. if def.app_name and not def.view and def.name ~= launcher_app.name and mtos:is_app_compatible(name)then
  32. table.insert(appslist_sorted, {name = name, def = def})
  33. end
  34. end
  35. table.sort(appslist_sorted, function(a,b) return a.name < b.name end)
  36. for i, e in ipairs(appslist_sorted) do
  37. local x = math.floor((i-1) / c_row_count)*2 + 1
  38. local y = ((i-1) % c_row_count)*2 + 1
  39. out = out .. mtos.theme:get_image_button(x..','..y..';1,1', 'desktop_icon', e.name, mtos.theme:get_texture(e.def.app_icon or 'logo.png'), "", (e.def.app_info or e.name))..
  40. mtos.theme:get_button((x-.5)..','..(y+1.08)..';2,.5', 'desktop_icon_label', e.name, e.def.app_name)
  41. end
  42. out = out..mtos.theme:get_button(mtos.theme.taskbar_clock_position_and_size, "major", "os_clock", os.date("%c"))
  43. return out
  44. end,
  45. appwindow_formspec_func = function(launcher_app, app, mtos)
  46. local formspec = 'size[15,10]'
  47. if mtos.theme.app_background then
  48. formspec = formspec..'background[0,0;15,10;'..mtos.theme.app_background..';true]'
  49. end
  50. if #mtos.sysram.stack > 0 then
  51. formspec = formspec..mtos.theme:get_button('-0.29,-0.31;1.09,0.61', 'back', 'os_back', '<', 'Return to previous screen')
  52. end
  53. if app.app_info then
  54. if #mtos.sysram.stack > 0 then
  55. formspec = formspec..mtos.theme:get_label("0.8,-0.29", app.app_info, "titlebar")
  56. else
  57. formspec = formspec..mtos.theme:get_label("-0.1,-0.29", app.app_info, "titlebar")
  58. end
  59. end
  60. formspec = formspec..mtos.theme:get_button('14.2,-0.31;1.09,0.61', 'exit', 'os_exit', mtos.theme.exit_character, 'Exit app')
  61. return formspec
  62. end,
  63. receive_fields_func = function(launcher_app, mtos, sender, fields)
  64. for name, descr in pairs(fields) do
  65. if laptop.apps[name] then
  66. mtos:set_app(name)
  67. break
  68. end
  69. end
  70. end,
  71. })