Advertisement
JereTheJuggler

Untitled

Mar 9th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. local connectionFreq = 23
  2. local replyFreq = 24
  3.  
  4. local running = true
  5.  
  6. local termWidth,termHeight = term.getSize()
  7.  
  8. term.clear()
  9. term.setTextColor(colors.black)
  10. term.setBackgroundColor(colors.gray)
  11. term.clearLine(1)
  12. term.setCursorPos(1,1)
  13. term.write("Request")
  14. term.setBackgroundColor(colors.red)
  15. term.setTextColor(colors.white)
  16. term.setCursorPos(termWidth-4,1)
  17. term.write("Close")
  18. term.setTextColor(colors.white)
  19. term.setBackgroundColor(colors.black)
  20.  
  21. local modem = peripheral.wrap("back")
  22. if not modem.isOpen(connectionFreq) then
  23. modem.open(connectionFreq)
  24. end
  25. if not modem.isOpen(replyFreq) then
  26. modem.open(replyFreq)
  27. end
  28.  
  29. local currentView = "main"
  30.  
  31. local mainWindow = window.create(term.current(),1,2,termWidth,termHeight-1,true)
  32. local addOrderWindow = window.create(term.current(),1,2,termWidth,termHeight-1,false)
  33. local viewOrdersWindow = window.create(term.current(),1,2,termWidth,termHeight-1,false)
  34. local inputWindow = window.create(mainWindow,1,6,termWidth,termHeight-7,true)
  35.  
  36. local function renderOrders()
  37. viewOrdersWindow.setBackgroundColor(colors.black)
  38. viewOrdersWindow.setTextColor(colors.white)
  39. viewOrdersWindow.clear()
  40. modem.transmit(connectionFreq,replyFreq,{
  41. operation="get_orders"
  42. })
  43. local orders = nil
  44. while orders == nil do
  45. local e,p1,p2,p3,p4,p5 = os.pullEvent()
  46. if e == "modem_message" then
  47. local side,freq,reply,message = p1,p2,p3,p4
  48. if freq == replyFreq then
  49. if type(message) == "table" then
  50. if message.operation == "get_orders" then
  51. orders = message.orders
  52. end
  53. end
  54. end
  55. end
  56. end
  57.  
  58. end
  59.  
  60. mainWindow.setTextColor(colors.black)
  61. mainWindow.setBackgroundColor(colors.green)
  62. mainWindow.setCursorPos(2,2)
  63. mainWindow.write(" Add Order ")
  64. mainWindow.setCursorPos(2,4)
  65. mainWindow.write(" View Orders ")
  66.  
  67. addOrderWindow.setTextColor(colors.white)
  68. addOrderWindow.setBackgroundColor(colors.red)
  69. addOrderWindow.setCursorPos(termWidth-12,termHeight-2)
  70. addOrderWindow.write("Cancel")
  71. addOrderWindow.setTextColor(colors.black)
  72. addOrderWindow.setBackgroundColor(colors.green)
  73. addOrderWindow.setCursorPos(termWidth-7,termHeight-2)
  74. addOrderWindow.write("Submit")
  75. addOrderWindow.setBackgroundColor(colors.yellow)
  76.  
  77. local function getInput(win,line)
  78. win.clearLine(line)
  79. win.setCursorPos(1,line)
  80. win.setTextColor(colors.white)
  81. term.setCursorBlink(true)
  82. local input = ""
  83. while true do
  84. local e,p1,p2,p3,p4,p5 = os.pullEvent()
  85. if e == "char" then
  86. input = input..p1
  87. win.clearLine(line)
  88. win.setCursorPos(1,line)
  89. win.write(input)
  90. elseif e == "key" then
  91. local k = keys.getName(p1)
  92. if k == "enter" then
  93. break
  94. elseif k == "backspace" then
  95. input = string.sub(input,1,string.len(input)-1)
  96. win.clearLine(line)
  97. win.setCursorPos(1,line)
  98. win.write(input)
  99. end
  100. end
  101. end
  102. return input
  103. end
  104.  
  105. while running do
  106. local e,p1,p2,p3,p4,p5 = os.pullEvent()
  107. if e == "modem_message" then
  108.  
  109. elseif e == "mouse_click" then
  110. local button,x,y = p1,p2,p3
  111. if y == 1 and x >= termWidth - 4 then
  112. running = false
  113. end
  114. if currentView == "main" then
  115. if x >= 2 and x <= 13 then
  116. if y == 3 then
  117. --add order
  118. --mainWindow.setVisible(false)
  119. --addOrderWindow.setVisible(true)
  120.  
  121. inputWindow.setCursorPos(1,1)
  122. inputWindow.setTextColor(colors.yellow)
  123. inputWindow.setBackgroundColor(colors.black)
  124. inputWindow.write("What Item? (type \"exit\" to cancel)")
  125. inputWindow.setCursorPos(1,2)
  126.  
  127. local name = string.lower(getInput(inputWindow,2))
  128. if name ~= "exit" then
  129. inputWindow.setCursorPos(1,3)
  130. inputWindow.setTextColor(colors.yellow)
  131. inputWindow.write("How Many? (type \"exit\" to cancel)")
  132. inputWindow.setTextColor(colors.white)
  133. local qty = getInput(inputWindow,4)
  134. if qty ~= "exit" then
  135. modem.transmit(connectionFreq,replyFreq,{
  136. operation="add_orders",
  137. items={
  138. {
  139. name=name,
  140. qty=qty
  141. }
  142. }
  143. })
  144. end
  145. end
  146. term.setCursorBlink(false)
  147. inputWindow.clear()
  148. elseif y == 5 then
  149. --view order
  150.  
  151. end
  152. end
  153. elseif currentView == "add_order" then
  154.  
  155. end
  156. elseif e == "key" then
  157.  
  158. end
  159. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement