Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local term = require("term")
- local event = require("event")
- local unicode=require("unicode")
- local computer = require("computer")
- local g = component.gpu
- local COLOR_CMD = 0xffff00 --Цвет консоли
- local COLOR1 = 0xfff000 --Жёлт.
- local COLOR2 = 0x00ff00 --Зел.
- local label = "&6Какая миникарта лучше?"
- computer.removeUser("krovyaka")
- event.shouldInterrupt = function () return false end
- function StrToTable(str)
- local t,values,st = {},{},str
- while true do
- if string.find(st,":")==nil then break end
- t[string.sub(st,1,string.find(st,":")-1)]=string.sub(st,string.find(st,":")+1,string.find(st,":")+1)
- table.insert(values,tonumber(string.sub(st,string.find(st,":")+1,string.find(st,":")+1)))
- st = string.sub(st,string.find(st,":")+2,string.len(str))
- end
- return t,values
- end
- function TableToStr(t)
- local str=""
- for key, value in pairs(t) do str=str .. key .. ":" .. value end
- return str
- end
- local filer = io.open("/home/votes.lua", "r")
- if filer:read()==nil then
- filer:close()
- local filew = io.open("/home/votes.lua", "w")
- filew:write("t1:1t2:2")
- filew:close()
- else
- filer:close()
- end
- function draw()
- g.setResolution(81,25)
- term.clear()
- g.setForeground(COLOR_CMD)
- g.set(1,1,"||============================================================================================================================================================||")
- g.set(1,25,"||============================================================================================================================================================||")
- g.fill(1,1,2,25,"|")
- g.fill(80,1,2,25,"|")
- g.setForeground(0xffffff)
- Button(15,12,18,3,COLOR1,COLOR2,"JourneyMap")
- Button(49,12,18,3,COLOR1,COLOR2,"VoxelMap")
- if unicode.len(label)>=120 then
- Text(12,5,unicode.sub(label,1,60))
- Text(12,6,unicode.sub(label,61,120))
- Text(12+math.floor((60-unicode.len(unicode.sub(label,121)))/2),7,unicode.sub(label,121))
- elseif unicode.len(label)>=60 then
- Text(12,5,unicode.sub(label,1,60))
- Text(12+math.floor((60-unicode.len(unicode.sub(label,61)))/2),6,unicode.sub(label,61))
- else
- Text(12+math.floor((60-unicode.len(label))/2),6,label)
- end
- end
- function Button(x,y,w,h,col1,col2,text) -- Кнопка
- g.setForeground(col1)
- g.set(x + w/2 - unicode.len(text)/2, y+h/2, text)
- g.setForeground(col2)
- for i = 1, w-2 do
- g.set(x+i,y,"━")
- g.set(x+i,y+h-1,"━")
- end
- for i = 1, h-2 do
- g.set(x,y+i,"┃")
- g.set(x+w-1,y+i,"┃")
- end
- g.set(x,y,"┏")
- g.set(x+w-1,y,"┓")
- g.set(x,y+h-1,"┗")
- g.set(x+w-1,y+h-1,"┛")
- end
- function Text(x,y,text) --Цветной текст
- local n = 1
- for i = 1, unicode.len(text) do
- if unicode.sub(text, i,i) == "&" then
- SetColor(unicode.sub(text, i + 1, i + 1))
- n = n + 2
- elseif unicode.sub(text, i - 1, i - 1) ~= "&" then
- g.set(x+i-n,y, unicode.sub(text, i,i))
- end
- end
- end
- function SetColor(index) --Список цветов
- if (index ~= "r") then back = g.getForeground() end
- if (index == "0") then g.setForeground(0x333333) end
- if (index == "1") then g.setForeground(0x0000ff) end
- if (index == "2") then g.setForeground(0x008000) end
- if (index == "3") then g.setForeground(0x30d5c8) end
- if (index == "4") then g.setForeground(0xff0000) end
- if (index == "5") then g.setForeground(0x8b00ff) end
- if (index == "6") then g.setForeground(0xffa500) end
- if (index == "7") then g.setForeground(0xbbbbbb) end
- if (index == "8") then g.setForeground(0x808080) end
- if (index == "9") then g.setForeground(0x79afe8) end
- if (index == "a") then g.setForeground(0x66ff66) end
- if (index == "b") then g.setForeground(0x00ffff) end
- if (index == "c") then g.setForeground(0xff6347) end
- if (index == "d") then g.setForeground(0xff00ff) end
- if (index == "e") then g.setForeground(0xffff00) end
- if (index == "f") then g.setForeground(0xffffff) end
- if (index == "r") then g.setForeground(back) end
- end
- function lines(votelist)
- local counter1,counter2 = 0,0
- for i=1,#votelist do
- if votelist[i]==1 then counter1=counter1+1 end
- if votelist[i]==2 then counter2=counter2+1 end
- end
- local length = unicode.len(string.rep("█",math.floor((counter1/#votelist)*60)))
- Text(11,18,"&1" .. string.rep("█",math.floor((counter1/#votelist)*60)))
- Text(11+length,18,"&4" .. string.rep("█",60-length))
- Text(12,20,"&f" .. counter1 )
- Text(70,20,"&f" .. counter2 )
- end
- function vote(nick,vo)
- local filer = io.open("/home/votes.lua", "r")
- local votes,_ = StrToTable(filer:read())
- filer:close()
- if votes[nick]==nil then
- Text(12+math.floor((60-unicode.len("&cСпасибо за голос, " .. nick))/2),10,"Спасибо за голос, " .. nick)
- else
- Text(12+math.floor((60-unicode.len("&cВы изменили свой выбор, " .. nick))/2),10,"Вы изменили свой выбор, " .. nick)
- end
- os.sleep(1.3)
- Text(4,10," ")
- votes[nick]=tostring(vo)
- local filew = io.open("/home/votes.lua", "w")
- filew:write(TableToStr(votes))
- filew:flush() filew:close()
- local filer = io.open("/home/votes.lua", "r")
- local _,votelist = StrToTable(filer:read())
- filer:close()
- lines(votelist)
- end
- function Buttons(w,h,nick)
- if w>=15 and w<=32 and h>=12 and h<= 14 then
- vote(nick,"1")
- elseif w>=50 and w<=66 and h>=12 and h<= 14 then
- vote(nick,"2")
- end
- end
- --while true do print(event.pull("touch")) os.sleep() end
- draw()
- while true do
- local e,_,w,h,_,nick = event.pull(1, "touch")
- if e == "touch" then
- Buttons(w,h,nick)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement