Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Menu File
- Written by TheShadow989
- ]]--
- local menu_options =
- {
- [1] = {text="Command ", yMenu=1, xMenu=1, yPos=8, xPos=3, color=colors.yellow},
- [2] = {text="Programs", yMenu=2, xMenu=1, yPos=9, xPos=3, color=colors.yellow},
- [3] = {text="Accounts", yMenu=3, xMenu=1, yPos=10, xPos=3, color=colors.yellow},
- [4] = {text="Details ", yMenu=4, xMenu=1, yPos=11, xPos=3, color=colors.yellow},
- [5] = {text="Shutdown", yMenu=5, xMenu=1, yPos=12, xPos=3, color=colors.red},
- [6] = {text="Settings", yMenu=1, xMenu=2, yPos=8, xPos=15, color=colors.yellow},
- [7] = {text="Scripts ", yMenu=2, xMenu=2, yPos=9, xPos=15, color=colors.yellow},
- [8] = {text="Attacks ", yMenu=1, xMenu=3, yPos=8, xPos=27, color=colors.yellow},
- [9] = {text="Internet", yMenu=2, xMenu=3, yPos=9, xPos=27, color=colors.yellow},
- [10] = {text="ServerFr", yMenu=3, xMenu=3, yPos=10, xPos=27, color=colors.yellow},
- [11] = {text=" Back ", yMenu=99, xMenu=0, yPos=14, xPos=15, color=colors.blue},
- [12] = {text=" Back ", yMenu=0, xMenu=99, yPos=9, xPos=39, color=colors.blue},
- }
- local function menuDraw(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
- term.clear()
- local yyMenu, xxMenu = 1,1
- local btnbacktoggle, btnbacktrue = false, false
- local xxxMenu, yyyMenu = 0, 0
- while true do
- menuDraw(yyMenu, xxMenu)
- local e = {os.pullEvent()}
- local limit, found = true, false
- local yMenulimit, xMenulimit = yyMenu, xxMenu
- if 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
- term.clear()
- term.setCursorPos(8,9)
- if yyMenu == 1 and xxMenu == 1 then
- print("You have chosen the 'Command' option.")
- elseif yyMenu == 2 and xxMenu == 1 then
- print("You have chosen the 'Programs' option.")
- elseif yyMenu == 3 and xxMenu == 1 then
- print("You have chosen the 'Accounts' option.")
- elseif yyMenu == 4 and xxMenu == 1 then
- print("You have chosen the 'Details' option.")
- elseif yyMenu == 5 and xxMenu == 1 then
- print("You have chosen the 'Shutdown' option.")
- elseif yyMenu == 1 and xxMenu == 2 then
- print("You have chosen the 'Settings' option.")
- elseif yyMenu == 2 and xxMenu == 2 then
- print("You have chosen the 'Scripts' option.")
- elseif yyMenu == 1 and xxMenu == 3 then
- print("You have chosen the 'Attacks' option.")
- elseif yyMenu == 2 and xxMenu == 3 then
- print("You have chosen the 'Internet' option.")
- elseif yyMenu == 3 and xxMenu == 3 then
- print("You have chosen the 'SeverFr' option.")
- elseif yyMenu == 99 and xxMenu == 0 then
- print("You have chosen the 'back' option.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement