Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --@author LightningLion58
- --Services:
- local UserInputService = game:GetService("UserInputService")
- local Studio = settings().Studio
- local Selection = game:GetService("Selection")
- local ChangeHistoryService = game:GetService("ChangeHistoryService")
- local Terrain = workspace:WaitForChild("Terrain")
- --Variables:
- --Initiate the UI:
- local mouse : PluginMouse = plugin:GetMouse()
- local toolbar : PluginToolbar = plugin:CreateToolbar("Extra Terrain Tools")
- local toggleMenuBtn : PluginToolbarButton= toolbar:CreateButton("Open/Close Terrain Tools", "Click this button to open the terrain tools window.", "rbxasset://textures/TerrainTools/icon_terrain_big.png")
- toggleMenuBtn.ClickableWhenViewportHidden = false
- local widgetInfo = DockWidgetPluginGuiInfo.new(
- Enum.InitialDockState.Left,
- false,
- false,
- 400, --default:
- 400,
- 350, --minimum
- 350
- )
- local GUI : DockWidgetPluginGui = plugin:CreateDockWidgetPluginGui("TerrainToolsUI", widgetInfo)
- GUI.Title = "Extra Terrain Tools"
- local frame = script.Parent:WaitForChild("TerrainEditorFrame")
- local Tools = frame:WaitForChild("Tools")
- local SelectRegionButton = Tools:WaitForChild("SelectRegionButton")
- local Instruction = frame:WaitForChild("Instruction")
- local CheckBox = frame.PasteAirCheckBox.CheckBox
- local function correctColors() --Correctly set the colors of the UI to match the studio theme
- frame.BackgroundColor3 = Studio.Theme:GetColor(Enum.StudioStyleGuideColor.MainBackground, Enum.StudioStyleGuideModifier.Default)
- local isDark = Studio.Theme.Name == "Dark"
- for _, frame in pairs(Tools:GetChildren()) do
- if(frame:IsA("Frame")) then
- frame.Title.TextColor3 = Studio.Theme:GetColor(Enum.StudioStyleGuideColor.MainText, Enum.StudioStyleGuideModifier.Default)
- if(isDark) then
- frame.Activation.BackgroundColor3 = Color3.fromRGB(0,0,0)
- else
- frame.Activation.BackgroundColor3 = Color3.fromRGB(255,255,255)
- end
- end
- end
- if(isDark) then
- CheckBox.BackgroundColor3 = Color3.fromRGB(38, 38, 38)
- else
- CheckBox.BackgroundColor3 = Color3.fromRGB(184, 184, 184)
- end
- CheckBox.Parent.Title.TextColor3 = Studio.Theme:GetColor(Enum.StudioStyleGuideColor.MainText, Enum.StudioStyleGuideModifier.Default)
- Instruction.TextColor3 = Studio.Theme:GetColor(Enum.StudioStyleGuideColor.MainText, Enum.StudioStyleGuideModifier.Default)
- end
- correctColors()
- Studio.ThemeChanged:Connect(correctColors) --Update the colors if the studio theme changes
- CheckBox.Activated:Connect(function() --Toggle the paste-air checkbox
- if(CheckBox.Text == "") then
- CheckBox.Text = "✓"
- else
- CheckBox.Text = ""
- end
- end)
- frame.Parent = GUI
- --Main Code: (Handles the terrain tools)
- --[[
- Three modes:
- selecting - when the user is selecting a region
- pasting - when the user is selecting where to paste the region
- changing - when the user is editing the size/position of the region selection box using the **handles**, not the studio tools.
- ]]
- local selecting = false
- local pasting = false
- local changing = false
- local currentRegion --The current region instance that has been copied.
- --[[
- The Region Selection uses 3 main instances:
- selectionBox - The selection box that you can scale and move to select the terrain region.
- highlight - Only used for decoration
- handles - The handles that you can use to resize and move the selection box
- ]]
- local selectionBox
- local handles
- local function newSelectionBox()
- selectionBox = Instance.new("Part")
- selectionBox.Size = Vector3.new(2,2,2)
- selectionBox.Locked = true
- selectionBox.Name = "TerrainToolsSelectionBox"
- selectionBox.Transparency = 0.95
- selectionBox.Color = Color3.fromRGB(0, 170, 255)
- selectionBox.TopSurface = Enum.SurfaceType.Smooth
- selectionBox.BottomSurface = Enum.SurfaceType.Smooth
- --[[
- roundToTop gets a number (n), and rounds it to the closest integer. If there's a decimal of 0.5, it will round it up.
- If size is true, it will make sure that the number is at least 1.
- ]]
- local function roundToTop(n : number, size : boolean?)
- n = math.round(n)
- if(size and n < 1) then
- return 1
- end
- if(n % 1 == 0.5) then
- return n + 0.5
- else
- return n
- end
- end
- --The code below makes sure the user doesn't break the plugin by using the studio tools on the selection box, or by deleting the selectionBox
- selectionBox:GetPropertyChangedSignal("Position"):Connect(function()
- if(not changing) then
- local x,y,z = selectionBox.Position.X, selectionBox.Position.Y, selectionBox.Position.Z
- selectionBox.Position = Vector3.new(roundToTop(x), roundToTop(y), roundToTop(z)) --Round the position, terrain CopyRegion gets an integer-based Vector3.
- end
- end)
- selectionBox:GetPropertyChangedSignal("Size"):Connect(function()
- if(not changing) then
- local x,y,z = selectionBox.Size.X, selectionBox.Size.Y, selectionBox.Size.Z
- selectionBox.Size = Vector3.new(roundToTop(x, true), roundToTop(y,true ), roundToTop(z,true ))
- end
- end)
- selectionBox:GetPropertyChangedSignal("Locked"):Connect(function() --Do not allow the selection box to be unlocked.
- --The reason for that is that using the studio tools on the box can break the selection box, or cause inaccurate selections.
- if(not selectionBox.Locked) then
- selectionBox.Locked = true
- end
- end)
- selectionBox:GetPropertyChangedSignal("Orientation"):Connect(function() --Do not allow the user to use the rotate tool, otherwise the wrong corner will be selected, thus the wrong region will be copied.
- selectionBox.Orientation = Vector3.zero
- end)
- selectionBox.AncestryChanged:Connect(function() --If the user destroys the selection box, toggle off the handles.
- if(not selectionBox:IsDescendantOf(game)) then
- handles.Visible = false
- handles.Adornee = nil
- else
- if(not selectionBox:IsDescendantOf(workspace)) then --If the try to move it elsewhere, put it back into the workspace.
- selectionBox.Parent = workspace
- end
- end
- end)
- end
- newSelectionBox()
- local highlight
- function onHighlightDestroy()
- if(highlight.Parent ~= selectionBox) then
- newHightlight()
- highlight.AncestryChanged:Connect(onHighlightDestroy)
- end
- end
- function newHightlight()
- highlight = Instance.new("SelectionBox")
- highlight.LineThickness = 0.1
- highlight.Color3 = Color3.fromRGB(0, 170, 255)
- highlight.Visible = true
- highlight.Adornee = selectionBox
- highlight.Parent = selectionBox
- highlight.AncestryChanged:Connect(onHighlightDestroy)
- end
- newHightlight()
- handles = Instance.new("Handles")
- handles.Name = "TerrainToolsHandles"
- handles.Style = Enum.HandlesStyle.Movement
- handles.Adornee = selectionBox
- handles.Visible = false
- handles.Color3 = Color3.fromRGB(0, 170, 255)
- handles.Parent = game:GetService("CoreGui")
- --The two functions below are used to allow the user to undo/redo an action they've performed.
- local lastRecordingActive = nil
- local function beginRecording(name)
- if(lastRecordingActive) then
- ChangeHistoryService:FinishRecording(lastRecordingActive, Enum.FinishRecordingOperation.Commit)
- end
- lastRecordingActive = ChangeHistoryService:TryBeginRecording(name)
- if(not lastRecordingActive) then
- error("Extra Terrain Tools - A plugin action has begun but was never finished")
- end
- end
- local function finishRecording()
- if(lastRecordingActive) then
- ChangeHistoryService:FinishRecording(lastRecordingActive, Enum.FinishRecordingOperation.Commit)
- lastRecordingActive = nil
- end
- end
- ChangeHistoryService.OnUndo:Connect(function(name)
- if(name == "Begin Selecting") then
- selecting = false
- SelectRegionButton.Title.Text = "Select Region"
- SelectRegionButton.Activation.Selecting.Enabled = true
- SelectRegionButton.Activation.NotSelecting.Enabled = false
- end
- if(selectionBox == nil) then
- newSelectionBox()
- end
- end)
- --Below is the code that allows the handles to resize and move the selection box:
- local function getSizeFromNormalId(normalId : Enum.NormalId) --Returns the size of the part on the axis based on the normalId. (e.g. Top/Bottom - Y axis...)
- return (selectionBox.Size * Vector3.FromNormalId(normalId):Abs()).Magnitude
- end
- --[[
- getPositionAndSize returns the new size and position of the selection box,
- based on the face that was clicked on and how far the handles were dragged.
- keepInSamePosition - If the player presses left-shift to keep the same position, this will return the same position.
- ]]
- local function getPositionAndSize(face, delta, keepInSamePosition)
- local addition = Vector3.FromNormalId(face)
- local moveAddition = addition/2
- addition = addition:Abs()
- addition *= math.round(delta)
- moveAddition *= math.round(delta)
- return (selectionBox.Size + addition), if keepInSamePosition then selectionBox.Position else selectionBox.Position + moveAddition
- end
- local lastDistance = 0 --This will be used to calculate how far the handles were dragged from the last time they were dragged.
- --Handling mouse events for the handles:
- handles.MouseButton1Down:Connect(function()
- beginRecording("Selection Box Resized")
- lastDistance = 0 --Reset the lastDistance, since the user is beginning a new drag.
- changing = true --User has begun editing the selection box using the handles.
- end)
- handles.MouseButton1Up:Connect(function()
- changing = false
- finishRecording()
- end)
- handles.MouseDrag:Connect(function(face, distance) --When the handles are dragged:
- local delta = distance - lastDistance --Calculate how far the were dragged
- if(math.abs(delta) >= 1) then --Make sure they were dragged at least one stud
- if(handles.Style == Enum.HandlesStyle.Resize) then --If the handles are set to Resize mode:
- if(math.round(delta) % 1 == 0.5) then --Make sure math.round will round 0.5 to 1, we don't want any .5's in the size.
- delta += 0.5
- end
- if(getSizeFromNormalId(face) + math.round(delta) < 1) then --Make sure the size of the face's axis will not be resized to less than 1 stud.
- return
- end
- --Get the new size and position, and keep the selection box in the same position if the user is pressing LeftShift:
- local size, position = getPositionAndSize(face, delta, UserInputService:IsKeyDown(Enum.KeyCode.LeftShift))
- selectionBox.Position = position
- selectionBox.Size = size
- else
- --Move the part along the face's axis by the distance dragged
- selectionBox.Position += Vector3.FromNormalId(face) * math.round(delta)
- end
- lastDistance = distance
- end
- end)
- --The code below handles the selection, deselection, copy-pasting and insert region instance.
- local thread
- local pastingThread
- local selectionPlacementConn : RBXScriptConnection?
- local pastingConnection : RBXScriptConnection?
- local function deselect() --Deselect without changing any text
- selecting = false
- selectionBox.Parent = nil
- if(selectionPlacementConn) then
- selectionPlacementConn:Disconnect()
- coroutine.close(thread)
- end
- handles.Adornee = nil
- handles.Visible = false
- end
- local function deselectRegion() --Handles the actual deselection, and the UI text changes.
- deselect()
- Instruction.Text = ""
- SelectRegionButton.Title.Text = "Select Region"
- SelectRegionButton.Activation.Selecting.Enabled = true
- SelectRegionButton.Activation.NotSelecting.Enabled = false
- if(pasting) then
- Tools.PasteRegionButton.Title.Text = "Paste Region"
- Tools.PasteRegionButton.Title2.Text = ""
- if(pastingConnection) then
- pastingConnection:Disconnect()
- end
- Instruction.Text = ""
- pasting = false
- coroutine.close(pastingThread)
- end
- end
- local function selectRegion(pastingRegion : TerrainRegion?) --Prompts the user to select a region (to copy or to paste)
- pasting = pastingRegion ~= nil
- --Update the text.
- Instruction.Text = "Click on the region you'd like to select"
- selecting = true --Update the mode variable.
- thread = coroutine.running()
- selectionPlacementConn = UserInputService.InputEnded:Connect(function(input, process)
- if(not process and input.UserInputType == Enum.UserInputType.MouseButton1) then
- coroutine.resume(thread) --Resume the thread only when the user presses left mouse click on the viewport.
- end
- end)
- SelectRegionButton.Title.Text = "Selecting..."
- coroutine.yield() --Yield the thread (will be resumed when click the left mouse button)
- if(mouse.Target) then --If the user is not selecting the sky.
- --Change the text according to the mode:
- beginRecording("Begin Selecting")
- if(not pasting) then
- Instruction.Text = "Press R to switch mode (Move, Scale)"
- else
- Instruction.Text = "Move the orange box to where you'd like to paste your region."
- end
- changing = true --About to change the position and size without the studio tools, so change the mode to true:
- selectionBox.Position = mouse.Hit.Position:Floor() --Round down the position.
- --Settings and colour based on the mode (copy/paste)
- if(pastingRegion) then
- selectionBox.Color = Color3.fromRGB(255, 170, 0)
- highlight.Color3 = Color3.fromRGB(255, 85, 0)
- handles.Color3 = Color3.fromRGB(255, 85, 0)
- selectionBox.Size = pastingRegion.SizeInCells*4
- handles.Style = Enum.HandlesStyle.Movement
- else
- selectionBox.Size = Vector3.new(2,2,2)
- selectionBox.Color = Color3.fromRGB(0, 170, 255)
- handles.Color3 = Color3.fromRGB(0, 170, 255)
- highlight.Color3 = Color3.fromRGB(0, 170, 255)
- end
- changing = false
- handles.Adornee = selectionBox
- selectionBox.Locked = true
- handles.Visible = true
- selectionBox.Parent = workspace
- --Changes the UI Text:
- finishRecording()
- SelectRegionButton.Title.Text = "Deselect Region"
- SelectRegionButton.Activation.Selecting.Enabled = false
- SelectRegionButton.Activation.NotSelecting.Enabled = true
- else
- --Changes the UI Text:
- Instruction.Text = ""
- SelectRegionButton.Title.Text = "Select Region"
- SelectRegionButton.Activation.Selecting.Enabled = true
- SelectRegionButton.Activation.NotSelecting.Enabled = false
- end
- end
- --Handles pasting a region:
- local function pasteRegion(region)
- if(selecting) then
- SelectRegionButton.Activation.Selecting.Enabled = true
- deselect()
- end
- Tools.PasteRegionButton.Title.Text = "Confirm (Left Click)"
- Tools.PasteRegionButton.Title2.Text = "Cancel (Right Click)"
- pastingThread = coroutine.running()
- coroutine.wrap(function() --Select a region (In a new thread, to allow the user to press the paste button with left/right mouse buttons.)
- selectRegion(region)
- end)()
- pastingConnection = Tools.PasteRegionButton.Activation.InputEnded:Connect(function(input) --When the user presses the button:
- if(input.UserInputType == Enum.UserInputType.MouseButton1) then --If the press was using the left mouse button:
- coroutine.resume(pastingThread) --Continue the pasting thread (see above)
- if pastingConnection then
- pastingConnection:Disconnect() --Stop listening for input on the button.
- end
- elseif(input.UserInputType == Enum.UserInputType.MouseButton2) then
- deselectRegion() --Cancel the selection and pasting.
- end
- end)
- coroutine.yield() --Yield until the user presses the left mouse button (or the right button, but then the coroutine will be closed)
- local minCorner = ((selectionBox.Position - selectionBox.Size/2)/4) --Calculate the minCorner (in cells, not studs)
- minCorner = Vector3int16.new(minCorner.X, minCorner.Y, minCorner.Z) --Convert it to an int16 Vector3
- beginRecording("Region Paste")
- Terrain:PasteRegion(region, minCorner, CheckBox.Text ~= "") --Paste the region, and also paste the air if the checkbox is selected.
- deselectRegion() --Finish the selection process.
- finishRecording()
- end
- local function getCorners(isInt16 : boolean?, isInCells : boolean?)
- local cornerMin = (selectionBox.Position - (selectionBox.Size/2):Floor())
- local cornerMax = (selectionBox.Position + (selectionBox.Size/2):Floor())
- if(isInCells) then
- cornerMin /= 4
- cornerMax /= 4
- end
- if(isInt16) then
- cornerMin = Vector3int16.new(cornerMin.X, cornerMin.Y, cornerMin.Z)
- cornerMax = Vector3int16.new(cornerMax.X, cornerMax.Y, cornerMax.Z)
- else
- cornerMin = Vector3.new(cornerMin.X, cornerMin.Y, cornerMin.Z)
- cornerMax = Vector3.new(cornerMax.X, cornerMax.Y, cornerMax.Z)
- end
- return cornerMin, cornerMax
- end
- -- Helper function to truncate a 3D array
- local function truncateArray(array, newSize: Vector3)
- local result = {}
- for x = 1, math.min(array.Size.X, newSize.X) do
- result[x] = {}
- for y = 1, math.min(array.Size.Y, newSize.Y) do
- result[x][y] = {}
- for z = 1, math.min(array.Size.Z, newSize.Z) do
- result[x][y][z] = array[x][y][z]
- end
- end
- end
- result.Size = Vector3.new(
- math.min(array.Size.X, newSize.X),
- math.min(array.Size.Y, newSize.Y),
- math.min(array.Size.Z, newSize.Z)
- )
- return result
- end
- --Shrink a Region3 to match a given size in voxel units
- local function shrinkRegion3ToFitArray(region: Region3, arraySize: Vector3, resolution: number): Region3
- local origin = region.CFrame.Position - (region.Size / 2)
- local newSize = Vector3.new(
- arraySize.X * resolution,
- arraySize.Y * resolution,
- arraySize.Z * resolution
- )
- local newCFrame = CFrame.new(origin + newSize / 2)
- return Region3.new(newCFrame.Position - newSize / 2, newCFrame.Position + newSize / 2)
- end
- --Adjust array and Region3
- local function fitArrayToRegion3(array, region : Region3, resolution : number)
- local arraySize = array.Size
- local regionSize = region.Size
- --Compute how many voxels fit in the Region3
- local regionVoxelSize = Vector3.new(
- math.floor(regionSize.X / resolution),
- math.floor(regionSize.Y / resolution),
- math.floor(regionSize.Z / resolution)
- )
- --Determine new voxel size that fits both
- local finalVoxelSize = Vector3.new(
- math.min(regionVoxelSize.X, arraySize.X),
- math.min(regionVoxelSize.Y, arraySize.Y),
- math.min(regionVoxelSize.Z, arraySize.Z)
- )
- --Truncate array to match final voxel size
- local truncatedArray = truncateArray(array, finalVoxelSize)
- --Shrink Region3 to match array size in world units
- local adjustedRegion = shrinkRegion3ToFitArray(region, truncatedArray.Size, resolution)
- return truncatedArray, adjustedRegion
- end
- local function rotateSelection(direction : number)
- local region = Region3.new(selectionBox.Position - selectionBox.Size/2, selectionBox.Position + selectionBox.Size/2):ExpandToGrid(4)
- selectionBox.Size = Vector3.new(selectionBox.Size.Z, selectionBox.Size.Y, selectionBox.Size.X)
- --Read current voxels:
- local materials, occupancies = Terrain:ReadVoxels(region, 4)
- local newSize = Vector3.new(occupancies.Size.Z, occupancies.Size.Y, occupancies.Size.X)
- local newMaterials, newOccupancies = {Size = newSize}, {Size = newSize}
- --Perform the rotation:
- for x = 1, occupancies.Size.Z, 1 do
- local newXIndex
- if(direction == 1) then
- newXIndex = occupancies.Size.Z - x + 1
- else
- newXIndex = x
- end
- newOccupancies[newXIndex] = {}
- newMaterials[newXIndex] = {}
- for y = 1, occupancies.Size.Y, 1 do
- newOccupancies[newXIndex][y] = {}
- newMaterials[newXIndex][y] = {}
- for z = occupancies.Size.X, 1, -1 do
- local newZIndex
- if(direction == 1) then
- newZIndex = z
- else
- newZIndex = occupancies.Size.X - z + 1
- end
- --Perform rotation on the 3D array along the Y axis:
- newOccupancies[newXIndex][y][newZIndex] = occupancies[occupancies.Size.X - z + 1][y][occupancies.Size.Z - x + 1]
- newMaterials[newXIndex][y][newZIndex] = materials[occupancies.Size.X - z + 1][y][occupancies.Size.Z - x + 1]
- end
- end
- end
- --Write the new voxels:
- local newRegion = Region3.new(selectionBox.Position - selectionBox.Size/2, selectionBox.Position + selectionBox.Size/2):ExpandToGrid(4)
- newOccupancies, newRegion = fitArrayToRegion3(newOccupancies, newRegion, 4)
- newMaterials, newRegion = fitArrayToRegion3(newMaterials, newRegion, 4)
- Terrain:WriteVoxels(newRegion, 4, newMaterials, newOccupancies)
- end
- --Below is the code the connects the tool button presses to their matching functions:
- local buttonFunctions = {
- ["SelectRegionButton"] = function() --This activates when the user presses the SelectRegionButton.
- if(selecting) then --If the user is already selecting, then deselect.
- deselectRegion()
- else --Otherwise, select.
- selectRegion()
- end
- end,
- ["CopyRegionButton"] = function()--This activates when the user presses the CopyRegionButton.
- local selected = Selection:Get()[1] --Gets their first selection and checks if it's a terrain region:
- if(selected and selected:IsA("TerrainRegion")) then
- --If it is and the user pressed copy, save it as the current region copied.
- currentRegion = selected:Clone()
- return
- end
- if(selecting) then --If they are selecting, then copy the selection:
- local cornerMin, cornerMax = getCorners(true, true)
- currentRegion = Terrain:CopyRegion(Region3int16.new(cornerMin, cornerMax))
- Tools.CopyRegionButton.Title.Text = "Copied!"
- task.wait(0.5)
- Tools.CopyRegionButton.Title.Text = "Copy Selection"
- else --If they have nothing selected, then tell them they need to select something:
- Tools.CopyRegionButton.Title.Text = "Nothing Selected!"
- task.wait(0.5)
- Tools.CopyRegionButton.Title.Text = "Copy Selection"
- end
- end,
- ["PasteRegionButton"] = function() --This activates when the user presses the PasteRegionButton.
- if(pasting) then --If the user isn't already pasting something.
- return
- end
- local selected = Selection:Get()[1] --Gets their first selection and checks if it's a terrain region:
- if(selected and selected:IsA("TerrainRegion")) then
- pasteRegion(selected)--If it is and the user pressed paste, then prompt them to select where to paste.
- else
- if(currentRegion) then --If a terrain region has already been selected and copied, then paste it:
- pasteRegion(currentRegion)
- else --If they have nothing copied, then tell them they need to select something:
- Tools.PasteRegionButton.Title.Text = "Nothing Selected!"
- task.wait(0.5)
- Tools.PasteRegionButton.Title.Text = "Paste Region"
- end
- end
- end,
- ["InsertRegionInstance"] = function() --This activates when the user presses the InsertRegionInstanceButton.
- if(currentRegion) then --If a terrain region has already been selected and copied, then insert it:
- beginRecording("Insert Terrain Region Instance")
- local newRegion = currentRegion:Clone()
- newRegion.Parent = workspace
- Selection:Set({newRegion})
- finishRecording()
- else --If they have nothing copied, then tell them they need to select something:
- Tools.InsertRegionInstance.Title.Text = "Nothing Selected!"
- task.wait(0.5)
- Tools.InsertRegionInstance.Title.Text = "Insert Region Instance"
- end
- end,
- ["RotateLeftButton"] = function()--This activates when the user presses the RotateLeftButton is pressed
- if(selecting and not pasting) then --If they are selecting, then copy the selection:
- beginRecording("Rotate Terrain Left")
- --Perform Rotation:
- rotateSelection(1)
- finishRecording()
- end
- end,
- ["RotateRightButton"] = function()--This activates when the user presses the RotateLeftButton is pressed
- if(selecting and not pasting) then --If they are selecting, then copy the selection:
- beginRecording("Rotate Terrain Right")
- --Perform Rotation:
- rotateSelection(-1)
- finishRecording()
- end
- end
- }
- --Connects the button events to their matching functions:
- for _, btn in pairs(Tools:GetChildren()) do
- if(btn:IsA("Frame")) then
- btn.Activation.Activated:Connect(buttonFunctions[btn.Name])
- end
- end
- --Below is the code that allows the user to select regions using the handles, and change the mode (resize/move) them using the R key.
- UserInputService.InputBegan:Connect(function(input, process)
- if(process or not selecting) then
- return
- end
- if(input.KeyCode == Enum.KeyCode.R and not pasting) then
- if(handles.Style == Enum.HandlesStyle.Resize) then
- handles.Style = Enum.HandlesStyle.Movement
- else
- handles.Style = Enum.HandlesStyle.Resize
- end
- elseif(input.KeyCode == Enum.KeyCode.Escape) then
- deselectRegion()
- elseif(input.KeyCode == Enum.KeyCode.C and UserInputService:IsKeyDown(Enum.KeyCode.LeftControl)) then
- buttonFunctions["CopyRegionButton"]()
- elseif(UserInputService:IsKeyDown(Enum.KeyCode.C) and UserInputService:IsKeyDown(Enum.KeyCode.LeftControl)) then
- buttonFunctions["CopyRegionButton"]()
- elseif(UserInputService:IsKeyDown(Enum.KeyCode.V) and UserInputService:IsKeyDown(Enum.KeyCode.LeftControl)) then
- buttonFunctions["PasteRegionButton"]()
- end
- end)
- --If the user selects a terrain region using the explorer, suggest them to copy/paste it using the plugin.
- Selection.SelectionChanged:Connect(function()
- local firstSelection = Selection:Get()[1]
- if(firstSelection and firstSelection:IsA("TerrainRegion")) then
- Tools.PasteRegionButton.Title.Text = "Paste Selected Region"
- Tools.CopyRegionButton.Title.Text = "Copy Selected Region"
- else
- Tools.PasteRegionButton.Title.Text = "Paste Region"
- Tools.CopyRegionButton.Title.Text = "Copy Selection"
- end
- end)
- --Deselect if the user clicks off the plugin or uninstalls/disables it:
- toggleMenuBtn.Click:Connect(function()
- GUI.Enabled = not GUI.Enabled
- if(GUI.Enabled == false) then
- deselectRegion()
- end
- end)
- plugin.Unloading:Connect(function()
- finishRecording()
- handles:Destroy()
- selectionBox:Destroy()
- end)
- --Thank you for checking out my plugin,
- --LightningLion58
Advertisement
Add Comment
Please, Sign In to add comment