Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("matchItem.lua")
- mi = _G["matchItem.lua"]
- curBrowse = "db"
- curPage = 1
- lineSel = 0
- db = {}
- function initDb()
- file = fs.open("blockId.db", "r")
- data = file.readAll()
- file.close()
- return textutils.unserialize(data)
- end
- function getId()
- key=nil
- id=""
- term.setCursorPos(34, lineSel)
- term.blit(" ", "ffffff", "555555")
- term.setCursorPos(34, lineSel)
- while true do
- local event,key = os.pullEvent("key")
- if key>=2 and key <=11 then
- if key==11 then
- key=0
- else
- key=key-1
- end
- if string.len(id) < 4 then
- term.blit(tostring(key), "f","5")
- id = id .. tostring(key)
- end
- end
- if key==28 then
- if confirmChange() then
- saveChanges(id)
- end
- drawScreen(id)
- break
- end
- end
- end
- function saveChanges(id)
- if id=="" or id==nil then return end
- if curBrowse == "db" then
- db[(lineSel-1)+((curPage-1)*12)].id = tonumber(id)
- else
- newItem = { newId = db[(lineSel-1)+((curPage-1)*12)].newId, id = id }
- db = initDb()
- table.insert(db, newItem)
- curBrowse = "db"
- end
- local file = fs.open("blockId.db", "w")
- data = textutils.serialize(db)
- file.write(data)
- file.close()
- end
- function confirmChange()
- local win = window.create(term.current(), 12, 6, 18, 4, true)
- win.setBackgroundColor(colors.lightBlue)
- win.setTextColor(colors.black)
- win.clear()
- win.setCursorPos(2,2)
- win.write("Confirm changes?")
- win.setCursorPos(4,3)
- win.write("(y)es / (n)o")
- key=0
- while true do
- local _,key = os.pullEvent("key")
- if key == 21 then
- return true
- end
- if key == 49 then
- return false
- end
- end
- end
- function selectLine(y, inverse)
- if (y-1)+((curPage-1)*12)>table.getn(db) then return end
- if inverse then
- term.setBackgroundColor(colors.yellow)
- term.setTextColor(colors.black)
- end
- term.setCursorPos(1, y)
- term.clearLine()
- term.write(db[(y-1)+((curPage-1)*12)].newId)
- term.setCursorPos(34, y)
- term.write(db[(y-1)+((curPage-1)*12)].id)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- lineSel=y
- end
- function drawScreen()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- if curBrowse == nil then curBrowse = "db" end
- if curPage == nil then curPage = 1 end
- if curBrowse=="db" then
- term.blit("Scan chest","0000000000", "3333333333")
- else
- term.blit("Scan db","0000000", "3333333")
- end
- term.setCursorPos(12,1)
- term.blit("Next","0000", "3333")
- term.setCursorPos(17,1)
- term.blit("Previous","00000000", "33333333")
- term.setCursorPos(26,1)
- term.blit("Modify Id","000000000", "333333333")
- term.setCursorPos(36,1)
- term.blit("Quit","0000", "3333")
- for i=1,12 do
- if i+((curPage-1)*12)>table.getn(db) then break end
- term.setCursorPos(1, i+1)
- term.write(db[i+((curPage-1)*12)].newId)
- term.setCursorPos(34, i+1)
- term.write(db[i+((curPage-1)*12)].id)
- end
- end
- db = initDb()
- drawScreen()
- local chest = peripheral.wrap("bottom")
- quit=false
- while quit==false do
- local _,_,x,y = os.pullEvent("mouse_click")
- if y==1 then
- -- NEXT BUTTON
- if x>=12 and x<=15 then
- if (curPage+1)*12 < table.getn(db)+12 then
- curPage=curPage+1
- print(curPage)
- lineSel=0
- drawScreen()
- end
- end
- -- PREVIOUS BUTTON
- if x>=17 and x<=24 then
- if curPage>1 then
- curPage=curPage-1
- lineSel=0
- drawScreen()
- end
- end
- -- MODIFY ID BUTTON
- if x>=26 and x<=34 then
- if lineSel>0 then
- if curBrowse == "db" then
- getId()
- else
- if db[lineSel-1].id == nil then
- getId()
- end
- end
- end
- end
- -- SCAN CHEST/DB NUTTON
- if x>=1 and x<=10 then
- if curBrowse == "db" then
- db = mi.getAllStacks(chest)
- curBrowse = "chest"
- else
- db = initDb()
- curBrowse = "db"
- end
- curPage = 1
- lineSel = 0
- drawScreen()
- end
- -- QUIT BUTTON
- if x>=36 and x<=39 then
- term.clear()
- quit=true
- end
- else
- if lineSel > 0 then
- selectLine(lineSel, false)
- end
- selectLine(y, true)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement