Advertisement
chen399d

InterfaceManager庫文本翻譯

Dec 27th, 2024 (edited)
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.78 KB | Source Code | 0 0
  1. local httpService = game:GetService("HttpService");
  2. local InterfaceManager = {};
  3. do
  4.     InterfaceManager.Folder = "FluentSettings";
  5.     InterfaceManager.Settings = {Theme="Dark",Acrylic=true,Transparency=true,MenuKeybind="LeftControl"};
  6.     InterfaceManager.SetFolder = function(self, folder)
  7.         self.Folder = folder;
  8.         self:BuildFolderTree();
  9.     end;
  10.     InterfaceManager.SetLibrary = function(self, library)
  11.         self.Library = library;
  12.     end;
  13.     InterfaceManager.BuildFolderTree = function(self)
  14.         local paths = {};
  15.         local parts = self.Folder:split("/");
  16.         for idx = 1, #parts do
  17.             paths[#paths + 1] = table.concat(parts, "/", 1, idx);
  18.         end
  19.         table.insert(paths, self.Folder);
  20.         table.insert(paths, self.Folder .. "/settings");
  21.         for i = 1, #paths do
  22.             local str = paths[i];
  23.             if not isfolder(str) then
  24.                 makefolder(str);
  25.             end
  26.         end
  27.     end;
  28.     InterfaceManager.SaveSettings = function(self)
  29.         writefile(self.Folder .. "/options.json", httpService:JSONEncode(InterfaceManager.Settings));
  30.     end;
  31.     InterfaceManager.LoadSettings = function(self)
  32.         local path = self.Folder .. "/options.json";
  33.         if isfile(path) then
  34.             local data = readfile(path);
  35.             local success, decoded = pcall(httpService.JSONDecode, httpService, data);
  36.             if success then
  37.                 for i, v in next, decoded do
  38.                     InterfaceManager.Settings[i] = v;
  39.                 end
  40.             end
  41.         end
  42.     end;
  43.     InterfaceManager.BuildInterfaceSection = function(self, tab)
  44.         assert(self.Library, "Must set InterfaceManager.Library");
  45.         local Library = self.Library;
  46.         local Settings = InterfaceManager.Settings;
  47.         InterfaceManager:LoadSettings();
  48.         local section = tab:AddSection("介面管理");
  49.         local InterfaceTheme = section:AddDropdown("InterfaceTheme", {Title="更改介面主題(顏色)",Values=Library.Themes,Default=Settings.Theme,Callback=function(Value)
  50.             Library:SetTheme(Value);
  51.             Settings.Theme = Value;
  52.             InterfaceManager:SaveSettings();
  53.         end});
  54.         InterfaceTheme:SetValue(Settings.Theme);
  55.         if Library.UseAcrylic then
  56.             section:AddToggle("AcrylicToggle", {Title="UI背景模糊(使介面背景無特效)",Default=Settings.Acrylic,Callback=function(Value)
  57.                 Library:ToggleAcrylic(Value);
  58.                 Settings.Acrylic = Value;
  59.                 InterfaceManager:SaveSettings();
  60.             end});
  61.         end
  62.         section:AddToggle("TransparentToggle", {Title="UI透明度(使介面透明)",Default=Settings.Transparency,Callback=function(Value)
  63.             Library:ToggleTransparency(Value);
  64.             Settings.Transparency = Value;
  65.             InterfaceManager:SaveSettings();
  66.         end});
  67.         local MenuKeybind = section:AddKeybind("MenuKeybind", {Title="介面快捷鍵綁定",Default=Settings.MenuKeybind});
  68.         MenuKeybind:OnChanged(function()
  69.             Settings.MenuKeybind = MenuKeybind.Value;
  70.             InterfaceManager:SaveSettings();
  71.         end);
  72.         Library.MinimizeKeybind = MenuKeybind;
  73.     end;
  74. end
  75. return InterfaceManager;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement