PluginGui
*Este contenido se traduce usando la IA (Beta) y puede contener errores. Para ver esta página en inglés, haz clic en aquí.
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
El título que se muestra por encima del contenido del PluginGui .
Alterna la visibilidad de este LayerCollector .
Determina si los LayerCollector reinicios (se elimina a sí mismo y se reclona en el personaje del jugador PlayerGui) cada vez que el personaje del jugador reaparece.
Controla cómo GuiObject.ZIndex se comporta en todos los descendientes de este LayerCollector .
Describe la posición actual de la pantalla de un elemento GuiBase2d , en píxeles.
Describe la rotación de la pantalla actual de un elemento GuiBase2d en grados.
Describe el tamaño de la pantalla actual de un elemento GuiBase2d , en píxeles.
Cuando se establece en true, la localización se aplicará a este GuiBase2d y a sus descendientes.
Una referencia a un LocalizationTable para usar para aplicar localización automatizada a este GuiBase2d y sus descendientes.
Personaliza el comportamiento de selección del gamepad en la dirección de abajo.
Personaliza el comportamiento de selección del gamepad en la dirección izquierda.
Personaliza el comportamiento de selección del gamepad en la dirección correcta.
Personaliza el comportamiento de selección del gamepad en la dirección de arriba.
Permite la personalización del movimiento de selección del gamepad.
Métodos
Vincula una función al botón de cierre PluginGui, reemplazando el comportamiento predeterminado.
Devuelve la posición del mouse en relación con el PluginGui.
Eventos
Se activa cuando el usuario suelta el ratón al pasar el mouse sobre un PluginGui durante una operación de arrastre iniciada por Plugin:StartDrag().
Se activa cuando el ratón del usuario entra en un PluginGui durante una operación de arrastre iniciada por Plugin:StartDrag().
Se activa cuando el mouse del usuario deja un PluginGui durante una operación de arrastre iniciada por Plugin:StartDrag().
Se activa cuando el ratón del usuario se mueve dentro de un PluginGui durante una operación de arrastre iniciada por Plugin:StartDrag().
Se activa cuando el usuario deja de interactuar con la ventana del PluginGui.
Se activa cuando el usuario comienza a interactuar con la ventana del PluginGui.
- SelectionChanged(amISelected : boolean,previousSelection : GuiObject,newSelection : GuiObject):RBXScriptSignal
Se enciende cuando la selección del gamepad se mueve a, deja o cambia dentro del conectado GuiBase2d o cualquier descendiente GuiObjects .
Propiedades
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:
- Plugin:CreateDockWidgetPluginGui() para crear un PluginGui
- DataModel:BindToClose() , que se puede usar para vincular una función al final del juego y no debe confundirse con esta función
Parámetros
La función para vincular el botón de cierre. Si no se especifica ninguna función, se desvinculará cualquier función previamente especificada.
Devuelve
GetRelativeMousePosition
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
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 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
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".
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 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
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".
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 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
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".
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 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
WindowFocusReleased
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.
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
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.
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)