Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- scheme = {
- ['txtcolor']=colors.white,
- ['selector']=colors.cyan,
- ['seperator']=colors.black,
- ['background']=colors.green
- }
- options = {
- "Help",
- "SampleOverflow",
- "I Leik Colurs"
- }
- optiontext = {
- "This is an example for a kiosk help line that could be implemented. a \"b\" surrounded in [] tags make it go down to the next line, for example... [b]split!",
- "This is an example of text overflow on the bar, as you can see, it puts a \"...\" at the end where it overflows",
- "Sadly at the moment, no colors."
- }
- optiontp = {
- "~ ~ ~",
- "~2 ~ ~",
- "~-2 ~ ~"
- }
- tx,ty = term.getSize()
- selected=1
- selectorpos=2
- selectorspeed=0.1 --The lower the faster
- function drawBar()
- term.setBackgroundColor(scheme['selector'])
- term.setCursorPos(2,selectorpos)
- if selectorpos%2==0 then
- write(" ")
- term.setCursorPos(2,selectorpos)
- drawText(options[selectorpos/2])
- else
- write(" ")
- end
- end
- function reDraw(nsp)
- nsp=nsp or selectorpos
- term.setBackgroundColor(scheme['background'])
- term.clear()
- for i=1,#options do
- term.setCursorPos(2,i*2)
- drawText(options[i])
- end
- term.setBackgroundColor(scheme['seperator'])
- for i=1,ty do
- term.setCursorPos(13,i)
- write(" ")
- end
- --This needs to be the last thing
- drawBar()
- if selectorpos ~= nsp then
- if nsp>selectorpos then
- repeat
- sleep(selectorspeed)
- term.setCursorPos(2,selectorpos)
- term.setBackgroundColor(scheme['background'])
- write(" ")
- if selectorpos%2==0 then
- term.setCursorPos(2,selectorpos)
- drawText(options[selectorpos/2])
- end
- selectorpos=selectorpos+1
- selected=selected+0.5
- drawBar()
- until selectorpos==nsp
- else
- repeat
- sleep(selectorspeed)
- term.setCursorPos(2,selectorpos)
- term.setBackgroundColor(scheme['background'])
- write(" ")
- if selectorpos%2==0 then
- term.setCursorPos(2,selectorpos)
- drawText(options[selectorpos/2])
- end
- selectorpos=selectorpos-1
- selected=selected-0.5
- drawBar()
- until selectorpos==nsp
- end
- end
- drawBar()
- --Drawing text here
- term.setBackgroundColor(scheme['background'])
- term.setCursorPos(15,2)
- write(options[selected])
- cline=1
- cpos=1
- itpos=1
- ntxt = optiontext[selected]
- repeat
- term.setCursorPos(14+cpos,cline+3)
- if ntxt:sub(itpos,itpos+2) == "[b]" then
- cline=cline+1
- cpos=1
- itpos=itpos+3
- else --reparse
- nxsp=0
- repeat
- nxsp=nxsp+1
- until ntxt:sub(itpos+nxsp,itpos+nxsp)==" " or itpos+nxsp>#ntxt
- if cpos+nxsp-1>tx-15 then
- cline=cline+1
- itpos=itpos+1
- cpos=1
- else
- write(ntxt:sub(itpos,itpos))
- itpos=itpos+1
- cpos=cpos+1
- end
- end
- until itpos>#ntxt
- end
- function drawText(txt)
- if #txt>10 then
- write(txt:sub(1,7).."...")
- else
- write(txt)
- end
- end
- cb = peripheral.wrap("back")
- while true do
- reDraw()
- e,p1,p2,p3=os.pullEvent()
- if e=="key" then
- key=p1
- if key==keys.up then
- if selected-1>=1 then
- reDraw((selected-1)*2)
- end
- elseif key==keys.down then
- if selected+1<=#options then
- reDraw((selected+1)*2)
- end
- elseif key==keys.enter then
- cb.setCommand("tp @p "..optiontp[selected])
- cb.runCommand()
- end
- elseif e=="mouse_click" then
- x,y = p2,p3
- if x>1 and x<12 and y%2==0 then
- if #options>=y/2 then
- reDraw(y)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement