Lua 関数の MessageBox は、メッセージボックスを作成するために用いられます。単純なものから、多くのオプションやユーザ入力を持つ複雑なものまで、さまざまな情報ポップアップを作成できます。
この関数は、入力引数として1つのテーブルを指定します。このテーブルによって、メッセージボックスに表示する複数の要素を定義できます。
メッセージボックス内の要素は、アルファベット順に表示されます。
この関数は、ユーザ・インターフェース機能の一部です。
テーブルには、上述の要素の一部またはすべてを含めることができます。
上述の色は、カラーテーマ で定義されている UI Colors の文字列や数値で指定できます(例: "Global.Text" または 1.27)。
メッセージボックスには、少なくとも title、message、および timeout やいくつかの基本的なコマンドボタンが必要です。以下の最初の3例を参照してください。
メッセージボックスに、inputs、states、selectors がないにもかかわらず、スクリプトがテーブル要素を使おうとすると、エラーが送出されます。
結果の抽出方法については、例を参照してください。
以下は、メッセージボックスのさまざまな要素を示す6つの例です。要素は組み合わせることができますが、例では機能の違いを強調しています。
1つの確認ボタンを表示する単純なメッセージボックスです。
return function ()
-- This creates a small pop-up with a single button.
local returnTable = MessageBox(
{
title = "Please confirm This",
commands = {{value = 1, name = "Confirm"}}
}
)
-- Print the content of the returned table.
Printf("Success = "..tostring(returnTable.success))
Printf("Result = "..returnTable.result)
end
この例では、いくつかのテキストと2つのコマンドボタンを含むポップアップが開きます。
return function ()
-- A table with two default buttons for the pop-up
local defaultCommandButtons = {
{value = 2, name = "OK"},
{value = 1, name = "Cancel"}
}
-- A table with the elements needed for the pop-up
local messageTable = {
icon = "object_smart",
backColor = "Window.Plugins",
title = "This is the title",
message = "This is a message\nThat can have multiple lines",
commands = defaultCommandButtons,
}
-- The creation on the actual pop-up with the result stored in a variable
local returnTable = MessageBox(messageTable)
-- Print the content of the returned table
Printf("Success = "..tostring(returnTable.success))
Printf("Result = "..returnTable.result)
end
この例では、メッセージボックスを3秒間表示した後、自動的に閉じます。
return function ()
-- This variable contains the table used as argument for the messagebox
local messageTable = {
title = "Do not worry",
message = "This message will self destruct - Goodbye!",
timeout = 3000,
timeoutResultCancel = false,
timeoutResultID = 99,
}
-- This creates the messagebox pop-up and store the return table in a variable
local returnTable = MessageBox(messageTable)
-- Print the content of the returned table
Printf("Success = "..tostring(returnTable.success))
Printf("Result = "..returnTable.result)
end
この例では、メッセージボックスに状態ボタンを追加します。分かりやすいように、ボタンはテーブルとして追加しています。
return function ()
-- A table with two default buttons for the pop-up
local defaultCommandButtons = {
{value = 2, name = "OK"},
{value = 1, name = "Cancel"}
}
-- A table with three state buttons
-- The buttons will be displayed alphabetically in the pop-up
local stateButtons = {
{name = "State B", state = false},
{name = "State A", state = false},
{name = "New State", state = false}
}
-- A table with the elements needed for the pop-up
local messageTable = {
icon = "object_smart",
backColor = "Window.Plugins",
title = "This is state buttons",
message = 'Toggle the states and click "Ok"',
commands = defaultCommandButtons,
states = stateButtons,
}
-- The creation on the actual pop-up with the result stored in a variable
local returnTable = MessageBox(messageTable)
-- Print the content of the returned table
Printf("Success = "..tostring(returnTable.success))
Printf("Result = "..returnTable.result)
-- Print a list with the state of the stateButtons
for name,state in pairs(returnTable.states) do
Printf("State '%s' = '%s'",name,tostring(state))
end
end
この例では、入力欄を表示しています。
return function ()
-- A table with two default buttons for the pop-up
local defaultCommandButtons = {
{value = 2, name = "OK"},
{value = 1, name = "Cancel"}
}
-- A table with three input fields
-- The fields will be displayed alphabetically in the pop-up based on name
local inputFields = {
{name = "Numbers Only", value = "1234", whiteFilter = "0123456789", vkPlugin = "NumericInput"},
{name = "Text Only", value = "abcdef", blackFilter = "0123456789"},
{name = "Maximum 10 characters", value = "", maxTextLength = 10}
}
-- Possible vkPlugin values:
-- - "TextInput" : same as default - standard on-screen keyboard
-- - "TextInputNumOnly" : text input but only with number buttons
-- - "TextInputNumOnlyRange" : text input but only with number and related range buttons
-- - "TextInputTimeOnly" : text input styled for time input - includes buttons for time values
-- - "NumericInput" : general number input
-- - "CueNumberInput" : number input styled for cue number
-- - "RelCueNumberInput" : number input with the relative "delta" button
-- - "IP4Prefix" : designed for inputting an IPv4 address allowing CIDR notation
-- A table with the elements needed for the pop-up
local messageTable = {
icon = "object_smart",
backColor = "Window.Plugins",
title = "This is input fields",
message = 'Change the values in the input fields and click "Ok"',
commands = defaultCommandButtons,
inputs = inputFields,
}
-- The creation on the actual pop-up with the result stored in a variable
local returnTable = MessageBox(messageTable)
-- Print the content of the returned table
Printf("Success = "..tostring(returnTable.success))
Printf("Result = "..returnTable.result)
-- Print a list with the values of the input fields
for name,value in pairs(returnTable.inputs) do
Printf("Input '%s' = '%s'",name,tostring(value))
end
end
この例では、さまざまなセレクタボタンを表示しています。
return function ()
-- A table with two default buttons for the pop-up
local defaultCommandButtons = {
{value = 2, name = "OK"},
{value = 1, name = "Cancel"}
}
-- A table with selector buttons
-- The buttons will be displayed alphabetically in the pop-up based on name
local selectorButtons = {
{ name="Swipe Selector", selectedValue=1, type=0, values={["Swipe1"]=1,["Swipe2"]=2}},
{ name="Radio Selector", selectedValue=2, type=1, values={["Radio1"]=1,["Radio2"]=2}},
{ name="Another Radio", selectedValue=3, type=1, values={["Radio3"]=3,["Radio4"]=4}}
}
-- State button to show grouping with swipe Selector button
local stateButton = {
{name = "State Button", state = false},
}
-- A table with the elements needed for the pop-up
local messageTable = {
icon = "object_smart",
backColor = "Window.Plugins",
title = "This is input fields",
message = 'Change the values in the input fields and click "Ok"',
commands = defaultCommandButtons,
states = stateButton,
selectors = selectorButtons,
}
-- The creation on the actual pop-up with the result stored in a variable
local returnTable = MessageBox(messageTable)
-- Print the content of the returned table
Printf("Success = "..tostring(returnTable.success))
Printf("Result = "..returnTable.result)
-- Print a list with the values of the selection buttons
for name,value in pairs(returnTable.selectors) do
Printf("Input '%s' = '%s'",name,tostring(value))
end
-- Print a list with the state of the stateButton
for name,state in pairs(returnTable.states) do
Printf("State '%s' = '%s'",name,tostring(state))
end
end