Skip to content
This repository was archived by the owner on Jul 13, 2025. It is now read-only.

Commit f9d7176

Browse files
authored
Always on top display fixes (#72)
Closes #19 Since SelectionBox does not have AlwaysOnTop property I had to create custom one with BoxHandle and CylinderHandles with this pr, all modes including `Outline` and `Box` have working AlwaysOnTop setting ![image](https://user-images.githubusercontent.com/34089907/184451387-dde6a538-5ffb-40aa-b7af-3b36de617ed4.png)
1 parent 4496ab1 commit f9d7176

File tree

3 files changed

+96
-17
lines changed

3 files changed

+96
-17
lines changed
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
local Modules = script.Parent.Parent.Parent.Parent
22
local Roact = require(Modules.Roact)
3+
local Util = require(Modules.Plugin.Util)
34

45
local function BoxAdorn(props)
5-
if props.Adornee.ClassName == "Attachment" then
6-
return Roact.createElement("BoxHandleAdornment", {
7-
Adornee = props.Adornee.Parent,
8-
CFrame = props.Adornee.CFrame,
9-
Size = Vector3.new(1.2, 1.2, 1.2),
10-
Transparency = 0.3,
6+
local children = {}
7+
if props.AlwaysOnTop then
8+
children = Util.GenerateOutline({
9+
Size = if props.Adornee.ClassName == "Attachment"
10+
then props.Adornee.Parent.Size
11+
elseif props.Adornee.ClassName == "Model" then props.Adornee:GetExtentsSize()
12+
else props.Adornee.Size,
13+
Adornee = if props.Adornee.ClassName == "Attachment" then props.Adornee.Parent else props.Adornee,
1114
Color3 = props.Color,
15+
Box = true,
1216
})
1317
end
1418
return Roact.createElement("SelectionBox", {
1519
LineThickness = 0.03,
1620
SurfaceTransparency = 0.7,
1721
SurfaceColor3 = props.Color,
18-
Adornee = props.Adornee,
22+
Adornee = if props.Adornee.ClassName == "Attachment" then props.Adornee.Parent else props.Adornee,
1923
Color3 = props.Color,
20-
})
24+
Visible = not props.AlwaysOnTop,
25+
}, children)
2126
end
2227

2328
return BoxAdorn
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
local Modules = script.Parent.Parent.Parent.Parent
22
local Roact = require(Modules.Roact)
3+
local Util = require(Modules.Plugin.Util)
34

45
local function OutlineAdorn(props)
5-
if props.Adornee.ClassName == "Attachment" then
6-
return Roact.createElement("BoxHandleAdornment", {
7-
Adornee = props.Adornee.Parent,
8-
CFrame = props.Adornee.CFrame,
9-
Size = Vector3.new(1.5, 1.5, 1.5),
10-
Transparency = 0.3,
6+
local children = {}
7+
if props.AlwaysOnTop then
8+
children = Util.GenerateOutline({
9+
Size = if props.Adornee.ClassName == "Attachment"
10+
then props.Adornee.Parent.Size
11+
elseif props.Adornee.ClassName == "Model" then props.Adornee:GetExtentsSize()
12+
else props.Adornee.Size,
13+
Adornee = if props.Adornee.ClassName == "Attachment" then props.Adornee.Parent else props.Adornee,
1114
Color3 = props.Color,
1215
})
1316
end
1417
return Roact.createElement("SelectionBox", {
15-
LineThickness = 0.05,
16-
Adornee = props.Adornee,
18+
LineThickness = 0.03,
19+
Adornee = if props.Adornee.ClassName == "Attachment" then props.Adornee.Parent else props.Adornee,
1720
Color3 = props.Color,
18-
})
21+
Visible = not props.AlwaysOnTop,
22+
}, children)
1923
end
2024

2125
return OutlineAdorn

src/Util.lua

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,78 @@ local function merge(...)
113113
return map
114114
end
115115

116+
local function GenerateOutline(props)
117+
local OutlineVertices = {
118+
{ 1, 1, -1 },
119+
{ -1, 1, -1 },
120+
{ -1, 1, -1 },
121+
{ -1, 1, 1 },
122+
{ -1, 1, 1 },
123+
{ 1, 1, 1 },
124+
{ 1, 1, 1 },
125+
{ 1, 1, -1 },
126+
{ 1, -1, -1 },
127+
{ -1, -1, -1 },
128+
{ -1, -1, -1 },
129+
{ -1, -1, 1 },
130+
{ -1, -1, 1 },
131+
{ 1, -1, 1 },
132+
{ 1, -1, 1 },
133+
{ 1, -1, -1 },
134+
{ 1, 1, -1 },
135+
{ 1, -1, -1 },
136+
{ -1, -1, -1 },
137+
{ -1, 1, -1 },
138+
{ 1, 1, 1 },
139+
{ 1, -1, 1 },
140+
{ -1, -1, 1 },
141+
{ -1, 1, 1 },
142+
}
143+
local Corners = {}
144+
for _, Vector in OutlineVertices do
145+
table.insert(
146+
Corners,
147+
(CFrame.new(props.Size.X / 2 * Vector[1], props.Size.Y / 2 * Vector[2], props.Size.Z / 2 * Vector[3])).Position
148+
)
149+
end
150+
local Instances = {}
151+
for i, _ in Corners do
152+
if i % 2 == 0 then
153+
continue
154+
end
155+
local displacement = Corners[i] - Corners[i + 1]
156+
table.insert(
157+
Instances,
158+
Roact.createElement("CylinderHandleAdornment", {
159+
Color3 = props.Color3,
160+
Adornee = props.Adornee,
161+
AlwaysOnTop = true,
162+
Height = displacement.Magnitude,
163+
CFrame = CFrame.lookAt(Corners[i], Corners[i + 1]) * CFrame.new(0, 0, -displacement.Magnitude / 2),
164+
Radius = 0.033,
165+
ZIndex = 0,
166+
})
167+
)
168+
end
169+
if props.Box then
170+
table.insert(
171+
Instances,
172+
Roact.createElement("BoxHandleAdornment", {
173+
Color3 = props.Color3,
174+
Transparency = 0.7,
175+
Adornee = props.Adornee,
176+
AlwaysOnTop = true,
177+
Size = props.Size,
178+
ZIndex = 0,
179+
})
180+
)
181+
end
182+
return Instances
183+
end
184+
116185
return {
117186
findIf = findIf,
118187
escapeTagName = escapeTagName,
119188
merge = merge,
189+
GenerateOutline = GenerateOutline,
120190
}

0 commit comments

Comments
 (0)