PluginGui

Veraltete anzeigen

*Dieser Inhalt wurde mit KI (Beta) übersetzt und kann Fehler enthalten. Um diese Seite auf Englisch zu sehen, klicke hier.

Nicht erstellbar
Nicht repliziert

PluginGui ist eine abstrakte Klasse für GUIs, die die Anzeige von GuiObjects in verschiedenen Roblox Studio- Widgets ermöglichen.Ab sofort ist der einzige verfügbare PluginGui-Typ DockWidgetPluginGui , aber es kann in Zukunft mehr geben!

Zusammenfassung

Eigenschaften

Eigenschaften von LayerCollector übernommenEigenschaften von GuiBase2d übernommen

Methoden

Ereignisse

Ereignisse von GuiBase2d übernommen

Eigenschaften

Title

Parallel lesen

Der Titel, der über den Inhalten der PluginGui angezeigt wird. Standard ist leerer String.

Methoden

BindToClose

()

Diese Funktion bindet eine Funktion an die Schaltfläche "Schließen" PluginGui, die das Standardverhalten überschreitet.

Standardmäßig, wenn der Benutzer auf die Schaltfläche 'x' in der oberen rechten Ecke des PluginGui klickt, wird die Eigenschaft Enabled auf falsch gesetzt, wodurch das Fenster geschlossen wird.Wenn eine benutzerdefinierte Funktion mit BindToClose gebunden wird, wird dieses Verhalten überschrieben, so dass Sie überprüfen können, ob der Benutzer wirklich das Fenster schließen oder ihm die Möglichkeit geben möchte, seine Arbeit zu speichern.

Da das Standard-Schließverhalten durch diese Funktion überschrieben wird, musst du die PluginGui so konfigurieren, dass sie manuell geschlossen wird, indem du PluginGui.Enabled auf falsch festlegst.Zum Beispiel müssen Benutzer in dem folgenden Snippet einen Bestätigungsknopf anklicken, um die grafische Benutzeroberflächezu schließen:


local closing = false
pluginGui:BindToClose(function()
-- stellen sie sicher, dass wir noch keinen button gemacht haben
if closing then
return
end
closing = true
-- bestätigungs-button erstellen
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
-- auf klickenhören
confirmButton.Activated:Connect(function()
-- schließe das gui
pluginGui.Enabled = false
-- bestätigungs-button entfernen
confirmButton:Destroy()
end)
end)

Du kannst BindToClose ohne Argument aufrufen, um "zu entfernen" und zum beschriebenen Standardverhalten zurückzukehren. Zum Beispiel:


pluginGui:BindToClose()

Siehe auch:

Parameter

function: function

Die Funktion, an die der Schließen-Button gebunden wird. Wenn keine Funktion angegeben wird, wird jede zuvor angegebene Funktion aufgelöst.

Standardwert: "nil"

Rückgaben

()

GetRelativeMousePosition

Plugin-Sicherheit

GetRelativeMousePosition gibt die Position der Maus im Verhältnis zur oberen linken Ecke des PluginGui zurück.Der zurückgegebene Wert ändert sich nur, wenn eine Maus-Eingabe auf dem PluginGui beginnt oder die Maus derzeit über dem Fenster schwebt.


Rückgaben

Die Bildschirmposition der Maus im Verhältnis zum PluginGui in Pixeln.

Code-Beispiele

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

Ereignisse

PluginDragDropped

Plugin-Sicherheit

PluginDragDropped feuert ab, wenn der Benutzer seine Maus über einen PluginGui während einer Drag-Operation freigibt, die von Plugin:StartDrag() gestartet wurde.

Siehe auch:

Parameter

dragData: Dictionary

Code-Beispiele

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

Plugin-Sicherheit

PluginDragEntered feuert ab, wenn die Maus des Benutzers während einer Drag-Operation von PluginGui in Plugin:StartDrag() eintreibt.

Dieses Ereignis ist nützlich für die Anzeige einer "Hier ablegen"-Benutzeroberfläche auf PluginGuis, wo eine Drag-Operation abgeworfen werden kann.Solche UI sollte versteckt werden, wenn entweder PluginDragLeft oder PluginDragDropped initiieren.

Siehe auch:

Parameter

dragData: Dictionary

Eine Kopie der Daten, die ursprünglich an Plugin:StartDrag() übermittelt wurden.


Code-Beispiele

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

Plugin-Sicherheit

PluginDragLeft feuert ab, wenn die Maus des Benutzers während einer Drag-Operation von PluginGui verlässt, die von Plugin:StartDrag() gestartet wurde.

Dieses Ereignis und PluginDragDropped sind nützlich, um eine "Drop Here"-Benutzeroberfläche auf PluginGuis auszublenden, wo eine Drag-Operation abgeworfen werden kann.Eine solche Benutzeroberfläche sollte angezeigt werden, wenn entweder PluginDragEntered Feuer ausbrechen.

Siehe auch:

Parameter

dragData: Dictionary

Eine Kopie der Daten, die ursprünglich an Plugin:StartDrag() übermittelt wurden.


Code-Beispiele

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

Plugin-Sicherheit

PluginDragMoved feuert ab, wenn die Maus des Benutzers innerhalb von PluginGui während einer Drag-Operation von Plugin:StartDrag() bewegt wird.

Siehe auch:

Parameter

dragData: Dictionary

WindowFocusReleased

Plugin-Sicherheit

WindowFocusReleased feuert sofort ab, wenn der Benutzer aufhört, mit dem Fenster des PluginGui zu interagieren, normalerweise durch Klicken auf etwas, das nicht im Fenster ist.Diese Funktionen funktionieren ähnlich wie das mit ähnlichem Namen benannte UserInputService.WindowFocusReleased.

Wenn sich der Fokus auf ein anderes bewegt, während der Benutzer dieses PluginGui im Fokus hatte, dann wird dieses Ereignis vor dem Ereignis des anderen ausgelöst.Wenn jedoch das Hauptspielfenster in den Fokus gerückt wird, feuert dieses Ereignis nach UserInputService.WindowFocused .


Code-Beispiele

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

Plugin-Sicherheit

Fensterfokussiert feuert sofort ab, wenn der Benutzer mit dem Fenster des PluginGui interagiert, normalerweise durch Klicken darauf.Diese Funktionen funktionieren ähnlich wie das mit ähnlichem Namen benannte UserInputService.WindowFocused.Es feuert vor allen GuiObject.InputBegan Ereignissen, die sich auf Mausknöpfe beziehen.

Wenn ein anderes PluginGui im Fokus steht und der Benutzer dieses PluginGui fokussiert, dann wird dieses Ereignis nach dem Ereignis des anderen WindowFocusReleased abgefeuert.Wenn jedoch das Hauptspielfenster im Fokus war, feuert dieses Ereignis nach UserInputService.WindowFocusReleased ab.


Code-Beispiele

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)