Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- testing use of events in interface
- tMails = {}
- iServerID = 16
- local go = true
- local active = 1
- local amount = 4
- function split(sMail)
- local tPositions = {0,0,0,0,0}
- local tContents = {"","","",""}
- local last = 0
- for i = 1 ,# tPositions do
- first, last = string.find(sMail,"#|#",last+1)
- tPositions[i] = last
- end -- end for
- for i =1,((# tPositions)-1) do
- tContents[i] = string.sub(sMail,tPositions[i]+1,tPositions[i+1]-3)
- end -- end for
- return tContents[1],tContents[2],tContents[3],tContents[4]
- end -- end split
- local function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- local function getStartPos(width, length)
- return math.ceil((width-length)/2)
- end
- local function firstLine(y,amount)
- return math.floor((y-amount)/2)
- end
- local function moveDown()
- active = active + 1
- if (active > amount) then
- active = 1
- end
- end
- local function moveUp()
- active = active - 1
- if (active <= 0) then
- active = amount
- end
- end
- local function execute(active)
- if (active == 4) then
- go = false
- elseif (active ==2) then
- shell.run("makeMailMenu")
- elseif (active == 1) then
- shell.run("getMail")
- elseif (active == 3) then
- shell.run("readMail")
- end
- end
- local function drawMenu(active)
- x,y = term.getSize()
- option1 = ((active ~= 1) and "Get Mail" or "[Get Mail]")
- option2 = ((active ~= 2) and "Send Mail" or "[Send Mail]")
- option3 = ((active ~= 3) and "Read Mail" or "[Read Mail]")
- option4 = ((active ~= 4) and "Exit" or "[Exit]")
- y1 = firstLine(y,amount)
- term.setCursorPos(getStartPos(x,string.len(option1)),y1)
- print(option1)
- term.setCursorPos(getStartPos(x,string.len(option2)),y1+1)
- print(option2)
- term.setCursorPos(getStartPos(x,string.len(option3)),y1+2)
- print(option3)
- term.setCursorPos(getStartPos(x,string.len(option4)),y1+3)
- print(option4)
- end
- clear()
- drawMenu(active)
- while go do
- event, param1 = os.pullEvent("key")
- if (param1 == 208) then
- moveDown()
- elseif (param1 == 200) then
- moveUp()
- elseif (param1 == 28) then
- execute(active)
- end
- clear()
- drawMenu(active)
- end
- clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement