Advertisement
Symmetryc

X V0.4

Apr 7th, 2013
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.13 KB | None | 0 0
  1. --[[ X ]]--
  2. local s = {}
  3. local op = {}
  4. if not fs.exists("XData") then
  5.     fs.makeDir("XData")
  6.     fs.makeDir("/XData/ModData")
  7.     fs.makeDir("/XData/SaveData")
  8.     g = fs.open("/XData/General", "w")
  9.     g.writeLine(2^7)   
  10.     g.writeLine(2^1)    
  11.     g.writeLine(2^1)   
  12.     g.writeLine(2^15)  
  13.     g.writeLine(2)     
  14.     g.close()
  15.     s[1] = fs.open("/XData/SaveData/Save1", "w")
  16.     s[2] = fs.open("/XData/SaveData/Save2", "w")
  17.     s[3] = fs.open("/XData/SaveData/Save3", "w")
  18.     s[1].writeLine("New")
  19.     s[2].writeLine("New")
  20.     s[3].writeLine("New")
  21.     s[1].close()
  22.     s[2].close()
  23.     s[3].close()
  24. end
  25. g = fs.open("/XData/General", "r")
  26. s[1] = fs.open("/XData/SaveData/Save1", "r")
  27. s[2] = fs.open("/XData/SaveData/Save2", "r")
  28. s[3] = fs.open("/XData/SaveData/Save3", "r")
  29. for i=1, 5 do
  30.     op[i] = tonumber(g.readLine())
  31. end
  32. file = {
  33.     {
  34.     s[1].readLine();
  35.     };
  36.     {
  37.     s[2].readLine();
  38.     };
  39.     {
  40.     s[3].readLine();
  41.     };
  42. }
  43. g.close()
  44. s[1].close()   
  45. s[2].close()
  46. s[3].close()
  47. local stop = false
  48. local toolbar = false
  49. local tbts = " [Options] [Controls] [About] [Exit]"
  50. local space = "                                       "
  51. local anDis = 0
  52. local swapped = 0
  53. local menuNum = 0
  54. local noFlicker = true
  55. local pnd = {0, 0, 0, 0, 0}
  56. local function disp(a)
  57.     crsr = 1
  58.     term.setTextColor(op[4])
  59.     if a then
  60.         for i=1, string.len(tbts), op[5] do
  61.             term.setBackgroundColor(op[2])
  62.             term.setCursorPos(1, 1)
  63.             write("[+]")
  64.             write(string.sub(tbts, i, -1))
  65.             term.setBackgroundColor(op[1])
  66.             write(space)
  67.             term.setBackgroundColor(2^15)
  68.             term.setCursorPos(2, 2)                
  69.             write(string.sub(space, i, -1))
  70.             term.setBackgroundColor(op[1])
  71.             write(space)
  72.             sleep(0.05)
  73.         end
  74.         toolbar = false
  75.     elseif a==false then
  76.         for i=1, string.len(tbts), op[5] do
  77.             term.setBackgroundColor(op[2])
  78.             term.setCursorPos(1, 1)
  79.             write("[-]")
  80.             write(string.sub(tbts, -i, -1))
  81.             term.setBackgroundColor(2^15)
  82.             term.setCursorPos(2, 2)
  83.             write(string.sub(space, -i-3, -1))
  84.             sleep(0.05)
  85.         end
  86.         toolbar = true
  87.     end
  88.     if toolbar then
  89.         term.setBackgroundColor(op[2])
  90.         term.setCursorPos(1, 1)
  91.         write("[-]"..tbts)
  92.         term.setBackgroundColor(2^15)
  93.         term.setCursorPos(2, 2)
  94.         write(space)
  95.     else
  96.         term.setBackgroundColor(op[1])
  97.         term.setCursorPos(4, 1)
  98.         write(space)
  99.         term.setCursorPos(5, 2)
  100.         write(space)
  101.         term.setBackgroundColor(op[2])
  102.         term.setCursorPos(1, 1)
  103.         write("[+]")
  104.         term.setBackgroundColor(2^15)
  105.         term.setCursorPos(2, 2)
  106.         write("   ")
  107.     end
  108. end
  109. local function anTimeSlider()
  110.     term.setBackgroundColor(op[1])
  111.     term.setCursorPos(24, 4)
  112.     write("     ")
  113.     term.setBackgroundColor(op[4])
  114.     term.setCursorPos(23+dp5, 4)
  115.     write(" ")
  116.     term.setBackgroundColor(op[2])
  117.     term.setCursorPos(35, 4)
  118.     write("          ")
  119.     term.setCursorPos(35, 4)
  120.     if dp5==1 then
  121.         write("Slow")
  122.     elseif dp5==2 then
  123.         write("Normal")
  124.     elseif dp5==3 then
  125.         write("Fast")
  126.     elseif dp5==4 then
  127.         write("Very Fast")
  128.     elseif dp5==5 then
  129.         write("Instant")
  130.     end
  131. end
  132. local function colorArrow()
  133.     for i=5, 14, 3 do
  134.         term.setCursorPos(24, i)
  135.         for i2=0, 15 do
  136.             if 2^i2==pnd[i/3-2/3] then
  137.                 write("^")
  138.             else
  139.                 write(" ")
  140.             end
  141.         end
  142.     end
  143. end
  144. local function swapOps()
  145.     for i=1, 5 do
  146.         swap = pnd[i]
  147.         pnd[i] = op[i]
  148.         op[i] = swap
  149.     end
  150.     swapped = swapped+1
  151. end
  152. local function preview()
  153.     toolbar = true
  154.     swapped = 0
  155.     swapOps()
  156.     while true do
  157.         term.setTextColor(op[4])
  158.         term.setBackgroundColor(op[1])
  159.         term.clear()
  160.         term.setBackgroundColor(op[3])
  161.         for i=1, 3 do  
  162.             c = i*5
  163.             for i2=-1, 1 do
  164.                 term.setCursorPos(9, i2+c)
  165.                 write("                                 ")
  166.                 term.setCursorPos(42, i2+c+1)
  167.                 term.setBackgroundColor(2^15)
  168.                 write(" ")
  169.                 term.setBackgroundColor(op[3])
  170.             end
  171.             term.setCursorPos(26-string.len(file[i][1])/2, c)
  172.             write(file[i][1])
  173.             term.setBackgroundColor(2^15)
  174.             term.setCursorPos(10, c+2)
  175.             write("                                 ")
  176.             term.setBackgroundColor(op[3])
  177.         end
  178.         term.setBackgroundColor(op[1])
  179.         term.setCursorPos(1, 19)
  180.         write('"Left Click" to exit or "Right Click" to compare')
  181.         disp()
  182.         event, p1, p2, p3 = os.pullEvent("mouse_click")
  183.         if p1==1 then
  184.             if 2%swapped==1 then
  185.                 swapOps()
  186.             end
  187.             break
  188.         elseif p1==2 then
  189.             disp(toolbar)
  190.             swapOps()
  191.         end
  192.     end
  193. end
  194. local function exit()
  195.     term.setCursorPos(44, 2)
  196.     write("/Exit\\")
  197.     term.setCursorPos(45, 1)
  198.     write("____")
  199.     term.setBackgroundColor(op[2])
  200.     term.setTextColor(op[4])
  201.     term.setCursorPos(8, 7)
  202.     write("Would you like to save you changes?")
  203.     term.setCursorPos(8, 12)
  204.     write("Save Changes         Cancel Changes")
  205. end
  206. local function input(a)
  207.     if a==0 then
  208.         while true do
  209.             event, p1, p2, p3 = os.pullEvent("mouse_click")
  210.             if p2>=9 and p2<=41 and p3>1 then
  211.                 if p3>=4 and p3<=6 then
  212.                     if p1==1 then
  213.                         --
  214.                         break
  215.                     else
  216.                         window(0, 1, p2, p3) --Menu, Win, X, Y
  217.                     end
  218.                 elseif p3>=9 and p3<=11 then
  219.                     if p1==1 then
  220.                         --
  221.                         break
  222.                     else
  223.                         window(0, 2, p2, p3)
  224.                     end
  225.                 elseif p3>=14 and p3<=16 then
  226.                     if p1==1 then
  227.                         --
  228.                         break
  229.                     else
  230.                         window(0, 3, p2, p3)
  231.                     end
  232.                 end
  233.             elseif p3==1 then              
  234.                 if p2>=1 and p2<=3 then
  235.                     disp(toolbar)
  236.                 elseif p2>=5 and p2<=13 and toolbar then
  237.                     menuNum = 1
  238.                     toolbar = false
  239.                     break
  240.                 elseif p2>=15 and p2<=24 and toolbar then
  241.                     menuNum = 2
  242.                     toolbar = false
  243.                     break
  244.                 elseif p2>=26 and p2<=32 and toolbar then
  245.                     menuNum = 3
  246.                     toolbar = false
  247.                     break
  248.                 elseif p2>=34 and p2<=39 and toolbar then
  249.                     stop = true
  250.                     break
  251.                 end
  252.             end
  253.         end
  254.     elseif a==1 then
  255.         while true do
  256.             event, p1, p2, p3 = os.pullEvent()
  257.             if crsr==1 then
  258.                 if event=="mouse_drag" and p2>=24 and p2<=28 and p3==4 then
  259.                     dp5 = p2-23
  260.                     if dp5==3 then
  261.                         pnd[5] = 5
  262.                     elseif dp5==4 then
  263.                         pnd[5] = 10
  264.                     elseif dp5==5 then
  265.                         pnd[5] = 100
  266.                     else
  267.                         pnd[5] = dp5
  268.                     end
  269.                     anTimeSlider()
  270.                 elseif event=="mouse_click" and p3==2 then
  271.                     if p2>=11 and p2<=15 then
  272.                         crsr = 2
  273.                         break
  274.                     elseif p2>=37 and p2<=43 then
  275.                         preview()
  276.                         break
  277.                     elseif p2>=45 and p2<=48 then
  278.                         crsr = 3
  279.                         break
  280.                     end
  281.                 end
  282.             elseif crsr==2 then
  283.                 if event=="mouse_click" and p2>=24 and p2<=39 then
  284.                     b = p2-24
  285.                     c = p3/3-1/3
  286.                     if c%1==0 then
  287.                         pnd[c] = 2^b
  288.                         colorArrow()
  289.                     elseif p3==13 then
  290.                         pnd[4] = 2^b
  291.                         colorArrow()
  292.                     end
  293.                 elseif event=="mouse_click" and p3==2 then
  294.                     if p2>=2 and p2<=9 then
  295.                         crsr = 1
  296.                         break
  297.                     elseif p2>=37 and p2<=43 then
  298.                         preview()
  299.                         break
  300.                     elseif p2>=45 and p2<=48 then
  301.                         crsr = 3
  302.                         break
  303.                     end
  304.                 end
  305.             elseif crsr==3 then
  306.                 if event=="mouse_click" and p3==12 then
  307.                     if p2>=8 and p2<=19 then
  308.                         for i=1, 5 do
  309.                             if not pnd[i] then
  310.                                 pnd[i] = op[i]
  311.                             else
  312.                                 op[i] = pnd[i]
  313.                             end
  314.                         end
  315.                         if op[5]==3 then
  316.                             op[5] = 5
  317.                         elseif op[5]==4 then
  318.                             op[5] = 10
  319.                         elseif op[5]==5 then
  320.                             op[5] = 100
  321.                         end
  322.                         menuNum = 0
  323.                         break
  324.                     elseif p2>=29 and p2<=42 then
  325.                         menuNum = 0
  326.                         break
  327.                     end
  328.                 elseif event=="mouse_click" and p3==2 then
  329.                     if p2>2 and p2<=9 then
  330.                         crsr = 1
  331.                         break
  332.                     elseif p2>=11 and p2<=15 then
  333.                         crsr = 2
  334.                         break
  335.                     elseif p2>=37 and p2<=43 then
  336.                         preview()
  337.                         break
  338.                     end
  339.                 end
  340.             end
  341.         end
  342.     elseif a==2 then
  343.         while true do
  344.             event, p1, p2, p3 = os.pullEvent()
  345.             if crsr==1 and event=="mouse_click" then
  346.                 if p2>=45 and p2<=48 and p3==2 then
  347.                     crsr = 2
  348.                     break
  349.                 end
  350.             elseif crsr==2 and event=="mouse_click" then
  351.                 if p2>2 and p2<=9 and p3==2 then
  352.                     crsr = 1
  353.                     break
  354.                 elseif p2>=8 and p2<=19 then
  355.                     menuNum = 0
  356.                     break
  357.                 elseif p2>=29 and p2<=42 then
  358.                     menuNum = 0
  359.                     break
  360.                 end
  361.             end
  362.         end
  363.     elseif a==3 then
  364.         while true do
  365.             event = os.pullEvent()
  366.             if event=="key" or event=="mouse_click" or event=="mouse_scroll" then
  367.                 menuNum = 0
  368.                 break
  369.             end
  370.         end
  371.     end
  372. end
  373. local function menu(a)
  374.     if menuNum==0 then
  375.         pnd[1] = op[1]
  376.         pnd[2] = op[2]
  377.         pnd[3] = op[3]
  378.         pnd[4] = op[4]
  379.         pnd[5] = op[5]
  380.         dp5 = pnd[5]
  381.         if pnd[5]==5 then
  382.             dp5 = 3
  383.         elseif pnd[5]==10 then
  384.             dp5 = 4
  385.         elseif pnd[5]==100 then
  386.             dp5 = 5
  387.         else
  388.             dp5 = pnd[5]
  389.         end
  390.         crsr = 1
  391.         term.setTextColor(op[4])
  392.         term.setBackgroundColor(op[1])
  393.         term.clear()
  394.         term.setCursorPos(18, 19)
  395.         write("X, by Symmetryc")
  396.         term.setBackgroundColor(op[3])
  397.         for i=1, 3 do  
  398.             c = i*5
  399.             for i2=-1, 1 do
  400.                 term.setCursorPos(9, i2+c)
  401.                 write("                                 ")
  402.                 term.setCursorPos(42, i2+c+1)
  403.                 term.setBackgroundColor(2^15)
  404.                 write(" ")
  405.                 term.setBackgroundColor(op[3])
  406.             end
  407.             term.setCursorPos(26-string.len(file[i][1])/2, c)
  408.             write(file[i][1])
  409.             term.setBackgroundColor(2^15)
  410.             term.setCursorPos(10, c+2)
  411.             write("                                 ")
  412.             term.setBackgroundColor(op[3])
  413.         end
  414.         if a==nil then
  415.             disp()
  416.         end
  417.     elseif menuNum==1 or menuNum==2 or menuNum==3 then
  418.         term.setBackgroundColor(op[2])
  419.         term.setTextColor(op[4])
  420.         term.clear()
  421.         term.setBackgroundColor(op[1])
  422.         term.setCursorPos(1, 1)
  423.         term.clearLine()
  424.         term.setCursorPos(1, 2)
  425.         term.clearLine()
  426.         term.setCursorPos(1, 18)
  427.         term.clearLine()
  428.         term.setCursorPos(1, 19)
  429.         term.clearLine()
  430.         for i=1, 19 do
  431.             term.setCursorPos(1, i)
  432.             write(" ")
  433.             term.setCursorPos(50, i)
  434.             write(" ")
  435.             term.setCursorPos(51, i)
  436.             write(" ")
  437.         end
  438.         term.setBackgroundColor(2^15)
  439.         for i=4, 18 do
  440.             term.setCursorPos(50, i)
  441.             write(" ")
  442.         end
  443.         term.setCursorPos(3, 18)
  444.         write("                                               ")
  445.         term.setBackgroundColor(op[1])
  446.         term.setCursorPos(3, 1)
  447.         if menuNum==1 then
  448.             write("_______ _____                     _______ ____")
  449.             term.setCursorPos(2, 2)
  450.             write("/General\\Color\\                   /Preview\\Exit\\")
  451.             term.setTextColor(op[2])
  452.             if crsr==1 then
  453.                 term.setCursorPos(2, 2)
  454.                 write("/General\\")
  455.                 term.setCursorPos(3, 1)
  456.                 write("_______")
  457.                 term.setBackgroundColor(op[2])
  458.                 term.setTextColor(op[4])
  459.                 term.setCursorPos(3, 4)
  460.                 write("Animation Speed")
  461.                 anTimeSlider()
  462.             elseif crsr==2 then
  463.                 term.setCursorPos(10, 2)
  464.                 write("/Color\\")
  465.                 term.setCursorPos(11, 1)
  466.                 write("_____")
  467.                 term.setBackgroundColor(op[2])
  468.                 term.setTextColor(op[4])
  469.                 term.setCursorPos(3, 4)
  470.                 write("Background Color")
  471.                 term.setCursorPos(3, 7)
  472.                 write("Toolbar Color")
  473.                 term.setCursorPos(3, 10)
  474.                 write("Button Color")
  475.                 term.setCursorPos(3, 13)
  476.                 write("Text Color")    
  477.                 for i=4, 13, 3 do
  478.                     term.setCursorPos(24, i)
  479.                     for i2=0, 15 do
  480.                         term.setBackgroundColor(2^i2)                  
  481.                         write(" ")
  482.                     end
  483.                 end
  484.                 term.setBackgroundColor(op[2])
  485.                 colorArrow()
  486.             elseif crsr==3 then
  487.                 exit()
  488.             end
  489.         elseif menuNum==2 then
  490.             write("_______                                   ____")
  491.             term.setCursorPos(2, 2)
  492.             write("/General\\                                 /Exit\\")
  493.             term.setTextColor(op[2])
  494.             if crsr==1 then
  495.                 term.setCursorPos(3, 1)
  496.                 write("_______")
  497.                 term.setCursorPos(2, 2)
  498.                 write("/General\\")
  499.                 term.setBackgroundColor(op[2])
  500.                 term.setTextColor(op[4])
  501.                 --
  502.             elseif crsr==2 then
  503.                 exit()
  504.             end
  505.         elseif menuNum==3 then
  506.             term.setTextColor(op[2])           
  507.             write("_____")
  508.             term.setCursorPos(2, 2)
  509.             write("/About\\")
  510.             term.setTextColor(op[4])
  511.             term.setBackgroundColor(op[2])
  512.             term.setCursorPos(3, 4)
  513.             write("Version: 0.4")
  514.             term.setCursorPos(3, 5)
  515.             write("Description: An RPG Game for Computercraft")
  516.             term.setCursorPos(3, 6)
  517.             write("Credits:")
  518.             term.setCursorPos(3, 7)
  519.             write("X, by Symmetryc")
  520.             term.setCursorPos(3, 8)
  521.             write("ComputerCraft, by dan200")
  522.             term.setCursorPos(3, 9)
  523.             write("Minecraft, by Mojang")
  524.             term.setCursorPos(3, 10)
  525.             write("CC-Emulator, by tomass1996")
  526.             term.setCursorPos(3, 11)
  527.             write("Sublime Text 2, by Sublime HQ")
  528.         end
  529.     end
  530.     if a==nil then
  531.         input(menuNum)
  532.     end
  533. end
  534. menu(true)
  535. disp(toolbar)
  536. input(0)
  537. while true do
  538.     menu()
  539.     g = fs.open("/XData/General", "w")
  540.     s[1] = fs.open("/XData/SaveData/Save1", "w")
  541.     s[2] = fs.open("/XData/SaveData/Save2", "w")
  542.     s[3] = fs.open("/XData/SaveData/Save3", "w")
  543.     g.writeLine(op[1])
  544.     g.writeLine(op[2])
  545.     g.writeLine(op[3])
  546.     g.writeLine(op[4])
  547.     g.writeLine(op[5])
  548.     g.close()  
  549.     for i=1, 3 do
  550.         s[i].writeLine(file[i][1])
  551.         s[i].close()
  552.     end
  553.     if stop==true then
  554.         term.setBackgroundColor(2^15)
  555.         term.setTextColor(2^0)
  556.         term.clear()
  557.         term.setCursorPos(1, 1)
  558.         break
  559.     end
  560. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement