Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local connectionFreq = 23
- local replyFreq = 24
- local running = true
- local termWidth,termHeight = term.getSize()
- term.clear()
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.gray)
- term.clearLine(1)
- term.setCursorPos(1,1)
- term.write("Request")
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.white)
- term.setCursorPos(termWidth-4,1)
- term.write("Close")
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- local modem = peripheral.wrap("back")
- if not modem.isOpen(connectionFreq) then
- modem.open(connectionFreq)
- end
- if not modem.isOpen(replyFreq) then
- modem.open(replyFreq)
- end
- local currentView = "main"
- local mainWindow = window.create(term.current(),1,2,termWidth,termHeight-1,true)
- local addOrderWindow = window.create(term.current(),1,2,termWidth,termHeight-1,false)
- local viewOrdersWindow = window.create(term.current(),1,2,termWidth,termHeight-1,false)
- local inputWindow = window.create(mainWindow,1,6,termWidth,termHeight-7,true)
- local function renderOrders()
- viewOrdersWindow.setBackgroundColor(colors.black)
- viewOrdersWindow.setTextColor(colors.white)
- viewOrdersWindow.clear()
- modem.transmit(connectionFreq,replyFreq,{
- operation="get_orders"
- })
- local orders = nil
- while orders == nil do
- local e,p1,p2,p3,p4,p5 = os.pullEvent()
- if e == "modem_message" then
- local side,freq,reply,message = p1,p2,p3,p4
- if freq == replyFreq then
- if type(message) == "table" then
- if message.operation == "get_orders" then
- orders = message.orders
- end
- end
- end
- end
- end
- end
- mainWindow.setTextColor(colors.black)
- mainWindow.setBackgroundColor(colors.green)
- mainWindow.setCursorPos(2,2)
- mainWindow.write(" Add Order ")
- mainWindow.setCursorPos(2,4)
- mainWindow.write(" View Orders ")
- addOrderWindow.setTextColor(colors.white)
- addOrderWindow.setBackgroundColor(colors.red)
- addOrderWindow.setCursorPos(termWidth-12,termHeight-2)
- addOrderWindow.write("Cancel")
- addOrderWindow.setTextColor(colors.black)
- addOrderWindow.setBackgroundColor(colors.green)
- addOrderWindow.setCursorPos(termWidth-7,termHeight-2)
- addOrderWindow.write("Submit")
- addOrderWindow.setBackgroundColor(colors.yellow)
- local function getInput(win,line)
- win.clearLine(line)
- win.setCursorPos(1,line)
- win.setTextColor(colors.white)
- term.setCursorBlink(true)
- local input = ""
- while true do
- local e,p1,p2,p3,p4,p5 = os.pullEvent()
- if e == "char" then
- input = input..p1
- win.clearLine(line)
- win.setCursorPos(1,line)
- win.write(input)
- elseif e == "key" then
- local k = keys.getName(p1)
- if k == "enter" then
- break
- elseif k == "backspace" then
- input = string.sub(input,1,string.len(input)-1)
- win.clearLine(line)
- win.setCursorPos(1,line)
- win.write(input)
- end
- end
- end
- return input
- end
- while running do
- local e,p1,p2,p3,p4,p5 = os.pullEvent()
- if e == "modem_message" then
- elseif e == "mouse_click" then
- local button,x,y = p1,p2,p3
- if y == 1 and x >= termWidth - 4 then
- running = false
- end
- if currentView == "main" then
- if x >= 2 and x <= 13 then
- if y == 3 then
- --add order
- --mainWindow.setVisible(false)
- --addOrderWindow.setVisible(true)
- inputWindow.setCursorPos(1,1)
- inputWindow.setTextColor(colors.yellow)
- inputWindow.setBackgroundColor(colors.black)
- inputWindow.write("What Item? (type \"exit\" to cancel)")
- inputWindow.setCursorPos(1,2)
- local name = string.lower(getInput(inputWindow,2))
- if name ~= "exit" then
- inputWindow.setCursorPos(1,3)
- inputWindow.setTextColor(colors.yellow)
- inputWindow.write("How Many? (type \"exit\" to cancel)")
- inputWindow.setTextColor(colors.white)
- local qty = getInput(inputWindow,4)
- if qty ~= "exit" then
- modem.transmit(connectionFreq,replyFreq,{
- operation="add_orders",
- items={
- {
- name=name,
- qty=qty
- }
- }
- })
- end
- end
- term.setCursorBlink(false)
- inputWindow.clear()
- elseif y == 5 then
- --view order
- end
- end
- elseif currentView == "add_order" then
- end
- elseif e == "key" then
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement