Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modem = peripheral.wrap("bottom")
- modem.open(105)
- modem.open(6105)
- PagePlus = function()
- page = page + 1
- if page>LastPage then
- page = LastPage
- end
- end
- PageMoins = function()
- page = page - 1
- if page<1 then
- page = 1
- end
- end
- function Panel()
- os.loadAPI("touch")
- monitor = peripheral.wrap("top")
- xMin = {27,3,15,}
- xMax = {37,13,25,}
- yMin = {2,6,10,14,18}
- yMax = {4,8,12,16,20}
- local h = fs.open("Liste","r")
- temp = h.readAll()
- modem.transmit(105,105,temp)
- tableau = textutils.unserialize(temp)
- h.close()
- lastNumber = 0
- page = 1
- screen = {}
- for i=1,(math.ceil(#tableau/15)) do
- screen[i] = touch.new("top")
- end
- LastPage = #screen
- if LastPage ~= 1 then
- for a=1,(LastPage-1) do
- for b=1,15 do
- xMinCord = xMin[b%3+1]
- xMaxCord = xMax[b%3+1]
- yMinCord = yMin[math.ceil(b/3)]
- yMaxCord = yMax[math.ceil(b/3)]
- screen[a]:add(tableau[(a-1)*15+b],nil,xMinCord,yMinCord,xMaxCord,yMaxCord,colors.red,colors.lime)
- end
- screen[a]:add("<<Page",function() PageMoins() end,6,23,17,25,colors.red,colors.lime)
- screen[a]:add("Page>>",function() PagePlus() end,22,23,33,25,colors.red,colors.lime)
- end
- end
- o = #tableau%15
- lastNumber = o%3
- screen[LastPage]:add("<<Page",function() PageMoins() end,6,23,17,25,colors.red,colors.lime)
- screen[LastPage]:add("Page>>",function() PagePlus() end,22,23,33,25,colors.red,colors.lime)
- if o>2 then
- for i=1,(o-lastNumber) do
- xMinCord = xMin[i%3+1]
- xMaxCord = xMax[i%3+1]
- yMinCord = yMin[math.ceil(i/3)]
- yMaxCord = yMax[math.ceil(i/3)]
- screen[LastPage]:add(tableau[(LastPage-1)*15+i],nil,xMinCord,yMinCord,xMaxCord,yMaxCord,colors.red,colors.lime)
- end
- end
- if lastNumber == 1 then
- screen[LastPage]:add(tableau[#tableau],nil,15,yMin[math.ceil(o/3)],25,yMax[math.ceil(o/3)],colors.red,colors.lime)
- elseif lastNumber == 2 then
- screen[LastPage]:add(tableau[#tableau-1],nil,9,yMin[math.ceil(o/3)],19,yMax[math.ceil(o/3)],colors.red,colors.lime)
- screen[LastPage]:add(tableau[#tableau],nil,21,yMin[math.ceil(o/3)],31,yMax[math.ceil(o/3)],colors.red,colors.lime)
- end
- while true do
- screen[page]:draw()
- monitor.setCursorPos(15,22)
- monitor.setBackgroundColor(colors.black)
- monitor.write("Page "..page.." of "..LastPage)
- local event, p1 = screen[page]:handleEvents(os.pullEvent())
- if event == "button_click" then
- if type(screen[page].buttonList[p1].func) == "function" then
- screen[page].buttonList[p1].func()
- else
- screen[page]:flash(p1,0.5)
- modem.transmit(105,106,"open")
- modem.transmit(105,104,p1)
- end
- end
- end
- end
- function Modem()
- local s = true
- local work = false
- while true do
- local event,side,channel,channelbis,msg = os.pullEvent("modem_message")
- if channel == 6105 then
- tab = textutils.unserialize(msg)
- local n = fs.open("Liste","r")
- texte = n.readAll()
- t = textutils.unserialize(texte)
- if tab[2] == "rm" then
- for j = 1,#t do
- if t[j] == tab[1] then
- table.remove(t,j)
- work = true
- modem.transmit(6105,105,"ok")
- end
- end
- if work == false then
- modem.transmit(6105,105,"non")
- end
- elseif tab[2] == "w" then
- for j = 1,#t do
- if t[j] == tab[1] then
- s = false
- end
- end
- if s then
- table.insert(t,tab[1])
- end
- end
- n.close()
- fs.delete("Backup")
- fs.copy("Liste","Backup")
- fs.delete("Liste")
- n = fs.open("Liste","w")
- txt = textutils.serialize(t)
- n.write(txt)
- n.close()
- os.reboot()
- end
- end
- end
- parallel.waitForAll(Panel,Modem)
Add Comment
Please, Sign In to add comment