Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- w,h = term.getSize()
- os.pullEvent = os.pullEventRaw
- local name = "Rie-UI"
- local version = "0.1"
- local prefix = "Dev"
- local seperator = "_"
- local update = false
- local menu = "0"
- local notifications = {}
- local seenUpdate = false
- local cntx = false
- local bgIndex = 1
- backgrounds = api.list(root.."/wallpaper")
- --Config
- backgroundColour = 1
- tbc = api.rColor("gray")
- bgIMG = backgrounds[2]
- tbTextColor = api.rColor("white")
- notificationBackground = api.rColor("gray")
- notificationText = api.rColor("white")
- drawBackground = function(img)
- api.rClear("-scr", {backgroundColour})
- paintutils.drawImage(paintutils.loadImage(img), 1, 2)
- end
- nextNotification = function()
- local tmpT = {}
- if #notifications >= 1 then
- for i = 2, #notifications do
- tmpT[i-1] = notifications[i]
- end
- end
- notifications = tmpT
- end
- local notif = {
- [1] = {x=math.floor(w)-18, xx=math.floor(w)-14, y=math.floor(h)-1, txt="[Yes]", cmd=function() shell.run("/RUI/.ds_data/update") os.reboot() end},
- [2] = {x=math.floor(w)-4, xx=math.floor(w), y=math.floor(h)-1, txt="[No]", cmd=function() menu = "0" update = true nextNotification() end}
- }
- drawNotification = function(info)
- for i = math.ceil(h)-5, math.ceil(h) do
- api.rPrint("-r", {22, i}, {string.rep(" ", 20)}, {1, "gray"}, -1)
- end
- if notifications[1] == "Update" then
- api.rPrint("-r", {1, math.floor(h)-4}, {"Update found!"}, {1, "gray"}, 1)
- api.rPrint("-r", {1, math.floor(h)-3}, {"Update to "..nVersion.." now?"}, {1, "gray"}, 0)
- term.setCursorPos(notif[1].x, notif[1].y)
- write(notif[1].txt)
- term.setCursorPos(notif[2].x, notif[2].y)
- write(notif[2].txt)
- end
- end
- --tables
- local context = {
- [0] = {txt="-------------", tcol="lightGray", bcol=tbc, offX=0, cmd=function() end},
- [1] = {txt=" New ", tcol=tbTextColor, bcol=tbc, offX=0, cmd=function() end},
- [2] = {txt=" S/H Icons ", tcol=tbTextColor, bcol=tbc, offX=0, cmd=function() end},
- [3] = {txt=" Edit Config ", tcol=tbTextColor, bcol=tbc, offX=0, cmd=function() shell.run("fg", "edit", "testConf") end},
- [4] = {txt="-------------", tcol="lightGray", bcol=tbc, offX=0, cmd=function() end},
- }
- local tBar = {
- [1] = {x=1, xx=3, y=1, txt="(R)", col=tbTextColor, cmd=function() menu = "start" end, offX=0},
- [2] = {x=math.floor(w-1), xx=math.floor(w), y=1, txt="v", col=tbTextColor, cmd=function() drawDropDown() end, offX=2},
- [3] = {x=math.floor(w)+2, xx=math.floor(w)+2, y=1, txt="", col=api.rColor("red"), cmd=function() menu = "update" end, offX=2}
- }
- local start = {
- [1] = {x=1, xx=13, y=2, txt=" ", tcol=tbTextColor, bcol=tbc, offX=0, cmd=function() end},
- [2] = {x=1, xx=13, y=3, txt=" Marketplace ", tcol=tbTextColor, bcol=tbc, offX=0, cmd=function() menu="0" end},
- [3] = {x=1, xx=13, y=4, txt=" Programs ", tcol=tbTextColor, bcol=tbc, offX=0, cmd=function() menu="0" end},
- [4] = {x=1, xx=13, y=5, txt=" Settings ", tcol=tbTextColor, bcol=tbc, offX=0, cmd=function() menu="0" end},
- [5] = {x=1, xx=13, y=6, txt="-------------", tcol=api.rColor("lightGray"), bcol=tbc, offX=0, cmd=function() end},
- [6] = {x=1, xx=13, y=7, txt=" Terminal ", tcol=tbTextColor, bcol=tbc, offX=0, cmd=function() api.rClear("-scr", {"black" ,1}) term.setCursorPos(1,1) term.setTextColor(api.rColor("yellow")) print("Welcome to the terminal") loggedin=false end},
- [7] = {x=1, xx=13, y=8, txt="-------------", tcol=api.rColor("lightGray"), bcol=tbc, offX=0, cmd=function() end},
- [8] = {x=1, xx=13, y=9, txt=" (S) (R) (L) ", tcol=tbTextColor, bcol=tbc, offX=0, cmd=function() end},
- [9] = {x=1, xx=13, y=10, txt=" ", tcol=tbTextColor, bcol=tbc, offX=0, cmd=function() end},
- }
- --functions
- drawContext = function(...)
- cOpts = {...}
- for i,v in pairs(context) do
- api.rPrint("-l", {cOpts[1], tonumber(cOpts[2]+i)-1}, {v.txt}, {v.tcol, v.bcol}, 0)
- end
- end
- drawTaskBar = function(...)
- tBarArgs = {...}
- api.rClear("-ln", {tbc, 1})
- api.rPrint("-l", {tBar[1].x, tBar[1].y}, {tBar[1].txt}, {tBar[1].col}, tBar[1].offX)
- api.rPrint("-l", {tBar[2].x, tBar[2].y}, {tBar[2].txt}, {tBar[2].col}, tBar[2].offX)
- api.rPrint("-l", {tBar[3].x, tBar[3].y}, {tBar[3].txt}, {tBar[3].col}, tBar[3].offX)
- for k,v in pairs(tBarArgs) do
- v()
- end
- end
- local prevClick = {}
- mouseClick = function(...)
- btns = {...}
- if btns[1] == 2 then
- cntx = true
- tmpCx = btns[2]
- tmpCy = btns[3]
- if btns[2] >= math.floor(w)-13 then tmpCx = math.floor(w)-13 end
- if btns[3] >= math.floor(h-1)-#context then tmpCy = math.floor(h-1)-#context end
- if btns[3] == 1 then tmpCy = 2 end
- drawContext(tmpCx, tmpCy+1)
- prevClick = {tmpCx, tmpCy}
- return true
- end
- if cntx then
- for k,v in pairs(context) do
- if btns[2] >= prevClick[1] and btns[2] <= prevClick[1]+#v.txt and btns[3] == tonumber(prevClick[2]+k) and btns[1] == 1 then
- v.cmd()
- cntx = false
- return true
- end
- end
- else
- for i,v in pairs(btns[4]) do
- for k,v in pairs(btns[4][i]) do
- if btns[2] >= v.x and btns[2] <= v.xx and btns[3] == v.y and btns[1] == 1 then
- v.cmd()
- return true
- end
- end
- end
- end
- if menu ~= "update" then
- menu = "0"
- end
- cntx = false
- end
- drawMenus = function(...)
- mOpts = {...}
- for k,v in pairs(mOpts[1]) do
- api.rPrint("-l", {v.x, v.y}, {v.txt}, {v.tcol, v.bcol}, 0)
- end
- end
- power = function(MtmpX, MtmpY, btnPressed)
- btnY = #start
- if MtmpX >= 2 and MtmpX <=4 and MtmpY == btnY then
- os.shutdown()
- elseif MtmpX >= 6 and MtmpX <=8 and MtmpY == btnY then
- os.reboot()
- elseif MtmpX >= 10 and MtmpX <=12 and MtmpY == btnY then
- api.rClear("-scr", {"black" ,1}) term.setCursorPos(1,1)
- shell.run("/RUI/.ds_data/.auth", "false")
- loggedin=false
- else
- mouseClick(btnPressed, MtmpX, MtmpY, {start})
- end
- end
- drawDesktop = function()
- drawBackground(bgIMG)
- api.rPrint("-r", {1, math.ceil(h)}, {prefix..seperator..version}, {"black"}, 0)
- drawTaskBar()
- end
- nextBackground = function()
- backgrounds = api.list(root.."/wallpaper")
- if bgIndex == #backgrounds then
- bgIMG = backgrounds[1]
- bgIndex = 1
- else
- bgIndex = bgIndex + 1
- bgIMG = backgrounds[bgIndex]
- end
- drawDesktop()
- end
- local dropDown = {
- [1] = {x=math.floor(w)-11, xx=math.floor(w), y=2, txt=" ---------- ", tcol=api.rColor("lightGray"), bcol=tbc, offX=0, cmd=function() end},
- [2] = {x=math.floor(w)-11, xx=math.floor(w), y=3, txt=" Background ", tcol=tbTextColor, bcol=tbc, offX=0, cmd=function() nextBackground() end},
- [3] = {x=math.floor(w)-11, xx=math.floor(w), y=4, txt=" ---------- ", tcol=api.rColor("lightGray"), bcol=tbc, offX=0, cmd=function() end}
- }
- drawDropDown = function()
- for k,v in pairs(dropDown) do
- api.rPrint("-l", {v.x, k+1}, {v.txt}, {v.tcol, v.bcol}, v.offX)
- end
- menu="drop"
- end
- -- init
- local init = function(...)
- initArgs = {...}
- api.rClear("-a", {1,1})
- drawBackground(bgIMG)
- api.rPrint("-r", {1, math.ceil(h)}, {prefix..seperator..version}, {"black"}, 0)
- drawTaskBar()
- end
- -- Main Code
- nVersion = http.get("https://pastebin.com/raw/Rrcssfup").readAll()
- init()
- main = function()
- while loggedin do
- if menu ~= "0" then
- if menu == "start" then
- drawMenus(start)
- end
- end
- local e = {os.pullEvent()}
- if e[1] == "mouse_click" then
- drawDesktop()
- if menu == "update" then
- if #notifications > 0 then
- mouseClick(e[2], e[3], e[4], {notif, tBar})
- end
- end
- if menu == "drop" then
- if #notifications > 0 then
- mouseClick(e[2], e[3], e[4], {notif, tBar, dropDown})
- else
- mouseClick(e[2], e[3], e[4], {tBar, dropDown})
- end
- end
- if e[3] > 1 and e[4] == 1 and menu ~= "update" then
- mouseClick(e[2], e[3], e[4], {tBar})
- end
- if e[4] > 1 then
- if menu ~= "0" then
- if menu == "start" then
- power(e[3], e[4], e[2])
- end
- end
- end
- if e[3] > 1 and e[4] > 1 then
- mouseClick(e[2], e[3], e[4], {tBar})
- end
- end
- end
- end
- notificationHandler = function()
- while loggedin do
- sleep(1)
- nVersion = http.get("https://pastebin.com/raw/Rrcssfup").readAll()
- if nVersion ~= version and not update and not seenUpdate then
- notifications[#notifications+1] = "Update"
- seenUpdate = true
- end
- if #notifications < 1 then
- tBar[2].x = math.floor(w)-1
- tBar[2].xx = math.floor(w)-1
- tBar[3].x = math.floor(w)+2
- tBar[3].xx = math.floor(w)+2
- tBar[3].txt=""
- else
- tBar[2].x = math.floor(w)-4
- tBar[2].xx = math.floor(w)-4
- tBar[3].x = math.floor(w)-2
- tBar[3].xx = math.floor(w)
- tBar[3].txt="(i)"
- for i,v in pairs(notifications) do
- if notifications[i] == "Update" then
- menu = "update"
- drawNotification("Update")
- end
- end
- end
- drawTaskBar()
- end
- end
- parallel.waitForAll(main, notificationHandler)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement