PluginGui

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

無法建立
未複製

PluginGui 是一個抽象類型的 GUI,可以在各種 Roblox Studio 工具中顯示 GuiObjects 。目前唯一可用的 PluginGui 類型是 DockWidgetPluginGui,但未來可能會有更多!

概要

屬性

屬性 繼承自 LayerCollector屬性 繼承自 GuiBase2d

方法

活動

活動 繼承自 GuiBase2d

屬性

Title

平行讀取

顯示在 PluginGui 內容上方的標題。默認為空字串。

方法

BindToClose

()

此功能將函數綁定到 PluginGui 關閉按鈕,覆蓋預設行為。

預設情況下,當使用者單擊右上角的 'x' 按鈕時, 屬性將設為 false,關閉窗口。當使用 BindToClose 綁定自訂功能時,此行為將被覆蓋,允許您檢查用戶真正想要關閉窗口或給他們機會儲存工作的情況。

因為預設關閉行為被此函數覆蓋,因此您需要配置 PluginGui 手動關閉,通過設置 PluginGui.Enabledfalse 來關閉。例如,在下面的代碼片段中,使用者必須單擊確認按鈕以關閉 GUI:


local closing = false
pluginGui:BindToClose(function()
-- 確認我們還沒有做過按鈕
if closing then
return
end
closing = true
-- 建立確認按鈕
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
-- 聆聽點擊
confirmButton.Activated:Connect(function()
-- 關閉 gui
pluginGui.Enabled = false
-- 移除確認按鈕
confirmButton:Destroy()
end)
end)

您可以呼叫 BindToClose 無參數來「解除綁定」並恢復上述描述的預設行為。例如:


pluginGui:BindToClose()

也見:

參數

function: function

用於綁定關閉按鈕的功能。如果未指定功能,則任何先前指定的功能都將被解除綁定。

預設值:"nil"

返回

()

GetRelativeMousePosition

外掛程式安全性

取得相對滑鼠位置返回滑鼠與左上角的 PluginGui 相對位置。返回的值只會在 PluginGui 上開始鼠標輸入,或者鼠標目前正在漂浮窗口上時才會發生變更。


返回

滑鼠對插件GUI的畫面位置,以畫素為單位。

範例程式碼

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()

活動

PluginDragDropped

外掛程式安全性

插件拖曳掉落 在使用者啟動拖曳操作後,將滑鼠放在 上時發生。

也見:

參數

dragData: Dictionary

範例程式碼

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

外掛程式安全性

插件拖入 在使用者的鼠標進入 PluginGui 期間發生,當由 Plugin:StartDrag() 啟動的拖動操作開始時。

此事件對於在 PluginGuis 上顯示「在此處拖曳」用戶介面有用,其中拖動操作可以被掉落。這種介面應在 PluginDragLeftPluginDragDropped 觸發射時隱藏。

也見:

參數

dragData: Dictionary

原本傳送到 Plugin:StartDrag() 的數據的副本。


範例程式碼

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

外掛程式安全性

插件拖動左 在使用者的鼠標在拖動操作由 PluginGui 開始時離開 Plugin:StartDrag() 時發生。

這個事件和 PluginDragDropped 有用於在 PluginGuis 上隱藏可拖曳的「在此處放置」用戶介面。這種介面應在 PluginDragEntered 發生時顯示。

也見:

參數

dragData: Dictionary

原本傳送到 Plugin:StartDrag() 的數據的副本。


範例程式碼

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

外掛程式安全性

插件拖動移動 在使用者的鼠標在拖動操作開始時移動到 PluginGui 內發生,當拖動操作由 Plugin:StartDrag() 開始時。

也見:

參數

dragData: Dictionary

WindowFocusReleased

外掛程式安全性

窗口焦點釋放 在使用者停止與 PluginGui 窗口互動時立即發生,通常是點擊窗口外的東西。這些功能與類似名稱的 UserInputService.WindowFocusReleased 事件相似。

如果焦點切換到另一個 PluginGui 時,使用者有此 PluginGui 在焦點上,則此事件會在其他人的 WindowFocused 事件之前發生。然而,如果主遊戲窗口被放置在焦點上,此事件將在 UserInputService.WindowFocused發射。


範例程式碼

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

外掛程式安全性

窗口聚焦 在使用者開始與 PluginGui 窗口互動時立即發生,通常通過單擊它來啟動。這些功能與類似名稱的 UserInputService.WindowFocused 事件相似。它在任何 GuiObject.InputBegan 與滑鼠按鈕相關的事件發生之前發射。

如果另一個 PluginGui 在焦點上,且使用者專注於此 PluginGui,則此事件會在另一個的 WindowFocusReleased 事件之後發生。然而,如果主遊戲窗口處於聚焦狀態,此事件將在 之後發射 UserInputService.WindowFocusReleased


範例程式碼

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)