local sbc = term.setBackgroundColor local stc = term.setTextColor local scp = term.setCursorPos local pa = paintutils local running = true local w,h = term.getSize() local states = { inHelp = false, inMain = true, inMenu = false, } function expandBox(fx,fy,tx,ty,col) for i =1, tx-fx do pa.drawFilledBox(fx,fy,i,ty,col) sleep(0.1) end end function despandBox(fx,fy,tx,ty,col) for i =fx-tx, 1 do pa.drawFilledBox(fx-i,fy,tx,ty,col) sleep(0.1) end end function cwrite(t,y) scp((w/2) - #t/2, y) write(t) end function drawhelp() if(not states.inHelp)then despandBox(1,2,12,19,colors.white) states.inMain = true return end scp(1,1) sbc(colors.gray) term.clearLine() cwrite("Help Menu",1) expandBox(1,2,12,19,colors.gray) drawbuttons() end function drawmenu() if(not states.inMenu)then despandBox(1,2,12,19,colors.white) else expandBox(1,2,12,19,colors.gray) drawbuttons() end end local buttons = { {n="Start",x=1,y=1,depends='inMain' or 'inMenu',tc=colors.white,bc=colors.gray,fbc=colors.black,ftc=colors.lightGray,click=function() states.inMenu = not states.inMenu drawmenu() end}, {n="Help ",x=2,y=3,depends='inMenu',tc=colors.white,bc=colors.gray,fbc=colors.black,ftc=colors.lightGray,click=function() states.inHelp = true states.inMain = false states.inMenu = false drawmenu() drawhelp() end}, {n="Reboot ",x=2,y=4,depends='inMenu',tc=colors.white,bc=colors.gray,fbc=colors.black,ftc=colors.lightBlue,click=function() os.reboot() end}, {n="Quit ",x=2,y=5,depends='inMenu',tc=colors.white,bc=colors.gray,fbc=colors.black,ftc=colors.red,click=function() end}, {n="Topic 1 ",x=2,y=3,depends='inHelp',tc=colors.white,bc=colors.gray,fbc=colors.black,ftc=colors.lightGray,click=function() end}, {n="Topic 2 ",x=2,y=4,depends='inHelp',tc=colors.white,bc=colors.gray,fbc=colors.black,ftc=colors.lightBlue,click=function() end}, {n="Quit ",x=2,y=5,depends='inHelp',tc=colors.white,bc=colors.gray,fbc=colors.black,ftc=colors.red,click=function() states.inHelp = false drawhelp() redraw() drawbuttons() states.inMenu = not states.inMenu drawmenu() end}, } function drawbuttons() -- Draw buttons based on state dependances for i = 1, #buttons do if(buttons[i].depends == nil or states[buttons[i].depends])then -- Draw button sbc(buttons[i].bc) stc(buttons[i].tc) scp(buttons[i].x,buttons[i].y) write(buttons[i].n) end end end function flashbutton(n) sbc(buttons[n].fbc) stc(buttons[n].ftc) scp(buttons[n].x,buttons[n].y) write(buttons[n].n) sleep(0.2) sbc(buttons[n].bc) stc(buttons[n].tc) scp(buttons[n].x,buttons[n].y) write(buttons[n].n) end function updatebuttons(e) if(e[1] == "mouse_click")then -- Update buttons based on state dependances for i = 1, #buttons do if(buttons[i].depends == nil or states[buttons[i].depends])then -- Update button local x,y = e[3], e[4] if(x >= buttons[i].x and x <= buttons[i].x+#buttons[i].n and y == buttons[i].y)then flashbutton(i) buttons[i].click() return end end end end end function redraw() sbc(colors.white) term.clear() scp(1,1) sbc(colors.gray) term.clearLine() scp(1,1) drawbuttons() end function loop() redraw() while running do -- Manage screen states (States that change the entire screen layout) local e = {os.pullEvent()} updatebuttons(e) end end loop()