Advertisement
Dream_007

Warp

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