PluginGui
*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.
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
Tiêu đề hiển thị trên nội dung của PluginGui .
Bật/tắt sự hiển thị của điều này LayerCollector .
Xác định xem có phải LayerCollector đặt lại (tự xóa bản thân và sao chép lại vào nhân vật của người chơi PlayerGui) mỗi khi nhân vật của người chơi hồi sinh.
Kiểm soát cách GuiObject.ZIndex hành xử trên tất cả các con trai của điều này LayerCollector .
Mô tả vị trí màn hình thực của một thành phần GuiBase2d , trong điểm ảnh.
Mô tả sự xoay màn hình thực sự của một thành phần GuiBase2d , trong độ.
Mô tả kích thước màn hình thực của một thành phần GuiBase2d , bằng像素.
Khi được đặt thành true , bản địa hóa sẽ được áp dụng cho GuiBase2d và con cháu của nó.
Một tham chiếu đến một LocalizationTable để được sử dụng để áp dụng lok hóa tự động cho GuiBase2d và con cháu của nó.
Tùy chỉnh hành vi lựa chọn gamepad theo chiều xuống.
Tùy chỉnh hành vi lựa chọn gamepad theo hướng bên trái.
Tùy chỉnh hành vi lựa chọn gamepad theo hướng bên phải.
Tùy chỉnh hành vi lựa chọn gamepad trong hướng lên.
Cho phép tùy chỉnh chuyển động lựa chọn gamepad.
Phương Pháp
Gắn một chức năng vào nút đóng PluginGui, thay thế hành vi mặc định.
Trả vị trí của chuột so với PluginGui.
Sự Kiện
Bắt lửa khi người dùng thả chuột khi lướt qua một PluginGui trong khi thực hiện hoạt động kéo bắt đầu bởi Plugin:StartDrag() .
Bắt lửa khi chuột của người dùng vào một PluginGui trong quá trình kéo bắt đầu bởi Plugin:StartDrag() .
Bắt lửa khi chuột của người dùng rời khỏi PluginGui trong quá trình kéo bắt đầu bởi Plugin:StartDrag() .
Bắt lửa khi chuột của người dùng di chuyển trong một PluginGui trong quá trình kéo bắt đầu bởi Plugin:StartDrag() .
Bắt lửa khi người dùng ngừng tương tác với cửa sổ của PluginGui.
Bắt lửa khi người dùng bắt đầu tương tác với cửa sổ của PluginGui.
- SelectionChanged(amISelected : boolean,previousSelection : GuiObject,newSelection : GuiObject):RBXScriptSignal
Bắt lửa khi lựa chọn gamepad di chuyển đến, rời hoặc thay đổi trong khu vực kết nối GuiBase2d hoặc bất kỳ con trai nào GuiObjects .
Thuộc Tính
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:
- Plugin:CreateDockWidgetPluginGui() để tạo một PluginGui
- DataModel:BindToClose() , có thể được sử dụng để gắn một chức năng vào kết thúc trò chơi và không nên nhầm lẫn với chức năng này
Tham Số
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.
Lợi Nhuận
GetRelativeMousePosition
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ã
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
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ố
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".
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
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ố
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".
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
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ố
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".
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
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ố
WindowFocusReleased
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.
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
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.
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)