Advertisement
blue695

Core Single App Prototype

Jul 10th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. core = {}
  2. core.temp = {}
  3. core.temp.term = term.current()
  4. user = {} -- Temporary
  5. user.apps = {} -- Temporary
  6. -- Test Code
  7. user.apps[1] = {path="rom/programs/fun/advanced/paint",image = ".Glass/UI/img/default_ico.nfp",x = 39,y = 7,name = "Hello"}
  8. user.apps[2] = {path="sketch",image = ".Glass/UI/img/default_ico.nfp",x = 25,y = 1,name = "Chicken"}
  9. user.apps[3] = {path="sketch",image = ".Glass/UI/img/default_ico.nfp",x = 5,y = 5,name = "Nong"}
  10. user.apps[4] = {path="sketch",image = ".Glass/UI/img/default_ico.nfp",x = 23,y = 10,name = "Ning"}
  11. -- End of Test Code
  12. -- To-do: Get .JSON from Glass Cloud
  13. core.test = function()
  14. shell.run("sketch")
  15. end
  16. core.runApp = function( path, name )
  17. term.setBackgroundColor( colors.cyan )
  18. term.setTextColor( colors.white )
  19. term.clear()
  20. term.setCursorPos(50,1)
  21. print( "x" )
  22. local func = function() os.run( {} , path ) end
  23. local process = coroutine.create( func )
  24. local win = window.create( core.temp.term , 1 , 2 , 51 , 19 , true )
  25. term.redirect( win )
  26. while true do
  27. local eventData = { os.pullEvent() }
  28. local event = eventData[1]
  29. if event == "mouse_click" then
  30. local button, x, y = eventData[2], eventData[3], eventData[4]
  31. if x == 50 and y == 1 then
  32. term.redirect( core.temp.term )
  33. win.setVisible( false )
  34. core.main()
  35. break
  36. elseif y > 1 then
  37. coroutine.resume( process, event, button, x, y - 1 )
  38. end
  39. elseif event == "mouse_drag" or event == "mouse_up" or event == "mouse_scroll" then
  40. local button, x, y = eventData[2], eventData[3], eventData[4]
  41. coroutine.resume( process, event, button, x, y - 1 )
  42. elseif coroutine.status( process ) == "dead" then
  43. win.setVisible( false )
  44. term.redirect( core.temp.term )
  45. core.main()
  46. break
  47. else coroutine.resume( process , table.unpack(eventData) )
  48. end
  49. end
  50. end
  51. core.main = function()
  52. while true do
  53. core.drawIcons()
  54. if core.temp.appRemove then
  55. table.remove(user.apps,core.temp.appRemove)
  56. core.temp.appRemove = nil
  57. core.drawIcons()
  58. end
  59. local e, button , x , y = os.pullEvent()
  60. for k , v in pairs(user.apps) do
  61. term.setTextColor(colors.black)
  62. term.setCursorPos(1,1)
  63. local appName = user.apps[k]["name"]
  64. local appX = user.apps[k]["x"]
  65. local appY = user.apps[k]["y"]
  66. local path = user.apps[k]["path"]
  67. if e == "mouse_click" and x == appX+12 and y == appY and button == 1 then
  68. core.temp.appRemove = k
  69. core.main()
  70. end
  71. if e == "mouse_click" and x >= appX and x <= appX+12 and y >= appY and y <= appY+6 and x ~= appX + 12 and button == 1 then
  72. core.runApp( user.apps[k]["path"] , user.apps[k]["name"] )
  73. end
  74. if e == "mouse_drag" and x >= appX and x <= appX+12 and y >= appY and y <= appY+6 and x ~= appX + 12 and button == 2 then
  75.  
  76. user.apps[k]["x"] = x - 1
  77. user.apps[k]["y"] = y - 1
  78. end
  79. end
  80. end
  81. end
  82. core.drawIcons = function()
  83. local icons = surface.create(51, 19, " ", colors.orange, colors.white)
  84. local bg = surface.load(".Glass/UI/img/hills.nfp")
  85. icons:drawSurface(1,1,bg)
  86. icons:drawText(2, 2, "=")
  87. icons:drawText(4, 2, "Glass UI Prototype")
  88. for k , v in pairs(user.apps) do
  89. local image = user.apps[k]["image"]
  90. local x = user.apps[k]["x"]
  91. local y = user.apps[k]["y"]
  92. local name = user.apps[k]["name"]
  93. local image2 = surface.load(image)
  94. icons:drawSurface(x,y,image2)
  95. icons:drawText(x+12,y,"x",nil,colors.white)
  96. icons:drawText(x+1,y,name,nil,colors.white)
  97. --local surf = surface.create(51, 19, " ", colors.orange, colors.blue)
  98. --surf.drawSurface(1, 1, image2)
  99. --surf.drawSurface(x, y, image2)
  100. --surf.drawText(x + 12, y + 1, name)
  101. --surf.drawText(3, 3, "Hello, world!")
  102. --local term = term.current()
  103. --surf.render(term)
  104. --paintutils.drawImage(image2,x,y)
  105. --term.setCursorPos(x + 12,y+1)
  106. --print("x")
  107. end
  108. icons:render(term)
  109. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement