Skip to content

Commit 5834ec3

Browse files
committed
2 parents d29bdfb + dbb59df commit 5834ec3

File tree

4 files changed

+149
-6
lines changed

4 files changed

+149
-6
lines changed

src/ScrollingFrame.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ function ScrollingFrame:AddScrollbarFromContainer(Container)
293293
local ScrollBar = Instance.new("ImageButton")
294294
ScrollBar.Size = UDim2.new(1, 0, 0, 100)
295295
ScrollBar.Name = "ScrollBar"
296-
ScrollBar.BackgroundColor3 = Color3.new(0.8, 0.8, 0.8)
297296
ScrollBar.BorderSizePixel = 0
298297
ScrollBar.Image = ""
299298
ScrollBar.Parent = Container

src/ThemeSwitcher.lua

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
-- Theme Switcher for Quenty's Class Converter Plugin
2+
-- provides support for Roblox Studio's Themes
3+
-- defaults to light theme if Roblox Studio ever supports more themes
4+
-- @author presssssure
5+
6+
local ThemeSwitcher = {}
7+
8+
local Studio = settings().Studio
9+
10+
local DockWidget = nil
11+
12+
local LightColors = {
13+
Background = Color3.fromRGB(255, 255, 255),
14+
BackgroundOnHover = Color3.fromRGB(242, 242, 242),
15+
16+
Text = Color3.fromRGB(40, 40, 40),
17+
DropDownText = Color3.fromRGB(27, 42, 53),
18+
DropDownMouseOverLerp = Color3.fromRGB(0, 0, 0),
19+
TextBoxText = Color3.fromRGB(49, 49, 49),
20+
21+
Line = Color3.fromRGB(230, 230, 230),
22+
ScrollBar = Color3.fromRGB(230, 230, 230),
23+
ScrollBarOnHover = Color3.fromRGB(161, 161, 161),
24+
Selected = Color3.fromRGB(90, 142, 243),
25+
26+
ButtonStyle = Enum.ButtonStyle.RobloxRoundDropdownButton,
27+
}
28+
local DarkColors = {
29+
Background = Color3.fromRGB(46, 46, 46),
30+
BackgroundOnHover = Color3.fromRGB(56, 56, 56),
31+
32+
Text = Color3.fromRGB(204, 204, 204),
33+
DropDownText = Color3.fromRGB(191, 206, 217),
34+
DropDownMouseOverLerp = Color3.fromRGB(255, 255, 255),
35+
TextBoxText = Color3.fromRGB(213, 213, 213),
36+
37+
Line = Color3.fromRGB(21, 21, 21),
38+
ScrollBar = Color3.fromRGB(76, 76, 76),
39+
ScrollBarOnHover = Color3.fromRGB(96, 96, 96),
40+
Selected = Color3.fromRGB(90, 142, 243),
41+
42+
ButtonStyle = Enum.ButtonStyle.RobloxButton,
43+
}
44+
local ConvertButtonTextColor = Color3.fromRGB(255, 255, 255)
45+
46+
47+
-- find theme colors (defaults to light if other themes are available besides light and dark)
48+
local function GetColorPalette(theme)
49+
if theme == Enum.UITheme.Dark then
50+
return DarkColors
51+
end
52+
return LightColors
53+
end
54+
55+
56+
-- determines if a button is a button in the dropdown menu
57+
local function isInDropDown(obj)
58+
return (obj.Parent.Parent.Parent.Parent and obj.Parent.Parent.Parent.Parent.Name == "DropDown")
59+
end
60+
61+
62+
-- determines if something is a "Line" (really skinny Frame that stretches across the page)
63+
local function isLine(obj)
64+
return obj.AbsoluteSize.Y == 1 or obj.AbsoluteSize.Y == 2
65+
end
66+
67+
68+
-- changes the theme of a given ui element
69+
function ThemeSwitcher.SwitchObject(obj, theme)
70+
if not obj:IsA("GuiBase") then return end
71+
theme = theme or Studio["UI Theme"]
72+
73+
local NewPalette = GetColorPalette(theme)
74+
75+
-- handle special cases first
76+
if isLine(obj) then -- lines in the main view
77+
obj.BackgroundColor3 = NewPalette.Line
78+
return
79+
elseif obj.Name == "Scrollbar" then -- scroll bar in the drop down
80+
obj.BackgroundColor3 = NewPalette.ScrollBar
81+
return
82+
elseif obj.Name == "CheckButton" then -- check boxes in the main view
83+
obj.Style = NewPalette.ButtonStyle
84+
-- no return on purpose, text color still needs to be changed
85+
elseif obj.Name == "ConvertButton" then -- ConvertButton's text color is always the same
86+
obj.TextColor3 = ConvertButtonTextColor
87+
return
88+
end
89+
90+
-- then change the text
91+
if obj.ClassName:find("Text") then
92+
local NewTextColor
93+
94+
if obj:IsA("TextBox") then
95+
NewTextColor = NewPalette.TextBoxText
96+
elseif isInDropDown(obj) then
97+
NewTextColor = NewPalette.DropDownText
98+
else
99+
NewTextColor = NewPalette.Text
100+
end
101+
102+
obj.TextColor3 = NewTextColor
103+
end
104+
105+
-- lastly change the background
106+
obj.BackgroundColor3 = NewPalette.Background
107+
end
108+
109+
110+
-- switches every ui element within
111+
local function SwitchAllObjects(NewTheme)
112+
for _, obj in pairs(DockWidget:GetDescendants()) do
113+
ThemeSwitcher.SwitchObject(obj, NewTheme)
114+
end
115+
end
116+
117+
118+
-- for when the user changes theme while having the window open
119+
Studio.ThemeChanged:Connect(function()
120+
SwitchAllObjects(Studio["UI Theme"])
121+
end)
122+
123+
124+
-- switches the plugin dock widget and all the objects within it
125+
function ThemeSwitcher.SetDockWidget(NewDockWidget)
126+
DockWidget = NewDockWidget
127+
128+
SwitchAllObjects(Studio["UI Theme"])
129+
DockWidget.DescendantAdded:Connect(function(obj)
130+
ThemeSwitcher.SwitchObject(obj, Studio["UI Theme"])
131+
end)
132+
end
133+
134+
135+
-- allow other scripts to access colors
136+
function ThemeSwitcher.GetColorFor(ElementString)
137+
local Palette = GetColorPalette(Studio["UI Theme"])
138+
return Palette[ElementString]
139+
end
140+
141+
return ThemeSwitcher

src/UI.lua

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local Signal = require(script.Parent:WaitForChild("Signal"))
33
local ScrollingFrame = require(script.Parent:WaitForChild("ScrollingFrame"))
44
local ValueObject = require(script.Parent:WaitForChild("ValueObject"))
55
local IconHandler = require(script.Parent:WaitForChild("IconHandler"))
6+
local ThemeSwitcher = require(script.Parent:WaitForChild("ThemeSwitcher"))
67
local HttpService = game:GetService("HttpService")
78

89
local function TrimString(str, pattern)
@@ -191,13 +192,13 @@ function DropDownButton:GetData()
191192
end
192193

193194
function DropDownButton:UpdateRender()
194-
local Desired = Color3.new(1, 1, 1)
195+
local Desired = ThemeSwitcher.GetColorFor("Background")
195196
if self.IsSelected.Value then
196-
Desired = Color3.new(90/255, 142/255, 243/255)
197+
Desired = ThemeSwitcher.GetColorFor("Selected")
197198
end
198199

199200
if self.MouseOver then
200-
Desired = Desired:lerp(Color3.new(0, 0, 0), 0.05)
201+
Desired = Desired:lerp(ThemeSwitcher.GetColorFor("DropDownMouseOverLerp"), 0.05)
201202
end
202203

203204
self.Gui.BackgroundColor3 = Desired
@@ -330,9 +331,9 @@ end
330331

331332
function DropDownFilter:UpdateRender()
332333
if self.MouseOver then
333-
self.Background.BackgroundColor3 = Color3.new(0.95, 0.95, 0.95)
334+
self.Background.BackgroundColor3 = ThemeSwitcher.GetColorFor("BackgroundOnHover")
334335
else
335-
self.Background.BackgroundColor3 = Color3.new(1, 1, 1)
336+
self.Background.BackgroundColor3 = ThemeSwitcher.GetColorFor("Background")
336337
end
337338

338339
if not self.Gui:IsFocused() then

src/init.server.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ end
1919
local Converter = require(script:WaitForChild("Converter"))
2020
local UI = require(script:WaitForChild("UI"))
2121
local Signal = require(script:WaitForChild("Signal"))
22+
local ThemeSwitcher = require(script:WaitForChild("ThemeSwitcher"))
2223

2324
local Selection do
2425
if not IS_DEBUG_MODE then
@@ -109,6 +110,7 @@ do
109110
240
110111
)
111112
screenGui = plugin:CreateDockWidgetPluginGui("Quenty_Class_Converter", info)
113+
ThemeSwitcher.SetDockWidget(screenGui)
112114
screenGui.Title = "Quenty's Class Converter Plugin"
113115
end
114116
screenGui:BindToClose(function()

0 commit comments

Comments
 (0)