ThommyCraft

GUI

Mar 3rd, 2015
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.81 KB | None | 0 0
  1. --[[
  2.     CC-Bank
  3.     Copyright © 2012  Yingtong Li
  4.  
  5.     CC-Bank is free software: you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation, either version 3 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     CC-Bank is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with CC-Bank.  If not, see <http://www.gnu.org/licenses/>.
  17. --]]
  18.  
  19. ret1, ret2 = nil, nil --return for parallel functions
  20.  
  21. textStart = 11
  22.  
  23. function drawHeader()
  24.     -- Big C
  25.     term.setBackgroundColor(colors.lightBlue)
  26.     term.setCursorPos(3, 2)         term.write("    ")
  27.     term.setCursorPos(2, 3)         term.write(" ")
  28.     term.setCursorPos(2, 4)         term.write(" ")
  29.     term.setCursorPos(2, 5)         term.write(" ")
  30.     term.setCursorPos(3, 6)         term.write("    ")
  31.  
  32.     -- Big B
  33.     term.setBackgroundColor(colors.orange)
  34.     term.setCursorPos(4, 7)         term.write(" ")
  35.     term.setCursorPos(7, 7)         term.write(" ")
  36.     term.setCursorPos(4, 8)         term.write("   ")
  37.  
  38.     -- Big M
  39.     term.setBackgroundColor(colors.lime)
  40.     term.setCursorPos(4, 4)         term.write("   ")
  41.     term.setCursorPos(8, 4)         term.write("   ")
  42.     term.setCursorPos(4, 5)         term.write(" ")
  43.     term.setCursorPos(7, 5)         term.write(" ")
  44.     term.setCursorPos(10, 5)        term.write(" ")
  45.     term.setCursorPos(10, 6)        term.write(" ")
  46.  
  47.     -- Text
  48.     term.setBackgroundColor(colors.black)
  49.     term.setCursorPos(13, 5)        term.write("Construction Bank of Minecraft")
  50.     term.setCursorPos(38, 2)        term.write("CC-Bank 0.2.0")
  51.  
  52.     term.setBackgroundColor(colors.black)
  53. end
  54.  
  55. function drawButtons()
  56.     term.setBackgroundColor(colors.lightGray)
  57.     term.setCursorPos(3, textStart)     term.write("  ")
  58.     term.setCursorPos(3, textStart + 2) term.write("  ")
  59.     term.setCursorPos(3, textStart + 4) term.write("  ")
  60.     term.setCursorPos(3, textStart + 6) term.write("  ")
  61.  
  62.     term.setCursorPos(48, textStart)    term.write("  ")
  63.     term.setCursorPos(48, textStart + 2)    term.write("  ")
  64.     term.setCursorPos(48, textStart + 4)    term.write("  ")
  65.     term.setCursorPos(48, textStart + 6)    term.write("  ")
  66.  
  67.     term.setBackgroundColor(colors.black)
  68. end
  69.  
  70. function drawButton(button, text)
  71.     local x, y
  72.     if button == 1 then x = 6       y = textStart       end
  73.     if button == 2 then x = 6       y = textStart + 2   end
  74.     if button == 3 then x = 6       y = textStart + 4   end
  75.     if button == 4 then x = 6       y = textStart + 6   end
  76.  
  77.     if button == 5 then x = 47 - #text  y = textStart       end
  78.     if button == 6 then x = 47 - #text  y = textStart + 2   end
  79.     if button == 7 then x = 47 - #text  y = textStart + 4   end
  80.     if button == 8 then x = 47 - #text  y = textStart + 6   end
  81.  
  82.     term.setCursorPos(x, y)
  83.     term.write(text)
  84. end
  85.  
  86. function drawError(error)
  87.     -- Outer Triangle
  88.     term.setBackgroundColor(colors.red)
  89.     term.setCursorPos(12, textStart)            term.write(" ")
  90.     term.setCursorPos(11, textStart + 1)        term.write(" ")
  91.     term.setCursorPos(10, textStart + 2)        term.write(" ")
  92.     term.setCursorPos(9, textStart + 3)         term.write(" ")
  93.     term.setCursorPos(8, textStart + 4)         term.write(" ")
  94.     term.setCursorPos(7, textStart + 5)         term.write(" ")
  95.     term.setCursorPos(6, textStart + 6)         term.write("             ")
  96.  
  97.     term.setCursorPos(13, textStart + 1)        term.write(" ")
  98.     term.setCursorPos(14, textStart + 2)        term.write(" ")
  99.     term.setCursorPos(15, textStart + 3)        term.write(" ")
  100.     term.setCursorPos(16, textStart + 4)        term.write(" ")
  101.     term.setCursorPos(17, textStart + 5)        term.write(" ")
  102.  
  103.     -- Inner Triangle
  104.     term.setBackgroundColor(colors.white)
  105.     term.setCursorPos(12, textStart + 1)        term.write(" ")
  106.     term.setCursorPos(11, textStart + 2)        term.write("   ")
  107.     term.setCursorPos(10, textStart + 3)        term.write("     ")
  108.     term.setCursorPos(9, textStart + 4)         term.write("       ")
  109.     term.setCursorPos(8, textStart + 5)         term.write("         ")
  110.  
  111.     -- !
  112.     term.setBackgroundColor(colors.black)
  113.     term.setCursorPos(12, textStart + 2)        term.write(" ")
  114.     term.setCursorPos(12, textStart + 3)        term.write(" ")
  115.     term.setCursorPos(12, textStart + 5)        term.write(" ")
  116.  
  117.     -- Text
  118.     term.setBackgroundColor(colors.black)
  119.     term.setCursorPos(20, textStart)            term.write(error)
  120.  
  121.     term.setBackgroundColor(colors.black)
  122. end
  123.  
  124. function center(y, sText)
  125.     local w, h = term.getSize()
  126.     x = math.max(math.floor((w - #sText) / 2), 0)
  127.     term.setCursorPos(x, y)
  128.     print(sText)
  129.     return x
  130. end
  131.  
  132. function waitForMouse()
  133.     while true do
  134.         local event, p1, p2, p3 = os.pullEvent("mouse_click")
  135.         if p1 == 1 then
  136.             ret1, ret2 = p2, p3
  137.             return p2, p3
  138.         end
  139.     end
  140. end
  141.  
  142. function waitForButton()
  143.     while true do
  144.         local mx, my = waitForMouse()
  145.         if my == textStart and mx >= 3 and mx <= 4 then         ret1 = 1    return 1    end
  146.         if my == textStart + 2 and mx >= 3 and mx <= 4 then     ret1 = 2    return 2    end
  147.         if my == textStart + 4 and mx >= 3 and mx <= 4 then     ret1 = 3    return 3    end
  148.         if my == textStart + 6 and mx >= 3 and mx <= 4 then     ret1 = 4    return 4    end
  149.  
  150.         if my == textStart and mx >= 48 and mx <= 49 then       ret1 = 5    return 5    end
  151.         if my == textStart + 2 and mx >= 48 and mx <= 49 then       ret1 = 6    return 6    end
  152.         if my == textStart + 4 and mx >= 48 and mx <= 49 then       ret1 = 7    return 7    end
  153.         if my == textStart + 6 and mx >= 48 and mx <= 49 then       ret1 = 8    return 8    end
  154.     end
  155. end
  156.  
  157. function waitForChar()
  158.     while true do
  159.         local event, p1 = os.pullEvent("char")
  160.         ret1 = p1
  161.         return p1
  162.     end
  163. end
  164.  
  165. function waitForKey()
  166.     while true do
  167.         local event, p1 = os.pullEvent("key")
  168.         ret1 = p1
  169.         return p1
  170.     end
  171. end
  172.  
  173. function waitForEnter()
  174.     while true do
  175.         local p1 = waitForKey()
  176.         if p1 == 28 then
  177.             return
  178.         end
  179.     end
  180. end
  181.  
  182. function waitForDisk()
  183.     while true do
  184.         local event, p1 = os.pullEvent("disk")
  185.         return
  186.     end
  187. end
Add Comment
Please, Sign In to add comment