willwac

Theme Editor for LuaIDE

Aug 21st, 2014
477
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local c = {colors.green, colors.brown, colors.black, colors.pink, colors.yellow, colors.orange, colors.magenta, colors.purple, colors.cyan, colors.red, colors.white, colors.lightBlue, colors.lightGray, colors.gray, colors.lime, colors.blue}
  2. local theme = {}
  3. term.setBackgroundColor(colors.white)
  4. term.clear()
  5. term.setTextColor(c[11])
  6. w,h = term.getSize()
  7. paintutils.drawLine(1,1,w,1,c[13])
  8. term.setCursorPos(1,1)
  9. write("LuaIDE Theme Editor")
  10. term.setBackgroundColor(c[11])
  11. term.setTextColor(c[3])
  12. term.setCursorPos(w/2-5,2)
  13. print("Menu Colors")
  14. print("Background")
  15. print("\nBackground Highlight")
  16. print("\nButton Color")
  17. print("\nPrompt Color")
  18. print("\nError Color")
  19. print("\nError Highlight")
  20. term.setCursorPos(w/2-3,h-1)
  21. write("1/3")
  22. function drawColor(tableStart)
  23.   for y=3,13,2 do
  24.     for x=1,16 do
  25.       paintutils.drawPixel(x+22,y,c[x])
  26.     end
  27.     term.setCursorPos(33,y)
  28.     term.setBackgroundColor(c[11])
  29.     term.setTextColor(c[13])
  30.     write("#")
  31.     term.setCursorPos(40,y)
  32.     term.setTextColor(c[3])
  33.     write("Selected:")
  34.   end
  35.   term.setBackgroundColor(c[13])
  36.   term.setTextColor(c[11])
  37.   term.setCursorPos(w-7,h-1)
  38.   write(" Next ")
  39.   local valid tc = true
  40.   while true do
  41.     local _,_,x,y = os.pullEvent("mouse_click")
  42.     if x>=w-7 and x<=w-1 and y==h-1 then
  43.       for i=tableStart+1,tableStart+6 do
  44.         if not theme[i] then tc = false end
  45.       end
  46.       if tc == true then return true end
  47.     end
  48.     if x<22 or y>13 or x>38 or y<3 then
  49.       valid = false
  50.     end
  51.     for i=4,13,2 do
  52.       if y == i then
  53.         valid = false
  54.       end
  55.     end
  56.     if valid == false then break end
  57.     paintutils.drawPixel(49,y,c[x-22])
  58.     if x==33 then
  59.       term.setTextColor(c[13])
  60.       term.setCursorPos(49,y)
  61.       write("#")
  62.     end
  63.     theme[tableStart+math.floor(y/2)] = c[x-22]
  64.   end
  65.   term.setTextColor(c[3])
  66.   if valid == false then
  67.     drawColor(tableStart)
  68.   end
  69. end
  70. drawColor(0)
  71. term.setBackgroundColor(c[11])
  72. term.clear()
  73. paintutils.drawLine(1,1,w,1,c[13])
  74. term.setCursorPos(1,1)
  75. term.setTextColor(c[11])
  76. write("LuaIDE Theme Editor")
  77. term.setBackgroundColor(c[11])
  78. term.setTextColor(c[3])
  79. term.setCursorPos(w/2-6,2)
  80. print("Editor Colors")
  81. print("Background")
  82. print("\nLine Highlight")
  83. print("\nLine Number Color")
  84. print("\nLine Number Highlight")
  85. print("\nError Color")
  86. print("\nError Highlight")
  87. term.setCursorPos(w/2-3,h-1)
  88. write("2/3")
  89. drawColor(6)
  90. term.setBackgroundColor(c[11])
  91. term.clear()
  92. paintutils.drawLine(1,1,w,1,c[13])
  93. term.setCursorPos(1,1)
  94. term.setTextColor(c[11])
  95. write("LuaIDE Theme Editor")
  96. term.setBackgroundColor(c[11])
  97. term.setTextColor(c[3])
  98. term.setCursorPos(w/2-6,2)
  99. print("Syntax Colors")
  100. print("Text Color")
  101. print("\nConditions")
  102. print("\nConstants")
  103. print("\nFunctions")
  104. print("\nStrings")
  105. print("\nComments")
  106. term.setCursorPos(w/2-3,h-1)
  107. write("3/3")
  108. drawColor(12)
  109. term.setBackgroundColor(c[11])
  110. term.clear()
  111. paintutils.drawLine(1,1,w,1,c[13])
  112. term.setCursorPos(1,1)
  113. term.setTextColor(c[11])
  114. write("LuaIDE Theme Editor")
  115. term.setBackgroundColor(c[11])
  116. term.setTextColor(c[3])
  117. term.setCursorPos(w/2-5,2)
  118. print("Save Theme")
  119. print("Writing to file.")
  120. print("Do not change your LuaIDE Theme in settings, or your custom theme will be erased!")
  121. local mark = {}
  122. for i=0, #theme do
  123.   local t = theme[i]
  124.   if t==1 then mark[i] = "white" end
  125.   if t==2 then mark[i] = "orange" end
  126.   if t==4 then mark[i] = "magenta" end
  127.   if t==8 then mark[i] = "lightBlue" end
  128.   if t==16 then mark[i] = "yellow" end
  129.   if t==32 then mark[i] = "lime" end
  130.   if t==64 then mark[i] = "pink" end
  131.   if t==128 then mark[i] = "gray" end
  132.   if t==256 then mark[i] = "lightGray" end
  133.   if t==512 then mark[i] = "cyan" end
  134.   if t==1024 then mark[i] = "purple" end
  135.   if t==2048 then mark[i] = "blue" end
  136.   if t==4096 then mark[i] = "brown" end
  137.   if t==8192 then mark[i] = "green" end
  138.   if t==16384 then mark[i] = "red" end
  139.   if t==32768 then mark[i] = "black" end
  140. end
  141. fs.delete("./.luaide_theme")
  142. local file = fs.open("./.luaide_theme","w")
  143. file.writeLine("background="..mark[1])
  144. file.writeLine("backgroundHighlight="..mark[2])
  145. file.writeLine("prompt="..mark[3])
  146. file.writeLine("promptHighlight="..mark[4])
  147. file.writeLine("err="..mark[5])
  148. file.writeLine("errHighlight="..mark[6])
  149. file.writeLine("")
  150. file.writeLine("editorBackground="..mark[7])
  151. file.writeLine("editorLineHightlight="..mark[8])
  152. file.writeLine("editorLineNumbers="..mark[9])
  153. file.writeLine("editorLineNumbersHighlight="..mark[10])
  154. file.writeLine("editorError="..mark[11])
  155. file.writeLine("editorErrorHighlight="..mark[12])
  156. file.writeLine("")
  157. file.writeLine("textColor="..mark[13])
  158. file.writeLine("conditional="..mark[14])
  159. file.writeLine("constant="..mark[15])
  160. file.writeLine("function="..mark[16])
  161. file.writeLine("string="..mark[17])
  162. file.writeLine("comment="..mark[18])
  163. file.close()
  164. term.setCursorPos(w/2-6,8)
  165. write("Press any key")
  166. os.pullEvent("mouse_click")
  167. term.setBackgroundColor(c[3])
  168. term.setTextColor(c[11])
  169. term.setCursorPos(1,1)
  170. term.clear()
RAW Paste Data