Advertisement
Guest User

123

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