PluginGui

Mostrar obsoleto

*Este contenido se traduce usando la IA (Beta) y puede contener errores. Para ver esta página en inglés, haz clic en aquí.

No creable
No replicado

PluginGui es una clase abstracta para interfaces gráicas que permiten la visualización de GuiObjects en varios widgets de Roblox Studio.A partir de ahora, el único tipo de PluginGui disponible es DockWidgetPluginGui, ¡pero puede haber más en el futuro!

Resumen

Propiedades

Propiedades heredados de LayerCollectorPropiedades heredados de GuiBase2d

Métodos

Eventos

Eventos heredados de GuiBase2d

Propiedades

Title

Leer paralelo

El título que se muestra por encima del contenido del PluginGui . Se prefiere a una cadena vacía.

Métodos

BindToClose

()

Esta función vincula una función al botón de cierre PluginGui, reemplazando el comportamiento predeterminado.

Por defecto, cuando el usuario hace clic en el botón 'x' en la esquina superior derecha del PluginGui la propiedad Enabled se establece en falso , cerrando la ventana.Cuando una función personalizada se vincula usando BindToClose este comportamiento se reemplaza, lo que te permite verificar si el usuario realmente quiere cerrar la ventana o darles una oportunidad para guardar su trabajo.

Como el comportamiento de cierre predeterminado se reemplaza por esta función, deberás configurar el PluginGui para cerrar manualmente al establecer PluginGui.Enabled en falso.Por ejemplo, en el siguiente fragmento se requiere que los usuarios hagan clic en un botón de confirmación para cerrar la Interfaz gráfica (o GUI):


local closing = false
pluginGui:BindToClose(function()
-- asegúrate de que no hayamos hecho ya un botón
if closing then
return
end
closing = true
-- botón de creación de confirmació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
-- escuchar para hacer hcer clic
confirmButton.Activated:Connect(function()
-- cierra el gui
pluginGui.Enabled = false
-- eliminar botón de confirmación
confirmButton:Destroy()
end)
end)

Puedes llamar a BindToClose sin argumento para 'desvincular' y volver al comportamiento predeterminado descrito anteriormente. Por ejemplo:


pluginGui:BindToClose()

Vea también:

Parámetros

function: function

La función para vincular el botón de cierre. Si no se especifica ninguna función, se desvinculará cualquier función previamente especificada.

Valor predeterminado: "nil"

Devuelve

()

GetRelativeMousePosition

Seguridad del plugin

GetRelativeMousePosition devuelve la posición del mouse en relación con el rincón superior izquierdo del PluginGui .El valor devuelto cambia solo si una entrada de ratón comenzó en el PluginGui, o si el ratón está actualmente pasando por encima de la ventana.


Devuelve

La posición de la pantalla del mouse con respecto al PluginGui en píxeles.

Muestras 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

Seguridad del plugin

PluginDragDropped se activa cuando el usuario suelta el mouse sobre un PluginGui durante una operación de arrastre iniciada por Plugin:StartDrag().

Vea también:

Parámetros

dragData: Dictionary

Muestras 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

Seguridad del plugin

PluginDragEntered se activa cuando el mouse del usuario entra en el PluginGui durante una operación de arrastre iniciada por Plugin:StartDrag() .

Este evento es útil para mostrar una interfaz de usuario "Soltar aquí" en PluginGuis donde se puede soltar una operación de arrastre.Tal interfaz de usuario debe ocultarse cuando se active PluginDragLeft o PluginDragDropped desencadenar.

Vea también:

Parámetros

dragData: Dictionary

Una copia de los datos originalmente enviados a Plugin:StartDrag() .


Muestras 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

Seguridad del plugin

PluginDragLeft se activa cuando el mouse del usuario deja un PluginGui durante una operación de arrastre iniciada por Plugin:StartDrag().

Este evento y PluginDragDropped son útiles para ocultar una interfaz de usuario "Soltar aquí" en PluginGuis donde se puede soltar una operación de arrastre.Tal interfaz de usuario debe mostrarse cuando se activen PluginDragEntered fuegos.

Vea también:

Parámetros

dragData: Dictionary

Una copia de los datos originalmente enviados a Plugin:StartDrag() .


Muestras 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

Seguridad del plugin

PluginDragMoved se activa cuando el mouse del usuario se mueve dentro de un PluginGui durante una operación de arrastre iniciada por Plugin:StartDrag() .

Vea también:

Parámetros

dragData: Dictionary

WindowFocusReleased

Seguridad del plugin

WindowFocusReleased dispara inmediatamente cuando el usuario deja de interactuar con la ventana del PluginGui, generalmente haciendo clic en algo que no está en la ventana.Estas funciones funcionan de manera similar al evento de nombre similar UserInputService.WindowFocusReleased .

Si el enfoque se mueve a otro PluginGui mientras el usuario tenía este PluginGui en el enfoque, entonces este evento se activa antes del evento del otro WindowFocused.Sin embargo, si la ventana del juego principal está siendo puesta en el foco, este evento dispara después de >.


Muestras 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

Seguridad del plugin

WindowFocused dispara inmediatamente cuando el usuario comienza a interactuar con la ventana del PluginGui, generalmente haciendo clic en ella.Estas funciones funcionan de manera similar al evento de nombre similar UserInputService.WindowFocused .Se activa antes de cualquier evento GuiObject.InputBegan relacionado con los botones del mouse.

Si otro PluginGui está en el enfoque y el usuario se enfoca en este PluginGui, entonces este evento se activa después del evento del otro WindowFocusReleased.Sin embargo, si la ventana principal del juego estaba en foco, este evento se activa después de .


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