Advertisement
Symmetryc

X V0.3

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