PluginGui

Afficher les obsolètes

*Ce contenu est traduit en utilisant l'IA (Beta) et peut contenir des erreurs. Pour consulter cette page en anglais, clique ici.

Création impossible
Non répliqué

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

Propriétés hérités de LayerCollectorPropriétés hérités de GuiBase2d

Méthodes

Évènements

Évènements hérités de GuiBase2d

Propriétés

Title

Lecture parallèle

Le titre qui est affiché au-dessus du contenu du PluginGui . Par défaut, il s'agit d'une chaîne vide.

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 :

Paramètres

function: function

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.

Valeur par défaut : "nil"

Retours

()

GetRelativeMousePosition

Sécurité des plugins

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

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

Évènements

PluginDragDropped

Sécurité des plugins

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

dragData: Dictionary

É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".

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

Sécurité des plugins

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

dragData: Dictionary

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".

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

Sécurité des plugins

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

dragData: Dictionary

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".

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

Sécurité des plugins

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

dragData: Dictionary

WindowFocusReleased

Sécurité des plugins

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.

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

Sécurité des plugins

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.

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)