Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --connect
- rednet.open("left")
- m = peripheral.wrap("right")
- --Clear
- m.setTextScale(1)
- m.setCursorPos(1,1)
- m.setBackgroundColor(colors.black)
- m.clear()
- --ID
- print(os.getComputerID())
- --listes
- listes_pc = {}
- --Variables
- pcDraw = 0
- page = 1
- pageMax = (math.floor(#listes_pc/10))+1
- ecran = "ecranMain"
- menu = false
- --Function creer Objet
- function creePc(pId, pTable)
- local pc = {}
- pc.id = pId
- pc.job = pTable.job
- pc.etat = pTable.etat
- table.insert(listes_pc, pc)
- print("pc cree")
- end
- --Function draw
- function drawRect(pX,pXMax,pY,pYMax,pColor)
- for x = pX, pXMax do
- for y = pY, pYMax do
- m.setCursorPos(x,y)
- m.setBackgroundColor(pColor)
- m.write(" ")
- end
- end
- end
- function drawBarreNav()
- drawRect(1,82,1,1,colors.gray)
- m.setCursorPos(79,1)
- m.setBackgroundColor(colors.lightGray)
- m.write("home")
- end
- function drawMenu()
- local x = 0
- drawRect(1-x,20-x,1,26,colors.gray)
- end
- function drawMain()
- drawRect(5,35,4,10,colors.red)
- drawRect(45,80,4,10,colors.red)
- drawRect(5,35,17,23,colors.red)
- drawRect(45,80,17,23,colors.red)
- m.setCursorPos(15,6)
- m.write("PC CONNECTE")
- end
- function drawPcCo()
- -- print("page = "..page.." pageMax = ".. pageMax)
- m.setBackgroundColor(colors.black)
- m.setCursorPos(1,2)
- m.write("ID")
- m.setCursorPos(9,2)
- m.write("|")
- m.setCursorPos(10,2)
- m.write("Job")
- m.setCursorPos(20,2)
- m.write("|")
- m.setCursorPos(21,2)
- m.write("Etat")
- m.setCursorPos(30,2)
- m.write("|")
- m.setCursorPos(40,2)
- m.write("|")
- m.setCursorPos(50,2)
- m.write("|")
- m.setCursorPos(60,2)
- m.write("|")
- m.setCursorPos(70,2)
- m.write("|")
- m.setCursorPos(71,2)
- m.write("Delete")
- for n = 1,10 do
- m.setCursorPos(1,(n*2)+1)
- m.write("----------------------------------------------------------------------------------")
- m.setCursorPos(9,(n*2)+2)
- m.write("|")
- m.setCursorPos(20,(n*2)+2)
- m.write("|")
- m.setCursorPos(30,(n*2)+2)
- m.write("|")
- m.setCursorPos(40,(n*2)+2)
- m.write("|")
- m.setCursorPos(50,(n*2)+2)
- m.write("|")
- m.setCursorPos(60,(n*2)+2)
- m.write("|")
- m.setCursorPos(70,(n*2)+2)
- m.write("|")
- end
- if page == pageMax then
- pcDraw = #listes_pc-(page-1)*10
- for n = 1, pcDraw do
- local i = n + (pageMax-1)*10
- m.setCursorPos(1,(n*2)+2)
- m.write(listes_pc[i].id)
- m.setCursorPos(10,(n*2)+2)
- m.write(listes_pc[i].job)
- m.setCursorPos(21,(n*2)+2)
- m.write(listes_pc[i].etat)
- m.setCursorPos(71,(n*2)+2)
- m.setBackgroundColor(colors.red)
- m.write(" x ")
- m.setBackgroundColor(colors.black)
- end
- else
- end
- m.setBackgroundColor(colors.lightGray)
- m.setCursorPos(1,26)
- m.write("<=")
- m.setBackgroundColor(colors.black)
- m.setCursorPos(40,26)
- m.write(page.."/"..pageMax)
- m.setBackgroundColor(colors.lightGray)
- m.setCursorPos(81,26)
- m.write("=>")
- m.setBackgroundColor(colors.black)
- end
- local id = os.getComputerID()
- local t = {
- job = "Moniteur",
- etat = "actif"
- }
- creePc(id,t)
- while true do
- --Draw
- m.setBackgroundColor(colors.black)
- m.clear()
- drawBarreNav()
- if menu == true then
- drawMenu()
- else
- m.setCursorPos(1,1)
- m.setBackgroundColor(colors.lightGray)
- m.write("menu")
- end
- if ecran == "ecranMain" then
- drawMain()
- end
- if ecran == "ecranPcCo" then
- drawPcCo()
- end
- local event, e1, e2, e3 = os.pullEvent()
- --event rednet
- if event == "rednet_message" then
- local id,msg = e1, e2
- local table = textutils.unserialize(msg)
- local test = true
- for n = 1, #listes_pc do
- print(n .. " " .. listes_pc[n].id)
- if id == listes_pc[n].id then
- test = false
- print("test = false")
- break
- end
- end
- if test == true then
- creePc(id, table)
- end
- end
- --event monitor
- if event == "monitor_touch" then
- local x,y = e2,e3
- if x >= 79 and x <= 82 then
- if y >= 1 and y <= 1 then
- ecran = "ecranMain"
- end
- end
- --MainMenu
- if ecran == "ecranMain" then
- --Bouton Haut Gauche
- if x >= 5 and x <= 35 then
- if y >= 4 and y <= 10 then
- ecran = "ecranPcCo"
- end
- end
- --Bouton Haut Droite
- if x >= 45 and x <=75 then
- if y >= 4 and y <= 10 then
- end
- end
- --Bouton bas gauche
- if x >= 5 and x <= 35 then
- if y >= 17 and y <= 23 then
- end
- end
- --Bouton bas droite
- if x >= 45 and x <= 75 then
- if y >= 17 and y <= 23 then
- end
- end
- end
- if ecran == "ecranPcCo" then
- --Boutons delete
- for n = 1, pcDraw do
- if x >= 71 and x <= 73 then
- if y >= (n*2)+2 and y <= (n*2)+3 then
- local i = n + (page-1)*10
- if i ~= 1 then
- rednet.send(listes_pc[i].id, "break")
- table.remove(listes_pc,i)
- end
- end
- end
- end
- --Bouton page-
- if x >= 1 and x <= 2 then
- if y >= 26 and y <= 27 then
- if page ~= 1 then
- page = page - 1
- end
- end
- end
- --Bouton page+
- if x >= 81 and x <= 82 then
- if y >= 26 and y <= 27 then
- if page ~= pageMax then
- page = page + 1
- end
- end
- end
- end
- end
- --event key
- if event == "key" then
- local key = e1
- if ecran == "ecranMain" then
- end
- if ecran == "ecranPcCo" then
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement