Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI(shell.dir().."/screen")
- local mo1 = {x1=0,x2=0,y1=0,y2=0,color=colors.lime,text="green",handle= function(ca) term.setBackgroundColor(colors.lime) shell.run('clear') end}
- ca = false
- local ah
- function def()
- mo2 = {x1=mo1.x1,x2=mo1.x2,y1=mo1.y2+1,y2=mo1.y2+1,color=colors.blue,text="blue",handle= function(ca) term.setBackgroundColor(colors.blue) shell.run('clear') end}
- mo3 = {x1=mo1.x1,x2=mo1.x2,y1=mo2.y2+1,y2=mo2.y2+1,color=colors.purple,text="clear",handle= function(ca) term.setBackgroundColor(colors.black) shell.run('clear') end}
- mo4 = {x1=mo1.x1,x2=mo1.x2,y1=mo3.y2+1,y2=mo3.y2+1,color=colors.red,text="quit",handle= function() term.setCursorPos(1,1) error('Quitted Program') end}
- contextmenu = {mo1,mo2,mo3,mo4}
- end
- function drawMenu()
- for i = 1,#contextmenu do
- screen.drawButton(contextmenu[i])
- end
- end
- while true do
- if ah ~= nil then
- contextmenu[ah].handle(ca)
- end
- if ca then
- drawMenu()
- end
- local ev,btn,x,y = os.pullEvent("mouse_click")
- if btn == 2 then
- screen.cls()
- mo1.x1 = x
- mo1.x2 = x+5
- mo1.y1 = y
- mo1.y2 = y
- ca = true
- def()
- drawMenu()
- elseif btn == 1 then
- local tp = false
- if not ca then
- screen.cls()
- else
- screen.cls()
- for i = 1,#contextmenu do
- if screen.pressed(contextmenu[i],x,y) then
- ah = i
- contextmenu[i].handle(ca)
- ca = true
- tp = true
- end
- end
- if not tp then
- ca = false
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement