Advertisement
pipocochigato1

linoria themes

Apr 1st, 2023 (edited)
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.68 KB | None | 0 0
  1. local httpService = game:GetService('HttpService')
  2. local ThemeManager = {} do
  3. ThemeManager.Folder = 'LinoriaLibSettings'
  4. -- if not isfolder(ThemeManager.Folder) then makefolder(ThemeManager.Folder) end
  5.  
  6. ThemeManager.Library = nil
  7. ThemeManager.BuiltInThemes = {
  8. ['Default'] = { 1, httpService:JSONDecode('{"FontColor":"ffffff","MainColor":"1c1c1c","AccentColor":"0055ff","BackgroundColor":"141414","OutlineColor":"323232"}') },
  9. ['Dracula'] = { 2, httpService:JSONDecode('{"FontColor":"ffffff","MainColor":"232533","AccentColor":"6271a5","BackgroundColor":"1b1c27","OutlineColor":"7c82a7"}') },
  10. ['Bitch Bot'] = { 3, httpService:JSONDecode('{"FontColor":"ffffff","MainColor":"1e1e1e","AccentColor":"7e48a3","BackgroundColor":"232323","OutlineColor":"141414"}') },
  11. ['Kiriot Hub'] = { 4, httpService:JSONDecode('{"FontColor":"ffffff","MainColor":"30333b","AccentColor":"ffaa00","BackgroundColor":"1a1c20","OutlineColor":"141414"}') },
  12. ['Fatality'] = { 5, httpService:JSONDecode('{"FontColor":"ffffff","MainColor":"1e1842","AccentColor":"c50754","BackgroundColor":"191335","OutlineColor":"3c355d"}') },
  13. ['Green'] = { 6, httpService:JSONDecode('{"FontColor":"ffffff","MainColor":"141414","AccentColor":"00ff8b","BackgroundColor":"1c1c1c","OutlineColor":"3c3c3c"}') },
  14. ['Jester'] = { 7, httpService:JSONDecode('{"FontColor":"ffffff","MainColor":"242424","AccentColor":"db4467","BackgroundColor":"1c1c1c","OutlineColor":"373737"}') },
  15. ['Mint'] = { 8, httpService:JSONDecode('{"FontColor":"ffffff","MainColor":"242424","AccentColor":"3db488","BackgroundColor":"1c1c1c","OutlineColor":"373737"}') },
  16. ['Tokyo Night'] = { 9, httpService:JSONDecode('{"FontColor":"ffffff","MainColor":"191925","AccentColor":"6759b3","BackgroundColor":"16161f","OutlineColor":"323232"}') },
  17. ['Ubuntu'] = { 10, httpService:JSONDecode('{"FontColor":"ffffff","MainColor":"3e3e3e","AccentColor":"e2581e","BackgroundColor":"323232","OutlineColor":"191919"}') },
  18. }
  19.  
  20. function ThemeManager:ApplyTheme(theme)
  21. local customThemeData = self:GetCustomTheme(theme)
  22. local data = customThemeData or self.BuiltInThemes[theme]
  23.  
  24. if not data then return end
  25.  
  26. -- custom themes are just regular dictionaries instead of an array with { index, dictionary }
  27.  
  28. local scheme = data[2]
  29. for idx, col in next, customThemeData or scheme do
  30. self.Library[idx] = Color3.fromHex(col)
  31.  
  32. if Options[idx] then
  33. Options[idx]:SetValueRGB(Color3.fromHex(col))
  34. end
  35. end
  36.  
  37. self:ThemeUpdate()
  38. end
  39.  
  40. function ThemeManager:ThemeUpdate()
  41. self.Library.FontColor = Options.FontColor.Value
  42. self.Library.MainColor = Options.MainColor.Value
  43. self.Library.AccentColor = Options.AccentColor.Value
  44. self.Library.BackgroundColor = Options.BackgroundColor.Value
  45. self.Library.OutlineColor = Options.OutlineColor.Value
  46.  
  47. self.Library.AccentColorDark = self.Library:GetDarkerColor(self.Library.AccentColor);
  48. self.Library:UpdateColorsUsingRegistry()
  49. end
  50.  
  51. function ThemeManager:LoadDefault()
  52. local theme = 'Default'
  53. local content = isfile(self.Folder .. '/themes/default.txt') and readfile(self.Folder .. '/themes/default.txt')
  54.  
  55. local isDefault = true
  56. if content then
  57. if self.BuiltInThemes[content] then
  58. theme = content
  59. elseif self:GetCustomTheme(content) then
  60. theme = content
  61. isDefault = false;
  62. end
  63. elseif self.BuiltInThemes[self.DefaultTheme] then
  64. theme = self.DefaultTheme
  65. end
  66.  
  67. if isDefault then
  68. Options.ThemeManager_ThemeList:SetValue(theme)
  69. else
  70. self:ApplyTheme(theme)
  71. end
  72. end
  73.  
  74. function ThemeManager:SaveDefault(theme)
  75. writefile(self.Folder .. '/themes/default.txt', theme)
  76. end
  77.  
  78. function ThemeManager:CreateThemeManager(groupbox)
  79. groupbox:AddLabel('Background color'):AddColorPicker('BackgroundColor', { Default = self.Library.BackgroundColor });
  80. groupbox:AddLabel('Main color') :AddColorPicker('MainColor', { Default = self.Library.MainColor });
  81. groupbox:AddLabel('Accent color'):AddColorPicker('AccentColor', { Default = self.Library.AccentColor });
  82. groupbox:AddLabel('Outline color'):AddColorPicker('OutlineColor', { Default = self.Library.OutlineColor });
  83. groupbox:AddLabel('Font color') :AddColorPicker('FontColor', { Default = self.Library.FontColor });
  84. local rainbowDisabled = false
  85. groupbox:AddToggle('RainbowTGGLE', {
  86. Text = 'Rainbow',
  87. Default = false, -- Default value (true / false)
  88. Tooltip = 'Rainbow colors hehe', -- Information shown when you hover over the toggle
  89. }):OnChanged(function()
  90. if Toggles.RainbowTGGLE.Value then
  91. rainbowDisabled = true
  92. else
  93. rainbowDisabled = false
  94. end
  95. end)
  96. local objects = {
  97. self.Library.AccentColor
  98. }
  99. local time = 1 -- time in seconds for the color to transition
  100. local step = 5 -- step size for RGB values
  101.  
  102.  
  103.  
  104.  
  105. local ThemesArray = {}
  106. for Name, Theme in next, self.BuiltInThemes do
  107. table.insert(ThemesArray, Name)
  108. end
  109.  
  110. table.sort(ThemesArray, function(a, b) return self.BuiltInThemes[a][1] < self.BuiltInThemes[b][1] end)
  111.  
  112. groupbox:AddDivider()
  113. groupbox:AddDropdown('ThemeManager_ThemeList', { Text = 'Theme list', Values = ThemesArray, Default = 1 })
  114.  
  115. groupbox:AddButton('Set as default', function()
  116. self:SaveDefault(Options.ThemeManager_ThemeList.Value)
  117. self.Library:Notify(string.format('Set default theme to %q', Options.ThemeManager_ThemeList.Value))
  118. end)
  119.  
  120. Options.ThemeManager_ThemeList:OnChanged(function()
  121. self:ApplyTheme(Options.ThemeManager_ThemeList.Value)
  122. end)
  123.  
  124. groupbox:AddDivider()
  125. groupbox:AddDropdown('ThemeManager_CustomThemeList', { Text = 'Custom themes', Values = self:ReloadCustomThemes(), AllowNull = true, Default = 1 })
  126. groupbox:AddInput('ThemeManager_CustomThemeName', { Text = 'Custom theme name' })
  127.  
  128. groupbox:AddButton('Load custom theme', function()
  129. self:ApplyTheme(Options.ThemeManager_CustomThemeList.Value)
  130. end)
  131.  
  132. groupbox:AddButton('Save custom theme', function()
  133. self:SaveCustomTheme(Options.ThemeManager_CustomThemeName.Value)
  134.  
  135. Options.ThemeManager_CustomThemeList.Values = self:ReloadCustomThemes()
  136. Options.ThemeManager_CustomThemeList:SetValues()
  137. Options.ThemeManager_CustomThemeList:SetValue(nil)
  138. end)
  139.  
  140. groupbox:AddButton('Refresh list', function()
  141. Options.ThemeManager_CustomThemeList.Values = self:ReloadCustomThemes()
  142. Options.ThemeManager_CustomThemeList:SetValues()
  143. Options.ThemeManager_CustomThemeList:SetValue(nil)
  144. end)
  145.  
  146. groupbox:AddButton('Set as default', function()
  147. if Options.ThemeManager_CustomThemeList.Value ~= nil and Options.ThemeManager_CustomThemeList.Value ~= '' then
  148. self:SaveDefault(Options.ThemeManager_CustomThemeList.Value)
  149. self.Library:Notify(string.format('Set default theme to %q', Options.ThemeManager_CustomThemeList.Value))
  150. end
  151. end)
  152.  
  153. ThemeManager:LoadDefault()
  154.  
  155. local function UpdateTheme()
  156. self:ThemeUpdate()
  157. end
  158.  
  159. Options.BackgroundColor:OnChanged(UpdateTheme)
  160. Options.MainColor:OnChanged(UpdateTheme)
  161. Options.AccentColor:OnChanged(UpdateTheme)
  162. Options.OutlineColor:OnChanged(UpdateTheme)
  163. Options.FontColor:OnChanged(UpdateTheme)
  164. task.spawn(function()
  165. while task.wait(0.1) do
  166. if rainbowDisabled == true then
  167. UpdateTheme()
  168. for hue = 0, 255, step do
  169. local color = Color3.fromRGB(255 - hue, hue, 0) -- red to yellow
  170. for i = 1, #objects do
  171. objects[i] = color
  172. end
  173. task.wait(time/255*step)
  174. end
  175. for hue = 0, 255, step do
  176. local color = Color3.fromRGB(0, 255 - hue, hue) -- yellow to green
  177. for i = 1, #objects do
  178. objects[i] = color
  179. end
  180. task.wait(time/255*step)
  181. end
  182. for hue = 0, 255, step do
  183. local color = Color3.fromRGB(hue, 0, 255 - hue) -- green to blue
  184. for i = 1, #objects do
  185. objects[i] = color
  186. end
  187. task.wait(time/255*step)
  188. end
  189. for hue = 0, 255, step do
  190. local color = Color3.fromRGB(255 - hue, 0, hue) -- blue to magenta
  191. for i = 1, #objects do
  192. objects[i] = color
  193. end
  194. task.wait(time/255*step)
  195. end
  196. for hue = 0, 255, step do
  197. local color = Color3.fromRGB(hue, 0, 255) -- magenta to red
  198. for i = 1, #objects do
  199. objects[i] = color
  200. end
  201. task.wait(time/255*step)
  202. end
  203. end
  204. end
  205. end)
  206. end
  207.  
  208. function ThemeManager:GetCustomTheme(file)
  209. local path = self.Folder .. '/themes/' .. file
  210. if not isfile(path) then
  211. return nil
  212. end
  213.  
  214. local data = readfile(path)
  215. local success, decoded = pcall(httpService.JSONDecode, httpService, data)
  216.  
  217. if not success then
  218. return nil
  219. end
  220.  
  221. return decoded
  222. end
  223.  
  224. function ThemeManager:SaveCustomTheme(file)
  225. if file:gsub(' ', '') == '' then
  226. return self.Library:Notify('Invalid file name for theme (empty)', 3)
  227. end
  228.  
  229. local theme = {}
  230. local fields = { "FontColor", "MainColor", "AccentColor", "BackgroundColor", "OutlineColor" }
  231.  
  232. for _, field in next, fields do
  233. theme[field] = Options[field].Value:ToHex()
  234. end
  235.  
  236. writefile(self.Folder .. '/themes/' .. file .. '.json', httpService:JSONEncode(theme))
  237. end
  238.  
  239. function ThemeManager:ReloadCustomThemes()
  240. local list = listfiles(self.Folder .. '/themes')
  241.  
  242. local out = {}
  243. for i = 1, #list do
  244. local file = list[i]
  245. if file:sub(-5) == '.json' then
  246. -- i hate this but it has to be done ...
  247.  
  248. local pos = file:find('.json', 1, true)
  249. local char = file:sub(pos, pos)
  250.  
  251. while char ~= '/' and char ~= '\\' and char ~= '' do
  252. pos = pos - 1
  253. char = file:sub(pos, pos)
  254. end
  255.  
  256. if char == '/' or char == '\\' then
  257. table.insert(out, file:sub(pos + 1))
  258. end
  259. end
  260. end
  261.  
  262. return out
  263. end
  264.  
  265. function ThemeManager:SetLibrary(lib)
  266. self.Library = lib
  267. end
  268.  
  269. function ThemeManager:BuildFolderTree()
  270. local paths = {}
  271.  
  272. -- build the entire tree if a path is like some-hub/phantom-forces
  273. -- makefolder builds the entire tree on Synapse X but not other exploits
  274.  
  275. local parts = self.Folder:split('/')
  276. for idx = 1, #parts do
  277. paths[#paths + 1] = table.concat(parts, '/', 1, idx)
  278. end
  279.  
  280. table.insert(paths, self.Folder .. '/themes')
  281. table.insert(paths, self.Folder .. '/settings')
  282.  
  283. for i = 1, #paths do
  284. local str = paths[i]
  285. if not isfolder(str) then
  286. makefolder(str)
  287. end
  288. end
  289. end
  290.  
  291. function ThemeManager:SetFolder(folder)
  292. self.Folder = folder
  293. self:BuildFolderTree()
  294. end
  295.  
  296. function ThemeManager:CreateGroupBox(tab)
  297. assert(self.Library, 'Must set ThemeManager.Library first!')
  298. return tab:AddLeftGroupbox('Themes')
  299. end
  300.  
  301. function ThemeManager:ApplyToTab(tab)
  302. assert(self.Library, 'Must set ThemeManager.Library first!')
  303. local groupbox = self:CreateGroupBox(tab)
  304. self:CreateThemeManager(groupbox)
  305. end
  306.  
  307. function ThemeManager:ApplyToGroupbox(groupbox)
  308. assert(self.Library, 'Must set ThemeManager.Library first!')
  309. self:CreateThemeManager(groupbox)
  310. end
  311.  
  312. ThemeManager:BuildFolderTree()
  313. end
  314. return ThemeManager
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement