Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
Fix debug widgets with absolute references
Browse files Browse the repository at this point in the history
  • Loading branch information
evaera committed Jun 30, 2022
1 parent f2c77bd commit 028aa2b
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 204 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
29 changes: 19 additions & 10 deletions lib/debugger/debugger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
42 changes: 21 additions & 21 deletions lib/debugger/widgets/container.lua
Original file line number Diff line number Diff line change
@@ -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
71 changes: 35 additions & 36 deletions lib/debugger/widgets/frame.lua
Original file line number Diff line number Diff line change
@@ -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
93 changes: 46 additions & 47 deletions lib/debugger/widgets/panel.lua
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 028aa2b

Please sign in to comment.