Advertisement
Guest User

test

a guest
Jul 1st, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.71 KB | None | 0 0
  1. mon = peripheral.find("monitor")
  2. mX, mY = mon.getSize()
  3. activeScreen = 1
  4.  
  5. function monPrint(txt)
  6.  local this = term.current()
  7.  term.redirect(mon)
  8.  print(txt)
  9.  term.redirect(this)
  10. end
  11.  
  12. function drawActiveScreen()
  13.  if screens[activeScreen] then
  14.   setlabel(screens[activeScreen]())
  15.  else
  16.   print("something went wrong!")
  17.  end
  18. end
  19.  
  20. function setlabel(text)
  21.  mon.setBackgroundColor(colors.gray)
  22.  mon.setTextColor(colors.white)
  23.  for i=1,3 do
  24.   mon.setCursorPos(1,mY-i-3)
  25.   mon.write("                                                                                                          ")
  26.  end
  27.  cWrite(text,mY-5)
  28. end
  29.  
  30. function screen1()
  31.  mon.setCursorPos(1,1)
  32.  mon.setBackgroundColor(colors.black)
  33.  mon.setTextColor(colors.yellow)
  34.  mon.write("Main information:")
  35.  mon.setCursorPos(1,3)
  36.  mon.setTextColor(colors.white)
  37.  monPrint("You can rightclick the buttons below to switch tabs to see more info on ranks, paths and their differences.")
  38.  return "  Information"
  39. end
  40.  
  41. function screen2()
  42.  mon.setCursorPos(1,1)
  43.  mon.setBackgroundColor(colors.black)
  44.  mon.setTextColor(colors.yellow)
  45.  mon.write("Rank type 1 information:")
  46.  mon.setTextColor(colors.white)
  47.  mon.setCursorPos(1,3)
  48.  monPrint("These ranks blablabla information blabla sigh I gotta sleep")
  49.  return "Rank type 1"
  50. end
  51.  
  52. function screen3()
  53.  
  54.  return "Rank type 2"
  55. end
  56.  
  57. function cWrite(text,line)
  58.  local len = string.len(text)
  59.  mon.setCursorPos(math.ceil(mX/2)-(len/2),line)
  60.  mon.write(text)
  61. end
  62.  
  63. function drawButton(mode,active)
  64.  local text = "unset"
  65.  if active == true then
  66.   mon.setBackgroundColor(colors.white)
  67.  else
  68.   mon.setBackgroundColor(colors.lightGray)
  69.  end
  70.  mon.setTextColor(colors.black)
  71.  if mode == "prev" then
  72.   xStart = 1
  73.   text = "Back"
  74.  else
  75.   xStart = (mX-1)/2 + 2
  76.   text = "Next"
  77.  end
  78.  bgText = ""
  79.  repeat
  80.   bgText = bgText.." "
  81.  until string.len(bgText) >= math.floor(mX/2)
  82.  for i=1,3 do
  83.   mon.setCursorPos(xStart,mY-(i-1))
  84.   mon.write(bgText)
  85.  end
  86.  if mode == "prev" then
  87.   mon.setCursorPos(xStart+5,mY-1)
  88.  else
  89.   mon.setCursorPos(xStart+5,mY-1)
  90.  end
  91.  mon.write(text)
  92. end
  93.  
  94. function main()
  95.  mon.setBackgroundColor(colors.black)
  96.  mon.clear()
  97.  drawButton("prev")
  98.  drawButton("next")
  99.  drawActiveScreen()
  100.  event = {os.pullEvent("monitor_touch")}
  101.  centerP = mX / 2
  102.  --print(textutils.serialize(event))
  103.  if event[4] >= mY-3 then
  104.   if event[3] < centerP then
  105.    activeScreen = activeScreen - 1
  106.    if activeScreen == 0 then
  107.     activeScreen = #screens
  108.    end
  109.   elseif event[3] > centerP then
  110.    activeScreen = activeScreen + 1
  111.    if activeScreen > #screens then
  112.     activeScreen = 1
  113.    end
  114.   end
  115.  end
  116.  --print(activeScreen)
  117. end
  118.  
  119. screens = {screen1,screen2,screen3}
  120. while true do
  121.  main()
  122. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement