SHARE
TWEET

Untitled

a guest Feb 23rd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- testing use of events in interface
  2.  
  3. tMails = {}
  4. iServerID = 16
  5.  
  6. local go = true
  7. local active = 1
  8. local amount = 4
  9.  
  10. function split(sMail)
  11.  local tPositions = {0,0,0,0,0}
  12.  local tContents = {"","","",""}
  13.  
  14.  local last = 0
  15.  for i = 1 ,# tPositions do
  16.   first, last = string.find(sMail,"#|#",last+1)
  17.   tPositions[i] = last
  18.  end -- end for
  19.  
  20.  for i =1,((# tPositions)-1) do
  21.   tContents[i] = string.sub(sMail,tPositions[i]+1,tPositions[i+1]-3)
  22.  end -- end for
  23.  
  24.  return tContents[1],tContents[2],tContents[3],tContents[4]
  25.  
  26. end -- end split
  27.  
  28.  
  29. local function clear()
  30.  term.clear()
  31.  term.setCursorPos(1,1)
  32. end
  33.  
  34. local function getStartPos(width, length)
  35.  return math.ceil((width-length)/2)
  36. end
  37.  
  38. local function firstLine(y,amount)
  39.  return math.floor((y-amount)/2)
  40. end
  41.  
  42. local function moveDown()
  43.  active = active + 1
  44.  if (active > amount) then
  45.   active = 1
  46.  end
  47. end
  48.  
  49. local function moveUp()
  50.  active = active - 1
  51.  if (active <= 0) then
  52.   active = amount
  53.  end
  54. end
  55.  
  56. local function execute(active)
  57.  if (active == 4) then
  58.   go = false
  59.  elseif (active ==2) then
  60.   shell.run("makeMailMenu")
  61.  elseif (active == 1) then
  62.   shell.run("getMail")
  63.  elseif (active == 3) then
  64.   shell.run("readMail")
  65.  end
  66. end
  67.  
  68. local function drawMenu(active)
  69.  x,y = term.getSize()
  70.  option1 = ((active ~= 1) and "Get Mail" or "[Get Mail]")
  71.  option2 = ((active ~= 2) and "Send Mail" or "[Send Mail]")
  72.  option3 = ((active ~= 3) and "Read Mail" or "[Read Mail]")
  73.  option4 = ((active ~= 4) and "Exit" or "[Exit]")
  74.  
  75.  y1 = firstLine(y,amount)
  76.  term.setCursorPos(getStartPos(x,string.len(option1)),y1)
  77.  print(option1)
  78.  term.setCursorPos(getStartPos(x,string.len(option2)),y1+1)
  79.  print(option2)
  80.  term.setCursorPos(getStartPos(x,string.len(option3)),y1+2)
  81.  print(option3)
  82.  term.setCursorPos(getStartPos(x,string.len(option4)),y1+3)
  83.  print(option4)
  84.  
  85. end
  86.  
  87.  
  88. clear()
  89. drawMenu(active)
  90. while go do
  91.  event, param1 = os.pullEvent("key")
  92.  if (param1 == 208) then
  93.   moveDown()
  94.  elseif (param1 == 200) then
  95.   moveUp()
  96.  elseif (param1 == 28) then
  97.   execute(active)
  98.  end
  99.  
  100.  clear()
  101.  drawMenu(active)
  102. end
  103.  
  104. clear()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top