Skip to content
This repository was archived by the owner on Aug 20, 2024. It is now read-only.

Commit 14d1757

Browse files
committed
Add unused code.
We'll use this later. I'm sure.
1 parent 6c4e2df commit 14d1757

File tree

3 files changed

+157
-0
lines changed

3 files changed

+157
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
local SignCollection = require(script.Parent.SignCollection)
2+
local HighlightSelection = require(script.Parent.HighlightSelection)
3+
local HighlightEditable = {}
4+
HighlightEditable.__index = HighlightEditable
5+
6+
-- Create a new highlight and set it to the selection.
7+
function HighlightEditable.highlight()
8+
local self = {}
9+
setmetatable(self, HighlightEditable)
10+
11+
HighlightSelection:setup()
12+
HighlightSelection:AddTable(SignCollection)
13+
14+
return self
15+
end
16+
17+
return HighlightEditable
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
local TweenService = game:GetService("TweenService")
2+
local Selection = game:GetService("Selection")
3+
4+
local selectColor = Color3.fromRGB(214, 129, 0)
5+
local hoverColor = Color3.fromRGB(255, 184, 0)
6+
local selectionColors = { selectColor, hoverColor }
7+
8+
local HighlightSelectionClass = {}
9+
HighlightSelectionClass.__index = HighlightSelectionClass
10+
11+
-- Create a new highlight and set it to the selection.
12+
function HighlightSelectionClass.setup(selection: Instance?)
13+
local self = {}
14+
setmetatable(self, HighlightSelectionClass)
15+
16+
local highlight = Instance.new("Highlight")
17+
highlight.Name = "HighlightSelection"
18+
highlight.FillTransparency = 1
19+
highlight.OutlineColor = selectionColors[1]
20+
-- highlight.Adornee = selection
21+
highlight.Parent = script
22+
self._highlight = highlight
23+
24+
self._selection = selection
25+
self._hover = false
26+
27+
self:SetHoverOver(true)
28+
self:SetEnabled(true)
29+
30+
self:_SetupSelectionHandling()
31+
32+
return self
33+
end
34+
35+
-- Detects if the selection is selected from Roblox Studio and changes the highlight color.
36+
function HighlightSelectionClass:_SetupSelectionHandling()
37+
Selection.SelectionChanged:Connect(function()
38+
local selected = Selection:Get()[1]
39+
40+
if selected == self._selection then
41+
self:SetHoverOver(true)
42+
else
43+
self:SetHoverOver(false)
44+
end
45+
end)
46+
end
47+
48+
-- Tweens the highlight color like in Roblox Studio depending on hover boolean.
49+
function HighlightSelectionClass:SetHoverOver(hover: boolean)
50+
self._hover = hover
51+
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, math.huge, true)
52+
53+
if self._hover == true then
54+
local tween = TweenService:Create(self._highlight, tweenInfo, { OutlineColor = selectionColors[2] })
55+
tween:Play()
56+
else
57+
self._highlight.OutlineColor = selectionColors[2]
58+
end
59+
end
60+
61+
-- Changes Enabled property of the Highlight based on the disabled boolean.
62+
function HighlightSelectionClass:SetEnabled(enabled: boolean)
63+
if enabled == true then
64+
self._highlight.Enabled = false
65+
else
66+
self._highlight.Enabled = true
67+
end
68+
end
69+
70+
-- Set highlight's parent to the new selection.
71+
function HighlightSelectionClass:Set(selection: Instance)
72+
self._highlight.Parent = selection
73+
end
74+
75+
-- Add instances to the selection.
76+
function HighlightSelectionClass:Add(instance: Instance)
77+
if self._highlight ~= nil then
78+
self._highlight.Adornee = instance
79+
end
80+
end
81+
82+
-- Add table to the selection.
83+
function HighlightSelectionClass:AddTable(table)
84+
for _, instance in ipairs(table) do
85+
self:Add(instance)
86+
end
87+
end
88+
89+
-- Returns selection of HighlightSelectionClass.
90+
function HighlightSelectionClass:GetSelection(): Instance?
91+
return self._selection
92+
end
93+
94+
-- Returns the highlight of HighlightSelectionClass.
95+
function HighlightSelectionClass:GetHighlight(): Highlight?
96+
return self._highlight
97+
end
98+
99+
return HighlightSelectionClass
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
local CollectionService = game:GetService("CollectionService")
2+
local Workspace = game:GetService("Workspace")
3+
4+
local tag = "_Sign" -- The tag you want to search for.
5+
local radius = 124 -- The radius of the circle around the center of the viewport.
6+
local minRadius = 32 -- The minimum radius of the circle around the center of the viewport.
7+
8+
local camera = Workspace.CurrentCamera
9+
local viewportSize = camera.ViewportSize
10+
local centerX = viewportSize.X / 2
11+
local centerY = viewportSize.Y / 2
12+
13+
local taggedInstances = CollectionService:GetTagged(tag) -- Get all instances with the tag.
14+
local filteredInstances = {} -- Tabe made of filteredInstances that isInRadius of camera.
15+
16+
-- Loop through each instance in taggedInstances and check if it is within radius of camera.
17+
for _, instance in ipairs(taggedInstances) do -- Loop through each instance.
18+
local position = instance.Position -- Get instance position.
19+
local isInRadius = false -- Flag to check if instance is within radius.
20+
21+
for angle = 0, 360, 10 do -- Loop through angles from 0 to 360 degrees with 10 degree increments.
22+
local x = centerX + math.cos(math.rad(angle)) * radius -- Calculate x coordinate on circle.
23+
local y = centerY + math.sin(math.rad(angle)) * radius -- Calculate y coordinate on circle.
24+
25+
local ray = camera:ViewportPointToRay(x, y) -- Get ray from camera through point on circle.
26+
local closestPoint = ray:ClosestPoint(position) -- Get closest point on ray to instance position.
27+
28+
local distance = (position - closestPoint).Magnitude -- Get distance between points.
29+
30+
if distance < minRadius then -- If distance is less than minRadius.
31+
isInRadius = true -- Set flag to true.
32+
break -- Break out of angle loop.
33+
end
34+
end
35+
36+
if isInRadius then -- If instance isInRadius then
37+
table.insert(filteredInstances, instance) -- Add instance to filteredInstances.
38+
end
39+
end
40+
41+
return filteredInstances

0 commit comments

Comments
 (0)