lub4095

startup

Aug 27th, 2015
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.09 KB | None | 0 0
  1. mon = peripheral.wrap("monitor_2")
  2. debugmon = peripheral.wrap("monitor_3")
  3. compmon = term.current()
  4. term.redirect(mon)
  5. paintutils.drawFilledBox(1,1,100,100,colors.black)
  6. save = false
  7. load = false
  8. play = false
  9. beat1 = false
  10. beat2 = false
  11. beat3 = false
  12. beat4 = false
  13. beat5 = false
  14. beat6 = false
  15. beat7 = false
  16. beat8 = false
  17. beat9 = false
  18. beat10 = false
  19. beatx = 4
  20. beat1y = 2
  21. beat2y = 4
  22. beat3y = 6
  23. beat4y = 8
  24. beat5y = 10
  25. beat6y = 12
  26. beat7y = 14
  27. beat8y = 16
  28. beat9y = 18
  29. beat10y = 20 -- y positions of selectable sounds
  30. beat1color = colors.white
  31. beat2color = colors.lime
  32. beat3color = colors.green
  33. beat4color = colors.yellow
  34. beat5color = colors.orange
  35. beat6color = colors.red
  36. beat7color = colors.gray
  37. beat8color = colors.blue
  38. beat9color = colors.magenta
  39. beat10color = colors.purple -- colors of selectable sounds
  40. buttonPlusx = 4
  41. buttonPlusxEnd = 6
  42. buttonMinusx = 2
  43. buttonMinusxEnd = 4
  44. buttony = 23
  45. buttonyEnd = 25 -- x,y positions for < > buttons
  46. timelinePos = 1 -- variable to store current clicked position in the timeline
  47. timelineStartDisplay = 9 -- defines the start of the timeline on the terminal
  48. timelineEndDisplay = 72 -- defines the end of the timeline on the terminal
  49. timelineStart = 0 -- defines the start of the timeline
  50. timelineIcon = "|"
  51. timelinePosDisplay = 9 -- variable to store current clicked position on the terminal
  52. tracky = 0 -- variable to store y position of clicked on the terminal
  53. keyPos = 0
  54. number = 1
  55. abc = 3
  56. ahstart = timelineStartDisplay
  57. ah = 0
  58. selectedBeat = "--"
  59. track = {}
  60. x1 = 0
  61. y1 = 0
  62. for i=1,10,1 do
  63.   track[i] = {}
  64. end
  65. function debugger()
  66.   term.redirect(debugmon)
  67.   term.clear()
  68.   term.setCursorPos(1,1)
  69.   textutils.tabulate(track[],colors.lightBlue)
  70.   print("aaaa")
  71.   --print(track[1][1])
  72.   term.redirect(mon)
  73. end
  74. function addKey() -- adding/replacing a key in the table
  75.   local a = x1 - timelineStartDisplay
  76.   timelinePos = timelineStart + a
  77.   drawAddedkey = true
  78.   local t = 1
  79.   for i=3,21,2 do -- go through all tracks
  80.     if y1 == i then
  81.       for key, value in ipairs(track[t]) do -- check if click is on existing key
  82.         if key == timelinePos then
  83.           tracky = y
  84.           if value ~= 0 and beatDelete == true then
  85.             track[t][timelinePos] = 0
  86.             break
  87.           end
  88.           if beat1 == true then
  89.             track[t][timelinePos] = "beat1"
  90.             break
  91.           elseif beat2 == true then
  92.             track[t][timelinePos] = "beat2"
  93.             break
  94.           elseif beat3 == true then
  95.             track[t][timelinePos] = "beat3"
  96.             break
  97.           elseif beat4 == true then
  98.             track[t][timelinePos] = "beat4"
  99.             break
  100.           elseif beat5 == true then
  101.             track[t][timelinePos] = "beat5"
  102.             break
  103.           elseif beat6 == true then
  104.             track[t][timelinePos] = "beat6"
  105.             break
  106.           elseif beat7 == true then
  107.             track[t][timelinePos] = "beat7"
  108.             break
  109.           elseif beat8 == true then
  110.             track[t][timelinePos] = "beat8"
  111.             break
  112.           elseif beat9 == true then
  113.             track[t][timelinePos] = "beat9"
  114.             break
  115.           elseif beat10 == true then
  116.             track[t][timelinePos] = "beat10"
  117.             break
  118.           end
  119.         end
  120.       end
  121.       if beat1 == true then
  122.         track[t][timelinePos] = "beat1"
  123.         break
  124.       elseif beat2 == true then
  125.         track[t][timelinePos] = "beat2"
  126.         break
  127.       elseif beat3 == true then
  128.         track[t][timelinePos] = "beat3"
  129.         break
  130.       elseif beat4 == true then
  131.         track[t][timelinePos] = "beat4"
  132.         break
  133.       elseif beat5 == true then
  134.         track[t][timelinePos] = "beat5"
  135.         break
  136.       elseif beat6 == true then
  137.         track[t][timelinePos] = "beat6"
  138.         break
  139.       elseif beat7 == true then
  140.         track[t][timelinePos] = "beat7"
  141.         break
  142.       elseif beat8 == true then
  143.         track[t][timelinePos] = "beat8"
  144.         break
  145.       elseif beat9 == true then
  146.         track[t][timelinePos] = "beat9"
  147.         break
  148.       elseif beat10 == true then
  149.         track[t][timelinePos] = "beat10"
  150.         break
  151.       else
  152.         track[t][timelinePos] = "nothing"
  153.       end
  154.     end
  155.     t = t + 1
  156.   end
  157.   debugger()  
  158. end
  159. function drawBeatsPaint() -- drawing the selectable sounds
  160.   term.redirect(mon)
  161.   paintutils.drawFilledBox(1,1,8,25,colors.black)
  162.   paintutils.drawPixel(beatx, beat1y, beat1color)
  163.   paintutils.drawPixel(beatx, beat2y, beat2color)
  164.   paintutils.drawPixel(beatx, beat3y, beat3color)
  165.   paintutils.drawPixel(beatx, beat4y, beat4color)
  166.   paintutils.drawPixel(beatx, beat5y, beat5color)
  167.   paintutils.drawPixel(beatx, beat6y, beat6color)
  168.   paintutils.drawPixel(beatx, beat7y, beat7color)
  169.   paintutils.drawPixel(beatx, beat8y, beat8color)
  170.   paintutils.drawPixel(beatx, beat9y, beat9color)
  171.   paintutils.drawPixel(beatx, beat10y, beat10color)
  172.   term.redirect(compmon)  
  173. end
  174. function drawBeatsText() -- drawing text for selectable sounds
  175.   mon.setBackgroundColor(colors.black)
  176.   mon.setTextColor(colors.white)
  177.   local x = beatx - 2
  178.   term.redirect(mon)
  179.   while true do
  180.   if number > 10 then
  181.     number = 1
  182.     abc = 3
  183.     break
  184.   end
  185.   term.setCursorPos(x, abc)
  186.   print("beat ",number)
  187.   number = number + 1
  188.   abc = abc + 2
  189.   end
  190.   local x2 = beatx - 2
  191.   if beat1 == true then
  192.     term.setCursorPos(x2,beat1y)
  193.     print(selectedBeat)
  194.   elseif beat2 == true then
  195.     term.setCursorPos(x2,beat2y)
  196.     print(selectedBeat)
  197.   elseif beat3 == true then
  198.     term.setCursorPos(x2,beat3y)
  199.     print(selectedBeat)
  200.   elseif beat4 == true then
  201.     term.setCursorPos(x2,beat4y)
  202.     print(selectedBeat)
  203.   elseif beat5 == true then
  204.     term.setCursorPos(x2,beat5y)
  205.     print(selectedBeat)
  206.   elseif beat6 == true then
  207.     term.setCursorPos(x2,beat6y)
  208.     print(selectedBeat)
  209.   elseif beat7 == true then
  210.     term.setCursorPos(x2,beat7y)
  211.     print(selectedBeat)
  212.   elseif beat8 == true then
  213.     term.setCursorPos(x2,beat8y)
  214.     print(selectedBeat)
  215.   elseif beat9 == true then
  216.     term.setCursorPos(x2,beat9y)
  217.     print(selectedBeat)
  218.   elseif beat10 == true then
  219.     term.setCursorPos(x2,beat10y)
  220.     print(selectedbeat)
  221.   end  
  222.   term.redirect(compmon)
  223. end
  224. function drawSettingsPaint() -- drawing settings menu
  225.   term.redirect(mon)
  226.   if settings == true then
  227.     paintutils.drawLine(59,1,70,1,colors.yellow)
  228.     paintutils.drawFilledBox(59,21,70,25,colors.green)
  229.     paintutils.drawFilledBox(46,21,57,25,colors.blue)
  230.     paintutils.drawFilledBox(33,21,44,25,colors.blue)
  231.   else
  232.     paintutils.drawLine(59,1,70,1,colors.orange)
  233.   end
  234.   term.redirect(compmon)
  235. end
  236. function drawSettingsText() -- drawing settings menu text
  237.   term.redirect(mon)
  238.   if settings == true then
  239.     term.setBackgroundColor(colors.green)
  240.     term.setCursorPos(63,23)
  241.     print("Play")
  242.     term.setBackgroundColor(colors.blue)
  243.     term.setCursorPos(50,23)
  244.     print("Save")
  245.     term.setCursorPos(37,23)
  246.     print("Load")
  247.     term.setBackgroundColor(colors.yellow)
  248.   else
  249.     term.setBackgroundColor(colors.orange)
  250.   end
  251.   term.setCursorPos(61,1)
  252.   print("Settings")
  253.   term.redirect(compmon)
  254. end
  255. function drawButtons() -- drawing < > buttons
  256.   term.redirect(mon)
  257.   if plus == true then
  258.     paintutils.drawFilledBox(buttonPlusx,buttony,buttonPlusxEnd,buttonyEnd,colors.yellow)
  259.     local x = buttonPlusx + 1
  260.     local y = buttony + 1
  261.     term.setCursorPos(x,y)
  262.     term.setBackgroundColor(colors.yellow)
  263.     print(">")
  264.     sleep(0.1)
  265.     plus = false
  266.   end
  267.   if minus == true then
  268.     paintutils.drawFilledBox(buttonMinusx,buttony,buttonMinusxEnd,buttonyEnd,colors.yellow)
  269.     local x = buttonMinusx + 1
  270.     local y = buttony + 1
  271.     term.setCursorPos(x,y)
  272.     term.setBackgroundColor(colors.yellow)
  273.     print("<")
  274.     sleep(0.1)
  275.     minus = false
  276.   end
  277.   paintutils.drawFilledBox(buttonPlusx,buttony,buttonPlusxEnd,buttonyEnd,colors.orange)
  278.   paintutils.drawFilledBox(buttonMinusx,buttony,buttonMinusxEnd,buttonyEnd,colors.orange)
  279.   local x = buttonPlusx + 1
  280.   local y = buttony + 1
  281.   term.setCursorPos(x,y)
  282.   term.setBackgroundColor(colors.orange)
  283.   print(">")
  284.   local x = buttonMinusx + 1
  285.   term.setCursorPos(x,y)
  286.   print("<")
  287.   term.redirect(compmon)
  288. end  
  289. function drawTimelinePaint() -- drawing the timeline
  290.   term.redirect(mon)
  291.   local x = beatx + 5
  292.   local y = 3
  293.   paintutils.drawFilledBox(x,2,100,23,colors.black)
  294.   while true do
  295.     if number > 10 then
  296.       y = 2
  297.       number = 1
  298.       break
  299.     end
  300.     paintutils.drawLine(x,y,100,y,colors.brown)
  301.     y = y + 2
  302.     number = number + 1
  303.   end
  304.   if drawAddedkey == true then  -- draws/deletes key
  305.     if beatDelete ~= true then
  306.       if beat1 == true then
  307.         paintutils.drawPixel(timelinePosDisplay,tracky,beat1color)
  308.       elseif beat2 == true then
  309.         paintutils.drawPixel(timelinePosDisplay,tracky,beat2color)
  310.       elseif beat3 == true then
  311.         paintuitls.drawPixel(timelinePosDisplay,tracky,beat3color)
  312.       elseif beat4 == teue then
  313.         paintuitls.drawPixel(timelinePosDisplay,tracky,beat4color)
  314.       elseif beat5 == teue then
  315.         paintuitls.drawPixel(timelinePosDisplay,tracky,beat5color)
  316.       elseif beat6 == teue then
  317.         paintuitls.drawPixel(timelinePosDisplay,tracky,beat6color)
  318.       elseif beat7 == teue then
  319.         paintuitls.drawPixel(timelinePosDisplay,tracky,beat7color)
  320.       elseif beat8 == teue then
  321.         paintuitls.drawPixel(timelinePosDisplay,tracky,beat8color)
  322.       elseif beat9 == teue then
  323.         paintuitls.drawPixel(timelinePosDisplay,tracky,beat9color)
  324.       elseif beat10 == teue then
  325.         paintuitls.drawPixel(timelinePosDisplay,tracky,beat10color)
  326.       end
  327.     else
  328.       paintutils.drawPixel(timelinePos,tracky,colors.brown)
  329.     end  
  330.     drawAddedkey = false
  331.     beatDelete = false 
  332.   end
  333.   term.redirect(compmon)
  334. end
  335. function drawTimelineText() -- drawing timeline text and timeslider
  336.   term.redirect(mon)
  337.   term.setBackgroundColor(colors.black)
  338.   local x = ahstart
  339.   local y = 23
  340.   local y2 = 22
  341.   local timelineEnd = timelineStart + 63
  342.   local b = ah
  343.   while true do -- draws timeline numeration
  344.     if x > 70 then
  345.       break
  346.     end
  347.     term.setCursorPos(x,y)
  348.     print(b)
  349.     b = b + 5
  350.     x = x + 5
  351.   end
  352.   local x = timelineStartDisplay
  353.   for i=1,63,1 do
  354.     term.setCursorPos(x,y2)
  355.     print("|")
  356.     x = x + 1
  357.   end
  358.   local y3 = 4
  359.   if timelinePosDisplay > timelineStartDisplay and timelinePosDisplay < timelineEndDisplay then -- draws the timeslider
  360.     for i=1,10,1 do
  361.       term.setCursorPos(timelinePosDisplay,y3)
  362.       print(timelineIcon)
  363.       if y3 >= 22 then
  364.         break
  365.       end
  366.       y3 = y3 + 2
  367.     end
  368.   end
  369.   term.redirect(compmon)
  370. end
  371. function clickDetect() -- Detects where you clicked
  372.   while true do
  373.   local event,side,x,y = os.pullEvent("monitor_touch")
  374.   if x == beatx and y >= beat1y and y <= beat10y then -- detects if you clicked on a selectable sound
  375.     if y == beat1y then
  376.       beat1 = true
  377.       break
  378.     elseif y == beat2y then
  379.       beat2 = true
  380.       break
  381.     elseif y == beat3y then
  382.       beat3 = true
  383.       break
  384.     elseif y == beat4y then
  385.       beat4 = true
  386.       break
  387.     elseif y == beat5y then
  388.       beat5 = true
  389.       break
  390.     elseif y == beat6y then
  391.       beat6 = true
  392.       break
  393.     elseif y == beat7y then
  394.       beat7 = true
  395.       break
  396.     elseif y == beat8y then
  397.       beat8 = true
  398.       break
  399.     elseif y == beat9y then
  400.       beat9 = true
  401.       break
  402.     elseif y == beat10y then
  403.       beat10 = true
  404.       break
  405.     end
  406.   end
  407.   if y >= buttony and y <= buttonyEnd then -- scrolls the timeline if you clicked < > buttons
  408.     if x >= buttonPlusx and x <= buttonPlusxEnd then
  409.       minus = true
  410.       timelinePosDisplay = timelinePosDisplay - 1
  411.       timelineStart = timelineStart - 1
  412.       if ahstart == 5 then
  413.         ahstart = ahstart - 5
  414.         ah = ah - 5
  415.         break
  416.       end
  417.       ahstart = ahstart - 1
  418.       break
  419.     end
  420.     if x >= buttonMinusx and x <= buttonMinusxEnd then
  421.       plus = true
  422.       timelinePosDisplay = timelinePosDisplay + 1
  423.       timelineStart = timelineStart + 1
  424.       if ahstart == 5 then
  425.         ahstart = ahstart + 5
  426.         ah = ah + 5
  427.         break
  428.       end
  429.       ahstart = ahstart + 1
  430.       break
  431.     end
  432.   end
  433.     if y >= 21 and y <= 25 and settings == true then -- opens settings menu
  434.       if x >= 59 and x <= 70 then
  435.         play = true
  436.         break
  437.       elseif x >= 46 and x <= 57 then
  438.         save = true
  439.         break
  440.       elseif x >= 33 and x <= 44 then
  441.         load = true
  442.         break
  443.       end
  444.     end
  445.     if x >= 59 and x <= 70 and y == 1 then -- closes settings menu
  446.       if settings == true then
  447.         settings = false
  448.         break
  449.       else
  450.         settings = true
  451.         break
  452.       end
  453.     end
  454.     if x >= timelineStartDisplay and x <= timelineEndDisplay and y >= 3 and y <= 22 then -- detects if you clicked in the timeline
  455.       if y % 2 ~= 0 then
  456.         x1 = x
  457.         y1 = y
  458.         addKey()
  459.       else
  460.         timelinePosDisplay = x
  461.         local a = x - timelineStartDisplay
  462.         timelinePos = timelineStart + a
  463.       end
  464.     end
  465.     settings = false
  466.     beat1 = false
  467.     beat2 = false
  468.     beat3 = false
  469.     beat4 = false
  470.     beat5 = false
  471.     beat6 = false
  472.     beat7 = false
  473.     beat8 = false
  474.     beat9 = false
  475.     beat10 = false -- resets things if you clicked nothing
  476.     break
  477.   end
  478. end
  479. while true do -- main loop
  480.   drawBeatsPaint()
  481.   drawBeatsText()
  482.   drawTimelinePaint()
  483.   drawTimelineText()
  484.   drawButtons()
  485.   drawSettingsPaint()
  486.   drawSettingsText()
  487.   clickDetect()
  488. end
Advertisement
Add Comment
Please, Sign In to add comment