Advertisement
MeXaN1cK

Panel v.2

Jun 3rd, 2016
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.37 KB | None | 0 0
  1. local event = require('event')
  2. local term = require('term')
  3. local c = require('component')
  4. local gpu = c.gpu
  5. local serialization = require('serialization')
  6. local unicode=require('unicode')
  7. local m = c.tunnel
  8. local shell=require('shell')
  9. rz=0
  10. page=1
  11. local logFile = 'logs.txt'
  12. fls=io.open(logFile,'w') fls:write('{}') fls:close()
  13. ------------{settings}-----------
  14. local exitWord ='Выход'
  15. local refreshWord='Обн.Кр.'
  16. color ={back=0x000000 ,button=123123 , ex=0xFF0000, err=0xFF0000,fore=0xFFFFFF,refresh=0xFFA500,tabl=0x898989}
  17. ----------------------------------
  18. oldFore=gpu.getForeground() oldBack=gpu.getBackground()
  19. A,B=gpu.getResolution() gpu.setBackground(color.back) amountButtons={}
  20. k=B
  21. k1=1
  22. local x1,y1,w1,h1=A-15,1,1,3 -- |>|
  23. local x2,y2,w2,h2=A-20,1,1,3 -- |<|
  24. local function saveTbl(tbl, fl) file = io.open(fl, 'w') file:write(serialization.serialize(tbl)) file:close() end
  25. local function loadTbl(fl) file = io.open(fl, 'r') if not file then file = io.open(fl, 'w') file:write('{}') return {} else return serialization.unserialize(file:read('*a')) end file:close() end
  26. function clr() gpu.setBackground(color.back) gpu.setForeground(color.fore) term.clear() end
  27. --buttons=loadTbl('bcr.txt')
  28. function aut()
  29. gpu.setBackground(color.tabl)
  30. gpu.setForeground(0xFFFF00)
  31. gpu.fill(1,1,A,1,' ')
  32. gpu.set(40,1,'Авторы [MeXaN1K] & [vah|PandaDoddo72Rus]')
  33. gpu.setForeground(color.fore)
  34. gpu.setBackground(color.back)
  35. gpu.setBackground(color.tabl)
  36. gpu.set(A-8,1,'Page: '..page)
  37. gpu.set(x1,y1,'|>|')
  38. gpu.set(x2,y2,'|<|')
  39. gpu.setBackground(color.back)
  40. end
  41.  
  42. function rbst()
  43. aut()
  44. gpu.fill(A-31,2,1,B,'|')
  45. gpu.setBackground(color.tabl)
  46. gpu.setForeground(0xFFFF00)
  47. gpu.fill(A-30,B,30+1,1,' ')
  48. gpu.set(A-24,B,'[Robot]: ')
  49. if rz == 0 then gpu.setForeground(0x00FF00) gpu.set(A-15,B,'Ready!')
  50. else gpu.setForeground(0xFF0000) gpu.set(A-15,B,' Busy!') end
  51. gpu.setBackground(color.back)
  52. gpu.setForeground(color.fore)
  53. end
  54.  
  55. function addLog(mess)
  56. flg=loadTbl(logFile)
  57. flg[#flg+1]=mess
  58. saveTbl(flg,logFile)
  59. end
  60.  
  61. function getxy() key,_,p1,p2,_,message=event.pull() end
  62.  
  63. function wait()
  64. aut()
  65. rz=1
  66. rbst()
  67. me=true
  68. chi=2
  69. buttonDraw()
  70. gpu.setBackground(color.tabl) gpu.setForeground(color.fore)
  71. gpu.fill(1,2,55,B,' ')
  72. gpu.fill(55,1,1,B,'|')
  73. gpu.set(1,chi,'[log]:')
  74. while me do
  75. lp=messCatch()
  76. if lp=='exit' then clr() me=false end
  77. if lp~=nil then
  78. chi=chi+1
  79. gpu.set(1,chi,' > '..lp) end
  80. if lp == 'finish' then
  81. os.sleep(1.5)
  82. rz=0
  83. me=false
  84. end
  85. end
  86. clr() rbst() buttonDraw()
  87. end
  88.  
  89. function buttonDraw()
  90. clr()
  91. aut()
  92. buttons=loadTbl('bcr.txt')
  93. term.clear()
  94. rbst()
  95. posi=1
  96. for i=k1,k-2 do
  97. posi=posi+1
  98. gpu.setBackground(color.back)
  99. if buttons[i]~=nil then
  100. if buttons[i]==exitWord then gpu.setBackground(color.ex) elseif buttons[i]==refreshWord then gpu.setBackground(color.refresh) else gpu.setBackground(color.button) end
  101. if buttons[i] ~=nil then gpu.fill(A-30,posi,A-(A-30)+1,1,' ') gpu.set(A-30,posi,buttons[i]) end
  102. end
  103. end
  104. gpu.setBackground(color.back)
  105. end
  106.  
  107. function messCatch()
  108. key,_,p1,p2,_,message=event.pull()
  109. if key=='modem_message' then
  110. addLog(message)
  111. return message
  112. elseif key=='touch' then
  113. if p1>55 then buttonDraw() return 'exit' end
  114. end
  115. end
  116.  
  117. function motionCatch()
  118. aut()
  119. a,b=nil,nil
  120. key,_,p1,p2,_,message=event.pull()
  121. rbst()
  122. if key=='modem_message' then
  123. addLog(message)
  124. a1=string.sub(message,1,3)
  125. b1=string.sub(message,4)
  126. if message=='start' then
  127. rz=1
  128. wait()
  129. elseif message=='finish' then
  130. rz=0
  131. buttonDraw()
  132. elseif a1=='add' then
  133. buti=loadTbl('bcr.txt')
  134. buti[#buti+1]=b1
  135. saveTbl(buti,'bcr.txt')
  136. clr() rbst() buttonDraw()
  137. elseif a1=='del' then
  138. buti=loadTbl('bcr.txt')
  139. b1=tostring(b1)
  140. buti2={}
  141. for i=1,#buti do
  142. if buti[i]~=b1 then buti2[#buti2+1]=buti[i] end
  143. end
  144. saveTbl(buti2,'bcr.txt')
  145. end
  146. clr() rbst() buttonDraw()
  147. elseif key=='touch' then
  148. if p1 > x1-1 and p1 < x1+w1+1 and p2 > y1-1 and p2 < h1+y1 then
  149. buttons=loadTbl('bcr.txt')
  150. mp=math.ceil(#buttons/(B-2))
  151. page=page+1
  152. if mp<page then page=mp
  153. else
  154. k=k+B
  155. k1=k1+(B-2)
  156. end
  157. clr() rbst() buttonDraw()
  158. elseif p1 > x2-1 and p1 < x2+w2+1 and p2 > y2-1 and p2 < h2+y2 then
  159. buttons=loadTbl('bcr.txt')
  160. k=k-B
  161. k1=k1-(B-2)
  162. if k1<1 then k1=1 end
  163. if k<B then k=B end
  164. page=page-1
  165. if page<1 then page=1 end
  166. clr() rbst() buttonDraw()
  167. elseif p1>A-30 and p2<B-1 and p2>1 then
  168. gpu.setBackground(color.back)
  169. if p2==B-1 then
  170. b=buttons[(p2-1)*page]
  171. else
  172. b=buttons[(p2-1)*page]
  173. end
  174. if b==exitWord then gpu.setBackground(oldBack) gpu.setForeground(oldFore) term.clear() os.exit()
  175. elseif b==refreshWord then clr() rbst() buttonDraw() else
  176. term.setCursor(10,5)
  177. io.write("Введите количество: ")
  178. a=io.read() a=tonumber(a) if a > 64 then a=64 term.setCursor(10,6) gpu.setForeground(color.err) io.write("Недопустимое число! [Больше 64:измененно на 64]") os.sleep(3)
  179. elseif a==0 then gpu.setForeground(color.err) io.write("Недопустимое число! [Равно нулю]") os.sleep(3)
  180. elseif a<0 then gpu.setForeground(color.err) io.write("Недопустимое число! [Отрицательное число]") os.sleep(3) end
  181. gpu.setForeground(color.fore)
  182. if b~=nil then
  183. a=tostring(a)
  184. a=string.gsub(a,'\n','')
  185. a=tonumber(a)
  186. if a<10 then mes="0"..a..b else mes=a..b end
  187. if a~=0 and a>0 then m.send(mes) end
  188. end
  189. end
  190. end
  191.  end
  192.  rbst()
  193.  return message
  194.  end
  195. getxy()
  196. buttonDraw()
  197. while true do
  198. motionCatch()
  199. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement