Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- future version wish: table implementation?
- -- cfg: add nhui auto update preferences [versions, hotfixes] (under new menu under options > preferences > updating > versions/hotfixes)
- -- misc: swap uninstall and about
- -- .nhuicfg: add variable to detect if config is outdated. give warning before install of a new version
- -- desk: add hotfix handling structure (versions fed by legacy startup, handled by desktop)
- -- hotfix: detect on startup; have options for more information on the hotfix; option for to never ask again; version list keeps base installs; if multiple hotfixes available, let user select hotfix to view more info/install on startup
- -- if auto update is true display message letting user know it's about to apply a hotfix
- -- hotfix function: checks for internet, runs hotfix link that detects target nhui programs and deletes them, downloads new versions in their place
- -- updates: add warning if version is not compatible
- -- add a spoof disclaimer for comedic effect (not responsible for damage caused for virtual computer etc)
- -- basic variables and functions
- nhver,wip="v0.5",true
- local nhuiProgs={["login"]="UwwmSJwL",["updater"]="ag7RuWX4",[".nhuicfg"]="mbD7EU2J"}
- local nhuiProgList={"startup","desktop","updater","login",".nhuicfg"}
- local colorList={["red"]=16384,["yellow"]=16,["white"]=1,["lightGrey"]=256,["grey"]=128}
- local colorListMono={["red"]=1,["yellow"]=1,["white"]=1,["lightGrey"]=256,["grey"]=128}
- local function setTxtColor(color)
- term.setTextColor(term.isColor() and colorList[color] or colorListMono[color])
- end
- local function printAt(text,setX,setY)
- term.setCursorPos(setX,setY) print(text)
- end
- local function resetScreen()
- term.clear() term.setCursorPos(1,1)
- end
- local function pingPastebin()
- http.request("http://pastebin.com")
- local requesting=true
- while requesting do
- resetScreen()
- print("Waiting for pastebin.com...")
- local event=os.pullEvent()
- if event=="http_success" then internet,requesting=true,false
- elseif event=="http_failure" then internet,requesting=false end
- end
- if internet==false then print("...could not connect.") sleep(1) resetScreen() end
- end
- local function anyKey()
- sleep(.2)
- local event,b,x,y=os.pullEventRaw()
- if (event=="key" and b~=0) or (event=="mouse_click" and x>0 and y>0) then anyKeyReq=nil end
- end
- local function openConfig() -- needs to be formatted to fs.open
- local file=fs.open(".nhuicfg", "r")
- sContents=file:read()
- file:close()
- tContents=textutils.unserialize(sContents)
- end
- local function editConfigLine(line,text) -- needs to be formatted to fs.open
- table.remove(tContents,line)
- table.insert(tContents,line,text)
- end
- local function saveConfig() -- needs to be formatted to fs.open
- sContents=textutils.serialize(tContents)
- local file=fs.open(".nhuicfg","w")
- file:write(sContents)
- file:close()
- end
- -- menu-related functions
- openConfig() -- needs to be formatted to fs.open
- local deskColors={["menuColor"]=tContents[4],["menuTextColor"]=tContents[5],["backgroundColor"]=tContents[6],["textColor"]=tContents[7],["secondaryTextColor"]=tContents[8],["tertiaryTextColor"]=tContents[9]}
- saveConfig()
- local function menuBar()
- term.setCursorPos(1,1) term.clearLine()
- term.setBackgroundColor(deskColors["menuColor"])
- term.setTextColor(deskColors["menuTextColor"])
- printAt((s==0 or s==nil) and "1|Start 2|Apps 3|Options 4|NhUI" or "-|Start -|Apps -|Options -|NhUI",2,1)
- end
- local function drawMenus()
- term.setTextColor(deskColors["menuTextColor"])
- term.setBackgroundColor(deskColors["menuColor"])
- if s==1 then printAt("1|CraftOS\n ---------\n 2|Shutdown\n 3|Restart",2,2)
- elseif s==2 then printAt("1|Clock",12,2)
- elseif s==3 then printAt("1|Password",21,2)
- elseif s==4 then printAt("1|Versions\n 2|Uninstall\n 3|About",33,2) end
- end
- local function drawDesktop()
- term.setBackgroundColor(deskColors["backgroundColor"])
- term.clear()
- if wip==true then setTxtColor("red") printAt("NOTE: WIP BUILD - POSSIBLY UNSTABLE",2,17) end
- setTxtColor("lightGrey") printAt("(Use " .. (term.isColor() and "mouse & " or "") .. "keyboard for selecting.)",2,18)
- setTxtColor("grey") printAt(nhver,47,18)
- menuBar()
- end
- local function displayTime()
- dispTime=true
- repeat
- local inGameTime=textutils.formatTime(os.time(),false)
- local x=term.getSize()
- printAt(inGameTime,23,1)
- sleep(.01)
- until dispTime==false
- end
- local function displayTimeMenu()
- printAt("Current in-game time:\n\n1|(Back)",1,1)
- while true do
- local event,b,x,y=os.pullEventRaw()
- if (event=="key" and b==keys.one) or (event=="mouse_click" and b==1 and x>=1 and x<=8 and y==3) then dispTime=false drawDesktop() return end
- end
- end
- -- executable-related functions
- local function runMenu()
- local yLine=2
- repeat
- term.setCursorPos(1,yLine) term.clearLine()
- yLine=yLine+1
- until yLine==6
- menuBar()
- drawMenus()
- end
- local function runShell()
- s=0 resetScreen()
- setTxtColor("yellow") print(os.version().." (run 'desktop' to return to desktop)")
- setTxtColor("white")
- sleep(.1)
- end
- local function runClock()
- s=0 resetScreen()
- parallel.waitForAny(displayTime,displayTimeMenu)
- end
- local function runPasswordSetup()
- s=0 resetScreen()
- pingPastebin()
- if internet==true then resetScreen()
- openConfig()
- if tContents[2]==true then print("This terminal is password protected.") else print("This terminal is not password protected.") end
- print("Would you like to set/change your password?\n\n1|Yes\n2|No\n3|(Back)")
- while true do
- local event,b,x,y=os.pullEventRaw()
- if (event=="key" and b==keys.one) or (event=="mouse_click" and b==1 and x>=1 and x<=5 and y==4) then
- fs.delete("login")
- shell.run("pastebin get",nhuiProgs["login"],"login")
- resetScreen()
- print("Desired password? (Note: will display input.)")
- editConfigLine(2,"true")
- local sInput=read()
- if sInput~="" then sPass=sInput end
- editConfigLine(3,sPass)
- saveConfig()
- print("\n\n@Preferences saved.\n@Press any key to return to desktop.")
- anyKey() drawDesktop() return
- elseif (event=="key" and b==keys.two) or (event=="mouse_click" and b==1 and x>=1 and x<=4 and y==5) then
- fs.delete("login")
- editConfigLine(2,"")
- editConfigLine(3,"")
- saveConfig()
- print("\n\n@Preferences saved.\n@Press any key to return to desktop.")
- anyKey() drawDesktop() return
- elseif (event=="key" and b==keys.three) or (event=="mouse_click" and b==1 and x>=1 and x<=8 and y==6) then drawDesktop() return end
- end
- elseif internet==false then drawDesktop() return end
- end
- local function runUpdater()
- s=0 resetScreen()
- pingPastebin()
- if internet==true then resetScreen()
- shell.run("pastebin run",nhuiProgs["updater"])
- drawDesktop()
- elseif internet==false then drawDesktop() return end
- end
- local function runUninstallCheck()
- s=0 resetScreen()
- print("Would you like to uninstall NhUI "..nhver.."?")
- setTxtColor("lightGrey") print("(User-created programs will *not* be deleted.)")
- setTxtColor("white") print("\n1|Yes\n2|No (Back)")
- while true do
- local event,b,x,y=os.pullEventRaw()
- if (event=="key" and b==keys.one) or (event=="mouse_click" and b==1 and x>=1 and x<=5 and y==4) then
- for i=1, #nhuiProgList do fs.delete(nhuiProgList[i]) end
- print("\n\n@NhUI "..nhver.." uninstalled successfully.\n@Press any key to reboot your computer.")
- anyKey() os.reboot()
- elseif (event=="key" and b==keys.two) or (event=="mouse_click" and b==1 and x>=1 and x<=11 and y==5) then drawDesktop() return end
- end
- end
- local function runAbout()
- s=0 resetScreen()
- print("NhUI Author: Nhorr (Philip)\n(Pastebin Link: pastebin.com/u/Nhorr)\n\n1|(Back)")
- while true do
- local event,b,x,y=os.pullEventRaw()
- if (event=="key" and b==keys.one) or (event=="mouse_click" and b==1 and x>=1 and x<=8 and y==4) then drawDesktop() return end
- end
- end
- -- desktop structure
- local function runDesktop()
- s=0 -- selection rule
- while true do
- local event,b,x,y=os.pullEventRaw()
- -- if selection rule = 0
- if (event=="key" and s==0 and b==keys.one) or (event=="mouse_click" and b==1 and x>=2 and x<=8 and y==1) then s=1 runMenu()
- elseif (event=="key" and s==0 and b==keys.two) or (event=="mouse_click" and b==1 and x>=12 and x<=17 and y==1) then s=2 runMenu()
- elseif (event=="key" and s==0 and b==keys.three) or (event=="mouse_click" and b==1 and x>=21 and x<=29 and y==1) then s=3 runMenu()
- elseif (event=="key" and s==0 and b==keys.four) or (event=="mouse_click" and b==1 and x>=33 and x<=38 and y==1) then s=4 runMenu()
- -- if selection rule = 1
- elseif (event=="key" and s==1 and b==keys.one) or (event=="mouse_click" and s==1 and b==1 and x>=2 and x<=10 and y==2) then runShell() break
- elseif event=="mouse_click" and s==1 and b==1 and x>=2 and x<=10 and y==3 then s=1 drawMenus()
- elseif (event=="key" and s==1 and b==keys.two) or (event=="mouse_click" and s==1 and b==1 and x>=2 and x<=11 and y==4) then os.shutdown()
- elseif (event=="key" and s==1 and b==keys.three) or (event=="mouse_click" and s==1 and b==1 and x>=2 and x<=10 and y==5) then os.reboot()
- -- if selection rule = 2
- elseif (event=="key" and s==2 and b==keys.one) or (event=="mouse_click" and s==2 and b==1 and x>=12 and x<=18 and y==2) then runClock()
- -- if selection rule = 3
- elseif (event=="key" and s==3 and b==keys.one) or (event=="mouse_click" and s==3 and b==1 and x>=21 and x<=30 and y==2) then runPasswordSetup()
- -- if selection rule = 4
- elseif (event=="key" and s==4 and b==keys.one) or (event=="mouse_click" and s==4 and b==1 and x>=33 and x<=42 and y==2) then runUpdater()
- elseif (event=="key" and s==4 and b==keys.two) or (event=="mouse_click" and s==4 and b==1 and x>=33 and x<=43 and y==3) then runUninstallCheck()
- elseif (event=="key" and s==4 and b==keys.three) or (event=="mouse_click" and s==4 and b==1 and x>=33 and x<=39 and y==4) then runAbout()
- elseif event=="key" or event=="mouse_click" then s=0 runMenu() end
- end
- end
- -- run desktop
- term.clear()
- parallel.waitForAll(drawDesktop,runDesktop)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement