Advertisement
Agent_Silence

GUIDE

Oct 24th, 2014 (edited)
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.31 KB | None | 0 0
  1. local tArgs = {...}
  2.  
  3.  
  4. function dualPull(...)
  5.   local e={...}
  6.   local ev={os.pullEvent()}
  7.   repeat
  8.     for k,v in pairs(e) do
  9.       if v==ev[1] then return unpack(ev) end
  10.     end
  11.     ev={os.pullEvent()}
  12.   until false
  13. end
  14. function shorten(sText,nLimit)
  15.   sText = #sText > nLimit and string.sub(sText,1,nLimit-3).."..." or sText
  16.   return sText
  17. end
  18.  
  19. function drawStartMenu(item)
  20. term.setBackgroundColor(colors.white)
  21. term.clear()
  22. paintutils.drawLine(16,1,16,19,colors.black)
  23. paintutils.drawLine(17,6,51,6,colors.black)
  24. term.setCursorPos(17,7)
  25. term.setTextColor(colors.black)
  26. term.setBackgroundColor(colors.white)
  27. term.setCursorPos(17,8)
  28. term.setCursorPos(17,7)
  29. term.write("GUIDE v1.7")
  30. term.setCursorPos(17,10)
  31. term.write("Changes in 1.7 --------------------")
  32. term.setCursorPos(17,12)
  33. term.write("+ New Start Menu")
  34. term.setCursorPos(17,13)
  35. term.write("+ Changelog")
  36. term.setCursorPos(17,14)
  37. term.write("- Old Ugly Start Menu")
  38. paintutils.drawLine(29,4,39,4,colors.green)
  39. term.setCursorPos(29,4)
  40. term.write("Select Item")
  41. term.setCursorPos(math.ceil((34 / 2) - (#item / 2))+17,3)
  42. term.setBackgroundColor(colors.white)
  43. term.setTextColor(colors.gray)
  44. term.write(item)
  45. end
  46.  
  47. function startMenu()
  48. local list = fs.list("/")
  49. local selected = math.ceil(#list/2)
  50. while true do
  51.   drawStartMenu(list[selected] or "")
  52.   for i=1,9 do
  53.     term.setCursorPos(1,i)
  54.     if list[selected - (10 - i)] then
  55.       term.setTextColor(fs.isDir(shell.dir().."/"..list[selected - (10 - i)]) and colors.green or colors.gray)
  56.     end    
  57.     term.setBackgroundColor(colors.white)
  58.     term.write(list[selected - (10 - i)] or "")
  59.   end
  60.   term.setCursorPos(1,10)
  61.   term.setBackgroundColor(colors.lightGray)
  62.   term.setTextColor(fs.isDir(shell.dir().."/"..list[selected]) and colors.green or colors.gray)
  63.   term.write(list[selected])
  64.   for i=1,9 do
  65.     term.setCursorPos(1,i+10)
  66.     if list[selected + i] then
  67.       term.setTextColor(fs.isDir(shell.dir().."/"..list[selected + i]) and colors.green or colors.gray)
  68.     end
  69.     term.setBackgroundColor(colors.white)
  70.     term.write(list[selected + i] or "")
  71.   end
  72.   sleep(0.05)
  73.   local event, arg1, x, y = dualPull("mouse_scroll","mouse_click")
  74.   if event == "mouse_scroll" then
  75.     if arg1 == -1 and 1 < selected then
  76.       selected = selected - 1
  77.     elseif arg1 == 1 and selected < #list then
  78.       selected =  selected + 1
  79.     end
  80.   elseif event == "mouse_click" then
  81.     if x < 16 then
  82.       if y < 10 and selected - (10 - y) > 0 then
  83.         selected = selected - (10 - y)
  84.       elseif y > 10 and selected + (y - 10) < #list + 1 then
  85.         selected = selected + (y - 10)
  86.       end
  87.     elseif x < 40 and x > 28 and y == 4 then
  88.       if fs.isReadOnly(shell.dir().."/"..list[selected]) == false and fs.isDir(shell.dir().."/"..list[selected]) == false and list[selected] ~= "Back To Home" then
  89.         return shell.dir()..list[selected]
  90.       elseif fs.isDir(shell.dir().."/"..list[selected]) == true then
  91.         local dir = shell.dir()
  92.         shell.setDir(shell.dir().."/"..list[selected])
  93.         list = fs.list(dir.."/"..list[selected].."/")
  94.         selected = 1
  95.         table.insert(list,1,"Back To Home")
  96.       elseif list[selected] == "Back To Home" then
  97.         shell.setDir("/")
  98.         list = fs.list("/")
  99.         selected = 1
  100.       end
  101.     end
  102.   end
  103. end
  104. end
  105.  
  106. if type(tArgs[1]) ~= "string" then
  107.   tArgs[1] = startMenu()
  108.   shell.setDir("/")
  109.  
  110. end
  111.  
  112. curColor = colors.black
  113. backColor = colors.white
  114. script = {}
  115.  
  116. function toColor(nColor)
  117.   for i,v in pairs(colors) do
  118.         if v == nColor then
  119.           return "colors."..i
  120.     end
  121.   end
  122. end
  123.  
  124. colorsL = {
  125. colors.white,
  126. colors.orange,
  127. colors.magenta,
  128. colors.lightBlue,
  129. colors.yellow,
  130. colors.lime,
  131. colors.pink,
  132. colors.gray,
  133. colors.lightGray,
  134. colors.cyan,
  135. colors.purple,
  136. colors.blue,
  137. colors.brown,
  138. colors.green,
  139. colors.red,
  140. colors.black}
  141.  
  142. function redraw()
  143.   for i,v in pairs(script) do
  144.     local exec = loadstring(v)
  145.     exec()
  146.   end
  147. end
  148.  
  149. function startScreen()
  150. term.setBackgroundColor(colors.lightGray)
  151. term.clear()
  152. paintutils.drawLine(1,1,1,19,colors.black)
  153. term.setCursorPos(2,1)
  154. term.setTextColor(colors.white)
  155. term.setBackgroundColor(colors.gray)
  156. term.write('How to use GUIDE')
  157. paintutils.drawLine(2,2,51,2,colors.black)
  158. paintutils.drawLine(18,2,18,1,colors.black)
  159. paintutils.drawLine(51,2,51,19,colors.black)
  160. paintutils.drawLine(51,19,1,19,colors.black)
  161. term.setCursorPos(2,3)
  162. term.setTextColor(colors.white)
  163. term.setBackgroundColor(colors.gray)
  164. term.write('Press 1 to create a line, space to end line, R ')
  165. term.setCursorPos(2,4)
  166. term.setTextColor(colors.white)
  167. term.setBackgroundColor(colors.gray)
  168. term.write('to reposition starting point')
  169. term.setCursorPos(2,6)
  170. term.setTextColor(colors.white)
  171. term.setBackgroundColor(colors.gray)
  172. term.write('Press 2 to write text, click to place text')
  173. term.setCursorPos(2,8)
  174. term.setTextColor(colors.white)
  175. term.setBackgroundColor(colors.gray)
  176. term.write('Press 3 to clear the screen with background color')
  177. term.setCursorPos(2,10)
  178. term.setTextColor(colors.white)
  179. term.setBackgroundColor(colors.gray)
  180. term.write('Press P to open Color Picker')
  181. term.setCursorPos(2,12)
  182. term.setTextColor(colors.white)
  183. term.setBackgroundColor(colors.gray)
  184. term.write('Press Tab to finish project')
  185. term.setCursorPos(2,14)
  186. term.setTextColor(colors.white)
  187. term.setBackgroundColor(colors.gray)
  188. term.write('Press Backspace to delete last GUI Item')
  189. term.setCursorPos(2,16)
  190. term.setTextColor(colors.white)
  191. term.setBackgroundColor(colors.gray)
  192. term.write('Background is used for line and clear')
  193. term.setCursorPos(2,17)
  194. term.setTextColor(colors.white)
  195. term.setBackgroundColor(colors.gray)
  196. term.write('Text is used for well, text.')
  197. paintutils.drawLine(2,5,50,5,colors.black)
  198. paintutils.drawLine(2,7,50,7,colors.black)
  199. paintutils.drawLine(2,9,50,9,colors.black)
  200. paintutils.drawLine(2,11,50,11,colors.black)
  201. paintutils.drawLine(2,13,51,13,colors.black)
  202. paintutils.drawLine(2,15,51,15,colors.black)
  203. paintutils.drawLine(1,18,51,18,colors.black)
  204. term.setCursorPos(2,19)
  205. term.setTextColor(colors.white)
  206. term.setBackgroundColor(colors.black)
  207. term.write('GUI made with GUIDE')
  208. end
  209.  
  210. function line()
  211.   local event,button,x,y = os.pullEvent("mouse_click")
  212.   local eventd,buttond,dragx,dragy = "",0,0,0
  213.   local oldx, oldy = 1,1
  214.   repeat
  215.     term.setBackgroundColor(colors.black)
  216.     term.clear()
  217.     redraw()
  218.     if eventd == "key" and buttond == keys.r then
  219.       paintutils.drawLine(x,y,oldx,oldy,backColor)
  220.       event,button,x,y = os.pullEvent("mouse_click")
  221.     end
  222.     if eventd == "mouse_drag" then
  223.       oldx, oldy = dragx,dragy
  224.         elseif eventd == "key" then
  225.           oldx = oldx
  226.           oldy = oldy
  227.         end
  228.         if eventd == "mouse_drag" then
  229.       paintutils.drawLine(x,y,dragx,dragy,backColor)
  230.     elseif eventd == "key" then
  231.           paintutils.drawLine(x,y,oldx,oldy,backColor)
  232.         end
  233.     eventd,buttond,dragx,dragy = dualPull("mouse_drag","key")
  234.     if eventd == "key" and buttond == keys.space then
  235.       table.insert(script,"paintutils.drawLine("..x..","..y..","..oldx..","..oldy..","..toColor(backColor)..")")
  236.     end
  237.   until eventd == "key" and buttond == keys.space
  238. end
  239.  
  240. function text()
  241.   local event,button,x,y = os.pullEvent("mouse_click")
  242.   term.setCursorPos(x,y)
  243.   local text = {}
  244.   repeat
  245.     local event,key = os.pullEvent()
  246.     if event == "char" then
  247.       table.insert(text,string.sub(key,1,1))
  248.       term.setCursorPos(x,y)
  249.       term.setTextColor(curColor)
  250.       term.setBackgroundColor(backColor)
  251.       term.write(table.concat(text))
  252.     elseif event == "key" then
  253.       if key == keys.backspace then
  254.         table.remove(text)
  255.         paintutils.drawLine(x,y,x+#text,y,backColor)
  256.         term.setCursorPos(x,y)
  257.         term.write(table.concat(text))
  258.       end
  259.     end
  260.   until key == keys.enter
  261.   table.insert(script,"term.setCursorPos("..x..","..y..")")
  262.   if lastColor ~= curColor and lastBackColor ~= backColor then
  263.   table.insert(script,"term.setTextColor("..toColor(curColor)..")")
  264.   table.insert(script,"term.setBackgroundColor("..toColor(backColor)..")")
  265.   lastColor = curColor
  266.   lastBackColor = backColor
  267.   end
  268.   table.insert(script,[[term.write("]]..table.concat(text)..[[")]])
  269. end
  270.  
  271. function drawColorPick()
  272. term.setBackgroundColor(colors.lightGray)
  273. term.clear()
  274. paintutils.drawLine(2,2,3,2,colors.white)
  275. paintutils.drawLine(4,2,5,2,colors.orange)
  276. paintutils.drawLine(6,2,7,2,colors.magenta)
  277. paintutils.drawLine(8,2,9,2,colors.lightBlue)
  278. paintutils.drawLine(2,3,3,3,colors.yellow)
  279. paintutils.drawLine(4,3,5,3,colors.lime)
  280. paintutils.drawLine(6,3,7,3,colors.pink)
  281. paintutils.drawLine(8,3,9,3,colors.gray)
  282. paintutils.drawLine(4,4,5,4,colors.cyan)
  283. paintutils.drawLine(6,4,7,4,colors.purple)
  284. paintutils.drawLine(8,4,9,4,colors.blue)
  285. paintutils.drawLine(2,5,3,5,colors.brown)
  286. paintutils.drawLine(4,5,5,5,colors.green)
  287. paintutils.drawLine(6,5,7,5,colors.red)
  288. paintutils.drawLine(8,5,9,5,colors.black)
  289. paintutils.drawLine(1,1,1,5,colors.black)
  290. paintutils.drawLine(1,6,7,6,colors.black)
  291. paintutils.drawLine(2,1,9,1,colors.black)
  292. paintutils.drawLine(10,1,10,4,colors.black)
  293. paintutils.drawLine(10,5,10,6,colors.black)
  294. paintutils.drawLine(10,6,8,6,colors.black)
  295. term.setCursorPos(11,1)
  296. term.setTextColor(colors.black)
  297. term.setBackgroundColor(colors.lightGray)
  298. term.write('Color Picker')
  299. term.setCursorPos(12,4)
  300. term.setTextColor(colors.black)
  301. term.setBackgroundColor(colors.gray)
  302. term.write('Background Color')
  303. term.setCursorPos(12,6)
  304. term.write('Text Color')
  305. paintutils.drawLine(10,6,10,19,colors.black)
  306. term.setCursorPos(11,12)
  307. term.setTextColor(colors.black)
  308. term.setBackgroundColor(colors.lightGray)
  309. term.write('This Color Picker GUI was made with GUIDE')
  310. term.setCursorPos(11,13)
  311. term.setTextColor(colors.black)
  312. term.setBackgroundColor(colors.lightGray)
  313. term.write(', A tool to improve tools. The GUI blade')
  314. term.setCursorPos(11,14)
  315. term.setTextColor(colors.black)
  316. term.setBackgroundColor(colors.lightGray)
  317. term.write('sharpener.')
  318. paintutils.drawLine(10,2,51,2,colors.black)
  319. paintutils.drawLine(11,10,51,10,colors.black)
  320. term.setCursorPos(12,8)
  321. term.setTextColor(colors.black)
  322. term.setBackgroundColor(colors.red)
  323. term.write('Cancel')
  324. end
  325.  
  326. function colorPick()
  327. drawColorPick()
  328. local function fillColor(nColor)
  329. for i=7,19 do
  330. paintutils.drawLine(1,i,9,i,nColor)
  331. end
  332. end
  333. local selectedColor = colors.white
  334. repeat
  335. local event,button,xpos,ypos = dualPull("mouse_click","mouse_drag")
  336. if xpos == 2 and ypos == 2 or xpos == 3 and ypos == 2 then
  337.  selectedColor = colors.white
  338. elseif xpos == 4 and ypos == 2 or xpos == 5 and ypos == 2 then
  339.  selectedColor = colors.orange
  340. elseif xpos == 6 and ypos == 2 or xpos == 7 and ypos == 2 then
  341.  selectedColor = colors.magenta
  342. elseif xpos == 8 and ypos == 2 or xpos == 9 and ypos == 2 then
  343.  selectedColor = colors.lightBlue
  344. elseif xpos == 2 and ypos == 3 or xpos == 3 and ypos == 3 then
  345.  selectedColor = colors.yellow
  346. elseif xpos == 4 and ypos == 3 or xpos == 5 and ypos == 3 then
  347.  selectedColor = colors.lime
  348. elseif xpos == 6 and ypos == 3 or xpos == 7 and ypos == 3 then
  349.  selectedColor = colors.pink
  350. elseif xpos == 8 and ypos == 3 or xpos == 9 and ypos == 3 then
  351.  selectedColor = colors.gray
  352. elseif xpos == 2 and ypos == 4 or xpos == 3 and ypos == 4 then
  353.  selectedColor = colors.lightGray
  354. elseif xpos == 4 and ypos == 4 or xpos == 5 and ypos == 4 then
  355.  selectedColor = colors.cyan
  356. elseif xpos == 6 and ypos == 4 or xpos == 7 and ypos == 4 then
  357.  selectedColor = colors.purple
  358. elseif xpos == 8 and ypos == 4 or xpos == 9 and ypos == 4 then
  359.  selectedColor = colors.blue
  360. elseif xpos == 2 and ypos == 5 or xpos == 3 and ypos == 5 then
  361.  selectedColor = colors.brown
  362. elseif xpos == 4 and ypos == 5 or xpos == 5 and ypos == 5 then
  363.  selectedColor = colors.green
  364. elseif xpos == 6 and ypos == 5 or xpos == 7 and ypos == 5 then
  365.  selectedColor = colors.red
  366. elseif xpos == 8 and ypos == 5 or xpos == 9 and ypos == 5 then
  367.  selectedColor = colors.black
  368. end
  369.  
  370. fillColor(selectedColor)
  371. if (xpos >= 12 and xpos <= 12+#"Text Color" and ypos == 6) then
  372.   curColor = selectedColor
  373. elseif (xpos >= 12 and xpos <= 12+#"Background Color" and ypos == 4 ) then
  374.   backColor = selectedColor
  375. end
  376. until (xpos >= 12 and xpos <= 18 and ypos == 8) or (xpos >= 12 and xpos <= 12+#"Text Color" and ypos == 6) or (xpos >= 12 and xpos <= 12+#"Background Color" and ypos == 4 )
  377. term.setBackgroundColor(colors.black)
  378. term.clear()
  379. redraw()
  380. end
  381.  
  382. function pixel()
  383.   repeat
  384.     term.setBackgroundColor(colors.black)
  385.     term.clear()
  386.     redraw()
  387.     local event, arg1, arg2, arg3 = dualPull("mouse_click","key","mouse_drag")
  388.     if event == "mouse_click" or event == "mouse_drag" then
  389.       paintutils.drawPixel(arg2,arg3,backColor)
  390.       table.insert(script,"paintutils.drawPixel("..arg2..","..arg3..","..toColor(backColor)..")")
  391.     elseif event == "key" then
  392.       if arg1 == keys.p then
  393.         colorPick()
  394.       end
  395.      
  396.       if arg1 == keys.backspace then
  397.         table.remove(script)
  398.       end
  399.     end
  400.   until event == "key" and arg1 == keys.space
  401. end
  402.  
  403. function clear()
  404.   term.setBackgroundColor(backColor)
  405.   term.clear()
  406.   table.insert(script,"term.setBackgroundColor("..toColor(backColor)..")")
  407.   table.insert(script,"term.clear()")
  408. end
  409.  
  410. startScreen()
  411.  
  412. function finish()
  413.   local file = fs.open(tArgs[1],"a")
  414.   file.writeLine(" ")
  415.   file.writeLine("function drawGUI()")
  416.   for i,v in pairs(script) do
  417.     file.writeLine(v)
  418.   end
  419.   file.writeLine("end")
  420.   file.writeLine("drawGUI()")
  421.   file.close()
  422.   term.setBackgroundColor(colors.black)
  423.   term.clear()
  424.   term.setCursorPos(1,1)
  425.   term.setTextColor(colors.white)
  426.   write("Thanks for using GUIDE by Requeim")
  427.   term.setCursorPos(1,2)
  428. end
  429.  
  430. function drawHotbar()
  431.   paintutils.drawLine(51,1,39,1,colors.gray)
  432.   paintutils.drawLine(39,2,39,19,colors.gray)
  433.   paintutils.drawLine(40,2,40,19,colors.gray)
  434.   paintutils.drawLine(41,19,41,2,colors.gray)
  435.   paintutils.drawLine(42,2,42,19,colors.gray)
  436.   paintutils.drawLine(43,19,43,2,colors.gray)
  437.   paintutils.drawLine(44,2,44,19,colors.gray)
  438.   paintutils.drawLine(45,19,45,2,colors.gray)
  439.   paintutils.drawLine(46,2,46,19,colors.gray)
  440.   paintutils.drawLine(47,19,47,2,colors.gray)
  441.   paintutils.drawLine(48,2,48,18,colors.gray)
  442.   paintutils.drawLine(48,2,48,19,colors.gray)
  443.   paintutils.drawLine(49,19,49,2,colors.gray)
  444.   paintutils.drawLine(50,2,50,19,colors.gray)
  445.   paintutils.drawLine(51,19,51,2,colors.gray)
  446.   paintutils.drawLine(40,3,50,3,colors.white)
  447.   term.setCursorPos(40,3)
  448.   term.setTextColor(colors.black)
  449.   term.setBackgroundColor(colors.white)
  450.   term.write(" Draw Line")
  451.   paintutils.drawLine(40,5,50,5,colors.white)
  452.   term.setCursorPos(40,5)
  453.   term.write("   Write")
  454.   paintutils.drawLine(40,7,50,7,colors.white)
  455.   term.setCursorPos(40,7)
  456.   term.write("   Clear")
  457.   paintutils.drawLine(40,9,50,9,colors.white)
  458.   term.setCursorPos(40,9)
  459.   term.write("Draw Pixels")
  460.   paintutils.drawLine(40,11,50,11,colors.white)
  461.   term.setCursorPos(40,11)
  462.   term.write("   Color")
  463.   term.setCursorPos(40,1)
  464.   term.setTextColor(colors.white)
  465.   term.setBackgroundColor(colors.gray)
  466.   term.write("   Hotbar")
  467.   term.setCursorPos(51,1)
  468.   term.setCursorPos(51,1)
  469.   term.setTextColor(colors.red)
  470.   term.setBackgroundColor(colors.white)
  471.   paintutils.drawLine(40,18,50,18,colors.green)
  472.   term.setCursorPos(40,18)
  473.   term.setTextColor(colors.black)
  474.   term.setBackgroundColor(colors.green)
  475.   term.write(" Need Help")
  476.   paintutils.drawLine(40,16,50,16,colors.green)
  477.   term.setCursorPos(40,16)
  478.   term.write("Im Finished")
  479.   paintutils.drawLine(40,13,50,13,colors.white)
  480.   term.setCursorPos(40,13)
  481.   term.setTextColor(colors.red)
  482.   term.setBackgroundColor(colors.white)
  483.   term.write("Delete Last")
  484.   term.setCursorPos(38,1)
  485.   term.setTextColor(colors.black)
  486.   term.setBackgroundColor(colors.white)
  487.   term.write(">")
  488. end
  489.  
  490. function hotbar()
  491.   repeat
  492.     drawHotbar()
  493.     local event, button, x, y = os.pullEvent("mouse_click")
  494.     if x < 51 and x > 39 then
  495.       if y == 3 then
  496.         line()
  497.         break
  498.       elseif y == 5 then
  499.         term.setBackgroundColor(colors.black)
  500.         term.clear()
  501.         redraw()
  502.         text()
  503.         break
  504.       elseif y == 7 then
  505.         clear()
  506.         break
  507.       elseif y == 9 then
  508.         pixel()
  509.         break
  510.       elseif y == 11 then
  511.         colorPick()
  512.         break
  513.       elseif y == 13 then
  514.         table.remove(script)
  515.         term.setBackgroundColor(colors.black)
  516.         term.clear()
  517.         redraw()
  518.       elseif y == 16 then
  519.         finish()
  520.         return
  521.       elseif y == 18 then
  522.        
  523.       end
  524.     end
  525.   until y == 1 and x == 38
  526.   term.setBackgroundColor(colors.black)
  527.   term.clear()
  528.   redraw()
  529. end
  530.  
  531. repeat
  532.   redraw()
  533.   term.setCursorPos(51,1)
  534.   term.setBackgroundColor(colors.white)
  535.   term.setTextColor(colors.black)
  536.   term.write("<")
  537.   local event, key, mousex, mousey = dualPull("key","mouse_click")
  538.   if event == "key" then
  539.     if key == keys.one then
  540.       line()
  541.     elseif key == keys.two then
  542.       text()
  543.     elseif key == keys.three then
  544.       clear()
  545.     elseif key == keys.p then
  546.       colorPick()
  547.     elseif key == keys.four then
  548.       pixel()
  549.     elseif key == keys.backspace then
  550.       table.remove(script)
  551.       term.setBackgroundColor(colors.black)
  552.       term.clear()
  553.       redraw()
  554.     end
  555.   elseif event == "mouse_click" then
  556.     if mousex == 51 and mousey == 1 then
  557.       hotbar()
  558.     end
  559.   end
  560. until key == keys.tab
  561. finish()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement