Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Args = {...}
- os.loadAPI("System/API/context")
- os.loadAPI("System/API/image")
- os.loadAPI("System/API/windows")
- ----------------------ПОДКЛЮЧЕНИЕ МОНИТОРА-----------------------
- local function findPeripheral(whatToFind)
- local PeriList = peripheral.getNames()
- for i=1,#PeriList do
- if peripheral.getType(PeriList[i]) == whatToFind then
- return PeriList[i]
- end
- end
- end
- --ПОИСК ПЕРИФЕРИИ
- local m = findPeripheral("monitor")
- if Args[1] == "m" then
- if m ~= nil then
- m = peripheral.wrap(m)
- if Args[2] ~= nil then
- m.setTextScale(tonumber(Args[2]))
- end
- term.redirect(m)
- end
- end
- if not term.isColor() then error("This program will work only on advanced computer.") end
- ----------------------ОБЪЯВЛЕНИЕ ПЕРЕМЕННЫХ----------------------
- local xSize, ySize = term.getSize()
- local centerX = math.floor(xSize/2)
- local centerY = math.floor(ySize/2)
- local appWidth = 10
- local appHeight = 6
- local countOfAppsByX = math.floor((xSize-2)/(appWidth+2))
- local countOfAppsByY = math.floor((ySize-5)/(appHeight+1))
- local countOfAppsOnDesktop = countOfAppsByX*countOfAppsByY
- local countOfDesktops = nil
- local startDisplayAllAppsFromX = centerX - math.floor((countOfAppsByX*(appWidth+2)-2)/2) + 1
- local startDisplayAllAppsFromY = centerY - math.floor((countOfAppsByY*(appHeight+1)-1)/2) + 1
- local currentDesktop = 1
- local currentBackground = colors.lightBlue
- local topBarColor = colors.gray
- --МАССИВЫ ОБЪЕКТОВ
- local Obj = {}
- local ObjBottom = {}
- local ObjApp = {}
- local clipboardName = nil
- local workPath = ""
- local workPathHistory = {}
- ----------------------ОБЪЯВЛЕНИЕ ФУНКЦИЙ----------------------
- --СОЗДАНИЕ ОБЪЕКТОВ ПРИЛОЖЕНИЙ
- local function newObjApp(name,x1,y1,width,height,id)
- ObjApp[name]={}
- ObjApp[name]["x1"]=x1
- ObjApp[name]["y1"]=y1
- ObjApp[name]["x2"]=x1+width-1
- ObjApp[name]["y2"]=y1+height-1
- ObjApp[name]["id"] = id
- end
- --СОЗДАНИЕ ДРУГИХ ОБЪЕКТОВ
- local function newObj(name,x1,y1,width,height)
- Obj[name]={}
- Obj[name]["x1"]=x1
- Obj[name]["y1"]=y1
- Obj[name]["x2"]=x1+width-1
- Obj[name]["y2"]=y1+height-1
- end
- --ОБЪЕКТОВ НИЖНИХ КНОПОК
- local function newObjBottom(name,x1,y1,width,height)
- ObjBottom[name]={}
- ObjBottom[name]["x1"]=x1
- ObjBottom[name]["y1"]=y1
- ObjBottom[name]["x2"]=x1+width-1
- ObjBottom[name]["y2"]=y1+height-1
- end
- --ОГРАНИЧЕНИЕ ДЛИНЫ СТРОКИ
- local function stringLimit(text,size)
- if string.len(text)<=size then return text end
- return string.sub(text,1,size-3).."..."
- end
- --ПРОСТОЕ ОТОБРАЖЕНИЕ ТЕКСТА ПО КООРДИНАТАМ
- local function usualText(x,y,text)
- term.setCursorPos(x,y)
- term.write(text)
- end
- --РИСОВАНИЕ КВАДРАТА С ЗАЛИВКОЙ
- local function square(x1,y1,width,height,color)
- local string = string.rep(" ",width)
- term.setBackgroundColor(color)
- for y=y1,(y1+height-1) do
- usualText(x1,y,string)
- end
- end
- --ЗАЛИВКА ЭКРАНА ЦВЕТОМ
- local function clearScreen(color)
- term.setBackgroundColor(color)
- term.clear()
- end
- --ОЧИСТКА ЭКРАНА И УСТАНОВКА КУРСОРА НА 1, 1
- local function prepareToExit()
- clearScreen(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(1,1)
- end
- --ПЛАВНОЕ ВКЛЮЧЕНИЕ ЭКРАНА
- local function fadeIn(time)
- clearScreen(colors.gray)
- sleep(time)
- clearScreen(colors.lightGray)
- sleep(time)
- clearScreen(colors.white)
- sleep(time)
- end
- --ПЛАВНОЕ ЗАТУХАНИЕ ЭКРАНА
- local function fadeOut(time)
- clearScreen(colors.lightGray)
- sleep(time)
- clearScreen(colors.gray)
- sleep(time)
- clearScreen(colors.black)
- sleep(time)
- term.setCursorPos(1,1)
- term.setTextColor(colors.white)
- end
- --ПОЛУЧЕНИЕ ФОРМАТА ФАЙЛА
- local function getFileFormat(name)
- local start,ending = string.find(name,"%.%w*$")
- if start == nil then
- return nil
- else
- return string.sub(name,start,ending)
- end
- end
- --КОПИРОВАНИЕ ОБОЕВ РАБОЧЕГО СТОЛА В СИСТЕМНУЮ ПАПКУ
- local function setWallpaper(path)
- fs.delete("System/wallpaper.png")
- fs.copy(path,"System/wallpaper.png")
- end
- --ФУНКЦИИ ДЛЯ РАБОТЫ С ФАЙЛАМИ И БУФЕРОМ ОБМЕНА
- local function copy(whatToCopy)
- fs.delete("System/clipboard.temp")
- fs.copy(whatToCopy,"System/clipboard.temp")
- end
- local function paste(path,name)
- fs.delete(path.."/"..name)
- fs.copy("System/clipboard.temp",path.."/"..name)
- end
- local function cut(path)
- fs.copy(path,"System/clipboard.temp")
- fs.delete(path)
- end
- --ВЕРХНЯЯ ПОЕБОНЬКА С ЧАСИКАМИ
- local function topBar(topBarColor)
- local time = textutils.formatTime(os.time(),false)
- term.setBackgroundColor(topBarColor)
- term.setTextColor(colors.white)
- local string = " OS "..string.rep(" ",xSize-5-#time)..time.." "
- usualText(1,1,string)
- end
- newObj("OS",1,1,6,1)
- --ФУНКЦИЯ ДЛЯ РЕОРГАНИЗАЦИИ ЭЛЕМЕНТОВ МАССИВА, ЧТОБ ПАПКИ В НАЧАЛЕ БЫЛИ, А ФАЙЛЫ В КОНЦЕ
- local function reorganizeFilesAndFolders(workPath,massivSudaPihay)
- local reorganizedMassiv = {}
- for i=1,#massivSudaPihay do
- if fs.isDir(workPath.."/"..massivSudaPihay[i]) then
- reorganizedMassiv[#reorganizedMassiv+1] = massivSudaPihay[i]
- end
- end
- for i=1,#massivSudaPihay do
- if not fs.isDir(workPath.."/"..massivSudaPihay[i]) then
- reorganizedMassiv[#reorganizedMassiv+1] = massivSudaPihay[i]
- end
- end
- return reorganizedMassiv
- end
- --ФУНКЦИЯ ОТРИСОВКИ КОНКРЕТНО ВЫБРАННОГО ПРИЛОЖЕНИЯ ПО ИМЕНИ
- local function drawKonkretnoApp(x,y,name,background,id)
- local xIconPos = x + 2
- if not fs.isDir(workPath.."/"..name) then
- local fileFormat = getFileFormat(name)
- if fileFormat == ".png" then
- image.draw(xIconPos,y,"System/Icons/image.png")
- elseif fileFormat == ".cfg" then
- image.draw(xIconPos,y,"System/Icons/config.png")
- elseif fileFormat == nil then
- if fs.exists("System/icons/"..name..".png") then
- image.draw(xIconPos,y,"System/Icons/"..name..".png")
- else
- image.draw(xIconPos,y,"System/Icons/default.png")
- end
- else
- image.draw(xIconPos,y,"System/Icons/default.png")
- end
- else
- image.draw(xIconPos,y,"System/Icons/folder.png")
- end
- newObjApp(name,x,y,appWidth,appHeight,id)
- name = stringLimit(name,10)
- term.setBackgroundColor(background)
- term.setTextColor(colors.black)
- usualText(math.floor(x+5-#name/2),y+5,name)
- end
- --ФУНКЦИЯ ОТРИСОВКИ ВООБЩЕ ВСЕХ ПРИЛОЖЕНИЙ НА РАБОЧЕМ СТОЛЕ
- local function displayApps(workPath,currentDesktop,background)
- --ОБНУЛЕНИЕ МАССИВОВ
- ObjApp = {}
- ObjBottom = {}
- --ОТРИСОВКА ОБОЕВ
- clearScreen(background)
- if fs.exists("System/wallpaper.png") then
- image.draw(1,2,"System/wallpaper.png")
- end
- --ОТРИСОВКА ВЕРХНЕЙ ШНЯГИ
- topBar(topBarColor)
- --ПОЛУЧИТЬ МАССИВ СО ВСЕМИ ФАЙЛАМИ/ПАПКАМИ
- local files = fs.list(workPath)
- --РЕОРГАНИЗОВАТЬ МАССИВ, ЧТОБ ПАПКИ БЫЛИ В НАЧАЛЕ
- files = reorganizeFilesAndFolders(workPath,files)
- local countOfFiles = #files
- countOfDesktops = math.ceil(countOfFiles/(countOfAppsByY*countOfAppsByX))
- --ОТРИСОВКА НИЖНЕГО ГОВНА
- local bottomButtonsStartX = nil
- if #workPathHistory == 0 then
- bottomButtonsStartX = centerX - math.floor((countOfDesktops*2+1)/2)
- else
- bottomButtonsStartX = centerX - math.floor((countOfDesktops*2-1)/2)
- end
- local bottomY = ySize-1
- for i=1,countOfDesktops do
- local bottomX = bottomButtonsStartX + i * 2
- if currentDesktop == i then
- paintutils.drawPixel(bottomX,bottomY,colors.white)
- else
- paintutils.drawPixel(bottomX,bottomY,colors.lightGray)
- end
- newObjBottom(i,bottomX,bottomY,1,1)
- end
- if #workPathHistory>0 then
- paintutils.drawPixel(bottomButtonsStartX,bottomY,colors.white)
- term.setTextColor(colors.black)
- usualText(bottomButtonsStartX,bottomY,"<")
- newObj("<",bottomButtonsStartX,bottomY,1,1)
- end
- --ОТРИСОВКА САМИХ ПРИЛОЖЕНИЙ
- local appCounter = 1 + currentDesktop * countOfAppsByY * countOfAppsByX - countOfAppsByY * countOfAppsByX
- for y = 1,countOfAppsByY do
- for x = 1,countOfAppsByX do
- if files[appCounter] ~= nil then
- drawKonkretnoApp(startDisplayAllAppsFromX+x*(appWidth+2)-(appWidth+2),startDisplayAllAppsFromY+y*(appHeight+1)-(appHeight+1),files[appCounter],background,appCounter)
- appCounter = appCounter + 1
- end
- end
- end
- end
- ----------------------------------СТАРТ ПРОГРАММЫ----------------------------------------
- --РИСУЕМ ВООБЩЕ ВСЕ ПРИЛОЖЕНИЯ
- displayApps(workPath,currentDesktop,currentBackground)
- --НАЧАЛО ЕБЛИ МОЗГА
- local exitFromProgram = false
- while true do
- if exitFromProgram then break end
- --СЧЕТЧИК ПРИЛОЖЕНИЙ, НАЧИНАЯ С 1 НА ТЕКУЩЕМ РАБОЧЕМ СТОЛЕ
- local appCounter = 1 + currentDesktop * countOfAppsByY * countOfAppsByX - countOfAppsByY * countOfAppsByX
- local event,side,x,y = os.pullEvent()
- --ХУЙНЮШКА ДЛЯ МОНИТОРА, А ТО ХЕР ЕГО ЗНАЕТ, КАКИЕ ИВЕНТЫ ОНО ШЛЕТ
- if event == "monitor_touch" then side = 1 end
- if event == "mouse_click" or event == "monitor_touch" then
- if side == 1 then
- --ПЕРЕМЕННАЯ ВЫХОДА ИЗ ВСЕХ ЦИКЛОВ, ПАТАММУШТА ЛУА ГОВНО И НЕ ПОДДЕРЖИВАЕТ МНОЖЕСТВЕННЫЙ BREAK
- local exit1 = false
- --ХУЙНЮШЕЧКА ДЛЯ КЛИКА "НАЗАД"
- if #workPathHistory > 0 then
- if x==Obj["<"]["x1"] and y==Obj["<"]["y1"] and #workPathHistory > 0 then
- --ТЫК
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.white)
- usualText(Obj["<"]["x1"],Obj["<"]["y1"],"<")
- sleep(0.2)
- --НЕ ТЫК
- workPath = workPathHistory[#workPathHistory]
- workPathHistory[#workPathHistory] = nil
- currentDesktop = 1
- displayApps(workPath,currentDesktop,currentBackground)
- exit1 = true
- end
- end
- --А ЭТО, КОРОЧ, ПЕРЕБОР ВСЕХ НИЖНИХ КНОПОЧЕК ДЛЯ ПЕРЕЛИСТЫВАНИЯ РАБОЧИХ СТОЛОВ
- for i=1,#ObjBottom do
- if exit1 then break end
- if x==ObjBottom[i]["x1"] and y==ObjBottom[i]["y1"] then
- currentDesktop = i
- displayApps(workPath,currentDesktop,currentBackground)
- exit1=true
- end
- end
- --А ЭТО ВООБЩЕ У-У-У-У-У
- --ЗАБЕЙ, КОРОЧ
- --ПРОСТО ЗАБЕЙ
- --В ОБЩЕМ
- --ЭТО ТАКАЯ ХУЙНЯ, КОТОРАЯ ПЕРЕБИРАЕТ МАССИВЧИК С ОБЪЕКТАМИ ПРИЛОЖЕНИЙ
- --КОРОЧ, ЗАБЫЛ УЖЕ, ЧТО ЭТО
- for key,val in pairs(ObjApp) do
- if exit1 then break end
- for i=appCounter,(appCounter+countOfAppsOnDesktop-1) do
- if exit1 then break end
- if ObjApp[key]["id"] == i then
- if x>=ObjApp[key]["x1"] and x<=ObjApp[key]["x2"] and y>=ObjApp[key]["y1"] and y<=ObjApp[key]["y2"] then
- square(ObjApp[key]["x1"],ObjApp[key]["y1"],appWidth,appHeight,colors.blue)
- drawKonkretnoApp(ObjApp[key]["x1"],ObjApp[key]["y1"],key,colors.blue,ObjApp[key]["id"])
- sleep(0.2)
- if not fs.isDir(workPath.."/"..key) then
- local fileFormat = getFileFormat(key)
- if key ~= "OS" and key ~= "os" and fileFormat ~= ".png" then
- fadeOut(0)
- prepareToExit()
- shell.run(workPath.."/"..key)
- local xCursor,yCursor = term.getCursorPos()
- usualText(1,yCursor+1,"Press any key to continue.")
- while true do
- local event = os.pullEvent()
- if event == "mouse_click" or event == "monitor_touch" or event == "key" then break end
- end
- fadeIn(0)
- elseif fileFormat == ".png" then
- fadeOut(0)
- shell.run("Photoshop "..workPath.."/"..key)
- fadeIn(0)
- elseif key == "OS" or key == "os" then
- windows.error(math.floor(xSize/2-16),math.floor(ySize/2-4),{"Can't open OS"},{"Cause it's already","running."})
- end
- exit1 = true
- displayApps(workPath,currentDesktop,currentBackground)
- else
- workPathHistory[#workPathHistory+1] = workPath
- workPath = workPath.."/"..key
- appCounter = 1
- currentDesktop = 1
- exit1 = true
- displayApps(workPath,1,currentBackground)
- end
- end
- end
- end
- end
- if x>=Obj["OS"]["x1"] and x<=Obj["OS"]["x2"] and y>=Obj["OS"]["y1"] and y<=Obj["OS"]["y2"] then
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.white)
- usualText(1,1," OS ")
- local contextAction = context.menu(Obj["OS"]["x1"]+1,Obj["OS"]["y1"]+1,{"Made by ECS",true},"-",{"About"},"-",{"Reboot"},{"Shutdown"},"-",{"Use Craft OS"})
- if contextAction == "About" then
- fadeOut(0)
- shell.run("Applications/About")
- fadeIn(0)
- displayApps(workPath,currentDesktop,currentBackground)
- elseif contextAction == "Reboot" then
- fadeOut(0)
- os.reboot()
- elseif contextAction == "Shutdown" then
- fadeOut(0)
- os.shutdown()
- elseif contextAction == "Use Craft OS" then
- exitFromProgram = true
- prepareToExit()
- elseif contextAction == nil then
- displayApps(workPath,currentDesktop,currentBackground)
- end
- end
- else
- local appSelected = false
- local exit1 = false
- for key,val in pairs(ObjApp) do
- if exit1 then break end
- for i=appCounter,(appCounter+countOfAppsOnDesktop-1) do
- if exit1 then break end
- if ObjApp[key]["id"] == i then
- if x>=ObjApp[key]["x1"] and x<=ObjApp[key]["x2"] and y>=ObjApp[key]["y1"] and y<=ObjApp[key]["y2"] then
- square(ObjApp[key]["x1"],ObjApp[key]["y1"],appWidth,appHeight,colors.blue)
- drawKonkretnoApp(ObjApp[key]["x1"],ObjApp[key]["y1"],key,colors.blue,ObjApp[key]["id"])
- local fileFormat = getFileFormat(key)
- local contextAction = nil
- if fileFormat ~= ".png" then
- contextAction = context.menu(x,y,{"Edit",fs.isDir(workPath.."/"..key)},"-",{"Cut"},{"Copy"},{"Delete"},{"Rename"},"-",{"Send via Wi-Fi",true})
- else
- contextAction = context.menu(x,y,{"Edit",fs.isDir(workPath.."/"..key)},{"Set as wallpaper"},"-",{"Cut"},{"Copy"},{"Delete"},{"Rename"},"-",{"Send via Wi-Fi",true})
- end
- if contextAction == "Edit" then
- exit = true
- fadeOut(0)
- prepareToExit()
- shell.run("edit "..workPath.."/"..key)
- fadeIn(0)
- elseif contextAction == "Cut" then
- if fs.isReadOnly(workPath.."/"..key) then
- windows.error(math.floor(xSize/2-16),math.floor(ySize/2-4),{"Can't cut this."},{"This file is aviable","to read-only."})
- else
- cut(workPath.."/"..key)
- clipboardName = key
- end
- elseif contextAction == "Copy" then
- if fs.isReadOnly(workPath.."/"..key) then
- windows.error(math.floor(xSize/2-16),math.floor(ySize/2-4),{"Can't copy this."},{"This file is aviable","to read-only."})
- else
- copy(workPath.."/"..key)
- clipboardName = key
- end
- elseif contextAction == "Delete" then
- if fs.isReadOnly(workPath.."/"..key) then
- windows.error(math.floor(xSize/2-16),math.floor(ySize/2-4),{"Can't delete this."},{"This file is aviable","to read-only."})
- else
- fs.delete(workPath.."/"..key)
- end
- elseif contextAction == "Rename" then
- if fs.isReadOnly(workPath.."/"..key) then
- windows.error(math.floor(xSize/2-16),math.floor(ySize/2-4),{"Can't rename this."},{"This file is aviable","to read-only."})
- else
- local filePath = windows.input(math.floor(xSize/2-12),math.floor(ySize/2-3),"New name",15,{"Name",""})
- fs.move(workPath.."/"..key,workPath.."/"..filePath[1])
- end
- elseif contextAction == "Set as wallpaper" then
- setWallpaper(workPath.."/"..key)
- end
- exit1 = true
- appSelected = true
- displayApps(workPath,currentDesktop,currentBackground)
- end
- end
- end
- end
- if y>=2 and appSelected == false then
- local canNotGoBack = true
- if #workPathHistory > 0 then canNotGoBack = false end
- local isClipboardEmpty = true
- if clipboardName ~= nil then isClipboardEmpty = false end
- local contextAction = context.menu(x,y,{"Back",canNotGoBack},"-",{"New file"},{"New folder"},{"Paste",isClipboardEmpty})
- if contextAction == "New file" then
- local filePath = windows.input(math.floor(xSize/2-12),math.floor(ySize/2-3),"New file",15,{"Name",""})
- fadeOut(0)
- prepareToExit()
- shell.run("edit "..workPath.."/"..filePath[1])
- fadeIn(0)
- elseif contextAction == "New folder" then
- local filePath = windows.input(math.floor(xSize/2-12),math.floor(ySize/2-3),"New folder",15,{"Name",""})
- fs.makeDir(workPath.."/"..filePath[1])
- elseif contextAction == "Back" then
- workPath = workPathHistory[#workPathHistory]
- workPathHistory[#workPathHistory] = nil
- elseif contextAction == "Paste" then
- if clipboardName ~= nil and fs.exists("System/clipboard.temp") then
- paste(workPath,clipboardName)
- end
- end
- displayApps(workPath,currentDesktop,currentBackground)
- end
- end
- --ОТРИСУЕМ ВЕРХНЮЮ ПАНЕЛЬКУ С ЧАСИКАМИ ПОСЛЕ НАЖАТИЯ НА ЭКРАН
- topBar(topBarColor)
- --ПОДДЕРЖКА КОЛЕСА МЫШИ, ПРОКРУЧИВАЮЩЕГО РАБОЧИЕ СТОЛЫ
- elseif event == "mouse_scroll" then
- if side == -1 then
- currentDesktop = currentDesktop + 1
- if currentDesktop > countOfDesktops then
- currentDesktop = countOfDesktops
- else
- displayApps(workPath,currentDesktop,currentBackground)
- end
- elseif side == 1 then
- currentDesktop = currentDesktop - 1
- if currentDesktop < 1 then
- currentDesktop = 1
- else
- displayApps(workPath,currentDesktop,currentBackground)
- end
- end
- end
- end
- fadeOut(0)
- prepareToExit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement