Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("touchpoint") --Personalized and modified Touchpoint API
- -- API Pastebin: 5QLmjqT1
- local storage = peripheral.wrap("right")
- local chestDir = "east"
- local chestSize = 54
- local mon = peripheral.wrap("top")
- local totalCows = 0
- local cowList = {}
- local cowListNames = {}
- mon.setTextScale(1)
- local maxX, maxY = mon.getSize()
- local keyboardPos = {}
- local searchChars = {}
- local foundCows = {}
- local currPage = 1
- local lastPage = 1
- local tp
- local buttonList = {}
- local searchButtonList = {}
- local pages = {}
- local emptyLabel = {
- " Empty Chest ",
- "Into Storage ",
- label = "emptyChest"
- }
- local refreshLabel = {
- " Refresh ",
- " Screen ",
- label = "refreshScreen"
- }
- local searchLabel = {
- " _ ",
- "|_|",
- "/ ",
- label = "search"
- }
- local prevLabel = {
- " ",
- " < ",
- " ",
- label = "prevPage"
- }
- local nextLabel = {
- " ",
- " > ",
- " ",
- label = "nextPage"
- }
- function searchCows(str)
- lastPage = currPage
- currPage = "search"
- tp = pages[currPage]
- end
- function closeSearch(str)
- currPage = lastPage
- lastPage = "search"
- tp = pages[currPage]
- end
- function refreshScreen(str)
- --doesn't need to do anything else
- end
- function emptyChest(str)
- local cnt = 0
- for i = 1, 54, 1 do
- local num = storage.pullItem(chestDir, i)
- cnt = cnt + num
- end
- print("Moved "..cnt.." items into storage.")
- pollStorage()
- makeCowList()
- end
- for i=1,5,1 do
- pages[i] = touchpoint.new("top")
- pages[i]:add(emptyLabel, emptyChest, 1, maxY-1, 14, maxY, colors.blue, colors.lightBlue)
- pages[i]:add(refreshLabel, refreshScreen, maxX-10, maxY-1, maxX, maxY, colors.blue, colors.lightBlue)
- pages[i]:add(searchLabel, searchCows, 20, maxY-2, 22, maxY, colors.purple, colors.magenta)
- end
- pages.search = touchpoint.new("top")
- function nextPage(str)
- lastPage = currPage
- currPage = currPage + 1
- if currPage > 5 then
- print("too many pages!")
- currPage = 5
- end
- tp = pages[currPage]
- end
- function prevPage(str)
- lastPage = currPage
- currPage = currPage - 1
- if currPage < 1 then
- print("Trying to go before page 1, ERROR!")
- currPage = 1
- end
- tp = pages[currPage]
- end
- function pollStorage()
- local tbl = storage.getAllStacks()
- totalCows = #tbl
- cowList = {}
- cowListNames = {}
- for k,v in ipairs(tbl) do
- local slot = v.all()
- if cowList[slot.display_name] then
- table.insert(cowList[slot.display_name].inSlots, k)
- else
- table.insert(cowListNames, slot.display_name)
- cowList[slot.display_name] = {}
- cowList[slot.display_name].inSlots = {}
- cowList[slot.display_name].inSlots[1] = k
- end
- end
- end
- function moveCows(str)
- local line = tonumber(string.match(str, "%d+"))
- for i = #cowList[cowListNames[line]].inSlots, 1, -1 do
- local num = storage.pushItem(chestDir, cowList[cowListNames[line]].inSlots[i])
- if num == 0 or num == nil then
- print("error moving "..cowListNames[line].." from slot "..cowList[cowListNames[line]].inSlots[i])
- break;
- end
- end
- end
- function makeCowList()
- for page,buttons in pairs(buttonList) do
- temp = pages[page]
- for k,button in pairs(buttons) do
- temp:remove(button)
- end
- end
- temp = pages[1]
- local pageCnt = 1
- buttonList = {}
- buttonList[pageCnt] = {}
- local line
- for k,v in ipairs(cowListNames) do
- if k % 16 == 0 then
- pageCnt = math.floor(k/16) + 1
- buttonList[pageCnt] = {}
- temp:remove("nextPage")
- temp:add(nextLabel, nextPage, 24, maxY-2, 26, maxY, colors.cyan, colors.lightBlue)
- temp = pages[pageCnt]
- temp:remove("prevPage")
- temp:add(prevLabel, prevPage, 16, maxY-2, 18, maxY, colors.cyan, colors.lightBlue)
- end
- if pageCnt > 1 then
- line = k - ((pageCnt - 1) * 16) + 1
- else
- line = k
- end
- local str = k..". "..v..": "..tostring(#cowList[v].inSlots).." -------------------"
- temp:add(str, nil, 1, line, maxX-7, line, colors.black, colors.black)
- table.insert(buttonList[pageCnt], str)
- temp:add("Move "..k, moveCows, maxX-6, line, maxX-1, line, colors.gray, colors.green)
- table.insert(buttonList[pageCnt], "Move "..k)
- --print("Total "..k..": "..tostring(#v.inSlots))
- --12. Nutrient Distillation total: 12
- end
- temp:add("Total Cows: "..totalCows, nil, 3, line+1, 22, line+1, colors.black, colors.black, colors.gray, colors.gray)
- table.insert(buttonList[pageCnt], "Total Cows: "..totalCows)
- end
- function makeSearchCowList(searchString)
- searchString = searchString or ""
- local foundTooMany = false
- foundCows = {}
- for k,v in ipairs(cowListNames) do
- if string.upper(v):find(searchString) then
- if #foundCows > 10 then
- foundTooMany = true
- break
- end
- local tmp = {
- key = k,
- name = v,
- }
- table.insert(foundCows, tmp)
- end
- end
- for _, button in pairs(searchButtonList) do
- pages.search:remove(button)
- end
- if (foundCows[1] == nil) and (searchString == "") then
- for i = 1,10 do
- local tmp = {
- key = i,
- name = cowListNames[i],
- }
- table.insert(foundCows, tmp)
- end
- foundTooMany = true
- end
- if (foundCows[1] == nil) and not (searchString == "") then
- pages.search:add("!!!No Cows Found!!!", nil, 6, 10, 34, 10, colors.black, colors.black, colors.red, colors.red)
- table.insert(searchButtonList, "!!!No Cows Found!!!")
- else
- for k,v in ipairs(foundCows) do
- local str = k..". "..v.name..": "..tostring(#cowList[v.name].inSlots).." -------------------"
- pages.search:add(str, nil, 1, k, maxX-7, k, colors.black, colors.black)
- table.insert(searchButtonList, str)
- pages.search:add("Move "..v.key, moveCows, maxX-6, k, maxX-1, k, colors.gray, colors.green)
- table.insert(searchButtonList, "Move "..v.key)
- end
- if foundTooMany then
- pages.search:add("...Results Overrun Space...", nil, 6, 12, 34, 12, colors.black, colors.black, colors.gray, colors.gray)
- table.insert(searchButtonList, "...Results Overrun Space...")
- end
- end
- end
- function pressKey(str)
- local searchString = ""
- if str == "<-" then
- table.remove(searchChars)
- elseif (str == "SPACE") and (#searchChars < 20)then
- table.insert(searchChars, " ")
- elseif #searchChars < 20 then
- table.insert(searchChars, str)
- else
- print("Search String too long, try removing characters")
- end
- for _,l in ipairs(searchChars) do
- searchString = searchString..l
- end
- searchString = string.upper(searchString)
- local label = {
- [1] = searchString,
- label = "searchString"
- }
- pages.search:remove("searchString")
- pages.search:add(label, nil, keyboardPos.x+3, keyboardPos.y+1, keyboardPos.x+3+string.len(searchString), keyboardPos.y+1, colors.white, colors.white, colors.gray, colors.gray)
- makeSearchCowList(searchString)
- end
- function makeKeyboard(leftX, topY)
- keyboardPos.x = leftX
- keyboardPos.y = topY
- tRow1 = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "(", ")",}
- tRow2 = {"Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", ":", "_",}
- tRow3 = {"A", "S", "D", "F", "G", "H", "J", "K", "L", "#", ";", "=",}
- tRow4 = {"/", "Z", "X", "C", "V", "B", "N", "M", "@", "~", "'", "+",}
- --tRow5 = {"[", "]", "{", "}", "&", "$", "%", "-", "*", "!", "?", ".",}
- -- addBox(name, startX, Xsize, startY, Ysize, textColor, BGColor)
- pages.search:addBox("box1", leftX, 25, topY, 7, colors.white, colors.blue)
- pages.search:addBox("box2", leftX+1, 23, topY+1, 2, colors.black, colors.white)
- pages.search:addBox("box3", leftX+1, 23, topY+3, 2, colors.black, colors.white)
- pages.search:addBox("box4", leftX+1, 23, topY+5, 1, colors.black, colors.white)
- spaceLabel = {
- " SPACE ",
- label = "SPACE"
- }
- pages.search:add(spaceLabel, pressKey, leftX+3, topY+6, leftX+11, topY+6, colors.white, colors.gray, colors.black, colors.white)
- backspaceLabel = {
- " <-BS- ",
- label = "<-"
- }
- pages.search:add(backspaceLabel, pressKey, leftX+13, topY+6, leftX+21, topY+6, colors.white, colors.gray, colors.black, colors.white)
- pages.search:add(">", nil, leftX+1, topY+1, leftX+1, topY+1, colors.gray, colors.white)
- i = leftX + 1
- for _, v in ipairs(tRow1) do
- pages.search:add(v, pressKey, i, topY+2, i, topY+2, colors.white, colors.gray, colors.black, colors.white)
- i = i + 2
- end
- i = leftX + 1
- for _,v in ipairs(tRow2) do
- pages.search:add(v, pressKey, i, topY+3, i, topY+3, colors.white, colors.gray, colors.black, colors.white)
- i = i + 2
- end
- i = leftX + 1
- for _,v in ipairs(tRow3) do
- pages.search:add(v, pressKey, i, topY+4, i, topY+4, colors.white, colors.gray, colors.black, colors.white)
- i = i + 2
- end
- i = leftX + 1
- for _,v in ipairs(tRow4) do
- pages.search:add(v, pressKey, i, topY+5, i, topY+5, colors.white, colors.gray, colors.black, colors.white)
- i = i + 2
- end
- -- i = leftX + 1
- -- for _,v in ipairs(tRow5) do
- -- pages.search:add(v, pressKey, i, topY+8, i, topY+8, colors.black, colors.white)
- -- i = i + 2
- -- end
- end
- local closeLabel = {
- "X",
- label = "CLOSE"
- }
- pages.search:add(closeLabel, closeSearch, maxX, 1, maxX, 1, colors.red, colors.green)
- makeKeyboard(8, 13)
- pollStorage()
- makeCowList()
- makeSearchCowList()
- tp = pages[1]
- tp:draw()
- os.startTimer(5)
- while true do
- local event, p1 = tp:handleEvents(os.pullEvent()) ---button_click, name
- if event == "button_click" then
- --remove toggling and simplify button running
- if type(tp.buttonList[p1].func) == "function" then
- tp:flash(p1)
- tp.buttonList[p1].func(p1)
- end
- pollStorage()
- makeCowList()
- tp:draw()
- end
- if event == "timer" then
- os.startTimer(5)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment