Advertisement
BIOSFERA

Untitled

Oct 21st, 2017
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. local component = require('component')
  2. local gpu = component.gpu
  3. local event = require('event')
  4. local term = require('term')
  5.  
  6. -------------
  7. local Admin = 'Ren' --Ник администратора. То бишь того, кто может заносить в чс нажатием на ползунок
  8. local side = 3 --сторона, из которой будет излучаться редстоун сигнал
  9. -------------
  10.  
  11. -----------КОНСТАНТЫ-----------
  12. local all = 2
  13. local name1='HISTORY '
  14. local name2='BLACK LIST'
  15. local inactiveC={bg=0x505050, fg=0xffffff} --цвета действительны для монитора 2 уровня
  16. local activeC = {bg=0xc0c0c0, fg=0x000000}
  17. local pimp = 0x5f5eff --цвет пимпочки переключателя
  18. local w = 32 --разрешение действительно для монитора (2 блока в ширину, 3 в высоту)
  19. local h = 25 --если вы хотите поменять ширину монитора, то разрешение придётся подыскивать самостоятельно
  20. local using = 1
  21.  
  22. -------------------------------
  23.  
  24. visited={}
  25. lazy={}
  26. count=0
  27.  
  28. function drawIt(all,active,...)
  29. z={}
  30. for k,name in ipairs{...} do
  31. z[k]=name
  32. end
  33. size = size or w/all
  34. gpu.setBackground(activeC.bg)
  35. gpu.setForeground(activeC.fg)
  36. term.clear()
  37. gpu.set((active-1)*size+1+(size-string.len(z[active]))/2,2,z[active])
  38. gpu.setBackground(inactiveC.bg)
  39. gpu.setForeground(inactiveC.fg)
  40. for k=1,all do
  41. if k~=active then
  42. gpu.fill((k-1)*size+1,1,size,3,' ')
  43. gpu.set((k-1)*size+1+(size-string.len(z[k]))/2,2,z[k])
  44. end
  45. end
  46. using = active
  47. if using == 1 then
  48. lastVisited()
  49. else
  50. tobl()
  51. end
  52. end
  53.  
  54. function lastVisited(nick)
  55. gpu.setBackground(activeC.bg)
  56. gpu.setForeground(activeC.fg)
  57. if nick and nick~=visited[count<7 and count or 7] then
  58. count=count+1
  59. if count>7 then
  60. table.remove(visited,1)
  61. end
  62. table.insert(visited,nick)
  63. end
  64. if using == 1 then
  65. for k=1, #visited do
  66. gpu.set(2,5+(k-1)*3,visited[k])
  67. switcher(k,1==bl[visited[k]])
  68. end
  69. end
  70. gpu.set(2,25,'Всего посетило: '..count)
  71. end
  72.  
  73. function switcher(num,pos)
  74. gpu.setBackground(inactiveC.bg)
  75. gpu.setForeground(inactiveC.fg)
  76. gpu.fill(23,5+(num-1)*3,7,1,' ')
  77. if pos then
  78. gpu.set(25,5+(num-1)*3,'IN')
  79. gpu.setBackground(pimp)
  80. gpu.fill(28,5+(num-1)*3,2,1,' ')
  81. else
  82. gpu.set(26,5+(num-1)*3,'OUT')
  83. gpu.setBackground(pimp)
  84. gpu.fill(23,5+(num-1)*3,2,1,' ')
  85. end
  86. gpu.setBackground(activeC.bg)
  87. gpu.setForeground(activeC.fg)
  88. end
  89.  
  90. function touched(x,y)
  91. if y<4 then
  92. local touse = math.ceil(x/size)
  93. if touse ~= using then
  94. drawIt(all,touse,name1,name2)
  95. end
  96. elseif x<30 and x>=23 and (y-2)%3==0 and (y-2)/3<=count and nameT == Admin and using == 1 then
  97. local fl = tobl(visited[(y-2)/3])
  98. switcher((y-2)/3,fl)
  99. elseif x<30 and x>=23 and (y-2)%3==0 and (y-2)/3 <= #lazy and nameT == Admin and using == 2 then
  100. local fl = tobl(lazy[(y-2)/3])
  101. end
  102. end
  103.  
  104.  
  105. function tobl(name)
  106. gpu.setBackground(activeC.bg)
  107. gpu.setForeground(activeC.fg)
  108. local r
  109. if bl==nil then
  110. bl={}
  111. f=io.open('bl.txt')
  112. for name in f:lines() do
  113. bl[name]=1
  114. table.insert(lazy,name)
  115. end
  116. f:close()
  117. end
  118. if name then
  119. if bl[name]==1 then
  120. bl[name]=nil
  121. for k,n in ipairs(lazy) do
  122. if n==name then table.remove(lazy,k) end
  123. end
  124. r = false
  125. else
  126. bl[name]=1
  127. table.insert(lazy,name)
  128. r = true
  129. end
  130. ::label::
  131. f=io.open('bl.txt','w')
  132. for name,_ in pairs(bl) do
  133. if f~=nil then
  134. f:write(name,'\n')
  135. else goto label end
  136. end
  137. if f~=nil then
  138. f:flush()
  139. else goto label end
  140. end
  141. if using == 2 then
  142. gpu.fill(1,4,32,20,' ')
  143. for k=1,#lazy do
  144. gpu.set(2,5+(k-1)*3,lazy[k])
  145. switcher(k,true)
  146. end
  147. end
  148. return r
  149.  
  150. end
  151.  
  152. ----------main-----------
  153. print('Коснитесь экрана, который будет использоваться в качестве монитора')
  154. _,address=event.pull('touch')
  155. component.setPrimary('screen',address)
  156. gpu.setResolution(w,h)
  157. drawIt(all,using,name1,name2)
  158. tobl()
  159. while true do
  160. what,_,x,y,nameW,nameT=event.pull()
  161. if what == 'walk' then
  162. lastVisited(nameW)
  163. if bl[nameW]==nil then
  164. component.redstone.setOutput(side,15)
  165. os.sleep(2)
  166. component.redstone.setOutput(side,0)
  167. end
  168. elseif what == 'touch' then touched(x,y) end
  169. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement