Advertisement
TwiXon4ik

Untitled

Oct 15th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.05 KB | None | 0 0
  1. -- by Dream007+
  2.  
  3. local c = require('component')
  4. local term = require('term')
  5. local ev = require('event')
  6. local ser = require('serialization')
  7. local fs = require('filesystem')
  8. local comp = require('computer')
  9. local u = require('unicode')
  10.  
  11. local len = u.len
  12. local av = c.isAvailable
  13. local rep = string.rep
  14. local uA, rU = comp.addUser, comp.removeUser
  15. local g = c.gpu
  16. local color = g.setForeground
  17.  
  18. -- /важные настройки/ --
  19. local owner = 'Dream007' -- игрок, админящий программу
  20. local pidor = 'TwiXon4ik' -- Когда я начинал это писать, только Бог и я понимали, что я делаю
  21. local gay = 'Desu65' -- Сейчас остался только Бог
  22. local relogTime = 30 -- время до автовыхода из меню добавления варпов (в секундах)
  23.  
  24. local configPath = '/warp.cfg'
  25. local nick = ''
  26. local maxW,maxH = 90,26
  27. local logTimer = 0
  28. local colors = { general = 0xFf0000, gray = 0x00BBFF, text = 0x00BBFF, white = 0x00BBFF, red = 0xFF0000, black = 0x000000 }
  29. local login = 0
  30. local n = 1
  31.  
  32.  
  33.  
  34. local advertising
  35. local positions = {Dream007="&6Test"}
  36. local commen = {}
  37. local colorsTable = {
  38. ['&0'] = function() color(0x000000) end,
  39. ['&1'] = function() color(0x0000AA) end,
  40. ['&2'] = function() color(0x00AA00) end,
  41. ['&3'] = function() color(0x00AAAA) end,
  42. ['&4'] = function() color(0xAA0000) end,
  43. ['&5'] = function() color(0xAA00AA) end,
  44. ['&6'] = function() color(0xFFAA00) end,
  45. ['&7'] = function() color(0xAAAAAA) end,
  46. ['&8'] = function() color(0x555555) end,
  47. ['&9'] = function() color(0x5555FF) end,
  48. ['&a'] = function() color(0x55FF55) end,
  49. ['&b'] = function() color(0x55FFFF) end,
  50. ['&c'] = function() color(0xFF5555) end,
  51. ['&d'] = function() color(0xFF55FF) end,
  52. ['&e'] = function() color(0xFFFF55) end,
  53. ['&f'] = function() color(0xFFFFFF) end,
  54. ['&r'] = function() color(0xFFFFFF) end
  55. }
  56.  
  57.  
  58. function conf_S()
  59. local file = io.open(configPath,'w')
  60. file:write(ser.serialize(positions,false)):flush():close()
  61. end
  62.  
  63. function conf_R()
  64. local file = io.open(configPath,'r')
  65. positions = ser.unserialize(file:read(fs.size(configPath)))
  66. file:close()
  67. end
  68.  
  69. if not fs.exists("/"..configPath) then
  70. conf_S()
  71. end
  72.  
  73. function drawMenu()
  74. term.clear()
  75. g.setResolution(maxW,maxH)
  76. drawBox(1,1,maxW,maxH,colors.general)
  77. drawBox(35,24,21,3,colors.general,'Добавить отзыв',4)
  78.  
  79. conf_R()
  80. local i = 0
  81.  
  82. for key, val in pairs(positions) do
  83. i=i+1
  84. end
  85. local C=i
  86. i=0
  87. local non = -1
  88. if C>15 then
  89. non=C-15
  90. non=math.random(0, non)
  91. end
  92. local l = 1
  93. for key, val in pairs(positions) do
  94. if non > 0 then
  95. non = non - 1
  96. else
  97. i=i+1
  98. printFormatText(3,(20-C)/2+i+4,84,val,colors.white)
  99. l = l + 1
  100. if l == 16 then
  101. break
  102. end
  103. end
  104. end
  105. if i > 0 then
  106. drawBox(2,(20-C)/2+4,maxW-4,2+i,colors.white)
  107. end
  108. end
  109.  
  110. function drawMenu2()
  111. drawBox(1,1,maxW,maxH,colors.general)
  112. drawBox(27,24,15,3,colors.general,'Добавить',3)
  113. drawBox(47,24,15,3,colors.general,'Отменить',3)
  114. setText(39,2,'Инструкция',colors.text)
  115. setText(27,4,'Нажмите ПКМ на кнопку [Добавить отзыв]',colors.text)
  116. setText(27,5,'После напишите в локальный чат свой отзыв',colors.text)
  117. setText(27,6,'Нажмите ПКМ на кнопку [Подтверить]',colors.text)
  118. setText(27,7,'Спасибо что оставили отзыв.Приятных покупок',colors.text)
  119. drawBox(2,16,maxW-3,3,colors.gray)
  120. if nick == owner or nick == pidor or nick == gay then
  121. drawBox(27,21,35,3,colors.general,'Админ панель',5)
  122. end
  123. end
  124.  
  125. function drawMenu3()
  126. if n == 0 then
  127. n=1
  128. end
  129. term.clear()
  130. drawBox(1,1,maxW,maxH,colors.general)
  131. drawBox(35,24,15,3,colors.general,'Закрыть',4)
  132. drawBox(35,17,15,3,colors.red,'Удалить',4)
  133. drawBox(51,17,10,3,colors.white,'----->',1)
  134. drawBox(24,17,10,3,colors.white,'<-----',1)
  135.  
  136. commen={}
  137. drawBox(2,13,maxW-3,3,colors.gray)
  138. conf_R()
  139. local i = 0
  140.  
  141. for key, val in pairs(positions) do
  142. i=i+1
  143. commen[i]=key
  144. end
  145. if #commen>0 then
  146. drawBox((90-u.len(commen[n]))/2-3,10,u.len(commen[n])+2,3,colors.text,commen[n],1)
  147. printFormatText(3,14,84,positions[commen[n]],colors.white)
  148. end
  149. end
  150.  
  151. function printLogTimer()
  152. logTime = logTime - 1
  153. if login ~= 0 then setText(44,3,logTime..'с. ',colors.general) end
  154. if logTime <= 0 then
  155. exit()
  156. end
  157. end
  158.  
  159.  
  160. function setText(x,y,text,col)
  161. color(col)
  162. g.set(x,y,text)
  163. end
  164.  
  165. function drawBox(x,y,width,height,col,txt,align)
  166. color(col)
  167. g.fill(x,y,1,height,'│')
  168. g.fill(x+width-1,y,1,height,'│')
  169. g.set(x,y,'┌'..rep('─',width-2)..'┐')
  170. g.set(x,y+height-1,'└'..rep('─',width-2)..'┘')
  171. if txt then
  172. g.set(x+align,y+1,txt)
  173. end
  174. end
  175.  
  176. function clearArea(x,y,width,height)
  177. g.fill(x,y,width,height,' ')
  178. end
  179.  
  180. function printFormatText(x,y,width,text,defColor,clearHeight)
  181. color(defColor)
  182. clearArea(x,y,width,clearHeight or 1)
  183. local crit = '&'
  184. local corr = 0
  185. local totalLen = 0
  186. for i = 1, u.len(text) do
  187. local letter = u.sub(text,i,i)
  188. if letter == crit then
  189. pcall(colorsTable[u.sub(text,i,i+1)])
  190. corr = corr + 2
  191. skip = true
  192. else
  193. if not skip then
  194. totalLen = i-corr-1
  195. g.set(totalLen+x,y,letter)
  196. end
  197. skip = false
  198. end
  199. if totalLen == width-1 then
  200. break
  201. end
  202. end
  203. end
  204.  
  205. function clipboarder(_,_,chatNick,data)
  206. if login==1 and chatNick == nick then
  207. advertising = data:lower():gsub('\\',' ')
  208. printFormatText(3,17,84,advertising,colors.white)
  209. end
  210. end
  211.  
  212. drawMenu()
  213.  
  214. function exit()
  215. login = 0
  216. local users={comp.users()}
  217. for i=1, #users do
  218. comp.removeUser(users[i])
  219. end
  220. ev.ignore('chat_message',clipboarder)
  221. ev.cancel(logTimer)
  222. drawMenu()
  223. end
  224.  
  225. function addComent()
  226. conf_R()
  227. positions[nick]="" .. nick .. ": " .. advertising
  228. conf_S()
  229. exit()
  230. end
  231.  
  232. while true do
  233. local e,_,w,h,_,name = ev.pull(1, "touch")
  234. if e == "touch" then
  235. logTime=relogTime
  236. nick=name
  237.  
  238. if login==1 then
  239. if w>=27 and w<=42 and h>=24 and h<=27 then
  240. addComent()
  241. elseif w>=47 and w<=62 and h>=24 and h<=27 then
  242. exit()
  243. elseif w>=27 and w<=62 and h>=21 and h<=24 and nick==owner or nick==pidor or nick==gay then
  244. login = 2
  245. drawMenu3()
  246. end
  247. elseif login==2 then
  248. if w>=35 and w<=50 and h>=24 and h<=27 then
  249. exit()
  250. elseif w>=24 and w<=34 and h>=17 and h<=20 then
  251. if n>1 then
  252. n=n-1
  253. drawMenu3()
  254. end
  255. elseif w>=51 and w<=61 and h>=17 and h<=20 then
  256. if n<#commen then
  257. n=n+1
  258. drawMenu3()
  259. end
  260. elseif w>=35 and w<=50 and h>=17 and h<=20 then
  261. positions[commen[n]]=nil
  262. conf_S()
  263. n=n-1
  264. drawMenu3()
  265. end
  266. else
  267. if w>=35 and w<=56 and h>=24 and h<=27 then
  268. uA(nick)
  269. logTimer = ev.timer(1,printLogTimer,math.huge)
  270. login = 1
  271. ev.listen('chat_message',clipboarder)
  272. term.clear()
  273. drawMenu2()
  274. end
  275. end
  276. end
  277. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement