Advertisement
emilistt

ColorCustomizationManager.lua

Apr 3rd, 2022
1,212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.71 KB | None | 0 0
  1. local Players = game:GetService("Players");
  2. local UserInputService = game:GetService("UserInputService");
  3. local TweenService = game:GetService("TweenService");
  4. local ReplicatedStorage = game:GetService("ReplicatedStorage");
  5.  
  6. local Player = Players.LocalPlayer;
  7.  
  8. local PlayerGui = Player.PlayerGui;
  9. local Mouse = Player:GetMouse();
  10.  
  11. local ColorFunctions = require(ReplicatedStorage.Modules.Utility.ColorFunctions);
  12.  
  13. local isHolding = false;
  14.  
  15. local CharacterCustomization = PlayerGui.CharacterCustomization;
  16. local RGBColorValue = CharacterCustomization.Color;
  17.  
  18. local ColorPicker = CharacterCustomization.ColorPicker;
  19. local RGBColor = ColorPicker.Color;
  20.  
  21. local Colors = {
  22.     "Hue",
  23.     "Lightness",
  24.     "Saturation"   
  25. }
  26.  
  27. local SaturationSequence = ColorSequence.new{
  28.     ColorSequenceKeypoint.new(0, Color3.fromHSV(0, 0, 0.5)),
  29.     ColorSequenceKeypoint.new(1, Color3.new(1, 0, 0))
  30. };
  31.  
  32. local LightnessSequence = ColorSequence.new{
  33.     ColorSequenceKeypoint.new(0, Color3.new(0, 0, 0)),
  34.     ColorSequenceKeypoint.new(0.5, Color3.new(1, 0, 0)),
  35.     ColorSequenceKeypoint.new(1, Color3.new(1, 1, 1))
  36. }
  37.  
  38. local function EvaluateColorSequence(ColorSequence, SequenceTime)
  39.  
  40.     if SequenceTime == 0 then
  41.         return ColorSequence.Keypoints[1].Value;
  42.     elseif SequenceTime == 1 then
  43.         return ColorSequence.Keypoints[#ColorSequence.Keypoints].Value;
  44.     end
  45.  
  46.     for i = 1, #ColorSequence.Keypoints - 1 do
  47.         local Current = ColorSequence.Keypoints[i];
  48.         local Next = ColorSequence.Keypoints[i + 1];
  49.        
  50.         if SequenceTime >= Current.Time and SequenceTime < Next.Time then
  51.             local alpha = (SequenceTime - Current.Time) / (Next.Time - Current.Time);
  52.  
  53.             return Color3.new(
  54.                 (Next.Value.R - Current.Value.R) * alpha + Current.Value.R,
  55.                 (Next.Value.G - Current.Value.G) * alpha + Current.Value.G,
  56.                 (Next.Value.B - Current.Value.B) * alpha + Current.Value.B
  57.             );
  58.         end
  59.     end
  60. end
  61.  
  62. local function ValueUpdate(ColorValue, ColorObject)
  63.     local Color = EvaluateColorSequence(ColorObject.UIGradient.Color, ColorValue.Value);
  64.  
  65.     --ColorObject.Icon.ImageColor3 = Color;
  66.    
  67.     if ColorValue.Name == "Hue" then
  68.         SaturationSequence = ColorSequence.new{
  69.             ColorSequenceKeypoint.new(0, Color3.fromHSV(0, 0, 0.5)),
  70.             ColorSequenceKeypoint.new(1, Color)
  71.         };
  72.         ColorPicker.Saturation.UIGradient.Color = SaturationSequence;
  73.         --ColorPicker.Saturation.Icon.ImageColor3 = EvaluateColorSequence(ColorPicker.Saturation.UIGradient.Color, CharacterCustomization.Saturation.Value);
  74.        
  75.         LightnessSequence = ColorSequence.new{
  76.             ColorSequenceKeypoint.new(0, Color3.new(0, 0, 0)),
  77.             ColorSequenceKeypoint.new(0.5, Color),
  78.             ColorSequenceKeypoint.new(1, Color3.new(1, 1, 1))
  79.         }
  80.         ColorPicker.Lightness.UIGradient.Color = LightnessSequence;
  81.         --ColorPicker.Lightness.Icon.ImageColor3 = EvaluateColorSequence(ColorPicker.Saturation.UIGradient.Color, CharacterCustomization.Lightness.Value);
  82.     end
  83.     local r, g, b = ColorFunctions.hsl2rgb(
  84.         CharacterCustomization.Hue.Value,
  85.         CharacterCustomization.Saturation.Value,
  86.         CharacterCustomization.Lightness.Value
  87.     );
  88.    
  89.     RGBColorValue.Value = Color3.new(r, g, b);
  90.    
  91.     RGBColor.BackgroundColor3 = RGBColorValue.Value;
  92. end
  93.  
  94. return function()
  95.     for _, v in ipairs(Colors) do
  96.         local ColorObject = ColorPicker:FindFirstChild(v);
  97.         local ColorValue = CharacterCustomization:FindFirstChild(v);
  98.  
  99.         if ColorObject and ColorValue then
  100.             local Connection, Connection2;
  101.            
  102.             local function Update()
  103.                 if not isHolding then
  104.                     return;
  105.                 end
  106.                 local Object_x = ColorObject.AbsolutePosition.X;
  107.  
  108.                 local Offset = math.clamp((Mouse.X - Object_x) / ColorObject.AbsoluteSize.X, 0, 1);
  109.  
  110.                 TweenService:Create(ColorObject.Icon, TweenInfo.new(0.3), {Position = UDim2.new(Offset, 0, 0.9, 0)}):Play();
  111.                 TweenService:Create(ColorValue, TweenInfo.new(0.3), {Value = Offset}):Play();
  112.    
  113.                 local Color = EvaluateColorSequence(ColorObject.UIGradient.Color, Offset);
  114.  
  115.                 --ColorObject.Icon.ImageColor3 = Color;
  116.  
  117.             end
  118.            
  119.             ColorValue:GetPropertyChangedSignal("Value"):Connect(function()
  120.                 ValueUpdate(ColorValue, ColorObject);
  121.             end)
  122.            
  123.             ColorObject.InputBegan:Connect(function(Input, GameProcessedEvent)
  124.                 if GameProcessedEvent or isHolding then
  125.                     return;
  126.                 end
  127.  
  128.                 if Input.UserInputType ~= Enum.UserInputType.MouseButton1 then
  129.                     return;
  130.                 end
  131.  
  132.                 isHolding = true;
  133.  
  134.                 Update();
  135.  
  136.                 Connection = UserInputService.InputEnded:Connect(function(Input, GameProcessedEvent)
  137.                     if GameProcessedEvent then
  138.                         return;
  139.                     end
  140.  
  141.                     if Input.UserInputType ~= Enum.UserInputType.MouseButton1 then
  142.                         return;
  143.                     end
  144.  
  145.  
  146.                     isHolding = false;
  147.                     Connection:Disconnect();
  148.                     Connection2:Disconnect();
  149.                 end)
  150.  
  151.                 Connection2 = Mouse.Move:Connect(Update);
  152.             end)
  153.         end
  154.     end
  155. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement