Advertisement
Guest User

startup

a guest
Apr 28th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.57 KB | None | 0 0
  1. local monitor1 = peripheral.wrap('top')
  2. local monWidth, monHeight
  3. local buttCount = 0
  4. local buttLoc = {}
  5. local buttSize = {}
  6.  
  7. local function nextLine()
  8.  x, y = monitor1.getCursorPos()
  9.  monitor1.setCursorPos(1 ,y+1)
  10.  a, b = term.getCursorPos()
  11.  term.setCursorPos(1 , y+1)
  12. end
  13.  
  14. local function monStart()
  15.  monitor1.clear()
  16.  monWidth, monHeight = monitor1.getSize()
  17.  monitor1.setCursorPos(1,1)
  18.  monitor1.setTextScale(.5)
  19.  monitor1.setTextColor(colors.black)
  20.  monitor1.setBackgroundColor(colors.white)
  21.  monitor1.clear()
  22. end
  23.  
  24. local function center(str)
  25.  local len = string.len(str)
  26.  x = monWidth/2 - len/2
  27.  y = monHeight/2
  28.  if monWidth%2 ~= 0 and len%2 ~= 0 then
  29.   x = x + 1
  30.  end
  31.  return x,y
  32. end
  33.  
  34. local function drawButt(a, b, c)
  35.  monitor1.setTextColor(colors.white)
  36.  monitor1.setBackgroundColor(colors.black)
  37.  monitor1.setCursorPos(a, b)
  38.  monitor1.write(c)
  39.  buttCount = buttCount + 1
  40.  buttLoc[buttCount] = {}
  41.  buttLoc[buttCount]["x"] = a
  42.  buttLoc[buttCount]["y"] = b
  43.  local buttLength = string.len(c)
  44.  buttSize[buttCount] = buttLength
  45. end
  46.  
  47. --Returns 0 if no button coord found, 1 if found
  48. local function checkButt(a, b)
  49. term.write(a..b)
  50.  local i = 1
  51.  while i <= buttCount do
  52.   if buttLoc[i]["x"] == a and buttLoc[i]["y"] == b then
  53.       return 1, i
  54.   elseif buttLoc[i]["y"] == b and buttLoc[i]["x"] ~= a then
  55.    for j=1,buttSize[i],1 do
  56.     if buttLoc[i]["x"] == a - j then
  57.      return 1, i
  58.     else
  59.     end
  60.    end
  61.    i = i + 1
  62.   else
  63.    i = i + 1
  64.   end
  65.  end
  66.  return 0, 0
  67. end
  68.  
  69. local function monWriteCen(c)
  70.  monitor1.setTextColor(colors.black)
  71.  monitor1.setBackgroundColor(colors.white)
  72.  local d, e = center(c)
  73.  monitor1.setCursorPos(d,e)
  74.  monitor1.write(c)
  75. end
  76.  
  77. local function monWrite(a, b, c)
  78.  monitor1.setTextColor(colors.black)
  79.  monitor1.setBackgroundColor(colors.white)
  80.  monitor1.setCursorPos(a,b)
  81.  monitor1.write(c)
  82. end
  83.  
  84. monStart()
  85. local screenText = "Right Click Monitor To Begin"
  86. monWriteCen(screenText)
  87.  
  88. --Wait for click
  89. os.pullEvent("monitor_touch")
  90.  
  91. monStart()
  92. screenText = "Thanks! Welcome!"
  93. monWriteCen(screenText)
  94.  
  95. --Draw Buttons
  96. drawButt(8,3," Button1 ")
  97. drawButt(8,8," Button2 ")
  98.  
  99. --Wait for click
  100. local event,side,x,y = os.pullEvent("monitor_touch")
  101.  
  102. local buttStatus, buttNumber = checkButt(x,y)
  103. if buttStatus == 1 then
  104.  monStart()
  105.  screenText = "Button #"..buttNumber.." Pressed!"
  106.  monWriteCen(screenText)
  107. else
  108.  monStart()
  109.  screenText = "No Button Pressed!"
  110.  monWriteCen(screenText)
  111. end
  112. --Debug
  113. --monWrite(1,8,x)
  114. --monWrite(1,11,y)
  115. --monWrite(1,9,buttStatus)
  116. --monWrite(1,11,buttNumber)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement