Can I implement mouse drag from one Studio plugin GUI to another?
I would like to be able to drag objects between two DockWidgetPluginGuis created by the same Studio plugin. I have dragging within a window working, but it seems I don't get any events for the other window while the mouse button is still held down.
Example code:
01 | local win 1 = plugin:CreateDockWidgetPluginGui( |
03 | DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true , true ) |
05 | win 1. Name = "MouseTest_Window1" |
06 | win 1. Title = "Mouse Test 1" |
07 | local frame 1 = Instance.new( "Frame" , win 1 ) |
08 | frame 1. Size = UDim 2. new( 1 , 0 , 1 , 0 ) |
09 | frame 1. BackgroundColor 3 = Color 3. new(. 5 , . 5 , . 5 ) |
10 | local square = Instance.new( "Frame" , frame 1 ) |
11 | square.Size = UDim 2. new( 0 , 50 , 0 , 50 ) |
12 | square.BackgroundColor 3 = Color 3. new(. 1 , 1 , . 1 ) |
14 | local win 2 = plugin:CreateDockWidgetPluginGui( |
16 | DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true , true ) |
18 | win 2. Name = "MouseTest_Window2" |
19 | win 2. Title = "Mouse Test 2" |
20 | local frame 2 = Instance.new( "Frame" , win 2 ) |
21 | frame 2. Size = UDim 2. new( 1 , 0 , 1 , 0 ) |
22 | frame 2. BackgroundColor 3 = Color 3. new(. 5 , . 5 , . 5 ) |
27 | local function MoveSquare(mouseX, mouseY) |
28 | print ( "Move" , mouseX, mouseY) |
30 | square.Position = UDim 2. new( 0 , mouseX + mouseToSquare.X, 0 , mouseY + mouseToSquare.Y) |
34 | local function OnEnterFrame(frame, x, y) |
35 | print ( "Enter" , frame.Parent.Name, x, y) |
39 | square.BackgroundTransparency = 0 |
43 | local function OnLeaveFrame() |
47 | square.BackgroundTransparency = 0.5 |
51 | square.InputBegan:Connect( function (input) |
52 | if input.UserInputType = = Enum.UserInputType.MouseButton 1 then |
53 | mouseToSquare = square.AbsolutePosition - Vector 2. new(input.Position.X, input.Position.Y) |
55 | event = input.Changed:Connect( function () |
56 | print ( "input object:" , input.UserInputState, input.UserInputType) |
57 | if input.UserInputState = = Enum.UserInputState.End then |
58 | square.BackgroundTransparency = 0 |
66 | frame 1. MouseEnter:Connect( function (x,y) OnEnterFrame(frame 1 , x, y) end ) |
67 | frame 1. MouseMoved:Connect(MoveSquare) |
68 | frame 1. MouseLeave:Connect(OnLeaveFrame) |
69 | frame 2. MouseEnter:Connect( function (x,y) OnEnterFrame(frame 2 , x, y) end ) |
70 | frame 2. MouseMoved:Connect(MoveSquare) |
71 | frame 2. MouseLeave:Connect(OnLeaveFrame) |
The green square can be dragged around window 1, and fades if the mouse leaves that window, but I don't get any print output at all when the mouse moves into or through window 2. If I release the mouse button in window 2, I do start getting input events there, so I could "snap" the object into the window at that time, but it would be much nicer to be able to see where you're placing it.
I also tried looking at the plugin mouse from plugin:Activate(true)
and plugin:GetMouse()
, but didn't see any events from it during this sort of drag either.
Is there some way to detect a mouse drag into another window, or is this just not possible?