LezChap

CAH Greeting

Jun 27th, 2015
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.79 KB | None | 0 0
  1. mon = peripheral.wrap("top")
  2. mon.setTextScale(2)
  3. mon.clear()
  4. winRules = window.create(mon, 1, 3, 41, 20, false)
  5. winNorm = window.create(mon, 1, 3, 41, 20, true)
  6. button = {}
  7.  
  8. function addButton(name, func, xmin, xmax, ymin, ymax, color, activeColor, textColor, label, isInvis)
  9.   color = color or colors.red
  10.   activeColor = activeColor or colors.lime
  11.   isInvis = isInvis or false
  12.   label = label or name
  13.   button[name] = {}
  14.   button[name]["func"] = func
  15.   button[name]["active"] = false
  16.   button[name]["xmin"] = xmin
  17.   button[name]["ymin"] = ymin
  18.   button[name]["xmax"] = xmax
  19.   button[name]["ymax"] = ymax
  20.   button[name]["color"] = color
  21.   button[name]["activeColor"] = activeColor
  22.   button[name]["textColor"] = textColor
  23.   button[name]["isInvis"] = isInvis
  24.   button[name]["label"] = label
  25. end
  26.  
  27. function screenButton()
  28.   local currcolor
  29.   for name, data in pairs(button)do
  30.     local active = data["active"]
  31.     if active  == true then
  32.       currcolor = data["activeColor"]
  33.     else
  34.       currcolor = data["color"]
  35.     end
  36.     if not data["isInvis"] then
  37.       fillButton(data["label"], currcolor, data["textColor"], data)
  38.     end
  39.   end
  40. end
  41.  
  42. function fillButton(text, color, textColor, bData)
  43.   if color ~= "invis" then
  44.     mon.setBackgroundColor(color)
  45.   end
  46.   mon.setTextColor(textColor)
  47.   local yspot = math.floor((bData["ymin"] + bData["ymax"])/2)
  48.   local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  49.   for j = bData["ymin"], bData["ymax"] do
  50.     mon.setCursorPos(bData["xmin"], j)
  51.     if j == yspot then
  52.       for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) + 1 do
  53.         if k == xspot then
  54.           if color == "invis" then
  55.             mon.setCursorPos(xspot + bData["xmin"], yspot)
  56.           end
  57.           mon.write(text)
  58.           if color == "invis" then
  59.             return
  60.           end
  61.         else
  62.           if color ~= "invis" then
  63.             mon.write(" ")
  64.           else
  65.             mon.setCursorPos(k+1, j)
  66.           end
  67.         end
  68.       end
  69.     else
  70.       if color ~= "invis" then
  71.         for i = bData["xmin"], bData["xmax"] do
  72.           mon.write(" ")
  73.         end
  74.       end
  75.     end
  76.   end
  77.   mon.setBackgroundColor(colors.black)
  78. end  
  79.  
  80. function toggleButton(name)
  81.   button[name]["active"] = not button[name]["active"]
  82.   screenButton()
  83. end
  84.  
  85. function flash(name)
  86.   toggleButton(name)
  87.   sleep(0.15)
  88.   toggleButton(name)
  89. end
  90.  
  91. function deactivateButton(name)
  92.   button[name]["active"] = false
  93. end
  94.  
  95. function activateButton(name)
  96.   button[name]["active"] = true
  97. end
  98.  
  99. function toggleInvisButton(name)
  100.   button[name]["isInvis"] = not button[name]["isInvis"]
  101.   screenButton()
  102. end
  103.  
  104. function checkxy(x, y)
  105.   for name, data in pairs(button) do
  106.     if not data["isInvis"] then
  107.       if y>=data["ymin"] and y<= data["ymax"] then
  108.         if x>=data["xmin"] and x<=data["xmax"] then
  109.             data["func"]()
  110.             --flash(name)
  111.             return true, name
  112.         end
  113.       end
  114.     end
  115.   end
  116.   return false, nil
  117. end
  118.  
  119. function center(obj, line, text)
  120.   local sizeX = obj.getSize()
  121.   local posX = ((sizeX - string.len(text)) / 2) + 1
  122.   obj.setCursorPos(posX, line)
  123.   obj.write(text)  
  124. end
  125.  
  126. function right(obj, line, text)
  127.   local sizeX = obj.getSize()
  128.   local posX = sizeX - string.len(text)
  129.   obj.setCursorPos(posX, line)
  130.   obj.write(text)
  131. end
  132.  
  133. function openRules()
  134.   toggleInvisButton("RULES")
  135.   winRules.setVisible(true)
  136.   winNorm.setVisible(false)  
  137.   toggleInvisButton("X")
  138. end
  139.  
  140. function closeRules()
  141.   winRules.setVisible(false)
  142.   winNorm.setVisible(true)
  143.   toggleInvisButton("X")
  144.   toggleInvisButton("RULES")
  145. end
  146.  
  147. mon.setTextColor(colors.white)
  148. center(mon, 1, "-=Cards Against Humanity=-")
  149. mon.setTextColor(colors.lightGray)
  150. center(mon, 2, "A party game for horrible people.")
  151.  
  152. addButton("X", closeRules, 40, 41, 20, 20, colors.lightGray, colors.red, colors.black, "X", true)
  153. winRules.setTextColor(colors.lightGray)
  154. winRules.setCursorPos(1, 2)
  155. winRules.write("1. Last person to take a shit is The ")
  156. winRules.setTextColor(colors.red)
  157. winRules.write("Card")
  158. winRules.setCursorPos(1, 3)
  159. winRules.write("  Czar. ")
  160. winRules.setTextColor(colors.lightGray)
  161. winRules.write("The ")
  162. winRules.setTextColor(colors.red)
  163. winRules.write("Card Czar ")
  164. winRules.setTextColor(colors.lightGray)
  165. winRules.write("reads the first")
  166. winRules.setCursorPos(1, 4)
  167. winRules.write("  question to the group.")
  168. winRules.setCursorPos(1, 5)
  169. winRules.write("2. The rest of the players answers the ")
  170. winRules.setCursorPos(1, 6)
  171. winRules.write("  question with one of their white ")
  172. winRules.setCursorPos(1, 7)
  173. winRules.write("  answer cards.  Pick the one you find ")
  174. winRules.setCursorPos(1, 8)
  175. winRules.write("  the funniest, or most offensive.")
  176. winRules.setCursorPos(1, 9)
  177. winRules.write("3. The ")
  178. winRules.setTextColor(colors.red)
  179. winRules.write("Card Czar ")
  180. winRules.setTextColor(colors.lightGray)
  181. winRules.write("reads all answer cards ")
  182. winRules.setCursorPos(1, 10)
  183. winRules.write("  out-loud, making them as entertaining ")
  184. winRules.setCursorPos(1, 11)
  185. winRules.write("  as possible. After reading all answers, ")
  186. winRules.setCursorPos(1, 12)
  187. winRules.write("  The ")
  188. winRules.setTextColor(colors.red)
  189. winRules.write("Card Czar ")
  190. winRules.setTextColor(colors.lightGray)
  191. winRules.write("picks the 'best' answer.  ")
  192. winRules.setCursorPos(1, 13)
  193. winRules.write("  The player who chose that card becomes ")
  194. winRules.setCursorPos(1, 14)
  195. winRules.write("  the new ")
  196. winRules.setTextColor(colors.red)
  197. winRules.write("Card Czar")
  198. winRules.setTextColor(colors.lightGray)
  199. winRules.write(", and earns an ")
  200. winRules.setCursorPos(1, 15)
  201. winRules.write("  '")
  202. winRules.setTextColor(colors.green)
  203. winRules.write("awesome point")
  204. winRules.setTextColor(colors.lightGray)
  205. winRules.write("'.")
  206. winRules.setCursorPos(1, 16)
  207. winRules.setTextColor(colors.lightGray)
  208. winRules.write("4. Repeat the process above until the ")
  209. winRules.setCursorPos(1, 17)
  210. winRules.write("  deck is gone, people get bored, or ")
  211. winRules.setCursorPos(1, 18)
  212. winRules.write("  everyone storms off being offended.")
  213. --winRules.setVisible(true)
  214.  
  215. winNorm.setTextColor(colors.gray)
  216. center(winNorm, 1, "(AKA Aknotsdeath)")
  217. addButton("RULES", openRules, 16, 27, 8, 10, colors.brown, colors.gold, colors.red, "RULES", false)
  218.  
  219. winNorm.setBackgroundColor(colors.black)
  220.  
  221. winNorm.setTextColor(colors.lightGray)
  222. center(winNorm, 11, "If you're ready to continue, enter ")
  223. center(winNorm, 12, "into the darkness to your right.")
  224. center(winNorm, 13, "Then pick a room and enjoy the game.")
  225. screenButton()
  226.  
  227. os.startTimer(15)
  228. while true do
  229.   event, param1, param2, param3 = os.pullEvent()
  230.   if event == "timer" then
  231.     os.startTimer(15)
  232.   end
  233.   if event == "monitor_touch" then
  234.     print(tostring(checkxy(param2, param3)))
  235.   end
  236. end
Advertisement
Add Comment
Please, Sign In to add comment