From d39f3bd5ea0840c6a7c23dd566f270db99df7ca7 Mon Sep 17 00:00:00 2001 From: Nidoxs Date: Wed, 14 Aug 2024 17:43:09 +0100 Subject: [PATCH 01/12] Allow disabling of systems by right clicking (+ refined tooltip) --- lib/debugger/clientBindings.luau | 41 +++++++++++---- lib/debugger/ui.luau | 59 ++++++++++++++++++--- lib/debugger/widgets/hoverInspect.luau | 5 +- lib/debugger/widgets/selectionList.luau | 68 +++++++++++++++++++++---- lib/debugger/widgets/tooltip.luau | 13 +++-- 5 files changed, 156 insertions(+), 30 deletions(-) diff --git a/lib/debugger/clientBindings.luau b/lib/debugger/clientBindings.luau index 405aed41..d5883971 100644 --- a/lib/debugger/clientBindings.luau +++ b/lib/debugger/clientBindings.luau @@ -1,5 +1,23 @@ local UserInputService = game:GetService("UserInputService") local CollectionService = game:GetService("CollectionService") + +local tags = { + system = "MatterDebuggerTooltip_System", + altHover = "MatterDebuggerTooltip_AltHover", +} + +local fromOffset = UDim2.fromOffset + +local function getOffset(mousePos: Vector2, tag: string): UDim2 + if tag == tags.altHover then + return fromOffset(mousePos.X + 20, mousePos.Y) + elseif tag == tags.system then + return fromOffset(mousePos.X + 20, mousePos.Y + 10) + end + + return fromOffset(mousePos.X, mousePos.Y + 10) +end + local function clientBindings(debugger) local connections = {} @@ -21,20 +39,23 @@ local function clientBindings(debugger) local mousePosition = UserInputService:GetMouseLocation() - for _, gui in CollectionService:GetTagged("MatterDebuggerTooltip") do - gui.Position = UDim2.new(0, mousePosition.X + 20, 0, mousePosition.Y) + for _, tag in tags do + for _, gui in CollectionService:GetTagged(tag) do + gui.Position = getOffset(mousePosition, tag) + end end end) ) - table.insert( - connections, - CollectionService:GetInstanceAddedSignal("MatterDebuggerTooltip"):Connect(function(gui) - local mousePosition = UserInputService:GetMouseLocation() - - gui.Position = UDim2.new(0, mousePosition.X + 20, 0, mousePosition.Y) - end) - ) + for _, tag in tags do + table.insert( + connections, + CollectionService:GetInstanceAddedSignal(tag):Connect(function(gui) + local mousePosition = UserInputService:GetMouseLocation() + gui.Position = getOffset(mousePosition, tag) + end) + ) + end return connections end diff --git a/lib/debugger/ui.luau b/lib/debugger/ui.luau index af4f968e..941921e1 100644 --- a/lib/debugger/ui.luau +++ b/lib/debugger/ui.luau @@ -29,6 +29,7 @@ end local IS_SERVER = RunService:IsServer() local IS_CLIENT = RunService:IsClient() +local LONG_SYSTEM_NAME = 24 local function ui(debugger, loop) local plasma = debugger.plasma @@ -48,6 +49,8 @@ local function ui(debugger, loop) end end + local hoveredSystem + custom.container(function() if debugger:_isServerView() then return @@ -141,7 +144,7 @@ local function ui(debugger, loop) }) plasma.space(5) - local items = {} + local listOfSystems = {} for _, system in systems do local samples = loop.profiling[system] @@ -168,24 +171,51 @@ local function ui(debugger, loop) icon = "\xf0\x9f\x92\xa5" end - table.insert(items, { - text = systemName(system), - sideText = averageFrameTime, + local barWidth + if longestDuration == 0 then + barWidth = 0 + else + barWidth = duration / longestDuration + end + + local systemIsDisabled = loop._skipSystems[system] + local systemName = systemName(system) + local length = string.len(systemName) + + if systemIsDisabled then + length += 4 + end + + table.insert(listOfSystems, { + text = if systemIsDisabled then `{systemName}` else systemName, + sideText = if systemIsDisabled then `{"(disabled)"}` else averageFrameTime, selected = debugger.debugSystem == system, system = system, icon = icon, - barWidth = duration / longestDuration, + barWidth = barWidth, index = index, }) end - local selected = custom.selectionList(items):selected() + local systemList = custom.selectionList(listOfSystems, custom) + local selected = systemList:selected() + local rightClicked = systemList:rightClicked() + hoveredSystem = systemList:hovered() + if selected then if selected.system == debugger.debugSystem then debugger.debugSystem = nil else debugger.debugSystem = selected.system end + elseif rightClicked and rightClicked.system then + local current = loop._skipSystems[rightClicked.system] + + if current == nil then + loop._skipSystems[rightClicked.system] = true + else + loop._skipSystems[rightClicked.system] = not current + end end if debugger.debugSystem then @@ -311,6 +341,23 @@ local function ui(debugger, loop) direction = Enum.FillDirection.Horizontal, padding = 0, }) + + if hoveredSystem and hoveredSystem.system then + local hoveredSystemName = systemName(hoveredSystem.system) + local length = string.len(hoveredSystemName) + local systemDisabled = loop._skipSystems[hoveredSystem.system] + + if systemDisabled then + length += 2 + end + + if length >= LONG_SYSTEM_NAME then + custom.tooltip(`{hoveredSystemName}{if systemDisabled then " (disabled)" else ""}`, { + tag = "MatterDebuggerTooltip_System", + backgroundTransparency = 0, + }) + end + end end return ui diff --git a/lib/debugger/widgets/hoverInspect.luau b/lib/debugger/widgets/hoverInspect.luau index d9b5daa3..c0c10d88 100644 --- a/lib/debugger/widgets/hoverInspect.luau +++ b/lib/debugger/widgets/hoverInspect.luau @@ -18,6 +18,9 @@ return function(plasma) end end - custom.tooltip(str) + custom.tooltip(str, { + tag = "MatterDebuggerTooltip_AltHover", + backgroundTransparency = 0.15, + }) end) end diff --git a/lib/debugger/widgets/selectionList.luau b/lib/debugger/widgets/selectionList.luau index 5842b00f..0ef7c057 100644 --- a/lib/debugger/widgets/selectionList.luau +++ b/lib/debugger/widgets/selectionList.luau @@ -1,13 +1,16 @@ return function(Plasma) local create = Plasma.create - local Item = Plasma.widget(function(text, selected, icon, sideText, _, barWidth, index) + local Item = Plasma.widget(function(text, selected, icon, sideText, barWidth, index) local clicked, setClicked = Plasma.useState(false) + local rightClicked, setRightClicked = Plasma.useState(false) + local hovered, setHovered = Plasma.useState(false) local style = Plasma.useStyle() local refs = Plasma.useInstance(function(ref) local button = create("TextButton", { [ref] = "button", + AutoButtonColor = false, Size = UDim2.new(1, 0, 0, 25), Text = "", @@ -62,6 +65,7 @@ return function(Plasma) BackgroundTransparency = 1, Size = UDim2.new(0, 0, 1, 0), Text = text, + RichText = true, TextXAlignment = Enum.TextXAlignment.Left, TextSize = 13, TextColor3 = style.textColor, @@ -81,6 +85,7 @@ return function(Plasma) Text = "", TextXAlignment = Enum.TextXAlignment.Left, TextSize = 11, + RichText = true, TextColor3 = style.mutedTextColor, Font = Enum.Font.Gotham, }), @@ -101,6 +106,20 @@ return function(Plasma) Activated = function() setClicked(true) end, + + MouseEnter = function() + setHovered(true) + end, + + MouseLeave = function() + setHovered(false) + end, + + InputBegan = function(input: InputObject) + if input.UserInputType == Enum.UserInputType.MouseButton2 then + setRightClicked(true) + end + end, }) return button @@ -120,8 +139,11 @@ return function(Plasma) refs.button.bar.Size = UDim2.new(barWidth or 0, 0, 0, 1) Plasma.useEffect(function() - refs.button.BackgroundColor3 = if selected then style.primaryColor else style.bg2 - end, selected) + refs.button.BackgroundColor3 = if selected + then style.primaryColor + elseif hovered then style.bg1 + else style.bg2 + end, selected, hovered) return { clicked = function() @@ -132,19 +154,29 @@ return function(Plasma) return false end, + rightClicked = function() + if rightClicked then + setRightClicked(false) + return true + end + + return false + end, + hovered = function() + return hovered + end, } end) - return Plasma.widget(function(items, options) - options = options or {} - + return Plasma.widget(function(items) Plasma.useInstance(function() local frame = create("Frame", { BackgroundTransparency = 1, - Size = options.width and UDim2.new(0, options.width, 0, 0) or UDim2.new(1, 0, 0, 0), + Size = UDim2.new(1, 0, 0, 0), create("UIListLayout", { SortOrder = Enum.SortOrder.LayoutOrder, + Padding = UDim.new(0, 2), }), }) @@ -156,19 +188,35 @@ return function(Plasma) end) local selected + local rightClicked + local hovered for _, item in items do - if - Item(item.text, item.selected, item.icon, item.sideText, options.width, item.barWidth, item.index):clicked() - then + local buttonInList = Item(item.text, item.selected, item.icon, item.sideText, item.barWidth, item.index) + + if buttonInList:clicked() then selected = item end + + if buttonInList:rightClicked() then + rightClicked = item + end + + if buttonInList:hovered() then + hovered = item + end end return { selected = function() return selected end, + rightClicked = function() + return rightClicked + end, + hovered = function() + return hovered + end, } end) end diff --git a/lib/debugger/widgets/tooltip.luau b/lib/debugger/widgets/tooltip.luau index a99f969a..499479df 100644 --- a/lib/debugger/widgets/tooltip.luau +++ b/lib/debugger/widgets/tooltip.luau @@ -1,8 +1,14 @@ local CollectionService = game:GetService("CollectionService") + +type Options = { + tag: string, + backgroundTransparency: number?, +} + return function(plasma) local create = plasma.create - return plasma.widget(function(text) + return plasma.widget(function(text, options: Options) local refs = plasma.useInstance(function(ref) local style = plasma.useStyle() @@ -16,9 +22,10 @@ return function(plasma) Font = Enum.Font.Code, TextStrokeTransparency = 0.5, TextColor3 = Color3.new(1, 1, 1), - BackgroundTransparency = 0.2, + BackgroundTransparency = options.backgroundTransparency or 0.2, BackgroundColor3 = style.bg1, AutomaticSize = Enum.AutomaticSize.XY, + ZIndex = 100, create("UIPadding", { PaddingBottom = UDim.new(0, 4), @@ -34,7 +41,7 @@ return function(plasma) }), }) - CollectionService:AddTag(ref.label, "MatterDebuggerTooltip") + CollectionService:AddTag(ref.label, options.tag) return ref.label end) From dae6d21232ebdad890032dfa575a2c51e0ef8de4 Mon Sep 17 00:00:00 2001 From: Nidoxs Date: Wed, 14 Aug 2024 18:18:56 +0100 Subject: [PATCH 02/12] Change color of system index label in system list --- lib/debugger/widgets/selectionList.luau | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/debugger/widgets/selectionList.luau b/lib/debugger/widgets/selectionList.luau index 0ef7c057..9d44a774 100644 --- a/lib/debugger/widgets/selectionList.luau +++ b/lib/debugger/widgets/selectionList.luau @@ -37,6 +37,7 @@ return function(Plasma) }), create("TextLabel", { + [ref] = "index", Name = "index", AutomaticSize = Enum.AutomaticSize.X, Size = UDim2.new(0, 0, 1, 0), @@ -61,6 +62,7 @@ return function(Plasma) }), create("TextLabel", { + [ref] = "mainText", AutomaticSize = Enum.AutomaticSize.X, BackgroundTransparency = 1, Size = UDim2.new(0, 0, 1, 0), @@ -103,8 +105,12 @@ return function(Plasma) ZIndex = 2, }), - Activated = function() - setClicked(true) + InputBegan = function(input: InputObject) + if input.UserInputType == Enum.UserInputType.MouseButton1 then + setClicked(true) + elseif input.UserInputType == Enum.UserInputType.MouseButton2 then + setRightClicked(true) + end end, MouseEnter = function() @@ -114,19 +120,13 @@ return function(Plasma) MouseLeave = function() setHovered(false) end, - - InputBegan = function(input: InputObject) - if input.UserInputType == Enum.UserInputType.MouseButton2 then - setRightClicked(true) - end - end, }) return button end) Plasma.useEffect(function() - refs.button.container.TextLabel.Text = text + refs.mainText.Text = text refs.button.container.Icon.Text = icon or "" refs.button.container.Icon.Visible = icon ~= nil end, text, icon) @@ -134,7 +134,7 @@ return function(Plasma) refs.button.container.sideText.Visible = sideText ~= nil refs.button.container.sideText.Text = if sideText ~= nil then sideText else "" refs.button.container.sideText.TextColor3 = if selected then style.textColor else style.mutedTextColor - refs.button.container.TextLabel.TextTruncate = sideText and Enum.TextTruncate.AtEnd or Enum.TextTruncate.None + refs.mainText.TextTruncate = sideText and Enum.TextTruncate.AtEnd or Enum.TextTruncate.None refs.button.bar.Size = UDim2.new(barWidth or 0, 0, 0, 1) @@ -143,6 +143,8 @@ return function(Plasma) then style.primaryColor elseif hovered then style.bg1 else style.bg2 + + refs.index.TextColor3 = if selected or hovered then style.textColor else style.mutedTextColor end, selected, hovered) return { From 97207f88d5f0d07a0639c01de8a1ee64400c9c47 Mon Sep 17 00:00:00 2001 From: Nidoxs Date: Wed, 14 Aug 2024 21:31:04 +0100 Subject: [PATCH 03/12] Push search feature with changes to avoid tedious merge conflict --- lib/debugger/debugger.luau | 1 + lib/debugger/ui.luau | 164 +++++++++++++++++----------- lib/debugger/widgets/textField.luau | 81 ++++++++++++++ 3 files changed, 180 insertions(+), 66 deletions(-) create mode 100644 lib/debugger/widgets/textField.luau diff --git a/lib/debugger/debugger.luau b/lib/debugger/debugger.luau index bf5b410a..d4150192 100644 --- a/lib/debugger/debugger.luau +++ b/lib/debugger/debugger.luau @@ -25,6 +25,7 @@ local customWidgetConstructors: { [string]: any } = { queryInspect = require(script.Parent.widgets.queryInspect), codeText = require(script.Parent.widgets.codeText), errorInspect = require(script.Parent.widgets.errorInspect), + textField = require(script.Parent.widgets.textField), } local IS_SERVER = RunService:IsServer() diff --git a/lib/debugger/ui.luau b/lib/debugger/ui.luau index 941921e1..40dc2cc1 100644 --- a/lib/debugger/ui.luau +++ b/lib/debugger/ui.luau @@ -2,6 +2,8 @@ local RunService = game:GetService("RunService") local World = require(script.Parent.Parent.World) local rollingAverage = require(script.Parent.Parent.rollingAverage) +local match, lower = string.match, string.lower + local function systemName(system) local systemFn = if type(system) == "table" then system.system else system local name = debug.info(systemFn, "n") @@ -127,10 +129,19 @@ local function ui(debugger, loop) plasma.space(15) plasma.heading("SYSTEMS") + + local searchFilter = "" + if IS_CLIENT then + plasma.space(5) + local textField = custom.textField("Search...") + searchFilter = textField:text() + searchFilter = string.gsub(searchFilter, "%s+", "") + end + plasma.space(10) - local durations = {} - local longestDuration = 0 + local searchResults = {} + local noResults = true for _, eventName in debugger._eventOrder do local systems = loop._orderedSystemsByEvent[eventName] @@ -139,92 +150,113 @@ local function ui(debugger, loop) continue end - plasma.heading(eventName, { - font = Enum.Font.Gotham, - }) - plasma.space(5) + for _, system in systems do + local nameOfSystem = systemName(system) + local noMatch = searchFilter ~= "" and not match(lower(nameOfSystem), lower(searchFilter)) - local listOfSystems = {} + if noMatch then + continue + end - for _, system in systems do - local samples = loop.profiling[system] - if samples then - local duration = rollingAverage.getAverage(samples) - durations[system] = duration - longestDuration = math.max(longestDuration, duration) + if searchResults[eventName] == nil then + searchResults[eventName] = {} end + + searchResults[eventName][nameOfSystem] = true + noResults = false end + end - for index, system in systems do - local averageFrameTime = "" - local icon + if noResults then + plasma.label("No search results") + else + local durations = {} + local longestDuration = 0 - local duration = durations[system] or 0 - local humanDuration, unit = formatDuration(duration) - averageFrameTime = string.format("%.0f%s", humanDuration, unit) + for _, eventName in debugger._eventOrder do + local systems = loop._orderedSystemsByEvent[eventName] - if duration > 0.004 then -- 4ms - icon = "\xe2\x9a\xa0\xef\xb8\x8f" + if not systems or searchResults[eventName] == nil then + continue end - if loop._systemErrors[system] then - icon = "\xf0\x9f\x92\xa5" - end + plasma.heading(eventName, { + font = Enum.Font.Gotham, + }) + plasma.space(5) - local barWidth - if longestDuration == 0 then - barWidth = 0 - else - barWidth = duration / longestDuration + local listOfSystems = {} + + for _, system in systems do + local samples = loop.profiling[system] + if samples then + local duration = rollingAverage.getAverage(samples) + durations[system] = duration + longestDuration = math.max(longestDuration, duration) + end end - local systemIsDisabled = loop._skipSystems[system] - local systemName = systemName(system) - local length = string.len(systemName) + for index, system in systems do + local nameOfSystem = systemName(system) - if systemIsDisabled then - length += 4 - end + if searchResults[eventName][nameOfSystem] == nil then + continue + end - table.insert(listOfSystems, { - text = if systemIsDisabled then `{systemName}` else systemName, - sideText = if systemIsDisabled then `{"(disabled)"}` else averageFrameTime, - selected = debugger.debugSystem == system, - system = system, - icon = icon, - barWidth = barWidth, - index = index, - }) - end + local averageFrameTime = "" + local icon - local systemList = custom.selectionList(listOfSystems, custom) - local selected = systemList:selected() - local rightClicked = systemList:rightClicked() - hoveredSystem = systemList:hovered() + local duration = durations[system] or 0 + local humanDuration, unit = formatDuration(duration) + averageFrameTime = string.format("%.0f%s", humanDuration, unit) - if selected then - if selected.system == debugger.debugSystem then - debugger.debugSystem = nil - else - debugger.debugSystem = selected.system + if duration > 0.004 then -- 4ms + icon = "\xe2\x9a\xa0\xef\xb8\x8f" + end + + if loop._systemErrors[system] then + icon = "\xf0\x9f\x92\xa5" + end + + table.insert(listOfSystems, { + text = nameOfSystem, + sideText = averageFrameTime, + selected = debugger.debugSystem == system, + system = system, + icon = icon, + barWidth = duration / longestDuration, + index = index, + }) end - elseif rightClicked and rightClicked.system then - local current = loop._skipSystems[rightClicked.system] - if current == nil then - loop._skipSystems[rightClicked.system] = true + local systemList = custom.selectionList(listOfSystems, custom) + local selected = systemList:selected() + local rightClicked = systemList:rightClicked() + hoveredSystem = systemList:hovered() + if selected then + if selected.system == debugger.debugSystem then + debugger.debugSystem = nil + else + debugger.debugSystem = selected.system + end + elseif rightClicked and rightClicked.system then + local current = loop._skipSystems[rightClicked.system] + + if current == nil then + loop._skipSystems[rightClicked.system] = true + else + loop._skipSystems[rightClicked.system] = not current + end + end + + if debugger.debugSystem then + debugger.debugSystemRuntime = durations[debugger.debugSystem] else - loop._skipSystems[rightClicked.system] = not current + debugger.debugSystemRuntime = nil end - end - if debugger.debugSystem then - debugger.debugSystemRuntime = durations[debugger.debugSystem] - else - debugger.debugSystemRuntime = nil + plasma.space(10) end - - plasma.space(10) end end) diff --git a/lib/debugger/widgets/textField.luau b/lib/debugger/widgets/textField.luau new file mode 100644 index 00000000..4abc3954 --- /dev/null +++ b/lib/debugger/widgets/textField.luau @@ -0,0 +1,81 @@ +-- temporary TextField component unique to Matter's repository +-- for the client system search feature +-- this should be a native Plasma component eventually +return function(Plasma) + local create = Plasma.create + + return Plasma.widget(function(placeholder, options) + options = options or { editable = true } + local text, setText = Plasma.useState("") + local lastUpdate, setLastUpdate = Plasma.useState(os.clock()) + + local refs = Plasma.useInstance(function(ref) + local style = Plasma.useStyle() + + return create("Frame", { + Size = UDim2.new(1, 0, 0, 20), + BackgroundTransparency = 1, + + create("UIPadding", { + PaddingLeft = UDim.new(0, 1), + PaddingRight = UDim.new(0, 1), + PaddingTop = UDim.new(0, 0), + PaddingBottom = UDim.new(0, 0), + }), + + create("TextBox", { + [ref] = "textField", + AnchorPoint = Vector2.new(0, 0), + TextEditable = options.editable, + BackgroundTransparency = 0, + BackgroundColor3 = style.bg1, + Font = Enum.Font.Gotham, + TextXAlignment = Enum.TextXAlignment.Left, + TextColor3 = style.textColor, + TextSize = 12, + Size = UDim2.fromScale(1, 1), + PlaceholderText = placeholder, + Text = text, + RichText = true, + + create("UICorner", { + CornerRadius = UDim.new(0, 4), + }), + + create("UIStroke", { + Thickness = 1, + ApplyStrokeMode = Enum.ApplyStrokeMode.Border, + }), + + create("UIPadding", { + PaddingLeft = UDim.new(0, 8), + PaddingRight = UDim.new(0, 8), + PaddingTop = UDim.new(0, 4), + PaddingBottom = UDim.new(0, 4), + }), + + Changed = function(property: string) + if property == "Text" then + setLastUpdate(os.clock()) + end + end, + }), + }) + end) + + local instance = refs.textField + local shouldUpdate = (os.clock() - lastUpdate) > 0.15 + + -- let's cap text updates to every 0.15 seconds + if shouldUpdate then + setText(instance.Text) + setLastUpdate(os.clock()) + end + + return { + text = function() + return text + end, + } + end) +end From 4a1ec7383877c4e4a9b5f84e46f8b87668742416 Mon Sep 17 00:00:00 2001 From: Nidoxs Date: Wed, 14 Aug 2024 21:42:05 +0100 Subject: [PATCH 04/12] Fix right click disablement (avoid merge conf) --- lib/debugger/ui.luau | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/debugger/ui.luau b/lib/debugger/ui.luau index 40dc2cc1..880bbec8 100644 --- a/lib/debugger/ui.luau +++ b/lib/debugger/ui.luau @@ -218,13 +218,28 @@ local function ui(debugger, loop) icon = "\xf0\x9f\x92\xa5" end + local barWidth + if longestDuration == 0 then + barWidth = 0 + else + barWidth = duration / longestDuration + end + + local systemIsDisabled = loop._skipSystems[system] + local systemName = systemName(system) + local length = string.len(systemName) + + if systemIsDisabled then + length += 4 + end + table.insert(listOfSystems, { - text = nameOfSystem, - sideText = averageFrameTime, + text = if systemIsDisabled then `{systemName}` else systemName, + sideText = if systemIsDisabled then `{"(disabled)"}` else averageFrameTime, selected = debugger.debugSystem == system, system = system, icon = icon, - barWidth = duration / longestDuration, + barWidth = barWidth, index = index, }) end From 51a8c6a194ada1fd88cd3c112de4acfbf7135162 Mon Sep 17 00:00:00 2001 From: Nidoxs Date: Wed, 14 Aug 2024 23:27:56 +0100 Subject: [PATCH 05/12] Rework logic for debugSystem setting --- lib/debugger/ui.luau | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/debugger/ui.luau b/lib/debugger/ui.luau index 880bbec8..6906d8e6 100644 --- a/lib/debugger/ui.luau +++ b/lib/debugger/ui.luau @@ -36,6 +36,7 @@ local LONG_SYSTEM_NAME = 24 local function ui(debugger, loop) local plasma = debugger.plasma local custom = debugger._customWidgets + local skipSystems = loop._skipSystems plasma.setStyle({ primaryColor = Color3.fromHex("bd515c"), @@ -175,8 +176,9 @@ local function ui(debugger, loop) for _, eventName in debugger._eventOrder do local systems = loop._orderedSystemsByEvent[eventName] + local searchResultsForEvent = searchResults[eventName] - if not systems or searchResults[eventName] == nil then + if not systems or searchResultsForEvent == nil then continue end @@ -199,7 +201,7 @@ local function ui(debugger, loop) for index, system in systems do local nameOfSystem = systemName(system) - if searchResults[eventName][nameOfSystem] == nil then + if searchResultsForEvent[nameOfSystem] == nil then continue end @@ -225,7 +227,7 @@ local function ui(debugger, loop) barWidth = duration / longestDuration end - local systemIsDisabled = loop._skipSystems[system] + local systemIsDisabled = skipSystems[system] local systemName = systemName(system) local length = string.len(systemName) @@ -248,19 +250,18 @@ local function ui(debugger, loop) local selected = systemList:selected() local rightClicked = systemList:rightClicked() hoveredSystem = systemList:hovered() + if selected then - if selected.system == debugger.debugSystem then + local selectedSystem = selected.system + if selectedSystem == debugger.debugSystem then debugger.debugSystem = nil else - debugger.debugSystem = selected.system + debugger.debugSystem = selectedSystem end - elseif rightClicked and rightClicked.system then - local current = loop._skipSystems[rightClicked.system] - - if current == nil then - loop._skipSystems[rightClicked.system] = true - else - loop._skipSystems[rightClicked.system] = not current + elseif rightClicked then + local rightClickedSystem = rightClicked.system + if rightClickedSystem then + skipSystems[rightClickedSystem] = not skipSystems[rightClickedSystem] end end @@ -323,7 +324,7 @@ local function ui(debugger, loop) end end) - local currentlyDisabled = loop._skipSystems[debugger.debugSystem] + local currentlyDisabled = skipSystems[debugger.debugSystem] if plasma @@ -332,7 +333,7 @@ local function ui(debugger, loop) }) :clicked() then - loop._skipSystems[debugger.debugSystem] = not currentlyDisabled + skipSystems[debugger.debugSystem] = not currentlyDisabled end end) :closed() @@ -392,7 +393,7 @@ local function ui(debugger, loop) if hoveredSystem and hoveredSystem.system then local hoveredSystemName = systemName(hoveredSystem.system) local length = string.len(hoveredSystemName) - local systemDisabled = loop._skipSystems[hoveredSystem.system] + local systemDisabled = skipSystems[hoveredSystem.system] if systemDisabled then length += 2 From e740b09ab07cc244409f6a479fd927c5ecd1897c Mon Sep 17 00:00:00 2001 From: "Nidoxs (B.H)" Date: Thu, 15 Aug 2024 19:38:03 +0100 Subject: [PATCH 06/12] Update changelog for unmentioned changes (#108) --- CHANGELOG.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92e91eb4..e90ac37a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,29 @@ The format is based on [Keep a Changelog][kac], and this project adheres to ## [Unreleased] +### Added + +- Better assertions / error messages added to `World` methods that accept + variadic component arguments. At least 1 component must be provided. These + assertions have been added to `get` `insert` `replace` `remove` +- Ability to sort the world inspect table by clicking the table headers (entity + count and component name) + +### Changed + +- The alt-hover tooltip's text is smaller and the background is slightly darker + for improved legibility. +- Component data now has syntax highlighting applied. This is present in the + **alt-hover tooltip** and the **entity inspector panel** in the debugger. + +### Fixed + +- The alt-hover tooltip now displays component data properly, with each + component being displayed on a new line. +- Removed extra new-lines in component data strings within the debugger entity + inspect tables. +- Fixed alt-hover erroring when hovered entity is despawned. + ## [0.8.3] - 2024-07-02 ### Fixed From ec39decf3be5f4d506fe5fdc44220b06cb5cd39f Mon Sep 17 00:00:00 2001 From: Nidoxs Date: Wed, 14 Aug 2024 17:43:09 +0100 Subject: [PATCH 07/12] Allow disabling of systems by right clicking (+ refined tooltip) --- lib/debugger/clientBindings.luau | 41 +++++++++++---- lib/debugger/ui.luau | 59 ++++++++++++++++++--- lib/debugger/widgets/hoverInspect.luau | 5 +- lib/debugger/widgets/selectionList.luau | 68 +++++++++++++++++++++---- lib/debugger/widgets/tooltip.luau | 13 +++-- 5 files changed, 156 insertions(+), 30 deletions(-) diff --git a/lib/debugger/clientBindings.luau b/lib/debugger/clientBindings.luau index 405aed41..d5883971 100644 --- a/lib/debugger/clientBindings.luau +++ b/lib/debugger/clientBindings.luau @@ -1,5 +1,23 @@ local UserInputService = game:GetService("UserInputService") local CollectionService = game:GetService("CollectionService") + +local tags = { + system = "MatterDebuggerTooltip_System", + altHover = "MatterDebuggerTooltip_AltHover", +} + +local fromOffset = UDim2.fromOffset + +local function getOffset(mousePos: Vector2, tag: string): UDim2 + if tag == tags.altHover then + return fromOffset(mousePos.X + 20, mousePos.Y) + elseif tag == tags.system then + return fromOffset(mousePos.X + 20, mousePos.Y + 10) + end + + return fromOffset(mousePos.X, mousePos.Y + 10) +end + local function clientBindings(debugger) local connections = {} @@ -21,20 +39,23 @@ local function clientBindings(debugger) local mousePosition = UserInputService:GetMouseLocation() - for _, gui in CollectionService:GetTagged("MatterDebuggerTooltip") do - gui.Position = UDim2.new(0, mousePosition.X + 20, 0, mousePosition.Y) + for _, tag in tags do + for _, gui in CollectionService:GetTagged(tag) do + gui.Position = getOffset(mousePosition, tag) + end end end) ) - table.insert( - connections, - CollectionService:GetInstanceAddedSignal("MatterDebuggerTooltip"):Connect(function(gui) - local mousePosition = UserInputService:GetMouseLocation() - - gui.Position = UDim2.new(0, mousePosition.X + 20, 0, mousePosition.Y) - end) - ) + for _, tag in tags do + table.insert( + connections, + CollectionService:GetInstanceAddedSignal(tag):Connect(function(gui) + local mousePosition = UserInputService:GetMouseLocation() + gui.Position = getOffset(mousePosition, tag) + end) + ) + end return connections end diff --git a/lib/debugger/ui.luau b/lib/debugger/ui.luau index af4f968e..941921e1 100644 --- a/lib/debugger/ui.luau +++ b/lib/debugger/ui.luau @@ -29,6 +29,7 @@ end local IS_SERVER = RunService:IsServer() local IS_CLIENT = RunService:IsClient() +local LONG_SYSTEM_NAME = 24 local function ui(debugger, loop) local plasma = debugger.plasma @@ -48,6 +49,8 @@ local function ui(debugger, loop) end end + local hoveredSystem + custom.container(function() if debugger:_isServerView() then return @@ -141,7 +144,7 @@ local function ui(debugger, loop) }) plasma.space(5) - local items = {} + local listOfSystems = {} for _, system in systems do local samples = loop.profiling[system] @@ -168,24 +171,51 @@ local function ui(debugger, loop) icon = "\xf0\x9f\x92\xa5" end - table.insert(items, { - text = systemName(system), - sideText = averageFrameTime, + local barWidth + if longestDuration == 0 then + barWidth = 0 + else + barWidth = duration / longestDuration + end + + local systemIsDisabled = loop._skipSystems[system] + local systemName = systemName(system) + local length = string.len(systemName) + + if systemIsDisabled then + length += 4 + end + + table.insert(listOfSystems, { + text = if systemIsDisabled then `{systemName}` else systemName, + sideText = if systemIsDisabled then `{"(disabled)"}` else averageFrameTime, selected = debugger.debugSystem == system, system = system, icon = icon, - barWidth = duration / longestDuration, + barWidth = barWidth, index = index, }) end - local selected = custom.selectionList(items):selected() + local systemList = custom.selectionList(listOfSystems, custom) + local selected = systemList:selected() + local rightClicked = systemList:rightClicked() + hoveredSystem = systemList:hovered() + if selected then if selected.system == debugger.debugSystem then debugger.debugSystem = nil else debugger.debugSystem = selected.system end + elseif rightClicked and rightClicked.system then + local current = loop._skipSystems[rightClicked.system] + + if current == nil then + loop._skipSystems[rightClicked.system] = true + else + loop._skipSystems[rightClicked.system] = not current + end end if debugger.debugSystem then @@ -311,6 +341,23 @@ local function ui(debugger, loop) direction = Enum.FillDirection.Horizontal, padding = 0, }) + + if hoveredSystem and hoveredSystem.system then + local hoveredSystemName = systemName(hoveredSystem.system) + local length = string.len(hoveredSystemName) + local systemDisabled = loop._skipSystems[hoveredSystem.system] + + if systemDisabled then + length += 2 + end + + if length >= LONG_SYSTEM_NAME then + custom.tooltip(`{hoveredSystemName}{if systemDisabled then " (disabled)" else ""}`, { + tag = "MatterDebuggerTooltip_System", + backgroundTransparency = 0, + }) + end + end end return ui diff --git a/lib/debugger/widgets/hoverInspect.luau b/lib/debugger/widgets/hoverInspect.luau index d9b5daa3..c0c10d88 100644 --- a/lib/debugger/widgets/hoverInspect.luau +++ b/lib/debugger/widgets/hoverInspect.luau @@ -18,6 +18,9 @@ return function(plasma) end end - custom.tooltip(str) + custom.tooltip(str, { + tag = "MatterDebuggerTooltip_AltHover", + backgroundTransparency = 0.15, + }) end) end diff --git a/lib/debugger/widgets/selectionList.luau b/lib/debugger/widgets/selectionList.luau index 5842b00f..0ef7c057 100644 --- a/lib/debugger/widgets/selectionList.luau +++ b/lib/debugger/widgets/selectionList.luau @@ -1,13 +1,16 @@ return function(Plasma) local create = Plasma.create - local Item = Plasma.widget(function(text, selected, icon, sideText, _, barWidth, index) + local Item = Plasma.widget(function(text, selected, icon, sideText, barWidth, index) local clicked, setClicked = Plasma.useState(false) + local rightClicked, setRightClicked = Plasma.useState(false) + local hovered, setHovered = Plasma.useState(false) local style = Plasma.useStyle() local refs = Plasma.useInstance(function(ref) local button = create("TextButton", { [ref] = "button", + AutoButtonColor = false, Size = UDim2.new(1, 0, 0, 25), Text = "", @@ -62,6 +65,7 @@ return function(Plasma) BackgroundTransparency = 1, Size = UDim2.new(0, 0, 1, 0), Text = text, + RichText = true, TextXAlignment = Enum.TextXAlignment.Left, TextSize = 13, TextColor3 = style.textColor, @@ -81,6 +85,7 @@ return function(Plasma) Text = "", TextXAlignment = Enum.TextXAlignment.Left, TextSize = 11, + RichText = true, TextColor3 = style.mutedTextColor, Font = Enum.Font.Gotham, }), @@ -101,6 +106,20 @@ return function(Plasma) Activated = function() setClicked(true) end, + + MouseEnter = function() + setHovered(true) + end, + + MouseLeave = function() + setHovered(false) + end, + + InputBegan = function(input: InputObject) + if input.UserInputType == Enum.UserInputType.MouseButton2 then + setRightClicked(true) + end + end, }) return button @@ -120,8 +139,11 @@ return function(Plasma) refs.button.bar.Size = UDim2.new(barWidth or 0, 0, 0, 1) Plasma.useEffect(function() - refs.button.BackgroundColor3 = if selected then style.primaryColor else style.bg2 - end, selected) + refs.button.BackgroundColor3 = if selected + then style.primaryColor + elseif hovered then style.bg1 + else style.bg2 + end, selected, hovered) return { clicked = function() @@ -132,19 +154,29 @@ return function(Plasma) return false end, + rightClicked = function() + if rightClicked then + setRightClicked(false) + return true + end + + return false + end, + hovered = function() + return hovered + end, } end) - return Plasma.widget(function(items, options) - options = options or {} - + return Plasma.widget(function(items) Plasma.useInstance(function() local frame = create("Frame", { BackgroundTransparency = 1, - Size = options.width and UDim2.new(0, options.width, 0, 0) or UDim2.new(1, 0, 0, 0), + Size = UDim2.new(1, 0, 0, 0), create("UIListLayout", { SortOrder = Enum.SortOrder.LayoutOrder, + Padding = UDim.new(0, 2), }), }) @@ -156,19 +188,35 @@ return function(Plasma) end) local selected + local rightClicked + local hovered for _, item in items do - if - Item(item.text, item.selected, item.icon, item.sideText, options.width, item.barWidth, item.index):clicked() - then + local buttonInList = Item(item.text, item.selected, item.icon, item.sideText, item.barWidth, item.index) + + if buttonInList:clicked() then selected = item end + + if buttonInList:rightClicked() then + rightClicked = item + end + + if buttonInList:hovered() then + hovered = item + end end return { selected = function() return selected end, + rightClicked = function() + return rightClicked + end, + hovered = function() + return hovered + end, } end) end diff --git a/lib/debugger/widgets/tooltip.luau b/lib/debugger/widgets/tooltip.luau index a99f969a..499479df 100644 --- a/lib/debugger/widgets/tooltip.luau +++ b/lib/debugger/widgets/tooltip.luau @@ -1,8 +1,14 @@ local CollectionService = game:GetService("CollectionService") + +type Options = { + tag: string, + backgroundTransparency: number?, +} + return function(plasma) local create = plasma.create - return plasma.widget(function(text) + return plasma.widget(function(text, options: Options) local refs = plasma.useInstance(function(ref) local style = plasma.useStyle() @@ -16,9 +22,10 @@ return function(plasma) Font = Enum.Font.Code, TextStrokeTransparency = 0.5, TextColor3 = Color3.new(1, 1, 1), - BackgroundTransparency = 0.2, + BackgroundTransparency = options.backgroundTransparency or 0.2, BackgroundColor3 = style.bg1, AutomaticSize = Enum.AutomaticSize.XY, + ZIndex = 100, create("UIPadding", { PaddingBottom = UDim.new(0, 4), @@ -34,7 +41,7 @@ return function(plasma) }), }) - CollectionService:AddTag(ref.label, "MatterDebuggerTooltip") + CollectionService:AddTag(ref.label, options.tag) return ref.label end) From 67c3915e2bfea8857a9f5f9b5b769b961c959292 Mon Sep 17 00:00:00 2001 From: Nidoxs Date: Wed, 14 Aug 2024 18:18:56 +0100 Subject: [PATCH 08/12] Change color of system index label in system list --- lib/debugger/widgets/selectionList.luau | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/debugger/widgets/selectionList.luau b/lib/debugger/widgets/selectionList.luau index 0ef7c057..9d44a774 100644 --- a/lib/debugger/widgets/selectionList.luau +++ b/lib/debugger/widgets/selectionList.luau @@ -37,6 +37,7 @@ return function(Plasma) }), create("TextLabel", { + [ref] = "index", Name = "index", AutomaticSize = Enum.AutomaticSize.X, Size = UDim2.new(0, 0, 1, 0), @@ -61,6 +62,7 @@ return function(Plasma) }), create("TextLabel", { + [ref] = "mainText", AutomaticSize = Enum.AutomaticSize.X, BackgroundTransparency = 1, Size = UDim2.new(0, 0, 1, 0), @@ -103,8 +105,12 @@ return function(Plasma) ZIndex = 2, }), - Activated = function() - setClicked(true) + InputBegan = function(input: InputObject) + if input.UserInputType == Enum.UserInputType.MouseButton1 then + setClicked(true) + elseif input.UserInputType == Enum.UserInputType.MouseButton2 then + setRightClicked(true) + end end, MouseEnter = function() @@ -114,19 +120,13 @@ return function(Plasma) MouseLeave = function() setHovered(false) end, - - InputBegan = function(input: InputObject) - if input.UserInputType == Enum.UserInputType.MouseButton2 then - setRightClicked(true) - end - end, }) return button end) Plasma.useEffect(function() - refs.button.container.TextLabel.Text = text + refs.mainText.Text = text refs.button.container.Icon.Text = icon or "" refs.button.container.Icon.Visible = icon ~= nil end, text, icon) @@ -134,7 +134,7 @@ return function(Plasma) refs.button.container.sideText.Visible = sideText ~= nil refs.button.container.sideText.Text = if sideText ~= nil then sideText else "" refs.button.container.sideText.TextColor3 = if selected then style.textColor else style.mutedTextColor - refs.button.container.TextLabel.TextTruncate = sideText and Enum.TextTruncate.AtEnd or Enum.TextTruncate.None + refs.mainText.TextTruncate = sideText and Enum.TextTruncate.AtEnd or Enum.TextTruncate.None refs.button.bar.Size = UDim2.new(barWidth or 0, 0, 0, 1) @@ -143,6 +143,8 @@ return function(Plasma) then style.primaryColor elseif hovered then style.bg1 else style.bg2 + + refs.index.TextColor3 = if selected or hovered then style.textColor else style.mutedTextColor end, selected, hovered) return { From 8e99049a8a37aadea273c3a3412115a60c09e4d8 Mon Sep 17 00:00:00 2001 From: Nidoxs Date: Wed, 14 Aug 2024 21:31:04 +0100 Subject: [PATCH 09/12] Push search feature with changes to avoid tedious merge conflict --- lib/debugger/debugger.luau | 1 + lib/debugger/ui.luau | 164 +++++++++++++++++----------- lib/debugger/widgets/textField.luau | 81 ++++++++++++++ 3 files changed, 180 insertions(+), 66 deletions(-) create mode 100644 lib/debugger/widgets/textField.luau diff --git a/lib/debugger/debugger.luau b/lib/debugger/debugger.luau index bf5b410a..d4150192 100644 --- a/lib/debugger/debugger.luau +++ b/lib/debugger/debugger.luau @@ -25,6 +25,7 @@ local customWidgetConstructors: { [string]: any } = { queryInspect = require(script.Parent.widgets.queryInspect), codeText = require(script.Parent.widgets.codeText), errorInspect = require(script.Parent.widgets.errorInspect), + textField = require(script.Parent.widgets.textField), } local IS_SERVER = RunService:IsServer() diff --git a/lib/debugger/ui.luau b/lib/debugger/ui.luau index 941921e1..40dc2cc1 100644 --- a/lib/debugger/ui.luau +++ b/lib/debugger/ui.luau @@ -2,6 +2,8 @@ local RunService = game:GetService("RunService") local World = require(script.Parent.Parent.World) local rollingAverage = require(script.Parent.Parent.rollingAverage) +local match, lower = string.match, string.lower + local function systemName(system) local systemFn = if type(system) == "table" then system.system else system local name = debug.info(systemFn, "n") @@ -127,10 +129,19 @@ local function ui(debugger, loop) plasma.space(15) plasma.heading("SYSTEMS") + + local searchFilter = "" + if IS_CLIENT then + plasma.space(5) + local textField = custom.textField("Search...") + searchFilter = textField:text() + searchFilter = string.gsub(searchFilter, "%s+", "") + end + plasma.space(10) - local durations = {} - local longestDuration = 0 + local searchResults = {} + local noResults = true for _, eventName in debugger._eventOrder do local systems = loop._orderedSystemsByEvent[eventName] @@ -139,92 +150,113 @@ local function ui(debugger, loop) continue end - plasma.heading(eventName, { - font = Enum.Font.Gotham, - }) - plasma.space(5) + for _, system in systems do + local nameOfSystem = systemName(system) + local noMatch = searchFilter ~= "" and not match(lower(nameOfSystem), lower(searchFilter)) - local listOfSystems = {} + if noMatch then + continue + end - for _, system in systems do - local samples = loop.profiling[system] - if samples then - local duration = rollingAverage.getAverage(samples) - durations[system] = duration - longestDuration = math.max(longestDuration, duration) + if searchResults[eventName] == nil then + searchResults[eventName] = {} end + + searchResults[eventName][nameOfSystem] = true + noResults = false end + end - for index, system in systems do - local averageFrameTime = "" - local icon + if noResults then + plasma.label("No search results") + else + local durations = {} + local longestDuration = 0 - local duration = durations[system] or 0 - local humanDuration, unit = formatDuration(duration) - averageFrameTime = string.format("%.0f%s", humanDuration, unit) + for _, eventName in debugger._eventOrder do + local systems = loop._orderedSystemsByEvent[eventName] - if duration > 0.004 then -- 4ms - icon = "\xe2\x9a\xa0\xef\xb8\x8f" + if not systems or searchResults[eventName] == nil then + continue end - if loop._systemErrors[system] then - icon = "\xf0\x9f\x92\xa5" - end + plasma.heading(eventName, { + font = Enum.Font.Gotham, + }) + plasma.space(5) - local barWidth - if longestDuration == 0 then - barWidth = 0 - else - barWidth = duration / longestDuration + local listOfSystems = {} + + for _, system in systems do + local samples = loop.profiling[system] + if samples then + local duration = rollingAverage.getAverage(samples) + durations[system] = duration + longestDuration = math.max(longestDuration, duration) + end end - local systemIsDisabled = loop._skipSystems[system] - local systemName = systemName(system) - local length = string.len(systemName) + for index, system in systems do + local nameOfSystem = systemName(system) - if systemIsDisabled then - length += 4 - end + if searchResults[eventName][nameOfSystem] == nil then + continue + end - table.insert(listOfSystems, { - text = if systemIsDisabled then `{systemName}` else systemName, - sideText = if systemIsDisabled then `{"(disabled)"}` else averageFrameTime, - selected = debugger.debugSystem == system, - system = system, - icon = icon, - barWidth = barWidth, - index = index, - }) - end + local averageFrameTime = "" + local icon - local systemList = custom.selectionList(listOfSystems, custom) - local selected = systemList:selected() - local rightClicked = systemList:rightClicked() - hoveredSystem = systemList:hovered() + local duration = durations[system] or 0 + local humanDuration, unit = formatDuration(duration) + averageFrameTime = string.format("%.0f%s", humanDuration, unit) - if selected then - if selected.system == debugger.debugSystem then - debugger.debugSystem = nil - else - debugger.debugSystem = selected.system + if duration > 0.004 then -- 4ms + icon = "\xe2\x9a\xa0\xef\xb8\x8f" + end + + if loop._systemErrors[system] then + icon = "\xf0\x9f\x92\xa5" + end + + table.insert(listOfSystems, { + text = nameOfSystem, + sideText = averageFrameTime, + selected = debugger.debugSystem == system, + system = system, + icon = icon, + barWidth = duration / longestDuration, + index = index, + }) end - elseif rightClicked and rightClicked.system then - local current = loop._skipSystems[rightClicked.system] - if current == nil then - loop._skipSystems[rightClicked.system] = true + local systemList = custom.selectionList(listOfSystems, custom) + local selected = systemList:selected() + local rightClicked = systemList:rightClicked() + hoveredSystem = systemList:hovered() + if selected then + if selected.system == debugger.debugSystem then + debugger.debugSystem = nil + else + debugger.debugSystem = selected.system + end + elseif rightClicked and rightClicked.system then + local current = loop._skipSystems[rightClicked.system] + + if current == nil then + loop._skipSystems[rightClicked.system] = true + else + loop._skipSystems[rightClicked.system] = not current + end + end + + if debugger.debugSystem then + debugger.debugSystemRuntime = durations[debugger.debugSystem] else - loop._skipSystems[rightClicked.system] = not current + debugger.debugSystemRuntime = nil end - end - if debugger.debugSystem then - debugger.debugSystemRuntime = durations[debugger.debugSystem] - else - debugger.debugSystemRuntime = nil + plasma.space(10) end - - plasma.space(10) end end) diff --git a/lib/debugger/widgets/textField.luau b/lib/debugger/widgets/textField.luau new file mode 100644 index 00000000..4abc3954 --- /dev/null +++ b/lib/debugger/widgets/textField.luau @@ -0,0 +1,81 @@ +-- temporary TextField component unique to Matter's repository +-- for the client system search feature +-- this should be a native Plasma component eventually +return function(Plasma) + local create = Plasma.create + + return Plasma.widget(function(placeholder, options) + options = options or { editable = true } + local text, setText = Plasma.useState("") + local lastUpdate, setLastUpdate = Plasma.useState(os.clock()) + + local refs = Plasma.useInstance(function(ref) + local style = Plasma.useStyle() + + return create("Frame", { + Size = UDim2.new(1, 0, 0, 20), + BackgroundTransparency = 1, + + create("UIPadding", { + PaddingLeft = UDim.new(0, 1), + PaddingRight = UDim.new(0, 1), + PaddingTop = UDim.new(0, 0), + PaddingBottom = UDim.new(0, 0), + }), + + create("TextBox", { + [ref] = "textField", + AnchorPoint = Vector2.new(0, 0), + TextEditable = options.editable, + BackgroundTransparency = 0, + BackgroundColor3 = style.bg1, + Font = Enum.Font.Gotham, + TextXAlignment = Enum.TextXAlignment.Left, + TextColor3 = style.textColor, + TextSize = 12, + Size = UDim2.fromScale(1, 1), + PlaceholderText = placeholder, + Text = text, + RichText = true, + + create("UICorner", { + CornerRadius = UDim.new(0, 4), + }), + + create("UIStroke", { + Thickness = 1, + ApplyStrokeMode = Enum.ApplyStrokeMode.Border, + }), + + create("UIPadding", { + PaddingLeft = UDim.new(0, 8), + PaddingRight = UDim.new(0, 8), + PaddingTop = UDim.new(0, 4), + PaddingBottom = UDim.new(0, 4), + }), + + Changed = function(property: string) + if property == "Text" then + setLastUpdate(os.clock()) + end + end, + }), + }) + end) + + local instance = refs.textField + local shouldUpdate = (os.clock() - lastUpdate) > 0.15 + + -- let's cap text updates to every 0.15 seconds + if shouldUpdate then + setText(instance.Text) + setLastUpdate(os.clock()) + end + + return { + text = function() + return text + end, + } + end) +end From 369a98e2556fa4b8b0599e57d87192c7dc69c3b5 Mon Sep 17 00:00:00 2001 From: Nidoxs Date: Wed, 14 Aug 2024 21:42:05 +0100 Subject: [PATCH 10/12] Fix right click disablement (avoid merge conf) --- lib/debugger/ui.luau | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/debugger/ui.luau b/lib/debugger/ui.luau index 40dc2cc1..880bbec8 100644 --- a/lib/debugger/ui.luau +++ b/lib/debugger/ui.luau @@ -218,13 +218,28 @@ local function ui(debugger, loop) icon = "\xf0\x9f\x92\xa5" end + local barWidth + if longestDuration == 0 then + barWidth = 0 + else + barWidth = duration / longestDuration + end + + local systemIsDisabled = loop._skipSystems[system] + local systemName = systemName(system) + local length = string.len(systemName) + + if systemIsDisabled then + length += 4 + end + table.insert(listOfSystems, { - text = nameOfSystem, - sideText = averageFrameTime, + text = if systemIsDisabled then `{systemName}` else systemName, + sideText = if systemIsDisabled then `{"(disabled)"}` else averageFrameTime, selected = debugger.debugSystem == system, system = system, icon = icon, - barWidth = duration / longestDuration, + barWidth = barWidth, index = index, }) end From d45b329c5277089fca1a523aa772012f7e3516e4 Mon Sep 17 00:00:00 2001 From: Nidoxs Date: Wed, 14 Aug 2024 23:27:56 +0100 Subject: [PATCH 11/12] Rework logic for debugSystem setting --- lib/debugger/ui.luau | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/debugger/ui.luau b/lib/debugger/ui.luau index 880bbec8..6906d8e6 100644 --- a/lib/debugger/ui.luau +++ b/lib/debugger/ui.luau @@ -36,6 +36,7 @@ local LONG_SYSTEM_NAME = 24 local function ui(debugger, loop) local plasma = debugger.plasma local custom = debugger._customWidgets + local skipSystems = loop._skipSystems plasma.setStyle({ primaryColor = Color3.fromHex("bd515c"), @@ -175,8 +176,9 @@ local function ui(debugger, loop) for _, eventName in debugger._eventOrder do local systems = loop._orderedSystemsByEvent[eventName] + local searchResultsForEvent = searchResults[eventName] - if not systems or searchResults[eventName] == nil then + if not systems or searchResultsForEvent == nil then continue end @@ -199,7 +201,7 @@ local function ui(debugger, loop) for index, system in systems do local nameOfSystem = systemName(system) - if searchResults[eventName][nameOfSystem] == nil then + if searchResultsForEvent[nameOfSystem] == nil then continue end @@ -225,7 +227,7 @@ local function ui(debugger, loop) barWidth = duration / longestDuration end - local systemIsDisabled = loop._skipSystems[system] + local systemIsDisabled = skipSystems[system] local systemName = systemName(system) local length = string.len(systemName) @@ -248,19 +250,18 @@ local function ui(debugger, loop) local selected = systemList:selected() local rightClicked = systemList:rightClicked() hoveredSystem = systemList:hovered() + if selected then - if selected.system == debugger.debugSystem then + local selectedSystem = selected.system + if selectedSystem == debugger.debugSystem then debugger.debugSystem = nil else - debugger.debugSystem = selected.system + debugger.debugSystem = selectedSystem end - elseif rightClicked and rightClicked.system then - local current = loop._skipSystems[rightClicked.system] - - if current == nil then - loop._skipSystems[rightClicked.system] = true - else - loop._skipSystems[rightClicked.system] = not current + elseif rightClicked then + local rightClickedSystem = rightClicked.system + if rightClickedSystem then + skipSystems[rightClickedSystem] = not skipSystems[rightClickedSystem] end end @@ -323,7 +324,7 @@ local function ui(debugger, loop) end end) - local currentlyDisabled = loop._skipSystems[debugger.debugSystem] + local currentlyDisabled = skipSystems[debugger.debugSystem] if plasma @@ -332,7 +333,7 @@ local function ui(debugger, loop) }) :clicked() then - loop._skipSystems[debugger.debugSystem] = not currentlyDisabled + skipSystems[debugger.debugSystem] = not currentlyDisabled end end) :closed() @@ -392,7 +393,7 @@ local function ui(debugger, loop) if hoveredSystem and hoveredSystem.system then local hoveredSystemName = systemName(hoveredSystem.system) local length = string.len(hoveredSystemName) - local systemDisabled = loop._skipSystems[hoveredSystem.system] + local systemDisabled = skipSystems[hoveredSystem.system] if systemDisabled then length += 2 From 32194b88a522d56ed812934413703dfd8e906227 Mon Sep 17 00:00:00 2001 From: Nidoxs Date: Thu, 15 Aug 2024 19:41:16 +0100 Subject: [PATCH 12/12] Add to changelog (left a gap for another addition on a diff branch) --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e90ac37a..654e6f75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ The format is based on [Keep a Changelog][kac], and this project adheres to assertions have been added to `get` `insert` `replace` `remove` - Ability to sort the world inspect table by clicking the table headers (entity count and component name) + +- Ability to search through systems in the **client debugger** system list. + - This is not yet possible in the **server debugger**. ### Changed