Advertisement
Guest User

Desktop.lua

a guest
Apr 26th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.88 KB | None | 0 0
  1. Core.last="System/Desktop.lua"
  2. f=fs.open("Apps/.desktop","r")
  3. tApps=textutils.unserialize(f.readAll())
  4. f.close()
  5. tApp=fs.list("Apps")
  6. x,y=0,0
  7. for i=1,#tApps do
  8. if tApp[i]==".desktop" then table.remove(tApp,i) end
  9. end
  10. for i=1,3 do
  11. for k=1,#tApp do
  12. for n=1,#tApps do
  13. for i=1,#tApps[n] do
  14. if tApp[k]==tApps[n][i] then table.remove(tApp,k) end
  15. end
  16. end
  17. end
  18. end
  19. if tApp then
  20. for i=1,math.ceil(#tApp/9) do
  21. tApps[i+2]={}
  22. for n=1,9 do
  23. tApps[i+2][n]=tApp[(i-1)*9+n]
  24. end
  25. end
  26. end
  27. Data=Core.getData()
  28. if type(m)~="number" then m=1 end
  29. local function drawApps(m)
  30. local nIcon=1
  31. tIcons={}
  32. Draw.clear(1)
  33. Draw.setStatusColor(Draw.StatusGlobal)
  34. Draw.isStatusVisible(true)
  35. Draw.status()
  36. term.setTextColor(2^15)
  37. for n=1,3 do
  38. for i=1,3 do
  39. if tApps[m][(n-1)*3+i] then
  40. tIcon=Draw.loadIcon("System/Images/default")
  41. if fs.exists("Apps/"..tApps[m][(n-1)*3+i].."/icon") then
  42. tIcon=Draw.loadIcon("Apps/"..tApps[m][(n-1)*3+i].."/icon")
  43. if tIcon==nil then tIcon=Draw.loadIcon("System/Images/default") end
  44. end
  45. Draw.icon(tIcon,(Screen.Width/3)*i-1/2*Screen.Width/3,n*5-3)
  46. tIcons[nIcon]={}
  47. tIcons[nIcon][1]=math.ceil(Screen.Width/3)*(i-1)+3
  48. tIcons[nIcon][2]=math.ceil(Screen.Width/3)*(i-1)+6
  49. tIcons[nIcon][3]=n*5-2
  50. tIcons[nIcon][4]=n*5+1
  51. tIcons[nIcon][5]=tApps[m][(n-1)*3+i]
  52. nIcon=nIcon+1
  53. if tApps[m][(n-1)*3+i]=="Date" then
  54. term.setCursorPos(math.ceil(Screen.Width/3)*(i-1)+4,n*5-2)
  55. if Time.date then
  56. _y,_m,nD=Time.date(os.day())
  57. else
  58. nD="--"
  59. end
  60. term.setTextColor(1)
  61. term.setBackgroundColor(2^14)
  62. if #tostring(nD)==1 then nD="0"..nD end
  63. print(nD)
  64. end
  65. term.setTextColor(2^15)
  66. sName=nil
  67. sName2=nil
  68. if #tApps[m][(n-1)*3+i]>10 then sName=tApps[m][(n-1)*3+i]:sub(1,9) sName2=tApps[m][(n-1)*3+i]:sub(9,#tApps[m][(n-1)*3+i]) else sName=tApps[m][(n-1)*3+i] end
  69. term.setCursorPos(math.ceil(Screen.Width/3)*(i-1)+(7/#sName)*2,n*5)
  70. term.setBackgroundColor(1)
  71. write(sName)
  72. if sName2 then
  73. term.setCursorPos(math.ceil(Screen.Width/3)*(i-1)+3,n*5+1)
  74. write(sName2)
  75. end
  76. end
  77. end
  78. end
  79. local tPixs={}
  80. for i=1,#tApps do paintutils.drawPixel((Screen.Width-#tApps)/2+2*(i-1),Screen.Height-1,256) tPixs[i]=(Screen.Width-#tApps)/2+2*(i-1) end
  81. paintutils.drawPixel(tPixs[m],Screen.Height-1,128)
  82. end
  83. drawApps(m)
  84. local desktop=true
  85. while desktop do
  86. tEvent={os.pullEventRaw()}
  87. if tEvent[1]=="mouse_click" then
  88. x,y=tEvent[3],tEvent[4]
  89. if oldx==x and oldy==y then
  90. for i=1,#tIcons do
  91. if x>=tIcons[i][1] and x<=tIcons[i][2] and y>=tIcons[i][3] and y<=tIcons[i][4] then shell.run("Apps/"..tIcons[i][5].."/Startup.lua") drawApps(m) end
  92. end
  93. end
  94. oldx,oldy=x,y
  95. elseif tEvent[1]=="mouse_drag" then
  96. if tEvent[3]<x-7 then
  97. if type(m)~="number" then m=1 end
  98. m=m+1
  99. if m>#tApps then m=#tApps end
  100. if m~=oldm then drawApps(m) end
  101. oldm=m
  102. x,y=tEvent[3],tEvent[4]
  103. end
  104. if tEvent[3]>x+7 then
  105. if type(m)~="number" then m=1 end
  106. m=m-1
  107. if m<1 then m=1 end
  108. if m~=oldm then drawApps(m) end
  109. oldm=m
  110. x,y=tEvent[3],tEvent[4]
  111. end
  112. end
  113. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement