Advertisement
ZNZNCOOP

Reactor_ControlV1

Jan 20th, 2015
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.07 KB | None | 0 0
  1. Rside= 'top'
  2. Mside= ''
  3. rc= peripheral.wrap(Rside)
  4. m = peripheral.wrap(Mside)
  5. if (m ~= nil) then term.redirect(m) end
  6. function drawLevel(x,y,nowlevel,maxLevel,name,color)
  7.    X,Y= term.getSize()
  8.    deltaY= Y-(Y-y)
  9.    k1= maxLevel/deltaY
  10.    k2= math.ceil(nowlevel/k1)
  11.    medium= math.ceil(k2/2)
  12.    if (name ~= nil) then length= #name+1 end
  13.    for i=1,k2 do
  14.       paintutils.drawLine(x,y-i,x+length,y-i,color)
  15.    end
  16.    term.setCursorPos(x+1,y-medium)
  17.    term.setTextColor(16384)
  18.    io.write(name)
  19.    term.setTextColor(1)
  20.    paintutils.drawPixel(X,Y,32768)
  21.    term.setCursorPos(x,y-deltaY+1)
  22.    io.write(nowlevel..'/'..maxLevel)
  23. end
  24. function cs()
  25.    X,Y= term.getSize()
  26.    for y=1,Y do
  27.       for x=1,X do
  28.          paintutils.drawPixel(x,y,32768)
  29.       end
  30.    end
  31.    term.clear()
  32.    term.setCursorPos(1,1)
  33. end
  34. X,Y= term.getSize()
  35. Button= {}
  36.  
  37. function Button:new(x,y,nameT,nameF,funcT,funcF)
  38.    Button[#Button+1]= {}
  39.    Button[#Button]['x']= x
  40.    Button[#Button]['y']= y
  41.    Button[#Button]['nameT']= nameT
  42.    Button[#Button]['nameF']= nameF
  43.    Button[#Button]['funcT']= funcT
  44.    Button[#Button]['funcF']= funcF
  45.    Button[#Button]['status']= false
  46.     Button[#Button]['color']= 8192
  47. end
  48.  
  49. function Button:nowName(count)
  50.    if (Button[count]['status'] == false) then return Button[count]['nameF'] end
  51.    if (Button[count]['status'] == true) then return Button[count]['nameT'] end
  52. end
  53.  
  54. function Button:update(x,y)
  55.    for i=1,#Button do
  56.       length= Button[i]['x']+#Button:nowName(i)
  57.       if (x > Button[i]['x'] and x < length  and y == Button[i]['y']) then
  58.          if (Button[i]['status'] == false) then
  59.             Button[i]['funcT']()
  60.             Button[i]['status']= true
  61.             Button[#Button]['color']= 16384
  62.          else
  63.             Button[i]['funcF']()
  64.             Button[i]['status']= false
  65.             Button[#Button]['color']=  8192
  66.          end
  67.       end
  68.    end
  69. end
  70.  
  71. function Button:draw()
  72.    for i=1,#Button do
  73.       term.setCursorPos(Button[i]['x'],Button[i]['y'])
  74.       if (Button[i]['status'] == false) then
  75.          paintutils.drawLine(Button[i]['x'],Button[i]['y'],Button[i]['x']+#Button:nowName(i),Button[i]['y'],Button[i]['color'])
  76.          term.setCursorPos(Button[i]['x'],Button[i]['y'])
  77.          io.write(Button[i]['nameF'])
  78.          paintutils.drawPixel(X,Y,32768)
  79.       else
  80.          paintutils.drawLine(Button[i]['x'],Button[i]['y'],Button[i]['x']+#Button:nowName(i),Button[i]['y'],Button[i]['color'])
  81.          term.setCursorPos(Button[i]['x'],Button[i]['y'])
  82.          io.write(Button[i]['nameT'])
  83.          paintutils.drawPixel(X,Y,32768)
  84.       end
  85.    end
  86. end
  87. function off() rs.setOutput(Rside,false) end
  88. function on() rs.setOutput(Rside,true) end
  89. c= 0
  90. heat= 0
  91. Output= 0
  92. Button:new(12,10,'Stop','Start',on,off)
  93. os.startTimer(1)
  94. while true do
  95.    Button:draw()
  96.    drawLevel(1,19,rc.getHeat(),rc.getMaxHeat(),'Heat',16)
  97.    drawLevel(21,19,rc.getEUOutput(),2048,'Output')
  98.    event,a,b,c= os.pullEvent()
  99.    if (event == 'mouse_click') then Button:update(b,c) end  
  100.    if (event == 'timer') then os.startTimer(1) end
  101.    cs()
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement