PluginGui
*Ce contenu est traduit en utilisant l'IA (Beta) et peut contenir des erreurs. Pour consulter cette page en anglais, clique ici.
PluginGui est une classe abstraite pour les interfaces graphiques qui permettent l'affichage de GuiObjects dans divers widgets de Roblox Studio.À l'heure actuelle, le seul type de PluginGui disponible est DockWidgetPluginGui, mais il pourrait y en avoir plus à l'avenir !
Résumé
Propriétés
Le titre qui est affiché au-dessus du contenu du PluginGui .
Bascule la visibilité de ce LayerCollector .
Détermine si les réinitialisations de LayerCollector (se supprime et se réclone dans le personnage du joueur de PlayerGui ) se produisent chaque fois que le personnage du joueur réapparaît.
Contrôle comment GuiObject.ZIndex se comporte sur tous les descendants de ce LayerCollector .
Décrit la position réelle d'un élément GuiBase2d sur l'écran, en pixels.
Décrit la rotation réelle de l'écran d'un élément GuiBase2d en degrés.
Décrit la taille réelle de l'écran d'un élément GuiBase2d, en pixels.
Lorsqu'il est défini à true, la localisation sera appliquée à ce GuiBase2d et à ses descendants.
Une référence à un LocalizationTable à utiliser pour appliquer une localisation automatisée à ce GuiBase2d et à ses descendants.
Personnalise le comportement de sélection du manette de jeu dans la direction descendante.
Personnalise le comportement de sélection du manette de jeu dans la direction de gauche.
Personnalise le comportement de sélection du gamepad dans la bonne direction.
Personnalise le comportement de sélection du gamepad dans la direction vers le haut.
Permet la personnalisation du mouvement de sélection du gamepad.
Méthodes
Liaison d'une fonction à la bouton de fermeture PluginGui, remplaçant le comportement par défaut.
Renvoie la position de la souris par rapport au PluginGui.
Évènements
Se déclenche lorsque l'utilisateur relâche sa souris en survolant un PluginGui lors d'une opération de glisser commencée par Plugin:StartDrag().
S'enflamme lorsque la souris de l'utilisateur entre dans un PluginGui pendant une opération de glissement commencée par Plugin:StartDrag().
S'enflamme lorsque la souris de l'utilisateur quitte un PluginGui pendant une opération de glissement commencée par Plugin:StartDrag().
S'enflamme lorsque la souris de l'utilisateur se déplace dans un PluginGui pendant une opération de glissement commencée par Plugin:StartDrag().
S'enflamme lorsque l'utilisateur cesse d'interagir avec la fenêtre du PluginGui.
S'enflamme lorsque l'utilisateur commence à interagir avec la fenêtre du PluginGui.
- SelectionChanged(amISelected : boolean,previousSelection : GuiObject,newSelection : GuiObject):RBXScriptSignal
Se déclenche lorsque la sélection de la manette de jeu se déplace, quitte ou change dans le connecteur GuiBase2d ou dans n'importe quel descendant GuiObjects.
Propriétés
Méthodes
BindToClose
Cette fonction lie une fonction à la bouton de fermeture PluginGui, en remplaçant le comportement par défaut.
Par défaut, lorsque l'utilisateur clique sur le bouton 'x' dans le coin supérieur droit du PluginGui la propriété Enabled est définie sur faux , fermant la fenêtre.Lorsqu'une fonction personnalisée est liée à l'aide de BindToClose, ce comportement est remplacé, vous permettant de vérifier si l'utilisateur veut vraiment fermer la fenêtre ou leur donner l'occasion de sauvegarder leur travail.
Comme le comportement de fermeture par défaut est remplacé par cette fonction, vous devrez configurer le PluginGui pour fermer manuellement en définissant PluginGui.Enabled sur faux .Par exemple, dans l'extrait ci-dessous, les utilisateurs sont tenus de cliquer sur un bouton de confirmation pour fermer l'interface interface utilisateur graphique:
local closing = false
pluginGui:BindToClose(function()
-- assurez-vous que nous n'avons pas déjà fait un bouton
if closing then
return
end
closing = true
-- créer bouton de confirmation
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
-- écouter pour cliquer
confirmButton.Activated:Connect(function()
-- fermer le gui
pluginGui.Enabled = false
-- supprimer le bouton de confirmation
confirmButton:Destroy()
end)
end)
Vous pouvez appeler BindToClose sans argument pour 'désolidariser' et revenir au comportement par défaut décrit ci-dessus. Par exemple :
pluginGui:BindToClose()
Voir aussi :
- Plugin:CreateDockWidgetPluginGui() pour créer un PluginGui
- DataModel:BindToClose() , qui peut être utilisé pour lier une fonction à la fin du jeu et ne doit pas être confondu avec cette fonction
Paramètres
La fonction à laquelle lier le bouton de fermeture. Si aucune fonction n'est spécifiée, toute fonction précédemment spécifiée sera désolidarisée.
Retours
GetRelativeMousePosition
GetRelativeMousePosition renvoie la position de la souris par rapport au coin supérieur gauche du PluginGui .La valeur retournée ne change que si une entrée de souris a commencé sur le PluginGui, ou si la souris se trouve actuellement sur la fenêtre.
Retours
La position de l'écran de la souris par rapport au PluginGui en pixels.
Échantillons de code
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()
Évènements
PluginDragDropped
PluginDragDropped se déclenche lorsque l'utilisateur relâche sa souris sur un PluginGui pendant une opération de glissement commencée par Plugin:StartDrag() .
Voir aussi :
Paramètres
Échantillons de code
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 déclenche lorsque la souris de l'utilisateur entre dans le PluginGui pendant une opération de glissement commencée par Plugin:StartDrag() .
Cet événement est utile pour afficher une interface utilisateur « Lâcher ici » sur PluginGuis où une opération de glisser peut être abandonnée.Une telle interface utilisateur doit être cachée lorsque PluginDragLeft ou PluginDragDropped lancer.
Voir aussi :
Paramètres
Une copie des données initialement transmises à Plugin:StartDrag().
Échantillons de code
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 déclenche lorsque la souris de l'utilisateur quitte un PluginGui pendant une opération de glissement commencée par Plugin:StartDrag().
Cet événement et PluginDragDropped sont utiles pour masquer une interface utilisateur "Lâcher ici" sur PluginGuis où une opération de glisser peut être abandonnée.Une telle interface utilisateur devrait être affichée lorsque des incendies PluginDragEntered se produisent.
Voir aussi :
Paramètres
Une copie des données initialement transmises à Plugin:StartDrag().
Échantillons de code
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 déclenche lorsque la souris de l'utilisateur se déplace dans un PluginGui pendant une opération de glissement commencée par Plugin:StartDrag() .
Voir aussi :
Paramètres
WindowFocusReleased
WindowFocusReleased se déclenche immédiatement lorsque l'utilisateur cesse d'interagir avec la fenêtre du PluginGui, généralement en cliquant sur quelque chose qui n'est pas dans la fenêtre.Ces fonctions fonctionnent de manière similaire à l'événement de même nom UserInputService.WindowFocusReleased.
Si la concentration se déplace vers un autre PluginGui alors que l'utilisateur avait ce PluginGui en focus, alors cet événement se déclenche avant l'événement de l'autre WindowFocused.Cependant, si la fenêtre de jeu principale est mise en évidence, cet événement se déclenche après UserInputService.WindowFocused.
Échantillons de code
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 lance immédiatement quand l'utilisateur commence à interagir avec la fenêtre du PluginGui, généralement en cliquant dessus.Ces fonctions fonctionnent de manière similaire à l'événement de même nom UserInputService.WindowFocused.Il se déclenche avant tout événement GuiObject.InputBegan lié aux boutons de souris.
Si un autre PluginGui est en focus et que l'utilisateur se concentre sur ce PluginGui, alors cet événement se déclenche après l'événement de l'autre WindowFocusReleased.Cependant, si la fenêtre principale du jeu était en focus, cet événement se déclenche après UserInputService.WindowFocusReleased .
Échantillons de code
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)