How make preview field in custom editor script? For example, preview-field automatically updates when name-field changed.
here’s my script, available at Assets Tab → Right Mouse Click → Create New Map
local M = {}
function M.get_commands()
return {
{
label = "Create New Map",
locations = {"Assets"},
run = function()
local filepath = ""
local cell_w = 32
local cell_h = 16
local map_w = 16
local map_h = 16
local result = editor.ui.show_dialog(editor.ui.dialog({
title = "Create New Map",
content = editor.ui.grid({
padding = editor.ui.PADDING.LARGE,
columns = {{}, {grow = true}},
children = {
-- filepath
{
editor.ui.label({
text = "Filepath",
alignment = editor.ui.ALIGNMENT.RIGHT
}),
editor.ui.string_field({
text = filepath,
on_value_changed = function(new_value)
filepath = new_value
end
})
},
-- cell width
{
editor.ui.label({
text = "Cell Width",
alignment = editor.ui.ALIGNMENT.RIGHT
}),
editor.ui.integer_field({
value = cell_w,
on_value_changed = function(new_value)
cell_w = new_value
end
})
},
-- cell height
{
editor.ui.label({
text = "Cell Height",
alignment = editor.ui.ALIGNMENT.RIGHT
}),
editor.ui.integer_field({
value = cell_h,
on_value_changed = function(new_value)
cell_h = new_value
end
})
},
-- map width
{
editor.ui.label({
text = "Map Width",
alignment = editor.ui.ALIGNMENT.RIGHT
}),
editor.ui.integer_field({
value = map_w,
on_value_changed = function(new_value)
map_w = new_value
end
})
},
-- map height
{
editor.ui.label({
text = "Map Height",
alignment = editor.ui.ALIGNMENT.RIGHT
}),
editor.ui.integer_field({
value = map_h,
on_value_changed = function(new_value)
map_h = new_value
end
})
},
-- preview
{
editor.ui.label({
text = "Preview",
alignment = editor.ui.ALIGNMENT.RIGHT,
}),
editor.ui.string_field({
enabled = false,
})
}
}
}),
buttons = {
editor.ui.dialog_button({
text = "Cancel",
cancel = true,
result = false
}),
editor.ui.dialog_button({
text = "Create",
default = true,
result = true
})
}
}))
-- finally
if result then
print(map_w, map_h, cell_w, cell_h, filepath)
end
end
}
}
end
return M