Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- --VARS------------------------------------------------------------------------
- local Path = A.RCpath()
- local conf = A.getT(Path)
- local User = A.RUser()
- local rng = true
- local Exit = nil
- local cm = 0
- local i = conf["BCI"]
- local xy = {0,0}
- local xy2= {0,0,1}
- local w,h = term.getSize()
- local tbi = {} -- this table sets up for picking images for icons
- local tbl = {} -- this keep the cords for tbi
- local tbP = {} -- sets up program change
- local tbl2 = {}
- local tbd = {}--used for the draging of icons
- local t = nill
- local wh = {term.getSize()}
- local Inumber = nil -- get to backgones
- local drag = {false,1,false}--is draged,index, (is currnetly draging)
- local src = "os/users/"..User.."/conf"
- --Buffers----------------------------------------------------------------
- local BPicon = buf.createBuffer()
- local BNicon = buf.createBuffer()
- local bdm = A.Rmeun()
- --Setup--------------------------------------------------------------------
- local programs = {
- programs_defaults = {
- __index = {
- image = "os/images/icons/icon1";
- localtion = nil;
- };
- };
- meta = {
- __newindex = function(t, key, value) --(posX, posY) or possition
- assert(type(value)=="table","Requires a table")
- if value.possition==nil then
- assert(value.posX,"Requires a X")
- assert(value.posY,"Requires a y")
- end
- value.name = value.name or nil
- setmetatable(value, t.programs_defaults)
- value.possition = value.possition or t:checkPossitions(value.posX,value.posY)
- if value.possition ==nil then
- return false
- end
- value.drag = false
- for index,k in pairs(t.programs) do
- if k.possition==value.possition then
- return false
- end
- end
- table.insert(t.programs,value)
- end;
- __call = function(self)
- for v,k in pairs(self.programs) do
- if not k.drag then
- buf.drawImage(bdm,self.possitions[k.possition][1],self.possitions[k.possition][2],k.image)
- else
- buf.drawImage(bdm,k.posX,k.posY,k.image)
- end
- end
- end;
- };
- possitions = {};
- setPossistions = function(self)
- local w,h = term.getSize()
- for x=2, w, 6 do
- if x+4<w then
- for y = 2, h, 6 do
- if y+4<h then
- table.insert(self.possitions,{[1]=x;[2]=y;[3]=x+4;[4]=y+4;})
- end
- end
- end
- end
- end;
- checkPossitions = function(self,x,y)
- for v,k in pairs(self.possitions) do
- if x>=k[1] and x<=k[3] then
- if y>=k[2] and y<=k[4] then
- return v
- end
- end
- end
- return false
- end;
- check_click = function(self,x,y) --returns a index
- for index,k in pairs(self.programs) do
- local pos = self:checkPossitions(x,y)
- if pos and pos==k.possition then
- return index
- end
- end
- return false
- end;
- return_XYindex = function(self,index)
- local pos = self.programs[index].possition
- return self.possitions[pos]
- end;
- run_program = function(self,index)
- assert(type(index)=="number","requires an index")
- if self.programs[index].localtion~=nil then
- if fs.exists(self.programs[index].localtion) then
- shell.run(self.programs[index].localtion)
- --sleep(2)
- return true
- end
- end
- return false
- end;
- remove_program = function(self,index)
- assert(type(index)=="number", "Requires A Index")
- self.programs[index] = nil
- return true
- end;
- save_programs = function(self,localtion)
- local file = fs.open(localtion, "w")
- file.write(textutils.serialize(self.programs))
- file.close()
- end;
- load_programs = function(self,localtion)
- if pcall(function()
- if fs.exists(localtion) then
- local file = fs.open(localtion,"r")
- local data = file.readAll()
- file.close()
- self.programs = textutils.unserialize(data)
- else
- self.programs = {}
- return false
- end
- for v,k in pairs(self.programs) do
- setmetatable(k,self.programs_defaults)
- end
- for v,k in pairs(self.programs)do
- if k.drag == true then
- k.drag = false
- end
- end
- end) then
- return true
- else
- return false
- end
- end;
- change_Pogram = function(self,index,localtion)
- assert(type(index)=="number", "Requires a Index")
- assert(type(localtion)=="string", "Requires a Localtion")
- if not fs.exists(localtion) then
- error("Requires a Adiquit Localtion")
- end
- self.programs[index].localtion = localtion
- end;
- change_image = function(self,index,localtion)
- assert(type(index)=="number", "Requires a Index")
- assert(type(localtion)=="string", "Requires a Localtion")
- if not fs.exists(localtion) then
- error("Requires a Adiquit Localtion")
- end
- self.programs[index].image = localtion
- end;
- change_possistion = function(self,index,possition)
- assert(type(index)=="number", "Requires a Index")
- assert(type(possition)=="number", "Requires a Possition")
- local taken = false
- for v,k in pairs(self.programs) do
- if k.possition == possition then taken = true end
- end
- if taken then return false end
- self.programs[index].possition = possition
- self.programs[index].drag = false
- return true
- end;
- change_possistionXY = function(self,index,posX, posY)
- assert(type(index)=="number", "Requires a Index")
- assert(type(posX)=="number", "Requires a X")
- assert(type(posY)=="number", "Requires a Y")
- local pos = self:checkPossitions(self,x,y)
- if not pos then return false end
- local taken = false
- for v,k in pairs(self.programs) do
- if k.possition == pos then taken = true end
- end
- if taken then return false end
- self.programs[index].possition = pos
- self.programs[index].drag = false
- return true
- end;
- change_possistionDrag = function(self,index,posX,posY)
- assert(type(index)=="number", "Requires a Index")
- assert(type(posX)=="number", "Requires a X")
- assert(type(posY)=="number", "Requires a Y")
- self.programs[index].drag = true
- if posX < 0 then
- error("196- Change_possistionDrag: Illegal possistion X: Index>"..index.." posX>"..posX,2)
- elseif posX > w-4 then
- posX = w-4
- end
- if posY < 0 then
- error("196- Change_possistionDrag: Illegal possistion Y: Index>"..index.." posX>"..posX,2)
- elseif posY > h-5 then
- posY = h-5
- end
- self.programs[index].posX = posX
- self.programs[index].posY = posY
- end;
- returnDrag = function(self,index)
- assert(type(index)=="number", "Requires a Index")
- if self.programs[index].drag then
- if self.programs[index].possition then
- self.programs[index].drag=false
- return true
- end
- end
- return false
- end;
- draw_blank = function(self)
- for i=1,24 do
- local d = true -- this draws it
- for v,k in pairs(self.programs) do
- if self.programs[v].possition==i then d = false end
- end
- if d then
- paintutils.drawImage(paintutils.loadImage("os/images/icons/blank"),self.possitions[i][1],self.possitions[i][2])
- end
- end
- end;
- compare_image = function(self,localtion)
- for index,k in pairs(self.programs) do
- if self.programs[index].image==localtion then
- return index
- end
- end
- return false
- end;
- compare_program = function(self,localtion)
- for index,k in pairs(self.programs) do
- if self.programs[index].localtion==localtion then
- return index
- end
- end
- return false
- end;
- programs = {};
- }
- function setup()
- programs:setPossistions()
- setmetatable(programs, programs.meta) --sets the metatable from meta to button
- programs:load_programs(src)
- end
- function setT(srcs,save)
- if type(srcs)=="string" and fs.exists(srcs) then
- local file = fs.open(srcs,"w")
- file.write(textutils.serialize(save))
- file.close()
- else
- error("tried to load unkown file: "..srcs)
- end
- end
- function getT(srcs,save) -- save = 1 or 1 == config
- if type(srcs)=="string" and fs.exists(srcs) and type(save)=="number" then
- local file = fs.open(srcs,"r")
- local data = file.readAll()
- file.close()
- if save==0 then
- icons = textutils.unserialize(data)
- elseif save==1 then
- --used for config
- else
- end
- else
- error("tried to load unkown file: "..srcs)
- end
- end
- local function getUser()
- Path = A.RCpath()
- conf = A.getT(Path)
- User = A.RUser()
- src = "os/users/"..User.."/conf"
- end
- function Picon()
- buf.copyBuffer(bdm,BPicon)
- tbP = { }
- tbPL = {} --used for finding if the program is public, private, or on the desktop
- for v,k in ipairs(fs.list("os/programs")) do --Public Programs
- if fs.isDir("os/programs/"..k) then
- for s,d in ipairs(fs.list("os/programs/"..k)) do
- table.insert(tbP,k.."/"..d)
- table.insert(tbPL,1)
- end
- else
- table.insert(tbP,k)
- table.insert(tbPL,1)
- end
- end
- for v,k in ipairs(fs.list("")) do --Desktop Programs
- if fs.isDir(k) then
- if k~="os" and k~="rom" then
- for s,d in ipairs(fs.list(k)) do
- table.insert(tbP,k.."/"..d)
- table.insert(tbPL,0)
- end
- end
- else
- if k ~= "startup" then
- table.insert(tbP,k)
- table.insert(tbPL,0)
- end
- end
- end
- local filepos = "os/users/"..User.."/programs"
- if fs.exists(filepos) then --Private Programs
- for v,k in ipairs(fs.list(filepos)) do
- filepos = filepos .."/"
- if fs.isDir(filepos..k) then
- for s,d in ipairs(fs.list(filepos..k)) do
- table.insert(tbP,k.."/"..d)
- table.insert(tbPL,2)
- end
- else
- table.insert(tbP,k)
- table.insert(tbPL,2)
- end
- end
- end
- local x = 7
- local y = 2
- local x2 = w-8
- local y2 = h-1
- buf.drawFilledBox(BPicon,x,y,x2,y2,colors.white)
- buf.drawBox(BPicon,x,y,x2,y2,colors.black)
- buf.drawLine(BPicon,x2-1,y+1,x2-1,y2-1,colors.orange)
- buf.drawPixel(BPicon,x2-1,y+1,colors.red)
- buf.drawPixel(BPicon,x2-1,y2-1,colors.red)
- buf.pos(x2-1,y+1)
- buf.bWrite(BPicon,"^",colors.white,colors.red)
- buf.pos(x2-1,y2-1)
- buf.bWrite(BPicon,"v",colors.white,colors.red)
- local X = x+2
- local Y = y+1
- buf.bc(colors.white)
- buf.tc(colors.black)
- for v,k in ipairs(tbP) do
- buf.pos(X,Y)
- buf.bWriteL(BPicon,k)
- local t = {X-1,Y,X+#k,k,tbPL[v]}
- table.insert(tbl2,t)
- Y=Y+1
- end
- buf.drawBuffer(BPicon)
- end
- function Nicon()
- buf.copyBuffer(bdm,BNicon)
- tbi = {}
- for v,k in ipairs(fs.list("os/images/icons")) do
- if fs.isDir("os/images/icons/"..k) then
- for s,d in ipairs(fs.list("os/images/icons/"..k)) do
- table.insert(tbi,k.."/"..d)
- end
- else
- if k=="blank" then
- else
- table.insert(tbi,k)
- end
- end
- end
- local imgN = math.ceil(#tbi/2)
- local x = math.ceil((w/2) - ((imgN*5+(imgN+3))/2))
- local y = math.ceil((h/2) - ((2*5+4)/2))
- local x2 = x+(imgN*6+2)
- local y2 = y+14
- buf.drawFilledBox(BNicon,x,y,x2,y2,colors.black)
- buf.drawBox(BNicon,x,y,x2,y2,colors.white)
- local cx = x+2
- local cy = y+2
- for v,k in ipairs(tbi) do
- buf.drawImage(BNicon,cx,cy,"os/images/icons/"..k)
- local t = {cx,cy,cx+5,cy+5,k}
- table.insert(tbl,t)
- if cy==y+2+6 then
- cy=cy-6
- cx=cx+6
- else
- cy=cy+6
- end
- end
- buf.drawBuffer(BNicon)
- end
- function dm()
- conf = A.getT(A.RCpath())
- buf.bc(conf["BCC"])
- A.dmeun(conf["BCI"],1,1)
- programs()
- buf.drawBuffer(bdm)
- A.Time(wh[1]-4,wh[2],conf["MC"],conf["MTC"])
- end
- -------------------------------------------------------------------------
- function main()
- setup()
- dm()
- t = os.startTimer(.1)
- while rng do
- getUser()
- local arg = { os.pullEvent() }
- programs:save_programs(src)
- --cm0------------------------------------------------------------------
- if arg[1]=="timer" and arg[2]==t then
- A.Time(wh[1]-4,wh[2],conf["MC"],conf["MTC"])
- t = os.startTimer(.01)
- elseif cm==0 then
- --Main Meun nothing open
- if arg[1]=="mouse_click" then
- if arg[2]==1 then
- if arg[3]>=2 and arg[3]<=8 and arg[4]==1 then
- A.dmeun1()
- cm=1
- else
- local x = arg[3]
- local y = arg[4]
- local index = programs:check_click(x,y)
- if index then
- tbd = {arg[3],arg[4],index}
- cm=9 --check double click and drag
- end
- end
- elseif arg[2]==2 then
- local x = arg[3]
- local y = arg[4]
- local index = programs:check_click(x,y)
- if index then
- local t = programs:return_XYindex(index) --table returned
- xy2 = {t[1],t[2],t[1]+14,t[2]+4,index}
- A.dmeun3(xy2)
- cm=3
- else
- xy = A.dmeun2(arg[3],arg[4])
- cm=2
- end
- end
- end
- --cm1------------------------------------------------------------------
- elseif cm==1 then
- --start meun
- if arg[1]=="mouse_click" then
- if arg[2]==1 then
- if arg[3]<=11 and arg[3]>1 then
- if arg[4]==3 then
- dm()
- rng=false
- Exit = "log"
- elseif arg[4]==4 then
- os.shutdown()
- elseif arg[4]==5 then
- os.reboot()
- elseif arg[4]==6 then
- dm()
- if A.userin(2,3,2) then
- rng=false
- Exit = "Manage"
- end
- elseif arg[4]==7 then
- shell.run("os/APIS/fig")
- YN = A.ExitIS(false)
- A.ExitIS(true,false)
- if YN then
- rng=false
- Exit="log"
- else
- dm()
- end
- t = os.startTimer(.3)
- end
- end
- end
- cm=0
- dm()
- end
- --cm2-----------------------------------------------------------------------
- elseif cm==2 then
- --right click meun
- local d = false
- if arg[1]=="mouse_click" then
- if arg[2]==1 then
- if arg[3]>=xy[1] and arg[3]<=xy[1]+11 then
- if arg[4]==xy[2]+1 then
- d="add Icon"
- elseif arg[4]==xy[2]+2 then
- A.dmeun7(xy)
- d="programs"
- elseif arg[4]==xy[2]+3 then
- dm()
- local input = A.userin(2,3,1)
- shell.run("paint",input) ---new icon
- elseif arg[4]==xy[2]+4 then
- end
- t = os.startTimer(.3)
- end
- end
- if d=="add Icon" then
- cm=4
- dm()
- elseif d=="programs" then
- cm=10
- else
- cm=0
- dm()
- end
- end
- --cm3-------------------------------------------------------------------
- elseif cm==3 then
- --right click on icons
- if arg[1]=="mouse_click" then
- term.setBackgroundColor(colors.blue)
- if arg[2]==1 then
- if arg[3]>=xy2[1] and arg[3]<=xy2[3]+10 then
- if arg[4]==xy2[4]+2 then
- cm=5
- dm()
- Nicon()
- elseif arg[4]==xy2[4]+3 then
- dm()
- Picon()
- cm=6
- elseif arg[4]==xy2[4]+4 then
- programs:remove_program(xy2[5])
- cm=0
- dm()
- else
- cm=0
- dm()
- end
- else
- cm=0
- dm()
- end
- else
- cm=0
- dm()
- end
- end
- --cm4-------------------------------------------------------------------
- elseif cm==4 then
- programs:draw_blank()
- --add icon
- if arg[1] == "mouse_click" then
- if arg[2]==1 then
- local x = arg[3]
- local y = arg[4]
- local cpos = programs:checkPossitions(x,y)
- if cpos then
- programs[1] = {possition = cpos;}
- dm()
- end
- end
- cm=0
- dm()
- end
- --cm5-------------------------------------------------------------------
- elseif cm==5 then
- --icon image meun
- if arg[1] == "mouse_click" then
- local ok = false
- for v,k in ipairs(tbl) do
- if arg[3]>=k[1] and arg[3]<=k[3] then
- if arg[4]>=k[2] and arg[4]<=k[4] then
- if arg[2]==1 then
- programs:change_image(xy2[5],"os/images/icons/"..k[5])
- cm=0
- elseif arg[2]==2 then
- ok = true
- Inumber = k
- end
- end
- end
- end
- if ok then
- A.dmeun4(Inumber[1],Inumber[4])
- cm=7
- else
- dm()
- cm=0
- end
- end
- --cm6--------------------------------------------------------------------
- elseif cm==6 then
- --program icon meun
- local ok = false
- if arg[1] == "mouse_click" then
- for v,k in ipairs(tbl2) do
- if arg[3]>=k[1] and arg[3]<=k[3] then
- if arg[4]==k[2] then
- if arg[2]==1 then
- if k[5] == 0 then
- programs:change_Pogram(xy2[5],k[4])
- elseif k[5] == 1 then
- programs:change_Pogram(xy2[5],"os/programs/"..k[4])
- elseif k[5] == 2 then
- programs:change_Pogram(xy2[5],"os/users/"..tostring(User).."/programs/"..k[4])
- end
- elseif arg[2]==2 then
- ok = true
- Inumber = k
- else
- cm=0
- dm()
- end
- end
- end
- end
- if ok then
- A.dmeun4(Inumber[1],Inumber[2]+1)
- cm=8
- else
- dm()
- cm=0
- end
- end
- elseif cm==7 then
- --right clikc image icon meun
- if arg[1] == "mouse_click" then
- if arg[2]==1 then
- if arg[3]>=Inumber[1] and arg[3]<=Inumber[3] then -- checks the x
- if arg[4] == Inumber[4]+1 then
- shell.run("paint","os/images/icons/"..Inumber[5])
- elseif arg[4] == Inumber[4]+2 then
- fs.delete("os/images/icons/"..Inumber[5])
- local index = programs:compare_image(Inumber[5])
- if type(index)=="number" then
- programs:change_image(index,"os/images/icons/icon1")
- end
- end
- t = os.startTimer(.3)
- end
- cm=5
- dm()
- Nicon()
- end
- end
- elseif cm==8 then
- if arg[1] == "mouse_click" then
- if arg[2]==1 then --Inumber = 1-first x 2-Y 3-second x 4-program name
- if arg[3]>Inumber[1] and arg[3]<Inumber[1]+9 then
- if arg[4]==Inumber[2]+2 then --Edit Program
- if Inumber[5] == 0 then --desktop
- shell.run("edit",Inumber[4])
- elseif Inumber[5] == 1 then --Public
- shell.run("edit","os/programs/"..Inumber[4])
- elseif Inumber[5] == 2 then --Private
- shell.run("edit","os/users/"..tostring(User).."/programs/"..Inumber[4])
- end
- elseif arg[4]==Inumber[2]+3 then --delete Program
- if Inumber[5] == 0 then --desktop
- shell.run("delete",Inumber[4])
- elseif Inumber[5] == 1 then --Public
- shell.run("delete","os/programs/"..Inumber[4])
- elseif Inumber[5] == 2 then --Private
- shell.run("delete","os/users/"..tostring(User).."/programs/"..Inumber[4])
- end
- local index = programs:compare_image(Inumber[4])
- if index then
- programs:change_image(index,"")
- end
- end
- end
- end
- cm=6
- Picon()
- end
- elseif cm==9 then
- if arg[1]=="mouse_drag" then
- if drag[1] and drag[3] then
- programs:change_possistionDrag(drag[2],arg[3],arg[4])
- elseif not drag[3] then
- local index = programs:check_click(arg[3],arg[4])
- if index then
- drag[1]=true
- drag[2]=index
- drag[3]=true
- programs:change_possistionDrag(drag[2],arg[3],arg[4])
- end
- end
- dm()
- elseif arg[1] == "mouse_click" then
- if arg[2]==1 then
- local x = arg[3]
- local y = arg[4]
- local index = programs:check_click(x,y)
- if index then
- programs:run_program(tbd[3])
- cm=0
- t = os.startTimer(.3)
- dm()
- else
- cm=0
- end
- end
- dm()
- elseif arg[1] == "mouse_up" then
- if drag[1] then
- local pos = programs:checkPossitions(arg[3],arg[4])
- if pos then
- programs:change_possistion(drag[2],pos)
- else
- programs:returnDrag(drag[2])
- end
- drag[1]=false
- end
- drag[3] = false
- dm()
- else
- cm=0
- dm()
- end
- elseif cm==10 then --new programs code, for desk,Public, and Private
- if arg[1] == "mouse_click" then
- if arg[2]==1 then
- dm()
- if arg[3]>=xy[1] and arg[3]<=xy[1]+11 then
- if arg[4]==xy[2]+1 then
- local input = A.userin(2,3,0)
- shell.run("edit",input) ---new icon
- elseif arg[4]==xy[2]+2 then
- local input = A.userin(2,3,0)
- shell.run("edit","os/programs/"..input) ---new icon
- elseif arg[4]==xy[2]+3 then
- local input = A.userin(2,3,0)
- shell.run("edit","os/users/"..User.."/programs/"..input) ---new icon
- elseif arg[4]==xy[2]+4 then
- shell.run("os/APIS/PastebinGet")
- end
- t = os.startTimer(.3)
- end
- end
- dm()
- cm=0
- end
- end
- end
- ----------------------------------------------------------------------
- if Exit == "log" or Exit == "Manage" then
- else
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- end
- return true
- end
- local ok, err = pcall(main)
- if not ok then
- A.Error(err)
- end
- if Exit == "Manage" then
- shell.run("os/APIS/manage")
- elseif Exit == "log" then
- shell.run("os/login")
- end
Add Comment
Please, Sign In to add comment