Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Menu File
- Written by TheShadow989
- ]]--
- local menu_options = { }
- local function drawMenu(yyMenu, xxMenu)
- for index, data in pairs(menu_options) do
- term.setCursorPos(data.xPos, data.yPos)
- menu_options[index].bounds =
- {
- x1 = data.xPos;
- x2 = #data.text+data.xPos+3;
- y = data.yPos;
- }
- if data.yMenu == yyMenu and data.xMenu == xxMenu then
- term.setTextColor(data.color)
- text = "[ "..data.text.." ]"
- else
- text = " "..data.text.." "
- end
- term.write(text)
- term.setTextColor(colors.white)
- end
- end
- local function checkClick(x,y)
- for index, data in pairs(menu_options) do
- if x>data.bounds.x1 and x<data.bounds.x2 and y==data.bounds.y then
- return data.yMenu, data.xMenu
- end
- end
- return false, false
- end
- local function drawTime()
- term.setCursorPos(1,2)
- write(" ")
- term.setCursorPos(1,2)
- write(textutils.formatTime(os.time()))
- end
- local function drawInterface()
- term.setCursorPos(1,1)
- write("Logged in as: ")
- term.setCursorPos(1,19)
- term.write("xOS Alpha 1.25 by TheShadow989")
- end
- function displayMenu(array, timert, interfacet)
- menu_options = array
- term.clear()
- local timertoggle = timert
- local interfacetoggle = interfacet
- local timer = os.startTimer(1)
- local yyMenu, xxMenu = 1,1
- local btnbacktoggle, btnbacktrue = false, false
- local xxxMenu, yyyMenu = 0, 0
- if interfacetoggle == true then
- drawInterface()
- end
- if timertoggle == true then
- drawTime()
- end
- while true do
- drawMenu(yyMenu, xxMenu)
- local e = {os.pullEvent()}
- local limit, found = true, false
- local yMenulimit, xMenulimit = yyMenu, xxMenu
- if e[1] == "timer" and timertoggle == true then
- if e[2] == timer then
- timer = os.startTimer(1)
- drawTime()
- end
- elseif e[1] == "key" then --dont need this if you only use keyboard controls
- if e[2] == keys.down then
- for index, data in pairs(menu_options) do
- if data.xMenu == 0 and data.yMenu == 99 then
- btnbacktrue = true
- end
- if data.xMenu == xxMenu then
- if found == false and data.yMenu > yyMenu then
- for i=1, 25, 1 do
- if data.yMenu == yyMenu+i then
- yyMenu = yyMenu+i
- limit = false
- found = true
- break
- end
- end
- end
- if data.yMenu < yMenulimit then
- yMenulimit = data.yMenu
- end
- end
- end
- if limit == true then
- if btnbacktoggle == false and btnbacktrue == true then
- btnbacktoggle = true
- xxxMenu, yyyMenu = xxMenu, yMenulimit
- yyMenu = 99
- xxMenu = 0
- elseif btnbacktoggle == true and btnbacktrue == true then
- btnbacktoggle = false
- xxMenu = xxxMenu
- yyMenu = yyyMenu
- else
- yyMenu = yMenulimit
- end
- end
- elseif e[2] == keys.up then
- for index, data in pairs(menu_options) do
- if data.xMenu == 0 and data.yMenu == 99 then
- btnbacktrue = true
- end
- if data.xMenu == xxMenu then
- if data.yMenu < yyMenu then
- for i=1, 25, 1 do
- if data.yMenu == yyMenu-i then
- f=i
- limit = false
- break
- end
- end
- end
- if data.yMenu > yMenulimit then
- yMenulimit = data.yMenu
- end
- end
- end
- if limit == true then
- if btnbacktoggle == false and btnbacktrue == true then
- btnbacktoggle = true
- xxxMenu, yyyMenu = xxMenu, yMenulimit
- yyMenu = 99
- xxMenu = 0
- elseif btnbacktoggle == true and btnbacktrue == true then
- btnbacktoggle = false
- xxMenu = xxxMenu
- yyMenu = yyyMenu
- else
- yyMenu = yMenulimit
- end
- else
- yyMenu = yyMenu-f
- end
- elseif e[2] == keys.right then
- for index, data in pairs(menu_options) do
- if data.yMenu == yyMenu then
- if found == false and data.xMenu > xxMenu then
- for i=1, 25, 1 do
- if data.xMenu == xxMenu+i then
- xxMenu = xxMenu+i
- limit = false
- found = true
- break
- end
- end
- end
- if data.xMenu < xMenulimit then
- xMenulimit = data.xMenu
- end
- end
- end
- if limit == true then
- xxMenu = xMenulimit
- end
- elseif e[2] == keys.left then
- for index, data in pairs(menu_options) do
- if data.yMenu == yyMenu then
- if data.xMenu < xxMenu then
- for i=1, 25, 1 do
- if data.xMenu == xxMenu-i then
- f=i
- limit = false
- break
- end
- end
- end
- if data.xMenu > xMenulimit then
- xMenulimit = data.xMenu
- end
- end
- end
- if limit == true then
- xxMenu = xMenulimit
- else
- xxMenu = xxMenu-f
- end
- elseif e[2] == keys.enter then
- break
- end
- elseif e[1] == "mouse_click" then
- yyMenuclick, xxMenuclick = checkClick(e[3], e[4]) --Check the mouse click
- if yyMenuclick and xxMenuclick then --If checkClick returns a value and not false
- yyMenu = yyMenuclick
- xxMenu = xxMenuclick
- break
- end
- end
- end
- return xxMenu, yyMenu
- end
Add Comment
Please, Sign In to add comment