Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- guis["main"] = {events = {}}
- function guis.main:init()
- term.clear()
- guiTools.printBorder(colors.gray)
- local w,h = term.getSize()
- guiTools.drawRect(1,3,w,1,colors.gray)
- guiTools.drawRect(30,3,1,h-3,colors.gray)
- guiTools.drawRect(30,12,w-30,1,colors.gray)
- self.orderCount = 0
- self.searchList = {}
- term.setCursorPos(2,4)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.setCursorPos(31,4)
- term.write(" + Stacks - ")
- term.setCursorPos(31,5)
- term.write(" + Half Stacks - ")
- term.setCursorPos(31,6)
- term.write(" + Single - ")
- term.setCursorPos(45,8)
- term.write("Stacks")
- term.setCursorPos(45,9)
- term.write("Items")
- term.setCursorPos(44,7)
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.white)
- term.write("<Reset>")
- term.setCursorPos(37,11)
- term.setBackgroundColor(colors.lime)
- term.setTextColor(colors.black)
- term.write("<Order>")
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.gray)
- term.setCursorPos(2,1)
- term.write("/ Search \\")
- term.setCursorPos(2,3)
- term.write("/ Results \\")
- term.setCursorPos(31,3)
- term.write("/ Order \\")
- term.setCursorPos(31,12)
- term.write("/ Active Orders \\")
- self.targetIndex = -1
- self.searchStr = ""
- self:fixPos()
- self:updateOrderCount()
- self:updateRetrievalList()
- end
- function guis.main:fixPos()
- term.setCursorPos(2+string.len(self.searchStr),2)
- term.setCursorBlink(true)
- end
- function guis.main:updateList()
- local w,h = term.getSize()
- guiTools.clearArea(2,4,30-2,h-4)
- -- local y=4
- for k,v in pairs(self.searchList) do
- term.setCursorPos(2,k+3)
- term.write(v)
- if self.targetIndex == k then
- term.setCursorPos(29,k+3)
- term.setBackgroundColor(colors.lime)
- term.write(" ")
- term.setBackgroundColor(colors.black)
- end
- end
- self:fixPos()
- end
- function guis.main:updateRetrievalList()
- local w,h = term.getSize()
- term.setCursorPos(31,13)
- guiTools.clearArea(31,13,w-31,h-13)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.setCursorPos(31,13)
- for dI = 1,math.min(3,#retrievalQueue),1 do
- local dY = (dI-1)*2
- term.setCursorPos(31,13+dY)
- term.write(string.sub(retrievalQueue[dI].name,1,w-31))
- term.setCursorPos(31,13+dY+1)
- local stacks = math.floor( retrievalQueue[dI].count / 64 )
- local items = retrievalQueue[dI].count - stacks*64
- if stacks > 0 then
- term.write(string.format("%d*64+%d",stacks,items))
- else
- term.write(string.format("%d",items))
- end
- term.write()
- end
- self:fixPos()
- end
- function guis.main:doSearch()
- self.targetIndex = -1
- self.searchList = findEntries(self.searchStr)
- self:updateList()
- end
- function guis.main.events:char(charIn)
- self:fixPos()
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.write(charIn)
- self.searchStr = self.searchStr .. charIn
- self:fixPos()
- self:startSearchTimer()
- end
- function guis.main:startSearchTimer()
- self.searchTimer = os.startTimer(1)
- end
- function guis.main.events:key(keyIn)
- if keyIn == keys.backspace then
- if string.len(self.searchStr) > 0 then
- self:fixPos()
- local x = term.getCursorPos()
- term.setCursorPos(x-1,2)
- term.setBackgroundColor(colors.black)
- term.write(" ")
- self.searchStr = string.sub(self.searchStr,0,string.len(self.searchStr)-1)
- self:fixPos()
- self:startSearchTimer()
- end
- elseif keyIn == keys.f4 then
- error("")
- end
- end
- function guis.main.events:timer(timerKey)
- if self.searchTimer == timerKey then
- self:doSearch()
- end
- end
- function guis.main:updateOrderCount()
- local w,h = term.getSize()
- term.setCursorPos(31,8)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- local stacks = math.floor(self.orderCount/64)
- term.write(guiTools.padString(string.format("%d",stacks),w-31-6).."Stacks")
- term.setCursorPos(31,9)
- local items = self.orderCount-stacks*64
- term.write(guiTools.padString(string.format("%d",items),w-31-6).."Items ")
- self:fixPos()
- end
- function guis.main:handleCountClick(dX,dY)
- local vMod = 0
- if dX == 18 then vMod = -1 end
- if dX == 1 then vMod = 1 end
- if vMod == 0 then return end
- local mods = {64,32,1}
- local mod = mods[dY+1]*vMod
- self.orderCount = math.max(self.orderCount+mod,0)
- self:updateOrderCount()
- end
- function guis.main.events:mouse_click(button,clickX,clickY)
- local w,h = term.getSize()
- if button == 1 then
- if clickX >= 2 and clickX <= 29 and clickY >= 4 and clickY <= h-1 then
- local index = clickY - 3
- if self.searchList[index] ~= nil then
- self.targetIndex = index
- self:updateList()
- end
- elseif clickX >= 31 and clickX <= w-1 and clickY >= 4 and clickY <= 11 then
- if clickY >= 4 and clickY <= 6 then
- self:handleCountClick(clickX-31,clickY-4)
- elseif clickY == 7 and clickX > w-1-7 and clickX <= w-1 then
- self.orderCount = 0
- self:updateOrderCount()
- elseif clickY == 11 and clickX >= 37 and clickX <= w-8 and self.targetIndex ~= -1 and self.orderCount > 0 then
- addRetrievalRequest(self.searchList[self.targetIndex],self.orderCount)
- end
- end
- end
- end
- function guis.main.events:retrieval_update()
- self:updateRetrievalList()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement