Advertisement
Agent_Silence

terminal

Dec 20th, 2015
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.79 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2. function fullLimitWrite(text,limit)
  3.     term.write(#text < limit+1 and text..(string.rep(" ",limit-#text)) or string.sub(text,1,limit-3).."...")
  4. end
  5.  
  6. function dualPull(...)
  7.     local args={...}
  8.     repeat
  9.         local event = {os.pullEvent()}
  10.         for i,v in pairs(args) do
  11.             if event[1] == v then
  12.                 return event[1],event[2],event[3],event[4],event[5],event[6]
  13.             end
  14.         end
  15.     until false
  16. end
  17.  
  18. function continue(text,ypos)
  19.     local maxx,maxy = term.getSize()
  20.     while true do
  21.         local event, button, x, y = os.pullEvent("mouse_click")
  22.         if x >= math.ceil((maxx/2)-(#text/2)) and x < (math.ceil((maxx/2)-(#text/2)) + #text) and y == ypos then
  23.             break
  24.         end
  25.     end
  26. end
  27.  
  28. local function centerWrite(text,setY)
  29.     local x,y = term.getSize()
  30.     term.setCursorPos(math.ceil((x / 2) - (#text / 2)), setY)
  31.     write(text)
  32. end
  33. local success = os.loadAPI("itemData")
  34. local items = (success and itemData.data) or {}
  35.  
  36. local curItem = 1
  37.  
  38. term.setBackgroundColor(colors.white)
  39. term.clear()
  40. term.setTextColor(colors.red)
  41. centerWrite("Crimson Co. Terminal",1)
  42. term.setTextColor(colors.black)
  43. centerWrite("Crimson Co. is a company dedicated",4)
  44. centerWrite("to bringing you the finest and cheapest goods",5)
  45. centerWrite("for all your essential needs.",6)
  46. term.setBackgroundColor(colors.lightGray)
  47. centerWrite("Continue to Browser",16)
  48.  
  49. continue("Continue to Browser",16)
  50. local info = window.create(term.native(),13,1,39,19)
  51.  
  52. while true do
  53. local timr = os.startTimer()
  54. term.setBackgroundColor(colors.white)
  55. term.clear()
  56. paintutils.drawLine(12,1,12,19,colors.black)
  57. term.setBackgroundColor(colors.white)
  58. for i=-9,9 do
  59. term.setCursorPos(1,10+i)
  60. if items[curItem+i] then
  61.     fullLimitWrite(items[curItem+i].name,11)
  62. end
  63. end
  64. term.setBackgroundColor(colors.lightBlue)
  65. term.setTextColor(colors.black)
  66. term.setCursorPos(1,10)
  67. fullLimitWrite(items[curItem].name)
  68. term.redirect(info)
  69. term.setBackgroundColor(colors.white)
  70. term.setTextColor(colors.black)
  71. term.clear()
  72. centerWrite("Name",1)
  73. centerWrite(items[curItem].name,2)
  74. centerWrite("Price",5)
  75. centerWrite(items[curItem].price,6)
  76. centerWrite("Location",9)
  77. centerWrite(items[curItem].location,10)
  78. centerWrite("Info",13)
  79. centerWrite(items[curItem].info,14)
  80. term.redirect(term.native())
  81.  
  82. local event, button, x, y = dualPull("mouse_click","mouse_scroll","timer")
  83. if event == "mouse_click" then
  84.     if x < 13 and (curItem - (10 - y)) < #items and (curItem - (10 - y)) > 0 then
  85.         curItem = (curItem - (10 - y))
  86.     end
  87.     if x == 51 and y == 1 then
  88.         break
  89.     end
  90. elseif event == "mouse_scroll" then
  91.     curItem = curItem + button
  92.     if curItem <=0 then
  93.         curItem = #items
  94.     elseif curItem > #items then
  95.         curItem = 1
  96.     end
  97.     sleep(0) -- Stops scroll wheel from going down/up 3 times
  98. elseif event == "timer" and button == timr then
  99.     os.reboot()
  100. end
  101.        
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement