Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Autos
- Official Desktop File
- ]]--
- os.pullEvent = os.pullEventRaw
- -- Loading APIs
- os.loadAPI("System/.osfiles/resources/APIs/autos")
- os.loadAPI("System/.osfiles/resources/APIs/settings")
- -- Current Menu | 0 = NONE | 1 = StartMenu |
- slc = 0
- -- Config path
- fs_config = "System/.osfiles/.cfg"
- -- Width, Height of Term
- w,h = term.getSize()
- -- Visibility of the icons
- ico_i1_visible = 1
- ico_i2_visible = 1
- -- Decides what icon should be dragged
- ico_selected = 1
- -- Senses mouse drag
- drag = 0
- dragTime = 0
- -- Senses the computers time
- time = os.startTimer(1)
- -- Shell start messages
- shellMessages = {
- "Check the changelog as well",
- "Also, check out the credits",
- "Click Yellow to go to CraftOS"
- }
- -- Config loading
- if fs.exists(fs_config) then
- loadedCFG = settings.openSettingsFile(fs_config)
- col_mainback = loadedCFG.getSectionedValue("Colors","col_mainback")
- col_maintext = loadedCFG.getSectionedValue("Colors","col_maintext")
- col_butnback = loadedCFG.getSectionedValue("Colors","col_butnback")
- col_butntitl = loadedCFG.getSectionedValue("Colors","col_butntitl")
- col_butntext = loadedCFG.getSectionedValue("Colors","col_butntext")
- col_butnhilt = loadedCFG.getSectionedValue("Colors","col_butnhilt")
- col_titlback = loadedCFG.getSectionedValue("Colors","col_titlback")
- col_titltext = loadedCFG.getSectionedValue("Colors","col_titltext")
- col_titlhilb = loadedCFG.getSectionedValue("Colors","col_titlhilb")
- col_titlhilt = loadedCFG.getSectionedValue("Colors","col_titlhilt")
- oss_ostype = loadedCFG.getSectionedValue("OSSettings","oss_ostype")
- oss_usertype = loadedCFG.getSectionedValue("OSSettings","oss_usertype")
- oss_version = loadedCFG.getSectionedValue("OSSettings","oss_version")
- oss_showIcons = loadedCFG.getSectionedValue("OSSettings","oss_showIcons")
- img_fileIcon1 = loadedCFG.getSectionedValue("Images","img_fileIcon1")
- img_fileIcon2 = loadedCFG.getSectionedValue("Images","img_fileIcon2")
- img_fileBack1 = loadedCFG.getSectionedValue("Images","img_fileBack1")
- ico_i1_x = loadedCFG.getSectionedValue("Icons","ico_i1_x")
- ico_i1_y = loadedCFG.getSectionedValue("Icons","ico_i1_y")
- ico_i2_x = loadedCFG.getSectionedValue("Icons","ico_i2_x")
- ico_i2_y = loadedCFG.getSectionedValue("Icons","ico_i2_y")
- loadedCFG.save(fs_config)
- col_mainback = tonumber(col_mainback)
- col_maintext = tonumber(col_maintext)
- col_butnback = tonumber(col_butnback)
- col_butntitl = tonumber(col_butntitl)
- col_butntext = tonumber(col_butntext)
- col_titlback = tonumber(col_titlback)
- col_titltext = tonumber(col_titltext)
- oss_showIcons = tonumber(oss_showIcons)
- ico_i1_x = tonumber(ico_i1_x)
- ico_i1_y = tonumber(ico_i1_y)
- ico_i2_x = tonumber(ico_i2_x)
- ico_i2_y = tonumber(ico_i2_y)
- ico_i1_visible = tonumber(ico_i1_visible)
- ico_i2_visible = tonumber(ico_i2_visible)
- else
- autos.clean(1,1)
- autos.pError("CRITICAL","OS Error: INVALID CONFIG")
- sleep(0.1)
- autos.pError("TRUBLSHT","Searching for issue fix...")
- sleep(1.5)
- autos.pError("TRUBLSHT","Re-install Autos")
- return
- end
- -- Detects OS type
- if oss_ostype == "acp_normal" then
- userType = "Adv.Computer"
- osType = "Computer Control"
- else
- autos.clean(1,1)
- autos.pError("CRITICAL","OS Error: INVALID OS TYPE")
- sleep(0.1)
- autos.pError("TRUBLSHT","Searching for issue fix...")
- sleep(1.5)
- autos.pError("TRUBLSHT","Re-install Autos")
- return
- end
- -- Loading the icon images
- fileIcon1 = paintutils.loadImage(img_fileIcon1)
- fileIcon2 = paintutils.loadImage(img_fileIcon2)
- -- The start menu
- function drawMenu_Start()
- autos.bColor(col_titlback)
- autos.tColor(col_titltext)
- autos.setCursor(1,15)
- print(" ")
- autos.setCursor(1,16)
- print(" CraftOS ")
- autos.setCursor(1,17)
- print(" Control Panel ")
- autos.setCursor(1,18)
- print(" ")
- end
- -- The title bar
- function draw_titleBar()
- autos.setCursor(1,19)
- autos.bColor(col_titlback)
- term.clearLine()
- autos.bColor(col_titlhilb)
- autos.tColor(col_titlhilt)
- autos.setCursor(1,19)
- print(" START ")
- autos.bColor(col_mainback)
- term.scroll(-1)
- end
- -- Draws the time
- function draw_time()
- autos.tColor(col_titlhilt)
- autos.bColor(col_titlback)
- autos.setCursor(36,19)
- print("Time: "..textutils.formatTime(os.time(),false))
- autos.bColor(col_mainback)
- term.scroll(-1)
- end
- -- Draws the desktop
- function draw_desktop()
- autos.bColor(col_mainback)
- autos.clean(1,1)
- -- Detects if it should draw the icons or not
- if oss_showIcons == 1 then
- if ico_i1_visible == 1 then
- paintutils.drawImage(fileIcon1,ico_i1_x,ico_i1_y)
- autos.setCursor(ico_i1_x+3,ico_i1_y)
- autos.tColor(colors.white)
- autos.bColor(colors.gray)
- print("Lua")
- end
- if ico_i2_visible == 1 then
- paintutils.drawImage(fileIcon2,ico_i2_x,ico_i2_y)
- autos.setCursor(ico_i2_x+2,ico_i2_y)
- autos.tColor(colors.white)
- autos.bColor(colors.gray)
- print("Ctrl")
- end
- end
- draw_titleBar()
- end
- -- Draws a message and does an action (exit or action)
- function launch_message(msg,action,exit)
- autos.draw_Box(11,12,31,3,col_butnback,col_butntitl,"MESSAGE",false)
- autos.bColor(colors.yellow)
- autos.setCursor(40,12)
- print(" ")
- autos.bColor(colors.red)
- autos.setCursor(41,12)
- print(" ")
- autos.bColor(col_butnback)
- autos.tColor(col_butntext)
- if #msg == 29 then
- autos.setCursor(12,13)
- elseif #msg == 27 then
- autos.setCursor(13,13)
- end
- print(msg)
- while true do
- local event,button,X,Y = os.pullEventRaw()
- if event == "mouse_click" then
- -- Detects the red button being clicked
- if X == 41 and Y == 12 and button == 1 then
- -- Launches the exit program (desktop or custom)
- if exit == "desktop" then
- launch_desktop()
- return
- else
- autos.bColor(colors.black)
- autos.clean(1,1)
- shell.run(exit)
- return
- end
- -- Detects the yellow button being clicked
- elseif X == 40 and Y == 12 and button == 1 then
- -- Launches the action program (desktop or custom)
- if action == "desktop" then
- launch_desktop()
- return
- else
- autos.bColor(colors.black)
- autos.clean(1,1)
- shell.run(action)
- return
- end
- end
- -- Computer time timer
- elseif event == "timer" then
- time = os.startTimer(1)
- draw_time()
- end
- end
- end
- -- The main function
- function launch_desktop()
- draw_desktop()
- while true do
- local event,button,X,Y = os.pullEventRaw()
- if event == "mouse_click" then
- -- The current menu (none in this case)
- if slc == 0 then
- -- The start menu being clicked
- if X>=1 and X<=7 and Y==19 and button==1 then
- drawMenu_Start()
- -- Sets the current menu to start menu
- slc = 1
- -- Icon 1's red button being clicked
- elseif X==ico_i1_x+1 and Y==ico_i1_y and button==1 then
- -- Makes Icon 1 invisible
- ico_i1_visible = 0
- draw_desktop()
- -- Icon 2's red button being clicked
- elseif X==ico_i2_x+1 and Y==ico_i2_y and button==1 then
- -- Makes Icon 2 invisible
- ico_i2_visible = 0
- draw_desktop()
- -- Icon 1's green button being clicked
- elseif X==ico_i1_x and Y==ico_i1_y and button==1 then
- -- Makes Icon 1 the selected icon (for dragging)
- ico_selected = 1
- draw_desktop()
- -- Icon 2's green button being clicked
- elseif X==ico_i2_x and Y==ico_i2_y and button==1 then
- -- Makes Icon 2 the selected icon (for dragging)
- ico_selected = 2
- draw_desktop()
- -- Icon 1 being run (Lua prompt)
- elseif X>=ico_i1_x and X<=ico_i1_x+5 and Y>=ico_i1_y+1 and Y<=ico_i1_y+5 and button==1 then
- -- Launches lua prompt message box (action and exit)
- launch_message("Press Yellow to start LUAJCMD","lua","desktop")
- draw_desktop()
- -- Icon 2 being run (control panel)
- elseif X>=ico_i2_x and X<=ico_i2_x+5 and Y>=ico_i2_y+1 and Y<=ico_i2_y+5 and button==1 then
- -- Launches control panel message box (action and exit)
- launch_message("That's not implemented yet...","desktop","desktop")
- draw_desktop()
- end
- -- The current menu (start menu)
- elseif slc == 1 then
- -- Control Panel selected
- if X>=1 and X<=15 and Y==17 and button==1 then
- -- Sets the menu back to none
- slc = 0
- autos.clean(1,1)
- draw_desktop()
- -- Launches control panel message box (action and exit)
- launch_message("That's not implemented yet...","desktop","desktop")
- draw_desktop()
- -- CraftOS launched
- elseif X>=1 and X<=15 and Y==16 and button==1 then
- -- Sets the menu back to none
- slc = 0
- autos.clean(1,1)
- draw_desktop()
- -- Launches the shell message box (action and exit)
- launch_message(shellMessages[math.random(1,#shellMessages)],"shell","desktop")
- return
- -- This debugs the menu and sets it back to none
- else
- slc = 0
- autos.clean(1,1)
- draw_desktop()
- end
- end
- -- The computer clock's timer
- elseif event == "timer" then
- -- Button is actually the timer's label
- if button==time then
- time = os.startTimer(1)
- draw_time()
- -- Again, button is the timer's label
- elseif button==dragTime then
- -- Detects dragging
- drag = false
- end
- elseif event == "mouse_drag" then
- -- Detects the current menu (none here)
- if slc == 0 then
- -- The current icon selected (chooses which one to drag)
- if ico_selected == 1 then
- -- Says its dragging
- drag = 1
- dragTime = os.startTimer(1)
- -- Sets the new coords for the icon
- ico_i1_x = X
- ico_i1_y = Y
- loadedCFG = settings.openSettingsFile(fs_config)
- loadedCFG.setSectionedValue("Icons","ico_i1_x",X)
- loadedCFG.setSectionedValue("Icons","ico_i1_y",Y)
- loadedCFG.save(fs_config)
- draw_desktop()
- -- Does it all again until user stops dragging
- if drag == 1 then
- dragTime = os.startTimer(1)
- ico_i1_x = X
- ico_i1_y = Y
- loadedCFG = settings.openSettingsFile(fs_config)
- loadedCFG.setSectionedValue("Icons","ico_i1_x",X)
- loadedCFG.setSectionedValue("Icons","ico_i1_y",Y)
- loadedCFG.save(fs_config)
- draw_desktop()
- end
- -- Repeat of previous except for Icon 2
- elseif ico_selected == 2 then
- drag = 1
- dragTime = os.startTimer(1)
- ico_i2_x = X
- ico_i2_y = Y
- loadedCFG = settings.openSettingsFile(fs_config)
- loadedCFG.setSectionedValue("Icons","ico_i2_x",X)
- loadedCFG.setSectionedValue("Icons","ico_i2_y",Y)
- loadedCFG.save(fs_config)
- draw_desktop()
- if drag == 1 then
- dragTime = os.startTimer(1)
- ico_i2_x = X
- ico_i2_y = Y
- loadedCFG = settings.openSettingsFile(fs_config)
- loadedCFG.setSectionedValue("Icons","ico_i2_x",X)
- loadedCFG.setSectionedValue("Icons","ico_i2_y",Y)
- loadedCFG.save(fs_config)
- draw_desktop()
- end
- end
- end
- end
- end
- end
- -- The start of the program (FRESH AND CLEAN)
- autos.bColor(col_mainback)
- autos.clean(1,1)
- launch_desktop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement