PluginGui

Hiển Thị Bản Đã Lỗi Thời

*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.

Không Thể Tạo
Không Sao Chép

PluginGui là một lớp trừu tượng cho GUI cho phép hiển thị GuiObjects trong các tiện ích Roblox Studio khác nhau.Tính đến thời điểm hiện tại, loại PluginGui duy nhất có sẵn là DockWidgetPluginGui, nhưng có thể sẽ có thêm trong tương lai!

Tóm Tắt

Thuộc Tính

Thuộc Tính kế thừa từ LayerCollectorThuộc Tính kế thừa từ GuiBase2d

Phương Pháp

Sự Kiện

Sự Kiện kế thừa từ GuiBase2d

Thuộc Tính

Title

Đọc Song Song

Tiêu đề được hiển thị trên nội dung của PluginGui . Mặc định là chuỗi trống.

Phương Pháp

BindToClose

()

Chức năng này gắn một chức năng vào nút đóng PluginGui, vượt qua hành vi mặc định.

Mặc định, khi người dùng nhấp vào nút 'x' ở góc trên bên phải của PluginGui tài sản Enabled được đặt thành sai , đóng cửa sổKhi chức năng tùy chỉnh được gắn bằng BindToClose hành vi này được viết lại, cho phép bạn kiểm tra xem người dùng có thực sự muốn đóng cửa sổ hay không hoặc cho họ cơ hội để lưu công việc của họ.

Vì hành vi đóng mặc định đã bị thay thế bởi chức năng này, bạn sẽ cần phải cấu hình PluginGui để đóng bằng tay bằng cách thiết lập PluginGui.Enabled thành false .Ví dụ, trong đoạn mã dưới đây người dùng phải nhấp vào nút xác nhận để đóng GUI:


local closing = false
pluginGui:BindToClose(function()
-- hãy chắc chắn rằng chúng tôi chưa tạo nút
if closing then
return
end
closing = true
-- tạo nút xác nhận
local confirmButton = Instance.new("TextButton")
confirmButton.AnchorPoint = Vector2.new(0.5, 0.5)
confirmButton.Size = UDim2.new(0.5, 0, 0.5, 0)
confirmButton.Position = UDim2.new(0.5, 0, 0.5, 0)
confirmButton.BackgroundColor3 = Color3.new(1, 0, 0)
confirmButton.Text = "Close?"
confirmButton.Parent = pluginGui
-- lắng nghe cho nhấp chuột
confirmButton.Activated:Connect(function()
-- đóng giao diện gui
pluginGui.Enabled = false
-- xóa nút xác nhận
confirmButton:Destroy()
end)
end)

Bạn có thể gọi BindToClose mà không có tham số để 'phá vỡ' và quay lại hành vi mặc định được mô tả ở trên. Ví dụ:


pluginGui:BindToClose()

Xem thêm:

Tham Số

function: function

Chức năng để gắn nút đóng vào. Nếu không có chức năng được xác định thì bất kỳ chức năng đã được xác định trước đó nào cũng sẽ bị bỏ khỏi.

Giá Trị Mặc Định: "nil"

Lợi Nhuận

()

GetRelativeMousePosition

Bảo Mật Plugin

GetRelativeMousePosition trả vị trí của chuột so với góc trên cùng bên trái của PluginGui .Giá trị trả về thay đổi chỉ nếu đầu vào chuột bắt đầu trên PluginGui, hoặc nếu chuột hiện đang lướt qua cửa sổ.


Lợi Nhuận

Vị trí màn hình của chuột so với PluginGui bằng像.

Mẫu mã

PluginGui:GetRelativeMousePosition

local RunService = game:GetService("RunService")
local widgetInfo = DockWidgetPluginGuiInfo.new(
Enum.InitialDockState.Float,
true,
false, -- Enabled state, override
200,
300, -- Size
150,
150 -- Minimum size
)
local testWidget = plugin:CreateDockWidgetPluginGui("TestWidget", widgetInfo)
function update()
local v2 = testWidget:GetRelativeMousePosition()
testWidget.Title = ("(%d, %d)"):format(v2.x, v2.y)
end
RunService.Stepped:Connect(update)
update()

Sự Kiện

PluginDragDropped

Bảo Mật Plugin

PluginDragDropped bắt lửa khi người dùng thả chuột của họ trên một PluginGui trong khi thực hiện một hoạt động kéo bắt đầu bởi Plugin:StartDrag() .

Xem thêm:

Tham Số

dragData: Dictionary

Mẫu mã

This code sample creates two plugin widget windows: a drag source and a drop target. In the source window, the script creates a TextBox and TextButton to allow the user to begin a plugin drag action. The drop target window will display the MimeType of whatever is dragged into it using a TextLabel. If the MimeType is text/plain, it will display the plain text data instead.

To run this code sample as a plugin, paste it into a Script. Then, right-click the script in the Explorer window and choose "Save as Local Plugin".

Plugin Drag and Drop

assert(plugin, "This script must be run as a Studio plugin")
local widgetInfo = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 300, 200)
local dragSourceWidget = plugin:CreateDockWidgetPluginGui("Drag Source", widgetInfo)
dragSourceWidget.Title = "Drag Source"
local textBox = Instance.new("TextBox")
textBox.Parent = dragSourceWidget
textBox.Size = UDim2.new(1, 0, 0, 32)
textBox.Text = "Hello, plugin drags"
local dragButton = Instance.new("TextButton")
dragButton.Size = UDim2.new(1, 0, 1, -32)
dragButton.Position = UDim2.new(0, 0, 0, 32)
dragButton.Text = "Edit the text above, then start drag here"
dragButton.Parent = dragSourceWidget
function onMouseButton1Down()
local dragData = {
Sender = "SomeDragSource",
MimeType = "text/plain",
Data = textBox.Text,
MouseIcon = "",
DragIcon = "",
HotSpot = Vector2.new(0, 0),
}
plugin:StartDrag(dragData)
end
dragButton.MouseButton1Down:Connect(onMouseButton1Down)
-- This widget will receive drops
local dragTargetWidget = plugin:CreateDockWidgetPluginGui("Drop Target", widgetInfo)
dragTargetWidget.Title = "Drop Target"
-- This TextLabel will display what was dropped
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(1, 0, 1, 0)
textLabel.Text = "Drop here..."
textLabel.Parent = dragTargetWidget
local function onDragDrop(dragData)
if dragData.MimeType == "text/plain" then
textLabel.Text = dragData.Data
else
textLabel.Text = dragData.MimeType
end
end
dragTargetWidget.PluginDragDropped:Connect(onDragDrop)
dragTargetWidget.PluginDragEntered:Connect(function(_dragData)
print("PluginDragEntered")
end)
dragTargetWidget.PluginDragLeft:Connect(function(_dragData)
print("PluginDragLeft")
end)
dragTargetWidget.PluginDragMoved:Connect(function(_dragData)
print("PluginDragMoved")
end)

PluginDragEntered

Bảo Mật Plugin

PluginDragEntered bắt lửa khi chuột của người dùng vào PluginGui trong khi thực hiện một hoạt động kéo bắt đầu bởi Plugin:StartDrag() .

Sự kiện này hữu ích để hiển thị một giao diện "Thả vào đây" trên PluginGuis nơi một hoạt động kéo có thể bị thả.Một UI như vậy nên được ẩn khi bắn PluginDragLeft hoặc PluginDragDropped .

Xem thêm:

Tham Số

dragData: Dictionary

Bản sao của dữ liệu ban đầu được chuyển đến Plugin:StartDrag() .


Mẫu mã

This code sample creates two plugin widget windows: a drag source and a drop target. In the source window, the script creates a TextBox and TextButton to allow the user to begin a plugin drag action. The drop target window will display the MimeType of whatever is dragged into it using a TextLabel. If the MimeType is text/plain, it will display the plain text data instead.

To run this code sample as a plugin, paste it into a Script. Then, right-click the script in the Explorer window and choose "Save as Local Plugin".

Plugin Drag and Drop

assert(plugin, "This script must be run as a Studio plugin")
local widgetInfo = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 300, 200)
local dragSourceWidget = plugin:CreateDockWidgetPluginGui("Drag Source", widgetInfo)
dragSourceWidget.Title = "Drag Source"
local textBox = Instance.new("TextBox")
textBox.Parent = dragSourceWidget
textBox.Size = UDim2.new(1, 0, 0, 32)
textBox.Text = "Hello, plugin drags"
local dragButton = Instance.new("TextButton")
dragButton.Size = UDim2.new(1, 0, 1, -32)
dragButton.Position = UDim2.new(0, 0, 0, 32)
dragButton.Text = "Edit the text above, then start drag here"
dragButton.Parent = dragSourceWidget
function onMouseButton1Down()
local dragData = {
Sender = "SomeDragSource",
MimeType = "text/plain",
Data = textBox.Text,
MouseIcon = "",
DragIcon = "",
HotSpot = Vector2.new(0, 0),
}
plugin:StartDrag(dragData)
end
dragButton.MouseButton1Down:Connect(onMouseButton1Down)
-- This widget will receive drops
local dragTargetWidget = plugin:CreateDockWidgetPluginGui("Drop Target", widgetInfo)
dragTargetWidget.Title = "Drop Target"
-- This TextLabel will display what was dropped
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(1, 0, 1, 0)
textLabel.Text = "Drop here..."
textLabel.Parent = dragTargetWidget
local function onDragDrop(dragData)
if dragData.MimeType == "text/plain" then
textLabel.Text = dragData.Data
else
textLabel.Text = dragData.MimeType
end
end
dragTargetWidget.PluginDragDropped:Connect(onDragDrop)
dragTargetWidget.PluginDragEntered:Connect(function(_dragData)
print("PluginDragEntered")
end)
dragTargetWidget.PluginDragLeft:Connect(function(_dragData)
print("PluginDragLeft")
end)
dragTargetWidget.PluginDragMoved:Connect(function(_dragData)
print("PluginDragMoved")
end)

PluginDragLeft

Bảo Mật Plugin

PluginDragLeft bắt lửa khi chuột của người dùng rời khỏi một PluginGui trong quá trình kéo bắt đầu bởi Plugin:StartDrag() .

Sự kiện này và PluginDragDropped hữu ích để ẩn giao diện người dùng "Thả vào đây" trên PluginGuis nơi một hoạt động kéo có thể bị thả.Một UI như vậy nên được hiển thị khi có lửa PluginDragEntered bắt lửa.

Xem thêm:

Tham Số

dragData: Dictionary

Bản sao của dữ liệu ban đầu được chuyển đến Plugin:StartDrag() .


Mẫu mã

This code sample creates two plugin widget windows: a drag source and a drop target. In the source window, the script creates a TextBox and TextButton to allow the user to begin a plugin drag action. The drop target window will display the MimeType of whatever is dragged into it using a TextLabel. If the MimeType is text/plain, it will display the plain text data instead.

To run this code sample as a plugin, paste it into a Script. Then, right-click the script in the Explorer window and choose "Save as Local Plugin".

Plugin Drag and Drop

assert(plugin, "This script must be run as a Studio plugin")
local widgetInfo = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 300, 200)
local dragSourceWidget = plugin:CreateDockWidgetPluginGui("Drag Source", widgetInfo)
dragSourceWidget.Title = "Drag Source"
local textBox = Instance.new("TextBox")
textBox.Parent = dragSourceWidget
textBox.Size = UDim2.new(1, 0, 0, 32)
textBox.Text = "Hello, plugin drags"
local dragButton = Instance.new("TextButton")
dragButton.Size = UDim2.new(1, 0, 1, -32)
dragButton.Position = UDim2.new(0, 0, 0, 32)
dragButton.Text = "Edit the text above, then start drag here"
dragButton.Parent = dragSourceWidget
function onMouseButton1Down()
local dragData = {
Sender = "SomeDragSource",
MimeType = "text/plain",
Data = textBox.Text,
MouseIcon = "",
DragIcon = "",
HotSpot = Vector2.new(0, 0),
}
plugin:StartDrag(dragData)
end
dragButton.MouseButton1Down:Connect(onMouseButton1Down)
-- This widget will receive drops
local dragTargetWidget = plugin:CreateDockWidgetPluginGui("Drop Target", widgetInfo)
dragTargetWidget.Title = "Drop Target"
-- This TextLabel will display what was dropped
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(1, 0, 1, 0)
textLabel.Text = "Drop here..."
textLabel.Parent = dragTargetWidget
local function onDragDrop(dragData)
if dragData.MimeType == "text/plain" then
textLabel.Text = dragData.Data
else
textLabel.Text = dragData.MimeType
end
end
dragTargetWidget.PluginDragDropped:Connect(onDragDrop)
dragTargetWidget.PluginDragEntered:Connect(function(_dragData)
print("PluginDragEntered")
end)
dragTargetWidget.PluginDragLeft:Connect(function(_dragData)
print("PluginDragLeft")
end)
dragTargetWidget.PluginDragMoved:Connect(function(_dragData)
print("PluginDragMoved")
end)

PluginDragMoved

Bảo Mật Plugin

PluginDragMoved bắt lửa khi chuột của người dùng di chuyển trong một PluginGui trong khi thực hiện một hoạt động kéo bắt đầu bởi Plugin:StartDrag() .

Xem thêm:

Tham Số

dragData: Dictionary

WindowFocusReleased

Bảo Mật Plugin

WindowFocusReleased bắt lửa ngay lập tức khi người dùng ngừng tương tác với cửa sổ của PluginGui, thường bằng cách nhấp vào một thứ gì đó không có trong cửa sổ.Các chức năng này hoạt động tương tự với sự kiện có tên tương tự UserInputService.WindowFocusReleased .

Nếu tập trung chuyển sang một khác PluginGui trong khi người dùng có PluginGui này trong tập trung, thì sự kiện này sẽ bắt lửa trước sự kiện của người khác WindowFocused .Tuy nhiên, nếu cửa sổ chính của trò chơi được đưa vào tập trung, sự kiện này bắt lửa sau UserInputService.WindowFocused .


Mẫu mã

This code sample demonstrates how the focus state of a PluginGui can be tracked using the WindowFocused() and WindowFocusReleased() events. It changes the Title() as the focus state changes.

Detecting PluginGui Focus State

local info = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 200, 50, 1, 1)
local widget = plugin:CreateDockWidgetPluginGui("TestWidget", info)
local function onFocusReleased()
widget.Title = "I'm not in focus :("
end
local function onFocused()
widget.Title = "I'm in focus :D"
end
widget.WindowFocusReleased:Connect(onFocusReleased)
widget.WindowFocused:Connect(onFocused)

WindowFocused

Bảo Mật Plugin

Tập trung cửa sổ bắt lửa ngay lập tức khi người dùng bắt đầu tương tác với cửa sổ của PluginGui, thường bằng cách nhấp vào nó.Các chức năng này hoạt động tương tự với sự kiện có tên tương tự UserInputService.WindowFocused .Nó bắn trước khi bất kỳ sự kiện GuiObject.InputBegan liên quan đến nút chuột.

Nếu một đối tượng khác PluginGui đang ở trong tâm trung và người dùng tập trung vào PluginGui này, thì sự kiện này sẽ bắt lửa sau sự kiện của người khác WindowFocusReleased.Tuy nhiên, nếu cửa sổ trò chơi chính đang ở trong tâm trí, sự kiện này sẽ bắn sau UserInputService.WindowFocusReleased .


Mẫu mã

This code sample demonstrates how the focus state of a PluginGui can be tracked using the WindowFocused() and WindowFocusReleased() events. It changes the Title() as the focus state changes.

Detecting PluginGui Focus State

local info = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, true, true, 200, 50, 1, 1)
local widget = plugin:CreateDockWidgetPluginGui("TestWidget", info)
local function onFocusReleased()
widget.Title = "I'm not in focus :("
end
local function onFocused()
widget.Title = "I'm in focus :D"
end
widget.WindowFocusReleased:Connect(onFocusReleased)
widget.WindowFocused:Connect(onFocused)