Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.07 KB | None | 0 0
  1. --[[
  2. Japanese Flashcards V0.1_ALPHA
  3.  
  4. Written by Torje 20.12.2014
  5.  
  6. Enjoy ^^
  7. --]]
  8.  
  9. -- Selection Menu
  10. local menu_options={
  11.   [1]={text="I",color=colors.red},
  12.   [2]={text="Cute",color=colors.pink},
  13.   [3]={text="Amazing",color=colors.blue},
  14.   [4]={text="Healthy",color=colors.green},
  15.   [5]={text="Black",color=colors.black},
  16.   [6]={text="Red",color=colors.red},
  17.   [7]={text="Eye",color=colors.yellow},
  18.   [8]={text="Human",color=colors.blue},
  19.   [9]={text="Big",color=colors.green},
  20.   [10]={text="Advance", color=colors.black}
  21. }
  22. local termX,termY=term.getSize()
  23.  
  24. local function menuDraw(selected)
  25.   local yPos = termY/2 - #menu_options/2
  26.   for index, data in pairs(menu_options) do
  27.     menu_options[index].bounds = {
  28.           x1 = termX/2 - (#data.text+4)/2,
  29.           x2 = termX/2 + (#data.text+4)/2,
  30.           y = yPos
  31.         }
  32.         term.setTextColor(data.color)
  33.         term.setCursorPos(data.bounds.x1, data.bounds.y)
  34.        
  35.         local text =
  36.         index==selected and "["..data.text.."]" or
  37.         " "..data.text.." "
  38.         term.write(text)
  39.         yPos = yPos+1
  40.   end
  41. end
  42. local function checkClick(x,y)
  43.   for index, data in pairs(menu_options) do
  44.     if x>= data.bounds.x1 and x<= data.bounds.x2 and y==data.bounds.y then
  45.           return index
  46.         end
  47.   end
  48.   return false
  49. end
  50. term.clear()
  51. local selector = 1
  52. while true do
  53.   menuDraw(selector)
  54.   local e = {os.pullEvent()}
  55.   if e[1] == "key" then
  56.     if e[2] == keys.down then
  57.           selector = selector < #menu_options and selector+1 or 1
  58.     elseif e[2] == keys.up then
  59.           selector = selector > 1 and selector-1 or 3 or #menu_options
  60.         elseif e[2] == keys.enter then
  61.           break
  62.         end
  63.   elseif e[1] == "mouse_click" then
  64.     local value = checkClick(e[3], e[4])
  65.         if value then
  66.           selector = value
  67.           break
  68.         end
  69.   end
  70. end
  71. if selector == 1 then
  72.   term.setBackgroundColor(colors.white)
  73.   term.clear()
  74.   term.setCursorPos(1,1)
  75.   paintutils.drawImage("/kanji/watashi")
  76.   term.setCursorPos(40,17)
  77.   term.write("watashi")
  78. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement