From 028aa2b0b7270b2557c320ecb826a41cda23789f Mon Sep 17 00:00:00 2001 From: "eryn L. K" Date: Thu, 30 Jun 2022 15:53:22 -0400 Subject: [PATCH] Fix debug widgets with absolute references --- CHANGELOG.md | 4 + lib/debugger/debugger.lua | 29 ++-- lib/debugger/widgets/container.lua | 42 +++--- lib/debugger/widgets/frame.lua | 71 +++++----- lib/debugger/widgets/panel.lua | 93 +++++++------ lib/debugger/widgets/selectionList.lua | 180 ++++++++++++------------- 6 files changed, 215 insertions(+), 204 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 429f239..c689af6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [0.5.1] - 2022-06030 +### Fixed +- Fix custom debugger widgets not using the Plasma instance the user passed in. + ## [0.5.0] - 2022-06-30 ### Added - Added Matter debugger. diff --git a/lib/debugger/debugger.lua b/lib/debugger/debugger.lua index 9cad72a..1befe67 100644 --- a/lib/debugger/debugger.lua +++ b/lib/debugger/debugger.lua @@ -2,13 +2,16 @@ local RunService = game:GetService("RunService") local ReplicatedStorage = game:GetService("ReplicatedStorage") local Players = game:GetService("Players") -local panel = require(script.Parent.widgets.panel) -local selectionList = require(script.Parent.widgets.selectionList) -local container = require(script.Parent.widgets.container) -local frame = require(script.Parent.widgets.frame) local hookWidgets = require(script.Parent.hookWidgets) local EventBridge = require(script.Parent.EventBridge) +local customWidgetConstructors = { + panel = require(script.Parent.widgets.panel), + selectionList = require(script.Parent.widgets.selectionList), + container = require(script.Parent.widgets.container), + frame = require(script.Parent.widgets.frame), +} + local remoteEvent local function systemName(system) @@ -96,8 +99,13 @@ function Debugger.new(plasma) _eventBridge = EventBridge.new(function(...) remoteEvent:FireClient(...) end), + _customWidgets = {}, }, Debugger) + for name, create in customWidgetConstructors do + self._customWidgets[name] = create(plasma) + end + if RunService:IsServer() then remoteEvent.OnServerEvent:Connect(function(player, action, instance, event, ...) if action == "event" then @@ -334,10 +342,11 @@ end ]=] function Debugger:draw(loop) local plasma = self.plasma + local ui = self._customWidgets - container(function() + ui.container(function() if self:_isServerView() then - panel(function() + ui.panel(function() if plasma.button("switch to client"):clicked() then self:switchToClientView() end @@ -347,7 +356,7 @@ function Debugger:draw(loop) return end - panel(function() + ui.panel(function() if RunService:IsClient() then if plasma.button("switch to server"):clicked() then self:switchToServerView() @@ -378,7 +387,7 @@ function Debugger:draw(loop) }) end - local selected = selectionList(items):selected() + local selected = ui.selectionList(items):selected() if selected then if selected.system == self.debugSystem then @@ -408,8 +417,8 @@ function Debugger:draw(loop) end) end - self.parent = container(function() - self.frame = frame() + self.parent = ui.container(function() + self.frame = ui.frame() end) end, { direction = Enum.FillDirection.Horizontal, diff --git a/lib/debugger/widgets/container.lua b/lib/debugger/widgets/container.lua index 95747fd..18ca8cf 100644 --- a/lib/debugger/widgets/container.lua +++ b/lib/debugger/widgets/container.lua @@ -1,27 +1,27 @@ -local ReplicatedStorage = game:GetService("ReplicatedStorage") -local Plasma = require(ReplicatedStorage.Packages.plasma) -local create = Plasma.create +return function(Plasma) + local create = Plasma.create -return Plasma.widget(function(fn, options) - options = options or {} + return Plasma.widget(function(fn, options) + options = options or {} - local padding = options.padding or 10 + local padding = options.padding or 10 - local frame = Plasma.useInstance(function() - return create("Frame", { - BackgroundTransparency = 1, - Position = UDim2.new(0, 0, 0, options.marginTop or 0), - Size = UDim2.new(1, 0, 1, -(options.marginTop or 0)), + local frame = Plasma.useInstance(function() + return create("Frame", { + BackgroundTransparency = 1, + Position = UDim2.new(0, 0, 0, options.marginTop or 0), + Size = UDim2.new(1, 0, 1, -(options.marginTop or 0)), - create("UIListLayout", { - SortOrder = Enum.SortOrder.LayoutOrder, - FillDirection = options.direction or Enum.FillDirection.Vertical, - Padding = UDim.new(0, padding), - }), - }) - end) + create("UIListLayout", { + SortOrder = Enum.SortOrder.LayoutOrder, + FillDirection = options.direction or Enum.FillDirection.Vertical, + Padding = UDim.new(0, padding), + }), + }) + end) - Plasma.scope(fn) + Plasma.scope(fn) - return frame -end) + return frame + end) +end diff --git a/lib/debugger/widgets/frame.lua b/lib/debugger/widgets/frame.lua index c92d66c..4b8b626 100644 --- a/lib/debugger/widgets/frame.lua +++ b/lib/debugger/widgets/frame.lua @@ -1,48 +1,47 @@ -local ReplicatedStorage = game:GetService("ReplicatedStorage") -local Plasma = require(ReplicatedStorage.Packages.plasma) +return function(Plasma) + return Plasma.widget(function() + local instance = Plasma.useInstance(function() + local style = Plasma.useStyle() -return Plasma.widget(function() - local instance = Plasma.useInstance(function() - local style = Plasma.useStyle() + local Frame = Instance.new("Frame") + Frame.BackgroundColor3 = style.bg2 + Frame.Position = UDim2.new(0.5, 0, 0.5, 0) + Frame.AnchorPoint = Vector2.new(0.5, 0.5) + Frame.Size = UDim2.new(0, 50, 0, 40) + Frame.Visible = false - local Frame = Instance.new("Frame") - Frame.BackgroundColor3 = style.bg2 - Frame.Position = UDim2.new(0.5, 0, 0.5, 0) - Frame.AnchorPoint = Vector2.new(0.5, 0.5) - Frame.Size = UDim2.new(0, 50, 0, 40) - Frame.Visible = false + local UICorner = Instance.new("UICorner") + UICorner.Parent = Frame - local UICorner = Instance.new("UICorner") - UICorner.Parent = Frame + local UIPadding = Instance.new("UIPadding") + UIPadding.PaddingBottom = UDim.new(0, 20) + UIPadding.PaddingLeft = UDim.new(0, 20) + UIPadding.PaddingRight = UDim.new(0, 20) + UIPadding.PaddingTop = UDim.new(0, 20) + UIPadding.Parent = Frame - local UIPadding = Instance.new("UIPadding") - UIPadding.PaddingBottom = UDim.new(0, 20) - UIPadding.PaddingLeft = UDim.new(0, 20) - UIPadding.PaddingRight = UDim.new(0, 20) - UIPadding.PaddingTop = UDim.new(0, 20) - UIPadding.Parent = Frame + local UIStroke = Instance.new("UIStroke") + UIStroke.Parent = Frame - local UIStroke = Instance.new("UIStroke") - UIStroke.Parent = Frame + local UIListLayout = Instance.new("UIListLayout") + UIListLayout.SortOrder = Enum.SortOrder.LayoutOrder + UIListLayout.Padding = UDim.new(0, 10) + UIListLayout.Parent = Frame - local UIListLayout = Instance.new("UIListLayout") - UIListLayout.SortOrder = Enum.SortOrder.LayoutOrder - UIListLayout.Padding = UDim.new(0, 10) - UIListLayout.Parent = Frame + local numChildren = #Frame:GetChildren() - local numChildren = #Frame:GetChildren() + Plasma.automaticSize(Frame) - Plasma.automaticSize(Frame) + local function updateVisibility() + Frame.Visible = #Frame:GetChildren() > numChildren + end - local function updateVisibility() - Frame.Visible = #Frame:GetChildren() > numChildren - end + Frame.ChildAdded:Connect(updateVisibility) + Frame.ChildRemoved:Connect(updateVisibility) - Frame.ChildAdded:Connect(updateVisibility) - Frame.ChildRemoved:Connect(updateVisibility) + return Frame + end) - return Frame + return instance end) - - return instance -end) +end diff --git a/lib/debugger/widgets/panel.lua b/lib/debugger/widgets/panel.lua index c09ac5b..7a37ddf 100644 --- a/lib/debugger/widgets/panel.lua +++ b/lib/debugger/widgets/panel.lua @@ -1,54 +1,53 @@ -local ReplicatedStorage = game:GetService("ReplicatedStorage") -local Plasma = require(ReplicatedStorage.Packages.plasma) -local create = Plasma.create - -return Plasma.widget(function(children, options) - options = options or {} - - options.fullHeight = if options.fullHeight then options.fullHeight else true - - Plasma.useInstance(function() - local style = Plasma.useStyle() - - local frame = create("Frame", { - BackgroundColor3 = style.bg2, - Position = UDim2.new(0, 0, 0, 0), - Size = UDim2.new(0, 250, if options.fullHeight then 1 else 0, 0), - - create("UIPadding", { - PaddingBottom = UDim.new(0, 20), - PaddingLeft = UDim.new(0, 20), - PaddingRight = UDim.new(0, 20), - PaddingTop = UDim.new(0, 20), - }), - create("UIStroke", {}), - - create("UIListLayout", { - SortOrder = Enum.SortOrder.LayoutOrder, - }), - - create("ScrollingFrame", { - BackgroundTransparency = 1, - Name = "Container", - VerticalScrollBarInset = Enum.ScrollBarInset.ScrollBar, - HorizontalScrollBarInset = Enum.ScrollBarInset.ScrollBar, - BorderSizePixel = 0, - ScrollBarThickness = 6, - ClipsDescendants = false, - Size = UDim2.new(1, 0, 1, 0), +return function(Plasma) + local create = Plasma.create + return Plasma.widget(function(children, options) + options = options or {} + + options.fullHeight = if options.fullHeight then options.fullHeight else true + + Plasma.useInstance(function() + local style = Plasma.useStyle() + + local frame = create("Frame", { + BackgroundColor3 = style.bg2, + Position = UDim2.new(0, 0, 0, 0), + Size = UDim2.new(0, 250, if options.fullHeight then 1 else 0, 0), + + create("UIPadding", { + PaddingBottom = UDim.new(0, 20), + PaddingLeft = UDim.new(0, 20), + PaddingRight = UDim.new(0, 20), + PaddingTop = UDim.new(0, 20), + }), + create("UIStroke", {}), create("UIListLayout", { SortOrder = Enum.SortOrder.LayoutOrder, }), - }), - }) - Plasma.automaticSize(frame.Container, { - axis = Enum.AutomaticSize.Y, - }) + create("ScrollingFrame", { + BackgroundTransparency = 1, + Name = "Container", + VerticalScrollBarInset = Enum.ScrollBarInset.ScrollBar, + HorizontalScrollBarInset = Enum.ScrollBarInset.ScrollBar, + BorderSizePixel = 0, + ScrollBarThickness = 6, + ClipsDescendants = false, + Size = UDim2.new(1, 0, 1, 0), + + create("UIListLayout", { + SortOrder = Enum.SortOrder.LayoutOrder, + }), + }), + }) - return frame, frame.Container - end) + Plasma.automaticSize(frame.Container, { + axis = Enum.AutomaticSize.Y, + }) - Plasma.scope(children) -end) + return frame, frame.Container + end) + + Plasma.scope(children) + end) +end diff --git a/lib/debugger/widgets/selectionList.lua b/lib/debugger/widgets/selectionList.lua index ab3913d..10a9d0b 100644 --- a/lib/debugger/widgets/selectionList.lua +++ b/lib/debugger/widgets/selectionList.lua @@ -1,100 +1,100 @@ -local ReplicatedStorage = game:GetService("ReplicatedStorage") -local Plasma = require(ReplicatedStorage.Packages.plasma) -local create = Plasma.create - -local Item = Plasma.widget(function(text, selected) - local clicked, setClicked = Plasma.useState(false) - local style = Plasma.useStyle() - - local button = Plasma.useInstance(function() - local button = create("TextButton", { - Size = UDim2.new(1, 0, 0, 40), - Text = "", - - create("UICorner", { - CornerRadius = UDim.new(0, 8), - }), - - create("UIPadding", { - PaddingBottom = UDim.new(0, 0), - PaddingLeft = UDim.new(0, 8), - PaddingRight = UDim.new(0, 8), - PaddingTop = UDim.new(0, 0), - }), - - create("UIListLayout", { - SortOrder = Enum.SortOrder.LayoutOrder, - FillDirection = Enum.FillDirection.Horizontal, - }), - - create("TextLabel", { - BackgroundTransparency = 1, - AutomaticSize = Enum.AutomaticSize.X, - Size = UDim2.new(0, 0, 1, 0), - Text = text, - TextXAlignment = Enum.TextXAlignment.Left, - TextSize = 19, - TextColor3 = style.textColor, - Font = Enum.Font.SourceSans, - }), - - Activated = function() - setClicked(true) +return function(Plasma) + local create = Plasma.create + + local Item = Plasma.widget(function(text, selected) + local clicked, setClicked = Plasma.useState(false) + local style = Plasma.useStyle() + + local button = Plasma.useInstance(function() + local button = create("TextButton", { + Size = UDim2.new(1, 0, 0, 40), + Text = "", + + create("UICorner", { + CornerRadius = UDim.new(0, 8), + }), + + create("UIPadding", { + PaddingBottom = UDim.new(0, 0), + PaddingLeft = UDim.new(0, 8), + PaddingRight = UDim.new(0, 8), + PaddingTop = UDim.new(0, 0), + }), + + create("UIListLayout", { + SortOrder = Enum.SortOrder.LayoutOrder, + FillDirection = Enum.FillDirection.Horizontal, + }), + + create("TextLabel", { + BackgroundTransparency = 1, + AutomaticSize = Enum.AutomaticSize.X, + Size = UDim2.new(0, 0, 1, 0), + Text = text, + TextXAlignment = Enum.TextXAlignment.Left, + TextSize = 19, + TextColor3 = style.textColor, + Font = Enum.Font.SourceSans, + }), + + Activated = function() + setClicked(true) + end, + }) + + return button + end) + + Plasma.useEffect(function() + button.TextLabel.Text = text + end, text) + + Plasma.useEffect(function() + button.BackgroundColor3 = if selected then Color3.fromHex("bd515c") else style.bg2 + end, selected) + + return { + clicked = function() + if clicked then + setClicked(false) + return true + end + + return false end, - }) - - return button + } end) - Plasma.useEffect(function() - button.TextLabel.Text = text - end, text) - - Plasma.useEffect(function() - button.BackgroundColor3 = if selected then Color3.fromHex("bd515c") else style.bg2 - end, selected) + return Plasma.widget(function(items) + Plasma.useInstance(function() + local frame = create("Frame", { + BackgroundTransparency = 1, + Size = UDim2.new(1, 0, 0, 0), - return { - clicked = function() - if clicked then - setClicked(false) - return true - end + create("UIListLayout", { + SortOrder = Enum.SortOrder.LayoutOrder, + }), + }) - return false - end, - } -end) + Plasma.automaticSize(frame, { + axis = Enum.AutomaticSize.Y, + }) -return Plasma.widget(function(items) - Plasma.useInstance(function() - local frame = create("Frame", { - BackgroundTransparency = 1, - Size = UDim2.new(1, 0, 0, 0), + return frame + end) - create("UIListLayout", { - SortOrder = Enum.SortOrder.LayoutOrder, - }), - }) + local selected - Plasma.automaticSize(frame, { - axis = Enum.AutomaticSize.Y, - }) + for _, item in items do + if Item(item.text, item.selected):clicked() then + selected = item + end + end - return frame + return { + selected = function() + return selected + end, + } end) - - local selected - - for _, item in items do - if Item(item.text, item.selected):clicked() then - selected = item - end - end - - return { - selected = function() - return selected - end, - } -end) +end