Advertisement
TwiXon4ik

Система отзыва на варп

Oct 11th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.64 KB | None | 0 0
  1. -- by Dream007+ and TwiXon4ik
  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 = {Durex77="azaza"}
  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(33,14,"Введите ваш отзыв в чат!",colors.text)
  115.         drawBox(2,16,maxW-3,3,colors.gray)
  116.         if nick == owner or nick == pidor then
  117.             drawBox(27,21,35,3,colors.general,'Админ панель',5)
  118.         end
  119.     end
  120.  
  121.     function drawMenu3()
  122.         if n == 0 then
  123.             n=1
  124.         end
  125.         term.clear()
  126.         drawBox(1,1,maxW,maxH,colors.general)
  127.         drawBox(35,24,15,3,colors.general,'Закрить',4)
  128.         drawBox(35,17,15,3,colors.red,'Удалить',4)
  129.         drawBox(51,17,10,3,colors.white,'----->',1)
  130.         drawBox(24,17,10,3,colors.white,'<-----',1)
  131.  
  132.         commen={}
  133.         drawBox(2,13,maxW-3,3,colors.gray)
  134.         conf_R()
  135.         local i = 0
  136.  
  137.         for key, val in pairs(positions) do
  138.             i=i+1
  139.             commen[i]=key
  140.         end
  141.         if #commen>0 then
  142.             drawBox((90-u.len(commen[n]))/2-3,10,u.len(commen[n])+2,3,colors.text,commen[n],1)
  143.             printFormatText(3,14,84,positions[commen[n]],colors.white)
  144.         end
  145.     end
  146.  
  147.     function printLogTimer()
  148.         logTime = logTime - 1
  149.         if login ~= 0 then setText(44,3,logTime..'с. ',colors.general) end
  150.         if logTime <= 0 then
  151.             exit()
  152.         end
  153.     end
  154.  
  155.  
  156.     function setText(x,y,text,col)
  157.         color(col)
  158.         g.set(x,y,text)
  159.     end
  160.  
  161.     function drawBox(x,y,width,height,col,txt,align)
  162.         color(col)
  163.         g.fill(x,y,1,height,'│')
  164.         g.fill(x+width-1,y,1,height,'│')
  165.         g.set(x,y,'┌'..rep('─',width-2)..'┐')
  166.         g.set(x,y+height-1,'└'..rep('─',width-2)..'┘')
  167.         if txt then
  168.             g.set(x+align,y+1,txt)
  169.         end
  170.     end
  171.  
  172.     function clearArea(x,y,width,height)
  173.         g.fill(x,y,width,height,' ')
  174.     end
  175.  
  176.     function printFormatText(x,y,width,text,defColor,clearHeight)
  177.         color(defColor)
  178.         clearArea(x,y,width,clearHeight or 1)
  179.         local crit = '&'
  180.         local corr = 0
  181.         local totalLen = 0
  182.         for i = 1, u.len(text) do
  183.             local letter = u.sub(text,i,i)
  184.             if letter == crit then
  185.                 pcall(colorsTable[u.sub(text,i,i+1)])
  186.                 corr = corr + 2
  187.                 skip = true
  188.             else
  189.                 if not skip then
  190.                     totalLen = i-corr-1
  191.                     g.set(totalLen+x,y,letter)
  192.                 end
  193.                 skip = false
  194.             end
  195.             if totalLen == width-1 then
  196.                 break
  197.             end
  198.         end
  199.     end
  200.  
  201.     function clipboarder(_,_,chatNick,data)
  202.         if login==1 and chatNick == nick then
  203.             advertising = data:lower():gsub('\\',' ')
  204.             printFormatText(3,17,84,advertising,colors.white)
  205.         end
  206.     end
  207.  
  208.     drawMenu()
  209.  
  210.     function exit()
  211.         login = 0
  212.         local users={comp.users()}
  213.         for i=1, #users do
  214.             comp.removeUser(users[i])
  215.         end
  216.         ev.ignore('chat_message',clipboarder)
  217.         ev.cancel(logTimer)
  218.         drawMenu()
  219.     end
  220.  
  221.     function addComent()
  222.         conf_R()
  223.         positions[nick]="" .. nick .. ": " .. advertising
  224.         conf_S()
  225.         exit()
  226.     end
  227.  
  228.     while true do
  229.         local e,_,w,h,_,name = ev.pull(1, "touch")
  230.         if e == "touch" then
  231.             logTime=relogTime
  232.             nick=name
  233.  
  234.             if login==1 then
  235.                 if w>=27 and w<=42 and h>=24 and h<=27 then
  236.                     addComent()
  237.                 elseif w>=47 and w<=62 and h>=24 and h<=27 then
  238.                     exit()
  239.                 elseif w>=27 and w<=62 and h>=21 and h<=24 and nick==owner or nick==pidor or nick==gay then
  240.                     login = 2
  241.                     drawMenu3()
  242.                 end
  243.             elseif login==2 then
  244.                 if w>=35 and w<=50 and h>=24 and h<=27 then
  245.                     exit()
  246.                 elseif w>=24 and w<=34 and h>=17 and h<=20 then
  247.                     if n>1 then
  248.                         n=n-1
  249.                         drawMenu3()
  250.                     end
  251.                 elseif w>=51 and w<=61 and h>=17 and h<=20 then
  252.                     if n<#commen then
  253.                         n=n+1
  254.                         drawMenu3()
  255.                     end
  256.                 elseif w>=35 and w<=50 and h>=17 and h<=20 then
  257.                     positions[commen[n]]=nil
  258.                     conf_S()
  259.                     n=n-1
  260.                     drawMenu3()
  261.                 end
  262.             else
  263.                 if w>=35 and w<=56 and h>=24 and h<=27 then
  264.                     uA(nick)
  265.                     logTimer = ev.timer(1,printLogTimer,math.huge)
  266.                     login = 1
  267.                     ev.listen('chat_message',clipboarder)
  268.                     term.clear()
  269.                     drawMenu2()
  270.                 end
  271.             end
  272.         end
  273.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement