PluginGui

Visualizza obsoleti

*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.

Non costruibile
Non Replicato

PluginGui è una classe astratta per le interfacce grafiche che consentono la visualizzazione di GuiObjects in vari widget di Roblox Studio.Al momento, l'unico tipo di PluginGui disponibile è DockWidgetPluginGui, ma potrebbero esserci più in futuro!

Sommario

Proprietà

Proprietà provenienti da LayerCollectorProprietà provenienti da GuiBase2d

Metodi

Eventi

Eventi provenienti da GuiBase2d

Proprietà

Title

Lettura Parallela

Il titolo che viene visualizzato sopra i contenuti del PluginGui . Si presta a vuoto.

Metodi

BindToClose

()

Questa funzione lega una funzione al pulsante di chiusura PluginGui, sostituendo il comportamento predefinito.

Per impostazione predefinita, quando l'utente fa clic sul pulsante 'x' nell'angolo in alto a destra del PluginGui la proprietà Enabled è impostata su falso , chiudendo la finestra.Quando una funzione personalizzata viene legata utilizzando BindToClose questo comportamento viene sovrascritto, consentendoti di controllare se l'utente vuole davvero chiudere la finestra o dare loro l'opportunità di salvare il loro lavoro.

Poiché il comportamento di chiusura predefinito viene sovrascritto da questa funzione, dovrai configurare il PluginGui per chiudere manualmente impostando PluginGui.Enabled su falso .Ad esempio, nel seguente snippet gli utenti sono tenuti a fare clic su un pulsante di conferma per chiudere l'GUI or Intefaccia grafica utentegrafica:


local closing = false
pluginGui:BindToClose(function()
-- assicurati che non abbiamo già creato un pulsante
if closing then
return
end
closing = true
-- crea pulsante di conferma
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
-- ascolta per clic
confirmButton.Activated:Connect(function()
-- chiudi la gui
pluginGui.Enabled = false
-- rimuovi il pulsante di conferma
confirmButton:Destroy()
end)
end)

Puoi chiamare BindToClose senza argomento per "dislegare" e tornare al comportamento predefinito descritto sopra. Ad esempio:


pluginGui:BindToClose()

Vedi anche:

Parametri

function: function

La funzione a cui associare il pulsante di chiusura. Se non viene specificata alcuna funzione, verrà dis associata qualsiasi funzione precedentemente specificata.

Valore predefinito: "nil"

Restituzioni

()

GetRelativeMousePosition

Sicurezza Plugin

GetRelativeMousePosition restituisce la posizione del mouse rispetto all'angolo superiore sinistro del PluginGui .Il valore restituito cambia solo se un input del mouse è iniziato sul PluginGui, o se il mouse è attualmente in movimento sopra la finestra.


Restituzioni

La posizione dello schermo del mouse rispetto al PluginGui in pixel.

Campioni di codice

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

Eventi

PluginDragDropped

Sicurezza Plugin

PluginDragDropped brucia quando l'utente rilascia il mouse su un PluginGui durante un'operazione di trascinamento iniziata da Plugin:StartDrag() .

Vedi anche:

Parametri

dragData: Dictionary

Campioni di codice

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

Sicurezza Plugin

PluginDragEntered si accende quando il mouse dell'utente entra nel PluginGui durante un'operazione di trascinamento iniziata da Plugin:StartDrag() .

Questo evento è utile per visualizzare un'interfaccia utente "Drop Here" su PluginGuis dove un'operazione di trascinamento può essere rilasciata.Un'interfaccia utente del genere dovrebbe essere nascosta quando si attiva PluginDragLeft o PluginDragDropped Lanciare.

Vedi anche:

Parametri

dragData: Dictionary

Una copia dei dati originariamente inviati a Plugin:StartDrag() .


Campioni di codice

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

Sicurezza Plugin

PluginDragLeft si attiva quando il mouse dell'utente lascia un PluginGui durante un'operazione di trascinamento iniziata da Plugin:StartDrag() .

Questo evento e PluginDragDropped sono utili per nascondere un'interfaccia utente "Drop Here" su PluginGuis dove un'operazione di trascinamento può essere rilasciata.Un'interfaccia utente del genere dovrebbe essere mostrata quando si attiva PluginDragEntered un incendio.

Vedi anche:

Parametri

dragData: Dictionary

Una copia dei dati originariamente inviati a Plugin:StartDrag() .


Campioni di codice

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

Sicurezza Plugin

PluginDragMoved si accende quando il mouse dell'utente si muove all'interno di un PluginGui durante un'operazione di trascinamento iniziata da Plugin:StartDrag() .

Vedi anche:

Parametri

dragData: Dictionary

WindowFocusReleased

Sicurezza Plugin

WindowFocusReleased brucia immediatamente quando l'utente smette di interagire con la finestra del PluginGui, di solito facendo clic su qualcosa che non è nella finestra.Queste funzioni funzionano in modo simile all'evento di nome simile UserInputService.WindowFocusReleased .

Se il focus si sposta su un altro PluginGui mentre l'utente aveva questo PluginGui in focus, allora questo evento si attiva prima dell'evento dell'altro WindowFocused.Tuttavia, se la finestra principale del gioco viene messa in primo piano, questo evento viene attivato dopo UserInputService.WindowFocused.


Campioni di codice

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

Sicurezza Plugin

WindowFocused brucia immediatamente quando l'utente inizia a interagire con la finestra del PluginGui, di solito facendo clic su di essa.Queste funzioni funzionano in modo simile all'evento di nome simile UserInputService.WindowFocused .Si attiva prima di qualsiasi evento GuiObject.InputBegan relativo ai pulsanti del mouse.

Se un altro PluginGui è in primo piano e l'utente si concentra su questo PluginGui, l'evento si attiva dopo l'evento dell'altro WindowFocusReleased.Tuttavia, se la finestra principale del gioco era in primo piano, questo evento si attiva dopo UserInputService.WindowFocusReleased .


Campioni di codice

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)