PluginGui

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

无法创建
未复制

插件图形用户界面是一个抽象类,允许显示 GuiObjects 在各个 Roblox Studio widget 中。目前为止,唯一可用的插件图形类型是 DockWidgetPluginGui ,但可能会有更多在未来!

概要

属性

继承自LayerCollector属性继承自GuiBase2d属性

方法

活动

继承自GuiBase2d活动

属性

Title

读取并联

显示在 PluginGui 上的标题。默认为空文字符串。

方法

BindToClose

void

此函数将函数绑定到 PluginGui 关闭按钮,覆盖默认行为。

默认情况下,当用户在PluginGui的右上角的“x”按钮上单击时,Enabled 属性设置为false,关闭窗口。当用户使用自定义函数使用 BindToClose 时,此行为已覆盖,允许您检查用户是否真的想关闭窗口或给予他们机会

由于此函数的默认关闭行为已被此功能覆盖,您需要配置 PluginGui 手动关闭,通过将 PluginGui.Enabled 设置为 关闭 。例如,在下面的示例中,用户需要单击确认按钮关闭 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()
-- 关闭图形用户界面
pluginGui.Enabled = false
-- 移除确认按钮
confirmButton:Destroy()
end)
end)

您可以使用 BindToClose 无参数地 ‘unbind’ 并恢复到上述描述的默认行为。例如:


pluginGui:BindToClose()

还请参阅:

参数

function: function

关闭按钮的函数。如果没有指定任何函数,那么上一个指定的函数将被取消。

默认值:"nil"

返回

void

GetRelativeMousePosition

插件安全性

获取相对鼠标位置将鼠标的位置与 PluginGui 的左上角相提并论。值返回只会改变,如果在 PluginGui 上输入鼠标,或者如果鼠标正在悬停窗口上。


返回

鼠标相对于插件管理器的屏幕位置以像素计表示。

代码示例

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

插件安全性

插件拖动到了 发生在用户在拖动操作开始时,当 PluginGui 上的鼠标放置在 Plugin:StartDrag() 下时。

还请参阅:

参数

dragData: Dictionary

代码示例

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 中的“Drop Here” UI,其中拖动操作可以丢弃。此界面应该在 PluginDragLeftPluginDragDropped 发生时触发藏。

还请参阅:

参数

dragData: Dictionary

数据的副本原始传送至 Plugin:StartDrag()


代码示例

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 中的“Drop Here” 用户界面,在拖动操作可以丢弃的情况下。此界面应该在 PluginDragEntered 发生时显示。

还请参阅:

参数

dragData: Dictionary

数据的副本原始传送至 Plugin:StartDrag()


代码示例

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

插件安全性

窗口焦点释放完成后会立即触发窗口,通常通过单击窗口外的某个东西来实现。 这与类似的 Class.UserInputService.WindowFocusReleased 事件工作相同。

如果焦点正在移动到另一个 PluginGui 而用户在焦点上有此 PluginGui,那么此事件在其他人的 WindowFocused 事件之前触发。 但如果主游戏窗口正在放置,那么此事件将在 后 触发 2>Class.UserInputService.WindowFocused2> 。


代码示例

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

插件安全性

窗口聚焦 会在用户与插件库图形用户界面互动时立即触发,通常通过单击它。这与同名的 UserInputService.WindowFocused 事件相同。它会触发前任何与鼠标按钮相关的 GuiObject.InputBegan 事件。

如果另一个 PluginGui 在聚焦中,而用户将此 PluginGui 聚焦,此事件在另一个的 WindowFocusReleased 事件后发生。但如果主游戏窗口处于聚焦状态,此事件在 1> Class.UserInputService.WindowFocusRelease1> 。


代码示例

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)