PluginGui
*Este conteúdo é traduzido por IA (Beta) e pode conter erros. Para ver a página em inglês, clique aqui.
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
O título que é exibido acima do conteúdo do PluginGui .
Alterna a visibilidade deste LayerCollector .
Determina se os ressets (se reinicia e se clona de novo no personagem do jogador) ocorrem sempre que o personagem do jogador respawna.
Controla como GuiObject.ZIndex se comporta em todos os descendentes deste LayerCollector .
Descreve a posição real da tela de um elemento GuiBase2d , em pixels.
Descreve a rotação real da tela de um elemento GuiBase2d em graus.
Descreve o tamanho real da tela de um elemento GuiBase2d , em pixels.
Quando definido para true , a localização será aplicada a este GuiBase2d e seus descendentes.
Uma referência a um LocalizationTable para ser usado para aplicar localização automatizada a este GuiBase2d e seus descendentes.
Personaliza o comportamento de seleção de gamepad na direção de baixo.
Personaliza o comportamento de seleção do gamepad na direção esquerda.
Personaliza o comportamento de seleção do gamepad na direção certa.
Personaliza o comportamento de seleção do gamepad na direção de cima.
Permite a personalização do movimento de seleção do gamepad.
Métodos
Vincula uma função ao botão de fechar PluginGui, substituindo o comportamento padrão.
Retorna a posição do mouse em relação ao PluginGui.
Eventos
Incêndios quando o usuário solta o mouse ao pairar sobre um PluginGui durante uma operação de arrastamento iniciada por Plugin:StartDrag().
Incêndios quando o mouse do usuário entra em um PluginGui durante uma operação de arrastamento iniciada por Plugin:StartDrag().
Incêndios quando o mouse do usuário deixa um PluginGui durante uma operação de arrastamento iniciada por Plugin:StartDrag() .
Incêndios quando o mouse do usuário se move dentro de um PluginGui durante uma operação de arrastamento iniciada por Plugin:StartDrag().
Foge quando o usuário para de interagir com a janela do PluginGui.
Foge quando o usuário começa a interagir com a janela do PluginGui.
- SelectionChanged(amISelected : boolean,previousSelection : GuiObject,newSelection : GuiObject):RBXScriptSignal
Incêndios quando a seleção do gamepad se move para, deixa ou muda dentro do conectado GuiBase2d ou qualquer descendente GuiObjects.
Propriedades
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:
- Plugin:CreateDockWidgetPluginGui() para criar um PluginGui
- DataModel:BindToClose() , que pode ser usado para vincular uma função ao final do jogo e não deve ser confundido com essa função
Parâmetros
A função para vincular o botão de fechar. Se nenhuma função for especificada, qualquer função previamente especificada será desvinculada.
Devolução
GetRelativeMousePosition
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
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
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
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".
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 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
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".
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 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
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".
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 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
WindowFocusReleased
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.
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
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.
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)