ZNZNCOOP

Reactor_ControlV2

Jan 20th, 2015
259
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- ================ INIT ================ --
  2. Rside= 'top'
  3. rc= peripheral.wrap(Rside)
  4. if (rc == nil) then error(Rside,' not found.') end
  5.  
  6. -- ================ ClearScreen ================ --
  7.  
  8. function cs()
  9.    X,Y= term.getSize()
  10.    for y=1,Y do
  11.       for x=1,X do
  12.          paintutils.drawPixel(x,y,32768)
  13.       end
  14.    end
  15.    term.clear()
  16.    term.setCursorPos(1,1)
  17. end
  18. -- ================ Buttons ================ --
  19. Button= {}
  20.  
  21. function Button:new(x,y,nameT,nameF,funcT,funcF)
  22.    Button[#Button+1]= {}
  23.    Button[#Button]['x']= x
  24.    Button[#Button]['y']= y
  25.    Button[#Button]['nameT']= nameT
  26.    Button[#Button]['nameF']= nameF
  27.    Button[#Button]['funcT']= funcT
  28.    Button[#Button]['funcF']= funcF
  29.    Button[#Button]['status']= false
  30. end
  31.  
  32. function Button:nowName(count)
  33.    if (Button[count]['status'] == false) then return Button[count]['nameF'] end
  34.    if (Button[count]['status'] == true) then return Button[count]['nameT'] end
  35. end
  36.  
  37. function Button:update(x,y)
  38.    for i=1,#Button do
  39.       length= Button[i]['x']+#Button:nowName(i)
  40.       if (x > Button[i]['x'] and x < length  and y == Button[i]['y']) then
  41.          DLine= {}
  42.          DLine.COUNT= 1
  43.          if (Button[i]['status'] == false) then
  44.             Button[i]['funcT']()
  45.             Button[i]['status']= true
  46.          else
  47.             Button[i]['funcF']()
  48.             Button[i]['status']= false
  49.          end
  50.       end
  51.    end
  52. end
  53.  
  54. function Button:draw()
  55.    for i=1,#Button do
  56.       term.setCursorPos(Button[i]['x'],Button[i]['y'])
  57.       if (Button[i]['status'] == false) then
  58.          paintutils.drawLine(Button[i]['x'],Button[i]['y'],Button[i]['x']+#Button:nowName(i),Button[i]['y'],8192)
  59.          term.setCursorPos(Button[i]['x'],Button[i]['y'])
  60.          io.write(Button[i]['nameF'])
  61.          paintutils.drawPixel(X,Y,32768)
  62.       else
  63.          paintutils.drawLine(Button[i]['x'],Button[i]['y'],Button[i]['x']+#Button:nowName(i),Button[i]['y'],8192)
  64.          term.setCursorPos(Button[i]['x'],Button[i]['y'])
  65.          io.write(Button[i]['nameT'])
  66.          paintutils.drawPixel(X,Y,32768)
  67.       end
  68.    end
  69. end
  70.  
  71. -- ================ DLine ================ --
  72.  
  73. DLine= {}
  74. DLine.COUNT= 1
  75. DLine.maxLevel= 0
  76. DLine.k1= 0
  77. DLine.Color= ''
  78. function config(maxLevel,color)
  79.    X,Y= term.getSize()
  80.    k1= math.ceil(maxLevel/(Y-1))
  81.    DLine.maxLevel= maxLevel
  82.    DLine.k1= k1
  83.    DLine.Color= color
  84. end
  85.  
  86. function add(nowlevel)
  87.    X,Y= term.getSize()
  88.    if (DLine.COUNT < X) then DLine.COUNT= DLine.COUNT+1 end
  89.    if DLine.COUNT >= X then table.remove(DLine,1) s() end
  90.    DLine[#DLine+1]= {}
  91.    DLine[#DLine]['x']= DLine.COUNT
  92.    DLine[#DLine]['y']= (Y+1)-math.ceil(nowlevel/DLine.k1)+1
  93.    if (DLine[#DLine]['y'] > Y) then DLine[#DLine]['y']= Y end
  94. end
  95.  
  96. function s(  )
  97.     for i=1,#DLine do
  98.        DLine[i]['x']= DLine[i]['x']-1
  99.     end
  100. end
  101. -- ================ GUI ================ --
  102. function draw()
  103.    for i=1,#DLine do
  104.       paintutils.drawPixel(DLine[i]['x'],DLine[i]['y'],16)
  105.    end
  106. end
  107.  
  108. function heats()
  109.    heat= rc.getHeat()
  110.    config(10000,16)
  111.    draw()
  112.    add(heat)
  113. end
  114.  
  115. function EUOutputs()
  116.    output= rc.getEUOutput()
  117.    config(2048,2048)
  118.    draw()
  119.    add(output)
  120. end
  121.  
  122. function setHeat()
  123.    STATUS= 'heat'
  124. end
  125.  
  126. function setEU()
  127.    STATUS= 'EUOutput'
  128. end
  129.  
  130. function on()
  131.    rs.setOutput(Rside,true)
  132. end
  133.  
  134. function off()
  135.    rs.setOutput(Rside,false)      
  136. end
  137.  
  138. -- ================ MAIN ================ --
  139. config(10000)
  140. Button:new(1,1,'Heat','Heat',setHeat,setHeat)
  141. Button:new(15,1,'EUOutput','UOutput',setEU,setEU)
  142. Button:new(25,1,'Stop','Start',on,off)
  143. STATUS= 'heat'
  144. os.startTimer(1)
  145. while true do
  146.    event,a,b,c= os.pullEvent()
  147.       if (event == 'timer') then
  148.       cs()
  149.       if (STATUS == 'heat') then
  150.          heats()
  151.       end
  152.       if (STATUS == 'EUOutput') then
  153.          EUOutputs()
  154.       end
  155.       Button:draw()
  156.       draw()
  157.       os.startTimer(1)
  158.    end
  159.    if (event == 'mouse_click') then Button:update(b,c) end
  160. end
RAW Paste Data