Pirnogion

MenuAPI

Nov 21st, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.22 KB | None | 0 0
  1. ----------------------------------------------------------------
  2. -- Program: MENU        -- Temporal variables: _<type>Varname --
  3. -- Author:  JaggerDer   -- Constants:          <type>VARNAME  --
  4. -- Created: 11.11.14    -- Argument:           a<type>Argname --
  5. ----------------------------------------------------------------
  6.  
  7. --<APIs>--
  8.  
  9. --<LOCAL VARIABLES>--
  10. local tMenuItem = {}
  11. local iCurrentItem = 0
  12.  
  13. --<CONSTANTS>--
  14. local iMAXITEMS = 0 --{0 - unlimited}
  15.  
  16. --[TEXTMENU]--
  17. function fDrawMenu()
  18.  term.clear()
  19.  
  20.  local _iMILen = #tMenuItem
  21.  local _sStr = nil
  22.  
  23.  for i = 1, _iMILen, 1 do
  24.   if (i ~= iCurrentItem+1) then
  25.    _sStr = i .. ": " .. tMenuItem[i]["name"]
  26.   else
  27.    _sStr = i .. ": " .. tMenuItem[i]["name"] .. " <- "
  28.   end
  29.  
  30.   term.setCursorPos(1, i)
  31.   write(_sStr)
  32.  end
  33. end
  34.  
  35. function fRegisterItem(asName, afFunc)
  36.  local _iMILen = #tMenuItem + 1
  37.  
  38.  tMenuItem[_iMILen] = {}
  39.  tMenuItem[_iMILen]["name"] = asName
  40.  tMenuItem[_iMILen]["func"] = afFunc
  41. end
  42.  
  43. function fNextItem()
  44.  iCurrentItem = (iCurrentItem + 1) % #tMenuItem
  45. end
  46.  
  47. function fPrevItem()
  48.  iCurrentItem = (iCurrentItem - 1) % #tMenuItem
  49. end
  50.  
  51. function fRunAction()
  52.  local _fFunc = tMenuItem[iCurrentItem+1]["func"]
  53.  
  54.  _fFunc()
  55. end
Advertisement
Add Comment
Please, Sign In to add comment