PluginGui

Tampilkan yang Tidak Digunakan Lagi

*Konten ini diterjemahkan menggunakan AI (Beta) dan mungkin mengandung kesalahan. Untuk melihat halaman ini dalam bahasa Inggris, klik di sini.

Tidak Dapat Dibuat
Tidak Direplikasi

PluginGui adalah kelas abstrak untuk GUI yang memungkinkan tampilan GuiObjects di berbagai widget Roblox Studio.Saat ini, satu-satunya jenis PluginGui yang tersedia adalah DockWidgetPluginGui , tetapi mungkin ada lebih banyak di masa depan!

Rangkuman

Properti

Properti diwarisi dari LayerCollectorProperti diwarisi dari GuiBase2d

Metode

Acara

Acara diwarisi dari GuiBase2d

Properti

Title

Baca Paralel

Judul yang ditampilkan di atas konten dari PluginGui . Nilai default ke string kosong.

Metode

BindToClose

()

Fungsi ini mengikat fungsi ke tombol tutup PluginGui, menggantikan perilaku default.

Secara default, ketika pengguna mengklik tombol 'x' di pojok kanan atas dari PluginGui properti Enabled diatur ke false , menutup jendela.Ketika fungsi khusus terikat menggunakan BindToClose perilaku ini ditulis ulang, memungkinkan Anda untuk memeriksa apakah pengguna benar-benar ingin menutup jendela atau memberi mereka kesempatan untuk menyimpan pekerjaan mereka.

Karena perilaku penutupan default ditulis ulang oleh fungsi ini, Anda perlu mengonfigurasi PluginGui untuk ditutup secara manual dengan mengatur PluginGui.Enabled ke false.Sebagai contoh, dalam potongan kode di bawah ini pengguna diminta untuk mengklik tombol konfirmasi untuk menutup GUI:


local closing = false
pluginGui:BindToClose(function()
-- pastikan kita belum membuat tombol
if closing then
return
end
closing = true
-- buat tombol konfirmasi
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
-- dengarkan untuk klik
confirmButton.Activated:Connect(function()
-- tutup gui
pluginGui.Enabled = false
-- hapus tombol konfirmasi
confirmButton:Destroy()
end)
end)

Anda dapat memanggil BindToClose tanpa argumen untuk 'membatalkan' dan kembali ke perilaku default yang dijelaskan di atas. Misalnya:


pluginGui:BindToClose()

Lihat juga:

Parameter

function: function

Fungsi untuk mengikat tombol tutup ke. Jika tidak ada fungsi yang ditentukan maka fungsi yang sebelumnya ditentukan akan dibatalkan.

Nilai Default: "nil"

Memberikan nilai

()

GetRelativeMousePosition

Keamanan Plugin

GetRelativeMousePosition mengembalikan posisi mouse relatif ke sudut kiri atas dari PluginGui .Nilai yang dikembalikan berubah hanya jika input mouse dimulai di PluginGui, atau jika mouse saat ini berada di atas jendela.


Memberikan nilai

Posisi layar mouse terhadap PluginGui dalam piksel.

Contoh Kode

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

Acara

PluginDragDropped

Keamanan Plugin

PluginDragDropped terbakar saat pengguna melepaskan mouse mereka di atas PluginGui selama operasi seret dimulai oleh Plugin:StartDrag() .

Lihat juga:

Parameter

dragData: Dictionary

Contoh Kode

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

Keamanan Plugin

PluginDragEntered terbakar saat mouse pengguna memasuki PluginGui selama operasi seret dimulai oleh Plugin:StartDrag() .

Acara ini berguna untuk menampilkan UI "Drop Here" di PluginGuis di mana operasi seret dapat dilepaskan.UI seperti itu harus disembunyikan saat PluginDragLeft atau PluginDragDropped terbakar.

Lihat juga:

Parameter

dragData: Dictionary

Salinan data awalnya dikirim ke Plugin:StartDrag() .


Contoh Kode

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

Keamanan Plugin

PluginDragLeft terbakar saat mouse pengguna meninggalkan PluginGui selama operasi seret dimulai oleh Plugin:StartDrag() .

Peristiwa ini dan PluginDragDropped berguna untuk menyembunyikan UI "Drop Here" di PluginGuis di mana operasi seret dapat dilepaskan.UI seperti itu harus ditampilkan saat PluginDragEntered terjadi.

Lihat juga:

Parameter

dragData: Dictionary

Salinan data awalnya dikirim ke Plugin:StartDrag() .


Contoh Kode

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

Keamanan Plugin

PluginDragMoved terbakar saat mouse pengguna bergerak di dalam PluginGui selama operasi seret dimulai oleh Plugin:StartDrag() .

Lihat juga:

Parameter

dragData: Dictionary

WindowFocusReleased

Keamanan Plugin

WindowFocusReleased langsung terbakar saat pengguna berhenti berinteraksi dengan jendela PluginGui, biasanya dengan mengklik sesuatu yang tidak ada di jendela.Fungsi ini berfungsi serupa dengan peristiwa berjudul serupa UserInputService.WindowFocusReleased .

Jika fokus bergeser ke yang lain PluginGui sementara pengguna memiliki PluginGui ini dalam fokus, maka peristiwa ini terjadi sebelum peristiwa lainnya WindowFocused .Namun, jika jendela permainan utama dibawa ke fokus, acara ini menembak setelah .


Contoh Kode

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

Keamanan Plugin

Fokus Jendela langsung terbakar saat pengguna mulai berinteraksi dengan jendela PluginGui, biasanya dengan mengkliknya.Fungsi ini berfungsi serupa dengan peristiwa berjudul serupa UserInputService.WindowFocused .Ini menembak sebelum setiap peristiwa GuiObject.InputBegan terkait tombol mouse.

Jika lain PluginGui berada dalam fokus dan pengguna memfokuskan PluginGui ini, maka peristiwa ini terjadi setelah peristiwa lain WindowFocusReleased .Namun, jika jendela permainan utama berfokus, acara ini menembak setelah UserInputService.WindowFocusReleased .


Contoh Kode

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)