Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cloneref = cloneref or function(o) return o end
- local httpService = cloneref(game:GetService('HttpService'))
- local httprequest = (syn and syn.request) or (http and http.request) or http_request or (fluxus and fluxus.request) or request
- local getassetfunc = getcustomasset or getsynasset
- local ThemeManager = {} do
- ThemeManager.Folder = 'LinoriaLibSettings'
- -- if not isfolder(ThemeManager.Folder) then makefolder(ThemeManager.Folder) end
- ThemeManager.Library = nil
- ThemeManager.BuiltInThemes = {
- ['Default'] = { 1, httpService:JSONDecode('{"FontColor":"ffffff","MainColor":"1c1c1c","AccentColor":"0055ff","BackgroundColor":"141414","OutlineColor":"323232"}') },
- ['BBot'] = { 2, httpService:JSONDecode('{"FontColor":"ffffff","MainColor":"1e1e1e","AccentColor":"7e48a3","BackgroundColor":"232323","OutlineColor":"141414"}') },
- ['Fatality'] = { 3, httpService:JSONDecode('{"FontColor":"ffffff","MainColor":"1e1842","AccentColor":"c50754","BackgroundColor":"191335","OutlineColor":"3c355d"}') },
- ['Jester'] = { 4, httpService:JSONDecode('{"FontColor":"ffffff","MainColor":"242424","AccentColor":"db4467","BackgroundColor":"1c1c1c","OutlineColor":"373737"}') },
- ['Mint'] = { 5, httpService:JSONDecode('{"FontColor":"ffffff","MainColor":"242424","AccentColor":"3db488","BackgroundColor":"1c1c1c","OutlineColor":"373737"}') },
- ['Tokyo Night'] = { 6, httpService:JSONDecode('{"FontColor":"ffffff","MainColor":"191925","AccentColor":"6759b3","BackgroundColor":"16161f","OutlineColor":"323232"}') },
- ['Ubuntu'] = { 7, httpService:JSONDecode('{"FontColor":"ffffff","MainColor":"3e3e3e","AccentColor":"e2581e","BackgroundColor":"323232","OutlineColor":"191919"}') },
- ['Quartz'] = { 8, httpService:JSONDecode('{"FontColor":"ffffff","MainColor":"232330","AccentColor":"426e87","BackgroundColor":"1d1b26","OutlineColor":"27232f"}') },
- ['Kiriot Hub'] = { 9, httpService:JSONDecode('{"FontColor":"ffffff","MainColor":"30333b","AccentColor":"ffaa00","BackgroundColor":"1a1c20","OutlineColor":"141414"}') },
- ['Green'] = { 10, httpService:JSONDecode('{"FontColor":"ffffff","MainColor":"141414","AccentColor":"00ff8b","BackgroundColor":"1c1c1c","OutlineColor":"3c3c3c"}') },
- ['Dracula'] = { 11, httpService:JSONDecode('{"FontColor":"ffffff","MainColor":"232533","AccentColor":"6271a5","BackgroundColor":"1b1c27","OutlineColor":"7c82a7"}') },
- }
- function ApplyBackgroundVideo(webmLink)
- if writefile == nil then return end;if readfile == nil then return end;if isfile == nil then return end
- if ThemeManager.Library == nil then return end
- if ThemeManager.Library.InnerVideoBackground == nil then return end
- if string.sub(tostring(webmLink), -5) == ".webm" then
- local CurrentSaved = ""
- if isfile(ThemeManager.Folder .. '/themes/currentVideoLink.txt') then
- CurrentSaved = readfile(ThemeManager.Folder .. '/themes/currentVideoLink.txt')
- end
- local VideoData = nil;
- if CurrentSaved == tostring(webmLink) then
- VideoData = {
- Success = true,
- Body = nil
- }
- else
- VideoData = httprequest({
- Url = tostring(webmLink),
- Method = 'GET'
- })
- end
- if (VideoData.Success) then
- VideoData = VideoData.Body
- if (isfile(ThemeManager.Folder .. '/themes/currentVideo.webm') == false and VideoData ~= nil) or VideoData ~= nil then
- writefile(ThemeManager.Folder .. '/themes/currentVideo.webm', VideoData)
- writefile(ThemeManager.Folder .. '/themes/currentVideoLink.txt', tostring(webmLink))
- end
- local Video = getassetfunc(ThemeManager.Folder .. '/themes/currentVideo.webm')
- ThemeManager.Library.InnerVideoBackground.Video = Video
- ThemeManager.Library.InnerVideoBackground.Visible = true
- ThemeManager.Library.InnerVideoBackground:Play()
- end
- end
- end
- function ThemeManager:ApplyTheme(theme)
- local customThemeData = self:GetCustomTheme(theme)
- local data = customThemeData or self.BuiltInThemes[theme]
- if not data then return end
- -- custom themes are just regular dictionaries instead of an array with { index, dictionary }
- if self.Library.InnerVideoBackground ~= nil then
- self.Library.InnerVideoBackground.Visible = false
- end
- local scheme = data[2]
- for idx, col in next, customThemeData or scheme do
- if idx ~= "VideoLink" then
- self.Library[idx] = Color3.fromHex(col)
- if getgenv().Linoria.Options[idx] then
- getgenv().Linoria.Options[idx]:SetValueRGB(Color3.fromHex(col))
- end
- else
- self.Library[idx] = col
- if getgenv().Linoria.Options[idx] then
- getgenv().Linoria.Options[idx]:SetValue(col)
- end
- ApplyBackgroundVideo(col)
- end
- end
- self:ThemeUpdate()
- end
- function ThemeManager:ThemeUpdate()
- -- This allows us to force apply themes without loading the themes tab :)
- if self.Library.InnerVideoBackground ~= nil then
- self.Library.InnerVideoBackground.Visible = false
- end
- local options = { "FontColor", "MainColor", "AccentColor", "BackgroundColor", "OutlineColor", "VideoLink" }
- for i, field in next, options do
- if getgenv().Linoria.Options and getgenv().Linoria.Options[field] then
- self.Library[field] = getgenv().Linoria.Options[field].Value
- if field == "VideoLink" then
- ApplyBackgroundVideo(getgenv().Linoria.Options[field].Value)
- end
- end
- end
- self.Library.AccentColorDark = self.Library:GetDarkerColor(self.Library.AccentColor);
- self.Library:UpdateColorsUsingRegistry()
- end
- function ThemeManager:LoadDefault()
- local theme = 'Default'
- local content = isfile(self.Folder .. '/themes/default.txt') and readfile(self.Folder .. '/themes/default.txt')
- local isDefault = true
- if content then
- if self.BuiltInThemes[content] then
- theme = content
- elseif self:GetCustomTheme(content) then
- theme = content
- isDefault = false;
- end
- elseif self.BuiltInThemes[self.DefaultTheme] then
- theme = self.DefaultTheme
- end
- if isDefault then
- getgenv().Linoria.Options.ThemeManager_ThemeList:SetValue(theme)
- else
- self:ApplyTheme(theme)
- end
- end
- function ThemeManager:SaveDefault(theme)
- writefile(self.Folder .. '/themes/default.txt', theme)
- end
- function ThemeManager:Delete(name)
- if (not name) then
- return false, 'no config file is selected'
- end
- local file = self.Folder .. '/themes/' .. name
- if not isfile(file) then return false, 'invalid file' end
- local success, decoded = pcall(delfile, file)
- if not success then return false, 'delete file error' end
- return true
- end
- function ThemeManager:CreateThemeManager(groupbox)
- groupbox:AddLabel('Background color'):AddColorPicker('BackgroundColor', { Default = self.Library.BackgroundColor });
- groupbox:AddLabel('Main color') :AddColorPicker('MainColor', { Default = self.Library.MainColor });
- groupbox:AddLabel('Accent color'):AddColorPicker('AccentColor', { Default = self.Library.AccentColor });
- groupbox:AddLabel('Outline color'):AddColorPicker('OutlineColor', { Default = self.Library.OutlineColor });
- groupbox:AddLabel('Font color') :AddColorPicker('FontColor', { Default = self.Library.FontColor });
- groupbox:AddInput('VideoLink', { Text = '.webm Video Background (Link)', Default = self.Library.VideoLink });
- local ThemesArray = {}
- for Name, Theme in next, self.BuiltInThemes do
- table.insert(ThemesArray, Name)
- end
- table.sort(ThemesArray, function(a, b) return self.BuiltInThemes[a][1] < self.BuiltInThemes[b][1] end)
- groupbox:AddDivider()
- groupbox:AddDropdown('ThemeManager_ThemeList', { Text = 'Theme list', Values = ThemesArray, Default = 1 })
- groupbox:AddButton('Set as default', function()
- self:SaveDefault(getgenv().Linoria.Options.ThemeManager_ThemeList.Value)
- self.Library:Notify(string.format('Set default theme to %q', getgenv().Linoria.Options.ThemeManager_ThemeList.Value))
- end)
- getgenv().Linoria.Options.ThemeManager_ThemeList:OnChanged(function()
- self:ApplyTheme(getgenv().Linoria.Options.ThemeManager_ThemeList.Value)
- end)
- groupbox:AddDivider()
- groupbox:AddInput('ThemeManager_CustomThemeName', { Text = 'Custom theme name' })
- groupbox:AddButton('Create theme', function()
- if Options.ThemeManager_CustomThemeName.Value ~= '' then
- self:SaveCustomTheme(getgenv().Linoria.Options.ThemeManager_CustomThemeName.Value..'.json')
- self.Library:Notify('Created theme')
- getgenv().Linoria.Options.ThemeManager_CustomThemeList:SetValues(self:ReloadCustomThemes())
- getgenv().Linoria.Options.ThemeManager_CustomThemeList:SetValue(nil)
- end
- end)
- groupbox:AddDivider()
- groupbox:AddDropdown('ThemeManager_CustomThemeList', { Text = 'Custom themes', Values = self:ReloadCustomThemes(), AllowNull = true, Default = 1 })
- groupbox:AddButton('Load theme', function()
- self:ApplyTheme(getgenv().Linoria.Options.ThemeManager_CustomThemeList.Value)
- end)
- groupbox:AddButton('Overwrite theme', function()
- self:SaveCustomTheme(getgenv().Linoria.Options.ThemeManager_CustomThemeList.Value)
- self.Library:Notify('Saved theme')
- end):AddButton('Delete theme', function()
- local name = getgenv().Linoria.Options.ThemeManager_CustomThemeList.Value
- local success, err = self:Delete(name)
- if not success then
- return self.Library:Notify('Failed to delete theme: ' .. err)
- end
- self.Library:Notify(string.format('Deleted theme %q', name))
- getgenv().Linoria.Options.ThemeManager_CustomThemeList:SetValues(self:ReloadCustomThemes())
- getgenv().Linoria.Options.ThemeManager_CustomThemeList:SetValue(nil)
- end)
- groupbox:AddButton('Refresh list', function()
- getgenv().Linoria.Options.ThemeManager_CustomThemeList:SetValues(self:ReloadCustomThemes())
- getgenv().Linoria.Options.ThemeManager_CustomThemeList:SetValue(nil)
- end)
- groupbox:AddButton('Set as default', function()
- if getgenv().Linoria.Options.ThemeManager_CustomThemeList.Value ~= nil and getgenv().Linoria.Options.ThemeManager_CustomThemeList.Value ~= '' then
- self:SaveDefault(getgenv().Linoria.Options.ThemeManager_CustomThemeList.Value)
- self.Library:Notify(string.format('Set default theme to %q', getgenv().Linoria.Options.ThemeManager_CustomThemeList.Value))
- end
- end)
- groupbox:AddButton('Reset default', function()
- local success = pcall(delfile, self.Folder .. '/themes/default.txt')
- if not success then
- return self.Library:Notify('Failed to reset default: delete file error')
- end
- self.Library:Notify('Set default theme to nothing')
- getgenv().Linoria.Options.ThemeManager_CustomThemeList:SetValues(self:ReloadCustomThemes())
- getgenv().Linoria.Options.ThemeManager_CustomThemeList:SetValue(nil)
- end)
- ThemeManager:LoadDefault()
- local function UpdateTheme()
- self:ThemeUpdate()
- end
- getgenv().Linoria.Options.BackgroundColor:OnChanged(UpdateTheme)
- getgenv().Linoria.Options.MainColor:OnChanged(UpdateTheme)
- getgenv().Linoria.Options.AccentColor:OnChanged(UpdateTheme)
- getgenv().Linoria.Options.OutlineColor:OnChanged(UpdateTheme)
- getgenv().Linoria.Options.FontColor:OnChanged(UpdateTheme)
- end
- function ThemeManager:GetCustomTheme(file)
- local path = self.Folder .. '/themes/' .. file
- if not isfile(path) then
- return nil
- end
- local data = readfile(path)
- local success, decoded = pcall(httpService.JSONDecode, httpService, data)
- if not success then
- return nil
- end
- return decoded
- end
- function ThemeManager:SaveCustomTheme(file)
- if file:gsub(' ', '') == '' then
- return self.Library:Notify('Invalid file name for theme (empty)', 3)
- end
- local theme = {}
- local fields = { "FontColor", "MainColor", "AccentColor", "BackgroundColor", "OutlineColor", "VideoLink" }
- for _, field in next, fields do
- if field == "VideoLink" then
- theme[field] = getgenv().Linoria.Options[field].Value
- else
- theme[field] = getgenv().Linoria.Options[field].Value:ToHex()
- end
- end
- writefile(self.Folder .. '/themes/' .. file, httpService:JSONEncode(theme))
- end
- function ThemeManager:ReloadCustomThemes()
- local list = listfiles(self.Folder .. '/themes')
- local out = {}
- for i = 1, #list do
- local file = list[i]
- if file:sub(-5) == '.json' then
- -- i hate this but it has to be done ...
- local pos = file:find('.json', 1, true)
- local char = file:sub(pos, pos)
- while char ~= '/' and char ~= '\\' and char ~= '' do
- pos = pos - 1
- char = file:sub(pos, pos)
- end
- if char == '/' or char == '\\' then
- table.insert(out, file:sub(pos + 1))
- end
- end
- end
- return out
- end
- function ThemeManager:SetLibrary(lib)
- self.Library = lib
- end
- function ThemeManager:BuildFolderTree()
- local paths = {}
- -- build the entire tree if a path is like some-hub/phantom-forces
- -- makefolder builds the entire tree on Synapse X but not other exploits
- local parts = self.Folder:split('/')
- for idx = 1, #parts do
- paths[#paths + 1] = table.concat(parts, '/', 1, idx)
- end
- table.insert(paths, self.Folder .. '/themes')
- for i = 1, #paths do
- local str = paths[i]
- if not isfolder(str) then
- makefolder(str)
- end
- end
- end
- function ThemeManager:SetFolder(folder)
- self.Folder = folder
- self:BuildFolderTree()
- end
- function ThemeManager:CreateGroupBox(tab)
- assert(self.Library, 'Must set ThemeManager.Library first!')
- return tab:AddLeftGroupbox('Themes')
- end
- function ThemeManager:ApplyToTab(tab)
- assert(self.Library, 'Must set ThemeManager.Library first!')
- local groupbox = self:CreateGroupBox(tab)
- self:CreateThemeManager(groupbox)
- end
- function ThemeManager:ApplyToGroupbox(groupbox)
- assert(self.Library, 'Must set ThemeManager.Library first!')
- self:CreateThemeManager(groupbox)
- end
- ThemeManager:BuildFolderTree()
- end
- return ThemeManager
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement