Clem105

Mine Control

Dec 27th, 2014
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.88 KB | None | 0 0
  1. local m = peripheral.wrap("left")
  2. local modem = peripheral.wrap("back")
  3. os.loadAPI("touch")
  4. t = touch.naw("left")
  5. local Data = {}
  6. local BackupFileName = "IDBackup"
  7. local currPage = 1
  8. local nbPage = 0
  9.  
  10.  
  11. function getID(FileName)
  12.     if fs.exists(FileName) == true then
  13.         h = fs.open(FileName,"r")
  14.         return textutils.unserialize(h.readAll())
  15.     else
  16.         print("Merci de configurer l'ensemble des ID")
  17.     end
  18. end
  19.  
  20. function save(FileName)
  21.     h = fs.open(FileName,"w")
  22.     h.write(textutils.serialize(ID))
  23. end
  24.  
  25. function fillTable()
  26.    local numNames = 0
  27.    local col = 2
  28.    local row = 12
  29.    local countRow = 1
  30.    local currName = 0
  31.    local npp = 12 --names per page
  32.    nbPage = math.ceil(#ID/npp)
  33.       for i = k,v  in pairs(ID) do
  34.        if i > npp*(currPage-1) and i < npp*currPage+1 then
  35.          row = 4+(countRow)
  36.          t:add(k,Mining(ID[i]), col, col+17 , row, row)
  37.          if col == 21 then
  38.            col = 2
  39.            countRow = countRow + 2
  40.          else
  41.            col = col+19
  42.          end
  43.        end
  44.       end
  45.     t:add("Next Page", nextPage, 21, 38, 1, 1)
  46.     t:add("Prev Page", prevPage, 2, 19, 1, 1)
  47.     t:add("Add Filter",addFilter,2,38,19,19)
  48.     t:add("Page :"..tostring(currPage).." of "..tostring(nbPage),nil,15,3,15,3,colors.black,colors.black)
  49.     t:draw()
  50.   end
  51.  
  52. function nextPage()
  53.    if page+1 <= pages then page = page+1 end
  54.    fillTable()
  55. end
  56.  
  57. function prevPage()
  58.    if page-1 >= 1 then page = page-1 end
  59.    fillTable()
  60. end  
  61.  
  62. function addFilter()
  63.     print("Entrez le nom du minerai ")
  64.     Name = read()
  65.     print("Entrez l'ID du minerai ")
  66.     Metadata = read()
  67.     ID[Name] = Metadata
  68.     save(BackupFileName)
  69.     FillTable()
  70. end
  71. --Main Code
  72.  
  73. ID = getID(BackupFileName)
  74. fillTable()
  75. while true do
  76.     local event, p1 = t:handleEvents(os.pullEvent())
  77.     if event == "button_click" then
  78.         t:toggleButton(p1)
  79.         p1.buttonList[p1].func(p1)
  80.         t:toggleButton(p1)
  81.     end
  82. end
Advertisement
Add Comment
Please, Sign In to add comment