PluginGui

Mostrar obsoleto

*Este conteúdo é traduzido por IA (Beta) e pode conter erros. Para ver a página em inglês, clique aqui.

Não criável
Não replicado

O PluginGui é uma classe abstrata para GUIs que permitem a exibição de GuiObjects em vários widgets do Roblox Studio.No momento, o único tipo de PluginGui disponível é DockWidgetPluginGui, mas pode haver mais no futuro!

Resumo

Propriedades

Propriedades herdados de LayerCollectorPropriedades herdados de GuiBase2d

Métodos

Eventos

Eventos herdados de GuiBase2d

Propriedades

Title

Ler Parallel

O título que é exibido acima do conteúdo do PluginGui . Padrão para uma string / cadeia / textovazia.

Métodos

BindToClose

()

Essa função vincula uma função ao botão de fechamento PluginGui, substituindo o comportamento padrão.

Por padrão, quando o usuário clica no botão 'x' no canto superior direito do PluginGui a propriedade Enabled é definida como falsa, fechando a janela.Quando uma função personalizada é vinculada usando BindToClose este comportamento é substituído, permitindo que você verifique se o usuário realmente quer fechar a janela ou dar-lhes uma oportunidade de salvar seu trabalho.

Como o comportamento padrão de fechamento é substituído por essa função, você precisará configurar o PluginGui definindo PluginGui.Enabledfalse.Por exemplo, no trecho a seguir, os usuários são obrigados a clicar em um botão de confirmação para fechar a Interface gráfica do usuário:


local closing = false
pluginGui:BindToClose(function()
-- certifique-se de que ainda não criamos um botão
if closing then
return
end
closing = true
-- criar botão de confirmação
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
-- ouvir para clique
confirmButton.Activated:Connect(function()
-- feche a gui
pluginGui.Enabled = false
-- remover botão de confirmação
confirmButton:Destroy()
end)
end)

Você pode chamar BindToClose sem argumento para 'desvincular' e reverter ao comportamento padrão descrito acima. Por exemplo:


pluginGui:BindToClose()

Veja também:

Parâmetros

function: function

A função para vincular o botão de fechar. Se nenhuma função for especificada, qualquer função previamente especificada será desvinculada.

Valor Padrão: "nil"

Devolução

()

GetRelativeMousePosition

Segurança do plugin

GetRelativeMousePosition retorna a posição do mouse em relação ao canto superior esquerdo do PluginGui .O valor retornado muda apenas se uma entrada de mouse começou no PluginGui ou se o mouse estiver atualmente pairando sobre a janela.


Devolução

A posição da tela do mouse em relação ao PluginGui em pixels.

Amostras de código

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

Eventos

PluginDragDropped

Segurança do plugin

PluginDragDropped dispara quando o usuário solta o mouse sobre um PluginGui durante uma operação de arrastamento iniciada por Plugin:StartDrag().

Veja também:

Parâmetros

dragData: Dictionary

Amostras de código

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

Segurança do plugin

PluginDragEntered dispara quando o mouse do usuário entra no PluginGui durante uma operação de arrastamento iniciada por Plugin:StartDrag().

Este evento é útil para exibir uma interface de usuário "Solte aqui" no PluginGuis onde uma operação de arrastamento pode ser solta.Tal UI deve ser oculta quando PluginDragLeft ou PluginDragDropped Iniciar / executar.

Veja também:

Parâmetros

dragData: Dictionary

Uma cópia dos dados originalmente enviados para Plugin:StartDrag() .


Amostras de código

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

Segurança do plugin

PluginDragLeft dispara quando o mouse do usuário deixa um PluginGui durante uma operação de arrastamento iniciada por Plugin:StartDrag().

Este evento e PluginDragDropped são úteis para ocultar uma interface de usuário "Drop Here" no PluginGuis onde uma operação de arrastamento pode ser solta.Tal UI deve ser mostrada quando PluginDragEntered ocorrem.

Veja também:

Parâmetros

dragData: Dictionary

Uma cópia dos dados originalmente enviados para Plugin:StartDrag() .


Amostras de código

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

Segurança do plugin

PluginDragMoved dispara quando o mouse do usuário se move dentro de um PluginGui durante uma operação de arrastamento iniciada por Plugin:StartDrag().

Veja também:

Parâmetros

dragData: Dictionary

WindowFocusReleased

Segurança do plugin

Foco de janela liberado dispara imediatamente quando o usuário para de interagir com a janela do PluginGui, geralmente clicando em algo que não está na janela.Essas funções funcionam de forma semelhante ao evento de mesmo nome UserInputService.WindowFocusReleased .

Se o foco estiver se movendo para outro PluginGui enquanto o usuário tinha este PluginGui em foco, então este evento será disparado antes do evento do outro WindowFocused.No entanto, se a janela principal do jogo estiver sendo colocada em destaque, este evento dispara depois de .


Amostras de código

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

Segurança do plugin

Foco na janela dispara imediatamente quando o usuário começa a interagir com a janela do PluginGui, geralmente clicando nela.Essas funções funcionam de forma semelhante ao evento de mesmo nome UserInputService.WindowFocused .Ele dispara antes de qualquer evento GuiObject.InputBegan relacionado a botões do mouse.

Se outro PluginGui estiver em destaque e o usuário focar neste PluginGui, então este evento será disparado após o evento do outro WindowFocusReleased.No entanto, se a janela principal do jogo estivesse em foco, este evento dispara após UserInputService.WindowFocusReleased.


Amostras de código

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)