Advertisement
incinirate

Kiosk

Jun 20th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.66 KB | None | 0 0
  1. scheme = {
  2.   ['txtcolor']=colors.white,
  3.   ['selector']=colors.cyan,
  4.   ['seperator']=colors.black,
  5.   ['background']=colors.green
  6. }
  7.  
  8. options = {
  9.   "Help",
  10.   "SampleOverflow",
  11.   "I Leik Colurs"
  12. }
  13.  
  14. optiontext = {
  15.   "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!",
  16.   "This is an example of text overflow on the bar, as you can see, it puts a \"...\" at the end where it overflows",
  17.   "Sadly at the moment, no colors."
  18. }
  19.  
  20. optiontp = {
  21.   "~ ~ ~",
  22.   "~2 ~ ~",
  23.   "~-2 ~ ~"
  24. }
  25.  
  26. tx,ty = term.getSize()
  27.  
  28. selected=1
  29. selectorpos=2
  30. selectorspeed=0.1 --The lower the faster
  31.  
  32. function drawBar()
  33.   term.setBackgroundColor(scheme['selector'])
  34.   term.setCursorPos(2,selectorpos)
  35.   if selectorpos%2==0 then
  36.     write("          ")
  37.     term.setCursorPos(2,selectorpos)
  38.     drawText(options[selectorpos/2])
  39.   else
  40.     write("          ")
  41.   end
  42. end
  43.  
  44. function reDraw(nsp)
  45.   nsp=nsp or selectorpos
  46.   term.setBackgroundColor(scheme['background'])
  47.   term.clear()
  48.  
  49.   for i=1,#options do
  50.     term.setCursorPos(2,i*2)
  51.     drawText(options[i])
  52.   end
  53.  
  54.   term.setBackgroundColor(scheme['seperator'])
  55.   for i=1,ty do
  56.     term.setCursorPos(13,i)
  57.     write(" ")
  58.   end
  59.  
  60.   --This needs to be the last thing
  61.   drawBar()
  62.   if selectorpos ~= nsp then
  63.     if nsp>selectorpos then
  64.       repeat
  65.         sleep(selectorspeed)
  66.         term.setCursorPos(2,selectorpos)
  67.         term.setBackgroundColor(scheme['background'])
  68.         write("          ")
  69.         if selectorpos%2==0 then
  70.           term.setCursorPos(2,selectorpos)
  71.           drawText(options[selectorpos/2])
  72.         end
  73.         selectorpos=selectorpos+1
  74.         selected=selected+0.5
  75.         drawBar()
  76.       until selectorpos==nsp
  77.     else
  78.       repeat
  79.         sleep(selectorspeed)
  80.         term.setCursorPos(2,selectorpos)
  81.         term.setBackgroundColor(scheme['background'])
  82.         write("          ")
  83.         if selectorpos%2==0 then
  84.           term.setCursorPos(2,selectorpos)
  85.           drawText(options[selectorpos/2])
  86.         end
  87.         selectorpos=selectorpos-1
  88.         selected=selected-0.5
  89.         drawBar()
  90.       until selectorpos==nsp
  91.     end
  92.   end
  93.   drawBar()
  94.  
  95.   --Drawing text here
  96.   term.setBackgroundColor(scheme['background'])
  97.  
  98.   term.setCursorPos(15,2)
  99.   write(options[selected])
  100.  
  101.   cline=1
  102.   cpos=1
  103.   itpos=1
  104.   ntxt = optiontext[selected]
  105.   repeat
  106.     term.setCursorPos(14+cpos,cline+3)
  107.     if ntxt:sub(itpos,itpos+2) == "[b]" then
  108.       cline=cline+1
  109.       cpos=1
  110.       itpos=itpos+3
  111.     else --reparse
  112.       nxsp=0
  113.       repeat
  114.         nxsp=nxsp+1
  115.       until ntxt:sub(itpos+nxsp,itpos+nxsp)==" " or itpos+nxsp>#ntxt
  116.       if cpos+nxsp-1>tx-15 then
  117.         cline=cline+1
  118.         itpos=itpos+1
  119.         cpos=1
  120.       else
  121.         write(ntxt:sub(itpos,itpos))
  122.         itpos=itpos+1
  123.         cpos=cpos+1
  124.       end
  125.     end
  126.   until itpos>#ntxt
  127. end
  128.  
  129. function drawText(txt)
  130.   if #txt>10 then
  131.     write(txt:sub(1,7).."...")
  132.   else
  133.     write(txt)
  134.   end
  135. end
  136.  
  137. cb = peripheral.wrap("back")
  138.  
  139. while true do
  140.   reDraw()
  141.   e,p1,p2,p3=os.pullEvent()
  142.   if e=="key" then
  143.     key=p1
  144.     if key==keys.up then
  145.       if selected-1>=1 then
  146.         reDraw((selected-1)*2)
  147.       end
  148.     elseif key==keys.down then
  149.       if selected+1<=#options then
  150.         reDraw((selected+1)*2)
  151.       end
  152.     elseif key==keys.enter then
  153.       cb.setCommand("tp @p "..optiontp[selected])
  154.       cb.runCommand()
  155.     end
  156.   elseif e=="mouse_click" then
  157.     x,y = p2,p3
  158.     if x>1 and x<12 and y%2==0 then
  159.       if #options>=y/2 then
  160.         reDraw(y)
  161.       end
  162.     end
  163.   end
  164. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement