Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- load libraries
- os.loadAPI("drawLib")
- os.loadAPI("buttonLib")
- os.loadAPI("dataLib")
- -- peripheral setup
- local controllername = "monitor_0"
- local controller = peripheral.wrap(controllername)
- local modem = peripheral.wrap('top')
- modem.closeAll()
- modem.open(2)
- -- local wmod = peripheral.wrap("bottom")
- -- wmod.closeAll()
- -- variables setup
- local controllerX, controllerY
- local currentApp = "home"
- local previousApp = "home"
- -- Application Variables Setup
- local northFarmActive = false
- local eastFarmActive = false
- local southFarmActive = false
- local westFarmActive = false
- local totalEssences = {}
- local essencesPage = 1
- local essencesPerPage = 13
- local currentSort = "None"
- function resizeMon()
- controllerX, controllerY = controller.getSize()
- end
- function transmitToSlaves(message)
- -- print('Transmitting: ' .. message)
- modem.transmit(1,2,message)
- end
- for i = 2, 5 do
- -- wmod.open(i)
- end
- function clearAll()
- drawLib.empty(controller)
- end
- -- Startup Functions
- function bootSequence()
- -- drawTitle(displayX/2-5, displayY/2, "Booting...", colors.white, colors.black,display)
- -- Application Triggers
- disableAllFarms()
- loadingScreen(controllerX,controllerY,controller)
- end
- function loadingScreen(monX,monY,monitor)
- drawLib.drawTitle(monX/2-7, monY/2, "All The Mods 7 OS", colors.white, colors.black,monitor)
- drawLib.drawTitle(monX/2-9, monY-3, "Loading... Please wait", colors.white, colors.black,monitor)
- for i=1, 30 do
- --drawContent(2, monY-1, monY-2, 2, i, 100, colors.red, colors.gray,monitor)
- drawLib.drawProg(2,monY-1, monX-2, 1, i, 30, colors.white, colors.gray,monitor)
- sleep(0.05)
- end
- drawLib.empty(monitor)
- end
- -- Utility Functions
- function formatNumbers(number,length)
- return tostring(math.floor(number))..string.rep(" ",length-#tostring(math.floor(number)))
- end
- function table_count(T)
- local count = 0
- for _ in pairs(T) do count = count + 1 end
- return count
- end
- function maxpages()
- return math.ceil((table_count(totalEssences) / essencesPerPage))
- end
- function atoz(a,b)
- return a[1] < b[1]
- end
- function getSortedEssencesTable()
- if currentSort == "None" then
- return totalEssences
- elseif currentSort == " A to Z " then
- return table.sort(totalEssences, compare)
- elseif currentSort == " Z to Z " then
- elseif currentSort == "Hi to Lo" then
- elseif currentSort == "Lo to Hi" then
- end
- end
- -- Application Functions
- function disableAllFarms()
- northFarmActive = false
- transmitToSlaves("northFarmOff")
- eastFarmActive = false
- transmitToSlaves("eastFarmOff")
- southFarmActive = false
- transmitToSlaves("southFarmOff")
- westFarmActive = false
- transmitToSlaves("westFarmOff")
- end
- function updateEssenceCounts()
- transmitToSlaves("provideEssenceCount")
- local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
- totalEssences = message
- end
- -- Add all buttons
- function addButtons()
- -- Homebar Page Change
- buttonLib.addButton(1,1,3,1,"pageLeft",colors.cyan,colors.red,true,"<- ","",1,1,"")
- buttonLib.addButton(controllerX-2,1,3,1,"pageRight",colors.cyan,colors.red,true," ->","",controllerX-2,1,"")
- -- Homebar Home
- buttonLib.addButton(1,1,5,1,"homeButton1",colors.lime,colors.lightGray,true,"/^\\","",2,1,"")
- buttonLib.addButton(1,2,5,1,"homeButton2",colors.lime,colors.lightGray,true,"|#|","",2,2,"")
- -- Homebar Back
- buttonLib.addButton(controllerX-4,1,5,1,"backButton1",colors.red,colors.lightGray,true,"/__","",controllerX-3,1,"")
- buttonLib.addButton(controllerX-4,2,5,1,"backButton2",colors.red,colors.lightGray,true,"\\ ","",controllerX-3,2,"")
- -- Applications
- buttonLib.addButton(3,4,11,3,"farms",colors.cyan,colors.gray,true,"Farms","",6,5,"")
- buttonLib.addButton(17,4,11,3,"setting",colors.cyan,colors.gray,true,"Setting","",19,5,"")
- buttonLib.addButton(3,8,11,3,"storage",colors.cyan,colors.gray,true,"Storage","",5,9,"")
- buttonLib.addButton(17,8,11,3,"graphs",colors.cyan,colors.gray,true,"Diagram","",19,9,"")
- --addButton(3,12,11,3,"timelog",colors.cyan,colors.gray,true,"TimeLog","",5,13,"")
- --addButton(17,12,11,3,"nothing",colors.cyan,colors.gray,false,"","Nothing",19,13,"")
- -- Farm Application Buttons
- --addButton(7,4,5,3,"northFarm",colors.green,colors.red,true,"N","N",9,5,"")
- --addButton(2,7,5,3,"westFarm",colors.green,colors.red,true,"W","W",4,8,"")
- --addButton(7,10,5,3,"southFarm",colors.green,colors.red,true,"S","S",9,11,"")
- --addButton(12,7,5,3,"eastFarm",colors.green,colors.red,true,"E","E",14,8,"")
- buttonLib.addButton(2,4,5,3,"northFarm",colors.green,colors.red,true,"N","N",4,5,"")
- buttonLib.addButton(2,8,5,3,"eastFarm",colors.green,colors.red,true,"E","E",4,9,"")
- buttonLib.addButton(2,12,5,3,"southFarm",colors.green,colors.red,true,"S","S",4,13,"")
- buttonLib.addButton(2,16,5,3,"westFarm",colors.green,colors.red,true,"W","W",4,17,"")
- buttonLib.addButton(31,6,3,1,"essencePageLeft",colors.blue,colors.gray,true,"<","<",32,6,"")
- buttonLib.addButton(47,6,3,1,"essencePageRight",colors.blue,colors.gray,true,">",">",48,6,"")
- -- Settings Application Buttons
- buttonLib.addButton(3,4,11,3,"restart",colors.red,colors.gray,true,"Restart","",5,5,"")
- end
- -- Generate The Gui Based On Current State
- function generateGUI(monitor)
- -- Draw Home Bar
- drawLib.drawLine(1,1,controllerX,2,colors.gray,monitor)
- buttonLib.drawButton("homeButton1",monitor)
- buttonLib.drawButton("homeButton2",monitor)
- buttonLib.drawButton("backButton1",monitor)
- buttonLib.drawButton("backButton2",monitor)
- drawLib.clearBox(controllerX/2-1,1,1,5,monitor,colors.gray)
- drawLib.putTime(controllerX/2-1,1,monitor,true,colors.gray)
- -- Draw Application Specific Items
- if currentApp == "home" then
- buttonLib.drawButton("farms",monitor)
- buttonLib.drawButton("storage",monitor)
- buttonLib.drawButton("graphs",monitor)
- buttonLib.drawButton("setting",monitor)
- elseif currentApp == "farms" then
- drawLib.drawTitle(controllerX/2-1, 2, "Farms", colors.white, colors.gray, monitor)
- buttonLib.setButtonState("northFarm",northFarmActive)
- buttonLib.drawButton("northFarm",monitor)
- buttonLib.setButtonState("westFarm",westFarmActive)
- buttonLib.drawButton("westFarm",monitor)
- buttonLib.setButtonState("southFarm",southFarmActive)
- buttonLib.drawButton("southFarm",monitor)
- buttonLib.setButtonState("eastFarm",eastFarmActive)
- buttonLib.drawButton("eastFarm",monitor)
- drawLib.drawTitle(9, 4, "Essences Collected :", colors.white, colors.black, monitor)
- local index = 0
- for key, value in pairs(getSortedEssencesTable()) do
- if index < essencesPage * essencesPerPage and index >= (essencesPage - 1) * essencesPerPage then
- local text = key .. string.rep(" ", 15 - #key) .. string.rep(" ", 5 - #(""..value)) .. value
- drawLib.drawTitle(9, 6 + (index%essencesPerPage), text, colors.white, colors.black, monitor)
- end
- index = index + 1
- end
- buttonLib.drawButton("essencePageLeft",monitor)
- drawLib.drawTitle(31, 4, " Page ", colors.white, colors.gray, monitor)
- drawLib.drawTitle(37, 6, essencesPage.." of "..maxpages(), colors.white, colors.black, monitor)
- buttonLib.drawButton("essencePageRight",monitor)
- --buttonLib.drawButton("essencePageLeft",monitor)
- drawLib.drawTitle(31, 8, " Sort ", colors.white, colors.gray, monitor)
- drawLib.drawTitle(38, 10, "None", colors.white, colors.black, monitor)
- --buttonLib.drawButton("essencePageRight",monitor)
- --buttonLib.drawButton("essencePageLeft",monitor)
- drawLib.drawTitle(31, 12, " Data ", colors.white, colors.gray, monitor)
- drawLib.drawTitle(37, 14, "Totals", colors.white, colors.black, monitor)
- --buttonLib.drawButton("essencePageRight",monitor)
- elseif currentApp == "storage" then
- drawLib.drawTitle(controllerX/2-2, 2, "Storage", colors.white, colors.gray, monitor)
- elseif currentApp == "graphs" then
- drawLib.drawTitle(controllerX/2-2, 2, "Diagram", colors.white, colors.gray, monitor)
- elseif currentApp == "setting" then
- drawLib.drawTitle(controllerX/2-2, 2, "Setting", colors.white, colors.gray, monitor)
- buttonLib.drawButton("restart",monitor)
- else error("App not found") end
- -- drawButton("pageLeft",monitor)
- -- drawButton("pageRight",monitor)
- end
- -- React To Touch Events
- function touchAreas(x,y,side)
- -- Is On the main controller screen
- if side == controllername then
- if buttonLib.isWithinBoundingBox(x,y,"homeButton1") then
- currentApp = "home"
- drawLib.empty(controller)
- elseif buttonLib.isWithinBoundingBox(x,y,"homeButton2") then
- currentApp = "home"
- drawLib.empty(controller)
- elseif buttonLib.isWithinBoundingBox(x,y,"backButton1") then
- elseif buttonLib.isWithinBoundingBox(x,y,"backButton2") then
- elseif currentApp == "home" then
- if buttonLib.isWithinBoundingBox(x,y,"farms") then
- currentApp = "farms"
- previousApp = "home"
- drawLib.empty(controller)
- elseif buttonLib.isWithinBoundingBox(x,y,"storage") then
- currentApp = "storage"
- previousApp = "home"
- drawLib.empty(controller)
- elseif buttonLib.isWithinBoundingBox(x,y,"graphs") then
- currentApp = "graphs"
- previousApp = "home"
- drawLib.empty(controller)
- elseif buttonLib.isWithinBoundingBox(x,y,"setting") then
- currentApp = "setting"
- previousApp = "home"
- drawLib.empty(controller)
- end
- elseif currentApp == "farms" then
- if buttonLib.isWithinBoundingBox(x,y,"northFarm") then
- if northFarmActive then transmitToSlaves("northFarmOff") else transmitToSlaves("northFarmOn") end
- if northFarmActive then northFarmActive = false else northFarmActive = true end
- -- transmit over network that northfarm must be toggled
- drawLib.empty(controller)
- elseif buttonLib.isWithinBoundingBox(x,y,"eastFarm") then
- if northFarmActive then transmitToSlaves("eastFarmOff") else transmitToSlaves("eastFarmOn") end
- if eastFarmActive then eastFarmActive = false else eastFarmActive = true end
- drawLib.empty(controller)
- elseif buttonLib.isWithinBoundingBox(x,y,"southFarm") then
- if northFarmActive then transmitToSlaves("southFarmOff") else transmitToSlaves("southFarmOn") end
- if southFarmActive then southFarmActive = false else southFarmActive = true end
- drawLib.empty(controller)
- elseif buttonLib.isWithinBoundingBox(x,y,"westFarm") then
- if northFarmActive then transmitToSlaves("westFarmOff") else transmitToSlaves("westFarmOn") end
- if westFarmActive then westFarmActive = false else westFarmActive = true end
- drawLib.empty(controller)
- elseif buttonLib.isWithinBoundingBox(x,y,"essencePageLeft") then
- if essencesPage > 1 then essencesPage = essencesPage - 1 end
- drawLib.empty(controller)
- elseif buttonLib.isWithinBoundingBox(x,y,"essencePageRight") then
- if essencesPage < maxpages() then essencesPage = essencesPage + 1 end
- drawLib.empty(controller)
- end
- elseif currentApp == "setting" then
- if buttonLib.isWithinBoundingBox(x,y,"restart") then
- os.reboot()
- else
- end
- else
- end
- else
- end
- end
- function waitForTouch()
- parallel.waitForAny(applicationWaiter,getTouch)
- end
- function applicationWaiter()
- parallel.waitForAny(wait,applicationLoop)
- end
- function applicationLoop()
- updateEssenceCounts()
- end
- function getTouch()
- event, side, xPos, yPos = os.pullEvent("monitor_touch")
- touchAreas(xPos, yPos, side)
- end
- function wait()
- sleep(0.5)
- end
- function init()
- clearAll()
- resizeMon()
- bootSequence()
- addButtons()
- clearAll()
- while true do
- generateGUI(controller)
- waitForTouch()
- end
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment