Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Minif OS
- --By Minif
- --Functions and Variables
- osRunning = true
- osUserBGImageExists = false
- osUserAdmin = false
- function osDrawWindow(name)
- paintutils.drawFilledBox(3,3,osScreenSizeX-2,osScreenSizeY-2,colors.white)
- paintutils.drawBox(3,3,osScreenSizeX-2,5,colors.lightGray)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(4,4)
- term.write(name)
- end
- function osConfirm(name,message,detail)
- osDrawWindow(name)
- term.setCursorPos(4,7)
- term.write(message)
- term.setCursorPos(4,8)
- term.write(detail)
- paintutils.drawBox(4,11,osScreenSizeX-3,11,colors.green)
- term.setCursorPos(5,11)
- term.write("Yes")
- paintutils.drawBox(4,13,osScreenSizeX-3,13,colors.red)
- term.setCursorPos(5,13)
- term.write("No")
- local choice = false
- while true do
- osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
- if osPX >= 3 and osPX <=osScreenSizeX-2 then
- if osPY == 11 then
- choice = true
- return true
- else if osPY == 13 then
- return false
- end
- end
- end
- end
- return choice
- end
- function osLoadPrefs()
- local pref = fs.open("/system/user/"..osEnteredUser.."/config", "r")
- local readFile = pref.readLine()
- if fs.exists(readFile) and not (fs.isDir(readFile)) then
- os_UserBGImage = paintutils.loadImage(readFile)
- osUserBGImageExists = true
- end
- local readLine = pref.readLine()
- if readLine == "true" then
- osUserAdmin = true
- end
- pref.close()
- end
- --Drawing
- function osDrawDesktop()
- osFillBG(colors.cyan)
- if osUserBGImageExists then
- paintutils.drawImage(os_UserBGImage,1,2)
- else
- if osBGImageExists then
- paintutils.drawImage(os_BGImage,1,1)
- end
- end
- end
- function osDrawMenu()
- paintutils.drawBox(1,1,osScreenSizeX,1,colors.blue)
- term.setBackgroundColor(colors.lightBlue)
- term.setTextColor(colors.black)
- term.setCursorPos(1,1)
- term.write("M >")
- term.setCursorPos(5,1)
- term.write("File >")
- term.setCursorPos(12,1)
- term.write("System >")
- end
- function osDrawAll()
- term.setCursorBlink(false)
- osLoadPrefs()
- osDrawDesktop()
- osDrawMenu()
- end
- function osDrawPerm(prog)
- paintutils.drawFilledBox(3,3,osScreenSizeX-2,osScreenSizeY-2,colors.white)
- paintutils.drawBox(3,3,osScreenSizeX-2,5,colors.lightGray)
- term.setCursorPos(4,4)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.red)
- term.write("Permissions Error")
- term.setCursorPos(4,7)
- term.setTextColor(colors.black)
- term.write("You do not have permission")
- term.setCursorPos(4,8)
- term.write("To access the program: "..prog)
- term.setCursorPos(4,10)
- term.write("Press any key to exit.")
- while true do
- local event = os.pullEvent()
- if event == "mouse_click" or event == "key" then
- return
- end
- end
- end
- --Menu Routines
- function osMenuM()
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- term.setCursorPos(1,1)
- term.write("M v")
- term.setCursorPos(1,2)
- term.write("Info ")
- term.setCursorPos(1,3)
- term.write("Log Out ")
- term.setCursorPos(1,4)
- term.write("Shut Down")
- osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
- if osPEvent == "mouse_click" then
- if osPB == 1 and osPY == 3 and osPX<=9 then
- osRunning = false
- else if osPB == 1 and osPY == 4 and osPX<=9 then
- os.shutdown()
- else if osPB == 1 and osPY == 2 and osPX<=9 then
- if fs.exists("system/tools/about") then
- shell.run("system/tools/about")
- else
- osBSOD("Critical file missing.","/system/tools/about is missing, and is needed to run.","Please re-install this file")
- end
- end
- end
- end
- end
- end
- function osMenuFile()
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- term.setCursorPos(5,1)
- term.write("File v")
- term.setCursorPos(5,2)
- term.write("Write ")
- term.setCursorPos(5,3)
- term.write("Paint ")
- term.setCursorPos(5,4)
- term.write("Search")
- term.setCursorPos(5,5)
- term.write("build ")
- osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
- if osPB == 1 and osPY == 2 and osPX >= 5 and osPX <= 10 then
- if fs.exists("system/tools/medit") then
- shell.run("system/tools/medit")
- else
- osBSOD("Critical file missing.","/system/tools/medit is missing, and is needed to run.","Please re-install this file")
- end
- else if osPB == 1 and osPY == 3 and osPX >= 5 and osPX <=10 then
- if fs.exists("system/tools/mpaint") then
- shell.run("system/tools/mpaint")
- else
- osBSOD("Critical file missing.","/system/tools/mpaint is missing, and is needed to run.","Please re-install this file")
- end
- else if osPB == 1 and osPY == 5 and osPX >= 5 and osPX <= 10 then
- if fs.exists("run") then
- shell.run("run")
- end
- else if osPB == 1 and osPY == 4 and osPX >= 5 and osPX <= 10 then
- if fs.exists("system/tools/look") then
- shell.run("system/tools/look")
- else
- osBSOD("Critical file missing.","/system/tools/look is missing, and is needed to run.","Please re-install this file")
- end
- end
- end
- end
- end
- end
- function osMenuSystem()
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- term.setCursorPos(12,1)
- term.write("System v")
- term.setCursorPos(12,2)
- term.write("Shell ")
- term.setCursorPos(12,3)
- term.write("Settings ")
- term.setCursorPos(12,4)
- term.write("Run Program")
- osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
- if osPB == 1 and osPY == 2 and osPX >= 12 and osPX <= 22 then
- if osUserAdmin then
- osFillBG(colors.black)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- print("Enter 'exit' to return to MinifOS")
- shell.run("shell")
- return
- else
- osDrawPerm("Shell")
- end
- else if osPB == 1 and osPY == 3 and osPX >= 12 and osPX <=22 then
- if fs.exists("system/tools/settings") then
- shell.run("system/tools/settings")
- return
- else
- osBSOD("Critical file missing.","/system/tools/settings is missing, and is needed to run.","Please re-install this file")
- end
- else if osPB == 1 and osPY == 4 and osPX >= 12 and osPX <= 22 then
- if fs.exists("system/tools/run") then
- shell.run("system/tools/run")
- else
- osBSOD("Critical file missing.","/system/tools/run is missing, and is needed to run.","Please re-install this file")
- end
- end
- end
- end
- end
- --Input Events
- local function handleClick(button,x,y)
- if button == 1 and y == 1 and x <= 3 then
- osMenuM()
- osDrawAll()
- end
- if button == 1 and y == 1 and x >= 5 and x <=10 then
- osMenuFile()
- osDrawAll()
- end
- if button == 1 and y == 1 and x >= 12 and x <=19 then
- osMenuSystem()
- osDrawAll()
- end
- end
- local function menuInput()
- osPEvent, osP1, osP2, osP3, osP4, osP5 = os.pullEvent()
- if osPEvent == "mouse_click" then
- handleClick(osP1,osP2,osP3)
- end
- end
- --Execution
- osLoadPrefs()
- osDrawAll()
- while osRunning do
- menuInput()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement