Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local w, h = term.getSize()
- local Entities = {}
- local Application
- local GameMode = false
- local AllowScroll = false
- local Screen_Background = colors.lightBlue
- local Screen_TextColor = colors.white
- local InputActive = -1
- local Desktop_Background
- local User_Name
- local Notifications = {}
- local NotTimer = -1
- local Popup_Data = -1
- local Desk_Apps = {}
- local Dropdown = false
- local Desk_Page = 1
- local Desk_EndPage = 3
- local Desktop_LineColors = {}
- settings.load("os/settings.txt")
- local Desktop_Back = settings.get("screen_desktop_background")
- local Dropdown_Back = settings.get("screen_dropdown_background")
- local function Clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function Startup()
- if h > settings.get("screen_maxHeight") then h = settings.get("screen_maxHeight") end
- term.setBackgroundColor(colours.black)
- Clear()
- os.sleep(1)
- local Image = paintutils.loadImage(Desktop_Back)
- paintutils.drawImage(Image,1,2)
- os.sleep(2)
- Start()
- end
- function Start()
- DesktopDraw()
- GetHomeApps()
- DrawApps()
- if settings.get("active_user") == "Guest" then os.queueEvent("system_notification","system","your account is not setup. click here to fix that!","os/System/Programs/SettingsApp.lua") end
- Loop()
- end
- function Loop()
- while true do
- local event, a, b, c, d, e, f, g = os.pullEvent()
- if NotTimer ~= -1 and os.time() >= NotTimer then
- NotTimer = -1
- Popup_Data = -1
- if Dropdown == false then
- if Application == nil then
- DesktopDraw()
- DrawApps()
- else
- DrawScreen()
- TopBarDraw()
- end
- end
- end
- if string.find(event,"system") then
- if event == "system_notification" then
- Notifications[#Notifications + 1] = {a,b,os.time(),c,d}
- Popup_Data = #Notifications
- NotTimer = os.time() + 0.40
- Popup(a,b)
- elseif event == "system_update" then
- elseif event == "system_alert" then
- elseif event == "system_error" then
- end
- elseif Dropdown == true then
- ManageDropdown(event,a,b,c,d)
- elseif Application == nil then
- if event == "mouse_click" then
- if c == 1 then
- DropToggle()
- elseif NotTimer ~= -1 and c == 3 and b < w/8 + 0.5 and b > w/8 - 0.75 then
- ClosePopup()
- elseif Popup_Data ~= -1 and c >= 3 and c <= 7 and b > w/8 + 0.5 and b <= w - w/8 then
- NotTimer = -1
- OpenNotification(Popup_Data)
- elseif ( b == 1 and Desk_Page > 1) == true or (b == w and Desk_Page < Desk_EndPage) == true then
- if b == 1 and Desk_Page > 1 then Desk_Page = Desk_Page - 1 else Desk_Page = Desk_Page + 1 end
- DesktopDraw()
- DrawApps()
- if Popup_Data ~= -1 then Popup() end
- else
- local App = CheckApps(b,c)
- if App ~= false then RunApp(App) end
- end
- elseif event == "key" then
- if a == keys.m then DropToggle() end
- elseif event == "desktop_update" then
- end
- elseif Application ~= nil then
- if GameMode == true then
- GameMode = false
- CloseApp()
- elseif event == "mouse_click" then
- local Entity = CheckEntities(b,c)
- if b > w/6 and b < w - (w/6) and c == h and Entity == false then
- CloseApp()
- elseif c == h - 1 and AllowScroll == true then
- term.scroll(1)
- DrawScreen()
- elseif InputActive ~= -1 and ((b < Entities[InputActive][5]) == true or (b > Entities[InputActive][4]) == true or (c > Entities[InputActive][6]) == true or (c < Entities[InputActive][6]) == true) == true then
- InputActive = -1
- elseif c == 1 then
- DropToggle()
- elseif NotTimer ~= -1 and c == 3 and b < w/8 + 0.5 and b > w/8 - 0.5 then
- ClosePopup()
- elseif NotTimer ~= -1 and c >= 3 and c <= 7 and b >= w/8 and b <= w - w/8 then
- NotTimer = -1
- OpenNotification(Popup_Data)
- Popup_Data = -1
- elseif Entity ~= false then
- RunEntity(Entity,"click")
- end
- elseif InputActive ~= -1 and event == "char" then
- EditInput(a)
- elseif event == "key" then
- if a == keys.m then
- DropToggle()
- elseif a == keys.x then
- CloseApp()
- elseif a == keys.enter and InputActive ~= -1 then
- shell.run(Application,Entities[InputActive][1],Entities[InputActive][3])
- InputActive = -1
- end
- elseif event == "application_task" then
- Task(a,b,c,d,e,f,g)
- end
- end
- UI()
- os.queueEvent("pass")
- end
- end
- --Toggle
- function DropToggle()
- if Dropdown == true then
- Dropdown = false
- if Application == nil then
- DesktopDraw()
- DrawApps()
- else
- term.setBackgroundColor(Screen_Background)
- Clear()
- TopBarDraw()
- DrawScreen()
- end
- if Popup_Data ~= -1 then Popup() end
- else
- Dropdown = true
- DrawDropdown()
- end
- end
- --Files
- function GetHomeApps()
- local Path = "os/Desktop_Shortcuts"
- local List = fs.list(Path)
- local X = 3
- local Y = 3
- local Page = 1
- for i = 1, #List do
- if string.find(List[i],".lnk") then
- local file = fs.open(fs.combine(Path,List[i]),"r")
- local Ap = file.readLine()
- if string.find(Ap,".cpf") or string.find(Ap,".lua") then
- Desk_Apps[#Desk_Apps + 1] = {Ap,file.readLine(),file.readLine(),X,Y,Page}
- if X + 7 < 22 then
- X = X + 7
- else
- X = 3
- Y = Y + 6
- end
- end
- end
- end
- end
- --Run
- function RunApp(App)
- term.setBackgroundColor(Screen_Background)
- Clear()
- TopBarDraw()
- Application = Desk_Apps[App][1]
- shell.run(Application,"start")
- end
- function MSG_RunApp(App,ar)
- term.setBackgroundColor(Screen_Background)
- Clear()
- TopBarDraw()
- Application = App
- shell.run(Application,"start",ar)
- end
- function RunEntity(i,action)
- if Entities[i][2] == "button" then
- if string.find(Entities[i][4],"lnk.") then
- local Ap = string.sub(Entities[i][4],5,string.len(Entities[i][4]))
- CloseApp()
- MSG_RunApp(Ap)
- elseif string.find(Entities[i][4],"tsk.") then
- shell.run(Application,string.sub(Entities[i][4],5,string.len(Entities[i][4])))
- end
- elseif Entities[i][2] == "input" then
- InputActive = i
- end
- end
- function OpenNotification(I)
- if Notifications[I][4] ~= nil then
- MSG_RunApp(Notifications[I][4],Notifications[I][5])
- if I == Popup_Data then
- Popup_Data = -1
- NotTimer = -1
- end
- Notifications[I] = nil
- else
- if I == Popup_Data then
- Popup_Data = -1
- NotTimer = -1
- end
- Notifications[I] = nil
- if Dropdown == false then
- if Application == nil then
- DesktopDraw()
- DrawApps()
- else
- DrawScreen()
- end
- else
- DrawDropdown()
- end
- end
- end
- --states
- function CloseApp()
- shell.run(Application,"stop")
- Application = nil
- Entities = {}
- DesktopDraw()
- DrawApps()
- InputActive = -1
- AllowScroll = false
- end
- function ClosePopup()
- NotTimer = -1
- Popup_Data = -1
- if Application == nil then
- DesktopDraw()
- DrawApps()
- else
- DrawScreen()
- end
- end
- --Check
- function CheckApps(X,Y)
- local Res = false
- for i = 1, #Desk_Apps do
- if Desk_Apps[i][4] <= X and Desk_Apps[i][4] + 5 >= X and Desk_Apps[i][5] <= Y and Desk_Apps[i][5] + 4 >= Y and Desk_Apps[i][6] == Desk_Page then Res = i end
- end
- return Res
- end
- function CheckEntities(X,Y)
- local X1 = 0
- local X2 = 0
- local Y1 = 0
- local Y2 = 0
- local R = false
- for i = 1, #Entities do
- if Entities[i][2] == "button" then
- X1 = Entities[i][5]
- Y1 = Entities[i][6]
- X2 = X1 + string.len(Entities[i][3])
- Y2 = Y1
- if X >= X1 and X <= X2 and Y >= Y1 and Y <= Y2 then R = i end
- elseif Entities[i][2] == "input" then
- X1 = Entities[i][5]
- Y1 = Entities[i][6]
- X2 = Entities[i][4]
- Y2 = Y1
- if X >= X1 and X <= X2 and Y >= Y1 and Y <= Y2 then R = i end
- end
- end
- return R
- end
- function EditInput(char)
- Entities[InputActive][3] = Entities[InputActive][3]..char
- DrawScreen()
- end
- function Task(a,b,c,d,e,f,g)
- if string.find(a,"create") then
- if a == "create_text" then--id,text,x,y
- Entities[#Entities + 1] = {b,"text",c,d,e+1}
- elseif a == "create_button" then--id,text,lnk/action,x,y
- Entities[#Entities + 1] = {b,"button",c,d,e,f+1}
- elseif a == "create_image" then--id,file,x,y
- Entities[#Entities + 1] = {b,"image",c,d,e+1}
- elseif a == "create_input" then--id,X2,X1,Y
- Entities[#Entities + 1] = {b,"input","",c,d,e+1}
- elseif a == "create_dropdown" then
- Entities[#Entities + 1] = {b,"drop",{},c,d+1}
- end
- elseif string.find(a,"set") then
- if a == "set_background" then
- Screen_Background = b
- elseif a == "set_textcolor" then
- Screen_TextColor = b
- elseif a == "set_scroll" then
- AllowScroll = b
- elseif a == "set_application" then
- if b == nil then
- CloseApp()
- else
- MSG_RunApp(b)
- end
- end
- elseif a == "edit" then
- local I = FindEntId(b)
- if I == false then
- elseif c == "text" then
- Entities[I][3] = d
- elseif c == "cords" then
- if Entities[I][2] == "text" then
- Entities[I][4] = d
- Entities[I][5] = e
- elseif Entities[I][2] == "button" then
- Entities[I][5] = d
- Entities[I][6] = e
- elseif Entities[I][2] == "image" then
- Entities[I][4] = d
- Entities[I][5] = e
- end
- end
- elseif a == "runGame" then
- Application = b
- GameMode = true
- elseif a == "get" then
- shell.run(Application,"item",Entities[b][2])
- else
- if a == "clearEntities" then
- InputActive = -1
- Entities = {}
- end
- end
- DrawScreen()
- end
- function FindEntId(ID)
- local Result
- for i = 1, #Entities do
- if Entities[i][1] == ID then Result = i end
- end
- if Result == nil then
- return false
- else
- return Result
- end
- end
- --Display
- function DesktopDraw()
- Clear()
- local Image = paintutils.loadImage(Desktop_Back)
- paintutils.drawImage(Image,1,2)
- TopBarDraw()
- end
- function DrawApps()
- for i = 1, #Desk_Apps do
- if Desk_Apps[i][6] == Desk_Page then
- if Desk_Apps[i][3] == "n" then
- paintutils.drawFilledBox(Desk_Apps[i][4],Desk_Apps[i][5],Desk_Apps[i][4] + 5, Desk_Apps[i][5] + 4, colors.gray)
- else
- local Image = paintutils.loadImage(Desk_Apps[i][3])
- paintutils.drawImage(Image,Desk_Apps[i][4],Desk_Apps[i][5])
- end
- local Text = string.sub(Desk_Apps[i][2],1,8)
- term.setCursorPos((Desk_Apps[i][4]+ 3) - string.len(Text)/2 , Desk_Apps[i][5] + 4)
- local Ba = fs.open(Desktop_Back,"r")
- local LineColor
- for I = 1, Desk_Apps[i][5] + 4 do
- LineColor = Ba.readLine()
- end
- Ba.close()
- local TextBack = "0"
- for T = 2, string.len(Text) do
- TextBack = TextBack.."0"
- end
- local F = (Desk_Apps[i][4]+ 3) - string.len(Text)/2
- term.blit(Text,TextBack,string.sub(LineColor,F, F + string.len(TextBack) - 1))
- end
- end
- local AX = w/2 - Desk_EndPage/2
- paintutils.drawFilledBox(AX - 1, h - 2, w/2 + Desk_EndPage/2 + 2, h, colors.gray)
- for i = 1, Desk_EndPage do
- if i == Desk_Page then
- paintutils.drawPixel(AX, h - 1, colors.white)
- else
- paintutils.drawPixel(AX, h - 1, colors.lightGray)
- end
- AX = AX + 2
- end
- end
- function TopBarDraw()
- paintutils.drawBox(1,1,9,1,colors.lightGray)
- paintutils.drawBox(w - 9,1,w,1,colors.lightGray)
- paintutils.drawBox(10,1, w - 10, 1, colors.gray)
- end
- function DrawDropdown()
- Clear()
- local Image = paintutils.loadImage(Dropdown_Back)
- paintutils.drawImage(Image,1,1)
- local Time = textutils.formatTime(os.time())
- term.setCursorPos(w/2 - string.len(Time)/2, 3)
- term.write(Time)
- term.setCursorPos(w/8,6)
- for I = 1, #Notifications do
- paintutils.drawFilledBox(w/8, (I * 3) + 4, w - w/8, (I * 3) + 7, colors.lightGray)
- term.setCursorPos(w/8, (I * 3) + 4)
- term.write(Notifications[I][1])
- term.setCursorPos(w - w/8 - 9, (I * 3) + 4)
- term.write(textutils.formatTime(Notifications[I][3]))
- local lines = require "cc.strings".wrap(Notifications[I][2], w - ((w/8) * 2))
- for i = 1, #lines do
- term.setCursorPos(w/8, (i + 7) * I)
- term.write(lines[i])
- end
- end
- paintutils.drawBox(w/10,h,w - w/10, h, colors.gray)
- end
- function DrawScreen()
- term.setBackgroundColor(Screen_Background)
- Clear()
- TopBarDraw()
- for i = 1, #Entities do
- if Entities[i][2] == "text" then
- term.setBackgroundColor(Screen_Background)
- term.setTextColor(Screen_TextColor)
- term.setCursorPos(Entities[i][4],Entities[i][5])
- term.write(Entities[i][3])
- elseif Entities[i][2] == "button" then
- term.setBackgroundColor(colors.yellow)
- term.setTextColor(colors.blue)
- term.setCursorPos(Entities[i][5],Entities[i][6])
- term.write(Entities[i][3])
- elseif Entities[i][2] == "image" then
- local Image = paintutils.loadImage(Entities[i][3])
- paintutils.drawImage(Image,Entities[i][4],Entities[i][5])
- elseif Entities[i][2] == "input" then
- paintutils.drawBox(Entities[i][5],Entities[i][6],Entities[i][4],Entities[i][6],colors.gray)
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- term.setCursorPos(Entities[i][5],Entities[i][6])
- term.write(Entities[i][3])
- end
- end
- local BarColor
- if Screen_Background == colors.white then
- BarColor = colors.gray
- else
- BarColor = colors.white
- end
- if AllowScroll == true then paintutils.drawBox(w/6, h - 1, w - (w/6), h - 1, colors.combine(Screen_Background,colors.blue)) end
- paintutils.drawBox(w/6, h, w - (w/6), h, BarColor)
- term.setBackgroundColor(Screen_Background)
- term.setTextColor(colors.white)
- if NotTimer ~= -1 then
- Popup()
- end
- end
- function Popup()
- local a = Notifications[Popup_Data][1]
- local b = Notifications[Popup_Data][2]
- local TI = Notifications[Popup_Data][3]
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- paintutils.drawFilledBox(w/8,3,w - w/8, 5,colors.white)
- paintutils.drawBox(w/8,3,w/8,3,colors.red)
- term.setBackgroundColor(colors.white)
- term.setCursorPos((w/8) + 1, 3)
- term.write(a)
- term.setCursorPos(w - w/8 - 7, 3)
- term.write(textutils.formatTime(TI))
- term.setCursorPos(w/8,4)
- local lines = require "cc.strings".wrap(b, w - ((w/8) * 2))
- for i = 1, #lines do
- term.setCursorPos(w/8, i + 3)
- term.write(lines[i])
- end
- term.setTextColor(colors.black)
- end
- function UI()
- if Application == nil then
- elseif Dropdown == false then
- end
- local Time = textutils.formatTime(os.time())
- if Dropdown == false then
- term.setCursorPos(w - 8, 1)
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colors.white)
- term.write(Time)
- term.setCursorPos(1,1)
- term.write(#Notifications)
- else
- term.setCursorPos(w/2 - string.len(Time)/2, 3)
- term.write(Time)
- end
- end
- function ManageDropdown(event,a,b,c,d)
- if event == "mouse_click" then
- if c == h then
- DropToggle()
- else
- for i = 1, #Notifications do
- if c >= (i*3) + 4 and c <= (i*3) + 7 and b > w/8 and b < w - w/8 then DropToggle() OpenNotification(i) end
- end
- end
- elseif event == "key" then
- if a == keys.m then
- DropToggle()
- end
- end
- end
- Startup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement