Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Touchscreen Program using Touchscreen API
- if viewportAPI then os.unloadAPI("viewportAPI") end
- os.loadAPI("viewportAPI")
- if buttonAPI then os.unloadAPI("buttonAPI") end
- os.loadAPI("buttonAPI")
- if eventDispatcherAPI then os.unloadAPI("eventDispatcherAPI") end
- os.loadAPI("eventDispatcherAPI")
- -- Declaring Vars
- rSide = "top"
- amenuItems = {}
- abuttons = {}
- aCurrentOrder = {}
- foodAmount = 1
- -- Filesystem Setup
- if not fs.exists("/menu") then
- fs.makeDir("/menu")
- print("Created menu folder. Please enter items before running again.")
- return
- end
- -- Creating Viewport for Buttons
- viewport = viewportAPI.new({term = term})
- -- Function for Button
- function clickHandler(element, posX, posY)
- for i=1,#amenuItems do
- if element.text == amenuItems[i] then
- cfile = fs.open("menu/"..amenuItems[i], "r")
- cfileColor = cfile.readLine()
- for i=1,foodAmount do
- aCurrentOrder[#aCurrentOrder+1] = cfileColor
- end
- cfile.close()
- end
- end
- element.backgroundColor = colors.lightGray
- viewport:redraw()
- --redstone.setBundledOutput(rSide, colors.white)
- sleep(0.1)
- element.backgroundColor = colors.white
- --redstone.setBundledOutput(rSide,0)
- return true
- end
- function sendOrder(element, posX, posY)
- element.backgroundColor = colors.gray
- element.text = "Processing"
- viewport:redraw()
- for i=1,#aCurrentOrder do
- color = aCurrentOrder[i]-0
- redstone.setBundledOutput(rSide, color)
- sleep(0.1)
- redstone.setBundledOutput(rSide, 0)
- sleep(0.1)
- end
- aCurrentOrder = {}
- element.backgroundColor = colors.lightGray
- element.text = "Checkout"
- viewport:redraw()
- return true
- end
- function cycleFoodAmount(element, posX, posY)
- element.backgroundColor = colors.gray
- viewport:redraw()
- sleep(0.1)
- element.backgroundColor = colors.lightGray
- if foodAmount == 1 then foodAmount = 8 element.text = foodAmount.."" return true
- elseif foodAmount == 8 then foodAmount = 16 element.text = foodAmount.."" return true
- else foodAmount = 1 element.text = foodAmount.."" return true end
- end
- topButton = buttonAPI.new({
- x = 2,
- y = 2,
- width = buttonAPI.width(0.95),
- height = 2,
- backgroundColor = colors.purple,
- textColor = colors.white,
- text = "Hyps Fried Chicken Menu" })
- viewport:addElement(topButton)
- checkoutButton = buttonAPI.new({
- x = buttonAPI.width(0.20),
- y = buttonAPI.height(0.90),
- width = buttonAPI.width(0.80),
- height = 2,
- backgroundColor = colors.lightGray,
- textColor = colors.white,
- callback = sendOrder,
- text = "Checkout" })
- viewport:addElement(checkoutButton)
- foodAmountButton = buttonAPI.new({
- x = 2,
- y = buttonAPI.height(0.90),
- width = buttonAPI.width(0.10),
- height = 2,
- backgroundColor = colors.lightGray,
- textColor = colors.white,
- callback = cycleFoodAmount,
- text = foodAmount.."" })
- viewport:addElement(foodAmountButton)
- amenuItems = fs.list("/menu")
- yStep = 2
- if amenuItems ~= nil then
- for i=1,#amenuItems do
- buttonX = 2
- buttonY = 3*yStep
- if i % 2 == 0 then
- buttonX = buttonAPI.width(0.55)
- yStep = yStep + 1
- end
- abuttons[i] = buttonAPI.new({
- x = buttonX,
- y = buttonY,
- width = buttonAPI.width(0.45),
- height = 2,
- callback = clickHandler,
- text = amenuItems[i] })
- end
- else
- error()
- end
- for i=1,#abuttons do
- viewport:addElement(abuttons[i])
- end
- viewport:redraw()
- eventDispatcherAPI.addHandler("mouse_click", function(event, side, xPos, yPos)
- viewport:handleClick(xPos, yPos)
- end)
- eventDispatcherAPI.runDispatchLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement