Advertisement
Guest User

Untitled

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