Skip to content

Commit 87f049e

Browse files
added new signals, changed stuff for toggle keybinds
1 parent b2a6a8f commit 87f049e

File tree

4 files changed

+52
-38
lines changed

4 files changed

+52
-38
lines changed

Example.client.luau

+2-2
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,10 @@ local ToggleKeybind = Tabs.Main:Toggle("ToggleWithKeybind", {
307307

308308
ToggleKeybind:Keybind("KeybindInToggle", {
309309
Title = "Keybind",
310-
Default = "Unknown"
310+
Default = Enum.KeyCode.Space
311311
})
312312

313-
ToggleKeybind.Keybind:SetValue("A")
313+
Main.Options.KeybindInToggle.Value = "A"
314314

315315
task.spawn(function()
316316
while true do

src/Components/Window.luau

+14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local Root = script.Parent.Parent
44
local Flipper = require(Root.Packages.Flipper)
55
local Creator = require(Root.Creator)
66
local Acrylic = require(Root.Acrylic)
7+
local Signal = require(Root.Packages.Flipper.Signal)
78
local Assets = require(script.Parent.Assets)
89
local Components = script.Parent
910

@@ -20,7 +21,11 @@ local New = Creator.New
2021
return function(Config)
2122
local Window = {
2223
Minimized = false,
24+
OnMinimized = Signal.new(),
25+
PostMinimized = Signal.new(),
2326
Maximized = false,
27+
OnMaximized = Signal.new(),
28+
PostMaximized = Signal.new(),
2429
Size = Config.Size,
2530
MinSize = Config.MinSize,
2631
CurrentPos = 0,
@@ -193,6 +198,8 @@ return function(Config)
193198
local OldSizeX
194199
local OldSizeY
195200
Window.Maximize = function(Value, NoPos, Instant)
201+
Window.OnMaximized:Fire(tick())
202+
196203
Window.Maximized = Value
197204
Window.TitleBar.MaxButton.Frame.Icon.Image = Value and Assets.Restore or Assets.Max
198205

@@ -214,6 +221,8 @@ return function(Config)
214221
Y = Spring(Value and 0 or Window.Position.Y.Offset, { frequency = 6 }),
215222
})
216223
end
224+
225+
Window.PostMaximized:Fire(tick())
217226
end
218227

219228
Creator.AddSignal(Window.TitleBar.Frame.InputBegan, function(Input)
@@ -305,6 +314,9 @@ return function(Config)
305314
function Window:Minimize()
306315
Window.Minimized = not Window.Minimized
307316
Window.Root.Visible = not Window.Minimized
317+
318+
Window.OnMinimized:Fire(tick())
319+
308320
if not MinimizeNotif then
309321
local Key = Library.MinimizeKeybind and Library.MinimizeKeybind.Value or Library.MinimizeKey.Name
310322

@@ -316,6 +328,8 @@ return function(Config)
316328
Duration = 6
317329
})
318330
end
331+
332+
Window.PostMinimized:Fire(tick())
319333
end
320334

321335
Creator.AddSignal(UserInputService.InputBegan, function(Input)

src/Elements/Toggle.luau

+27-27
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,29 @@ function Element:New(Idx, Config)
102102
Toggle:SetValue(not Toggle.Value)
103103
end)
104104

105-
Toggle.Keybind = setmetatable({}, {
105+
Toggle.Keybind = setmetatable({}, { -- TODO: Rewrite this piece of shit
106106
__call = function(_, self, Idx, Config)
107-
local Keybind = {
108-
Value = Config.Default or Config.Value or Enum.KeyCode.Unknown,
109-
Toggled = false,
110-
Mode = Config.Mode or "Toggle",
111-
Type = "Keybind",
112-
Callback = Config.Callback or function(Value) end,
113-
ChangedCallback = Config.ChangedCallback or function(New) end,
114-
}
115-
107+
local KeybindProxy = newproxy(true)
108+
local Keybind = getmetatable(KeybindProxy)
109+
110+
Keybind.Value = Config.Default or Config.Value or Enum.KeyCode.Unknown
111+
Keybind.Toggled = false
112+
Keybind.Mode = Config.Mode or "Toggle"
113+
Keybind.Type = "Keybind"
114+
Keybind.Callback = Config.Callback or function(Value) end
115+
Keybind.ChangedCallback = Config.ChangedCallback or function(New) end
116+
117+
Keybind.__newindex = function(self, index, newvalue)
118+
if index == "Value" then
119+
return Keybind:SetValue(newvalue)
120+
end
121+
return rawset(self, index, newvalue)
122+
end
123+
124+
Keybind.__metatable = "The metatable is locked"
125+
116126
local Picking = false
117-
127+
118128
local KeybindDisplayLabel = New("TextLabel", {
119129
FontFace = Font.new("rbxasset://fonts/families/GothamSSm.json", Enum.FontWeight.Regular, Enum.FontStyle.Normal),
120130
Text = Library.Utilities:Prettify(Keybind.Value),
@@ -194,7 +204,7 @@ function Element:New(Idx, Config)
194204
Key = Key or Keybind.Value
195205
Mode = Mode or Keybind.Mode
196206

197-
rawset(Keybind, "Value", Key)
207+
Keybind.Value = Key
198208
Keybind.Mode = Mode
199209

200210
KeybindDisplayLabel.Text = Library.Utilities:Prettify(Keybind.Value)
@@ -252,9 +262,7 @@ function Element:New(Idx, Config)
252262
then
253263
Picking = false
254264

255-
Keybind.Value = Key
256-
257-
KeybindDisplayLabel.Text = Library.Utilities:Prettify(Keybind.Value)
265+
Keybind:SetValue(Key)
258266

259267
Library:SafeCallback(Keybind.ChangedCallback, Input.KeyCode or Input.UserInputType)
260268
Library:SafeCallback(Keybind.Changed, Input.KeyCode or Input.UserInputType)
@@ -288,20 +296,12 @@ function Element:New(Idx, Config)
288296
end)
289297

290298
Creator.AddSignal(KeybindDisplayFrame:GetPropertyChangedSignal("AbsoluteSize"), UpdateTogglePosition)
291-
292-
Library.Options[Idx] = Keybind
299+
300+
Library.Options[Idx] = KeybindProxy
293301

294302
Keybind.Instance = KeybindDisplayFrame
295-
296-
Toggle.Keybind = setmetatable(Keybind, {
297-
__newindex = function(self, index, newvalue)
298-
if index == "Value" then
299-
Keybind:SetValue(newvalue)
300-
end
301-
302-
return rawset(self, index, newvalue)
303-
end
304-
})
303+
304+
Toggle.Keybind = KeybindProxy
305305

306306
return Toggle.Keybind
307307
end

src/init.luau

+9-9
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ local ElementsTable = require(Root.Elements)
5151
local Acrylic = require(Root.Acrylic)
5252
local Icons = require(Root.Icons)
5353
local Themes = require(Root.Themes)
54+
local Signal = require(Root.Packages.Flipper.Signal)
5455

5556
local NotificationModule = require(Components.Notification)
5657

@@ -110,13 +111,15 @@ local Library = {
110111
Options = {},
111112
Themes = Themes.Names,
112113

113-
OnUnload = nil,
114-
PostUnload = nil,
114+
OnUnload = Signal.new(),
115+
PostUnload = Signal.new(),
116+
ThemeChanged = Signal.new(),
115117
CreatedWindow = nil,
116118
WindowFrame = nil,
117119
Utilities = {
118120
Themes = Themes,
119-
Shared = SharedTable
121+
Shared = SharedTable,
122+
Creator = Creator
120123
},
121124
Connections = Creator.Signals,
122125
Unloaded = false,
@@ -265,6 +268,7 @@ function Library:SetTheme(Name: string)
265268
if Library.CreatedWindow and table.find(Library.Themes, Name) then
266269
Library.Theme = Name
267270
Creator.UpdateTheme()
271+
Library.ThemeChanged:Fire(Name)
268272
end
269273
end
270274

@@ -273,9 +277,7 @@ function Library:Destroy()
273277
Library.Unloaded = true
274278
Library.Loaded = false
275279

276-
if typeof(Library.OnUnload) == "function" then
277-
Library:SafeCallback(Library.OnUnload, tick())
278-
end
280+
Library.OnUnload:Fire(tick())
279281

280282
if Library.UseAcrylic then
281283
Library.CreatedWindow.AcrylicPaint.Model:Destroy()
@@ -337,9 +339,7 @@ function Library:Destroy()
337339
task.delay(info.Time, function()
338340
Library.GUI:Destroy()
339341

340-
if typeof(Library.PostUnload) == "function" then
341-
Library:SafeCallback(Library.PostUnload, tick())
342-
end
342+
Library.PostUnload:Fire(tick())
343343
end)
344344
end
345345
end

0 commit comments

Comments
 (0)