Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local c = require('component')
- local term = require('term')
- local ev = require('event')
- local ser = require('serialization')
- local fs = require('filesystem')
- local comp = require('computer')
- local u = require('unicode')
- local len = u.len
- local av = c.isAvailable
- local rep = string.rep
- local uA, rU = comp.addUser, comp.removeUser
- local g = c.gpu
- local color = g.setForeground
- -- /важные настройки/ --
- local owner = 'Durex77' -- игрок, админящий программу
- local relogTime = 30 -- время до автовыхода из меню добавления варпов (в секундах)
- local configPath = '/warp.cfg'
- local nick = ''
- local maxW,maxH = 90,26
- local logTimer = 0
- local colors = { general = 0x00ff45, gray = 0x404040, text = 0xDADADA, white = 0xFFFFFF, red = 0xFF0000, black = 0x000000 }
- local login = 0
- local n = 1
- local advertising
- local positions = {Durex77="azaza"}
- local commen = {}
- local colorsTable = {
- ['&0'] = function() color(0x000000) end,
- ['&1'] = function() color(0x0000AA) end,
- ['&2'] = function() color(0x00AA00) end,
- ['&3'] = function() color(0x00AAAA) end,
- ['&4'] = function() color(0xAA0000) end,
- ['&5'] = function() color(0xAA00AA) end,
- ['&6'] = function() color(0xFFAA00) end,
- ['&7'] = function() color(0xAAAAAA) end,
- ['&8'] = function() color(0x555555) end,
- ['&9'] = function() color(0x5555FF) end,
- ['&a'] = function() color(0x55FF55) end,
- ['&b'] = function() color(0x55FFFF) end,
- ['&c'] = function() color(0xFF5555) end,
- ['&d'] = function() color(0xFF55FF) end,
- ['&e'] = function() color(0xFFFF55) end,
- ['&f'] = function() color(0xFFFFFF) end,
- ['&r'] = function() color(0xFFFFFF) end
- }
- function conf_S()
- local file = io.open(configPath,'w')
- file:write(ser.serialize(positions,false)):flush():close()
- end
- function conf_R()
- local file = io.open(configPath,'r')
- positions = ser.unserialize(file:read(fs.size(configPath)))
- file:close()
- end
- if not fs.exists("/"..configPath) then
- conf_S()
- end
- function drawMenu()
- term.clear()
- g.setResolution(maxW,maxH)
- drawBox(1,1,maxW,maxH,colors.general)
- drawBox(35,24,21,3,colors.general,'Добавить отзыв',4)
- conf_R()
- local i = 0
- for key, val in pairs(positions) do
- i=i+1
- end
- local C=i
- i=0
- local non = -1
- if C>15 then
- non=C-15
- non=math.random(0, non)
- end
- local l = 1
- for key, val in pairs(positions) do
- if non > 0 then
- non = non - 1
- else
- i=i+1
- printFormatText(3,(20-C)/2+i+4,84,val,colors.white)
- l = l + 1
- if l == 16 then
- break
- end
- end
- end
- if i > 0 then
- drawBox(2,(20-C)/2+4,maxW-4,2+i,colors.white)
- end
- end
- function drawMenu2()
- drawBox(1,1,maxW,maxH,colors.general)
- drawBox(27,24,15,3,colors.general,'Добавить',3)
- drawBox(47,24,15,3,colors.general,'Отменить',3)
- setText(33,14,"Введите ваш отзыв в чат!",colors.text)
- drawBox(2,16,maxW-3,3,colors.gray)
- if nick == owner then
- drawBox(27,21,35,3,colors.general,'Админ панель',5)
- end
- end
- function drawMenu3()
- if n == 0 then
- n=1
- end
- term.clear()
- drawBox(1,1,maxW,maxH,colors.general)
- drawBox(35,24,15,3,colors.general,'Закрить',4)
- drawBox(35,17,15,3,colors.red,'Удалить',4)
- drawBox(51,17,10,3,colors.white,'----->',1)
- drawBox(24,17,10,3,colors.white,'<-----',1)
- commen={}
- drawBox(2,13,maxW-3,3,colors.gray)
- conf_R()
- local i = 0
- for key, val in pairs(positions) do
- i=i+1
- commen[i]=key
- end
- if #commen>0 then
- drawBox((90-u.len(commen[n]))/2-3,10,u.len(commen[n])+2,3,colors.text,commen[n],1)
- printFormatText(3,14,84,positions[commen[n]],colors.white)
- end
- end
- function printLogTimer()
- logTime = logTime - 1
- if login ~= 0 then setText(44,3,logTime..'с. ',colors.general) end
- if logTime <= 0 then
- exit()
- end
- end
- function setText(x,y,text,col)
- color(col)
- g.set(x,y,text)
- end
- function drawBox(x,y,width,height,col,txt,align)
- color(col)
- g.fill(x,y,1,height,'│')
- g.fill(x+width-1,y,1,height,'│')
- g.set(x,y,'┌'..rep('─',width-2)..'┐')
- g.set(x,y+height-1,'└'..rep('─',width-2)..'┘')
- if txt then
- g.set(x+align,y+1,txt)
- end
- end
- function clearArea(x,y,width,height)
- g.fill(x,y,width,height,' ')
- end
- function printFormatText(x,y,width,text,defColor,clearHeight)
- color(defColor)
- clearArea(x,y,width,clearHeight or 1)
- local crit = '&'
- local corr = 0
- local totalLen = 0
- for i = 1, u.len(text) do
- local letter = u.sub(text,i,i)
- if letter == crit then
- pcall(colorsTable[u.sub(text,i,i+1)])
- corr = corr + 2
- skip = true
- else
- if not skip then
- totalLen = i-corr-1
- g.set(totalLen+x,y,letter)
- end
- skip = false
- end
- if totalLen == width-1 then
- break
- end
- end
- end
- function clipboarder(_,_,chatNick,data)
- if login==1 and chatNick == nick then
- advertising = data:lower():gsub('\\',' ')
- printFormatText(3,17,84,advertising,colors.white)
- end
- end
- drawMenu()
- function exit()
- login = 0
- local users={comp.users()}
- for i=1, #users do
- comp.removeUser(users[i])
- end
- ev.ignore('chat_message',clipboarder)
- ev.cancel(logTimer)
- drawMenu()
- end
- function addComent()
- conf_R()
- positions[nick]=advertising
- conf_S()
- exit()
- end
- while true do
- local e,_,w,h,_,name = ev.pull(1, "touch")
- if e == "touch" then
- logTime=relogTime
- nick=name
- if login==1 then
- if w>=27 and w<=42 and h>=24 and h<=27 then
- addComent()
- elseif w>=47 and w<=62 and h>=24 and h<=27 then
- exit()
- elseif w>=27 and w<=62 and h>=21 and h<=24 and nick==owner then
- login = 2
- drawMenu3()
- end
- elseif login==2 then
- if w>=35 and w<=50 and h>=24 and h<=27 then
- exit()
- elseif w>=24 and w<=34 and h>=17 and h<=20 then
- if n>1 then
- n=n-1
- drawMenu3()
- end
- elseif w>=51 and w<=61 and h>=17 and h<=
- if
- n
- drawMenu3
- end
- elseif w>=35 and w<=50 and h>=17 and h<=
- positions[commen[n]
- conf_S
- n=n
- drawMenu3(
- end
- else
- if w>=35 and w<=56 and h>=24 and h<=27
- uA
- logTimer = ev.timer(1,printLogTimer,math
- login =
- ev.listen('chat_message',
- term.clear(
- drawMenu2(
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement