improve aseprite tile-props extension ux
This commit is contained in:
parent
5637fa18c8
commit
75948c2894
1 changed files with 153 additions and 121 deletions
|
|
@ -9,8 +9,8 @@ local function log(msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getSelectedTile()
|
local function get_selected_tile()
|
||||||
log("getSelectedTile() called")
|
log("get_selected_tile() called")
|
||||||
|
|
||||||
if not app then
|
if not app then
|
||||||
log("ERROR: app is nil!")
|
log("ERROR: app is nil!")
|
||||||
|
|
@ -49,10 +49,10 @@ local function getSelectedTile()
|
||||||
return tileset, tileIndex
|
return tileset, tileIndex
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getTileProperties(tileset, tileIndex)
|
local function get_tile_properties(tileset, tile_index)
|
||||||
log("getTileProperties() called for tile index: " .. tostring(tileIndex))
|
log("get_tile_properties() called for tile index: " .. tostring(tile_index))
|
||||||
|
|
||||||
local tile = tileset:tile(tileIndex)
|
local tile = tileset:tile(tile_index)
|
||||||
if not tile then
|
if not tile then
|
||||||
log("Could not get tile object")
|
log("Could not get tile object")
|
||||||
return {}
|
return {}
|
||||||
|
|
@ -83,10 +83,10 @@ local function getTileProperties(tileset, tileIndex)
|
||||||
return props
|
return props
|
||||||
end
|
end
|
||||||
|
|
||||||
local function setTileProperties(tileset, tileIndex, props)
|
local function set_tile_properties(tileset, tile_index, props)
|
||||||
log("setTileProperties() called for tile index: " .. tostring(tileIndex))
|
log("set_tile_properties() called for tile index: " .. tostring(tile_index))
|
||||||
|
|
||||||
local tile = tileset:tile(tileIndex)
|
local tile = tileset:tile(tile_index)
|
||||||
if not tile then
|
if not tile then
|
||||||
log("Could not get tile object")
|
log("Could not get tile object")
|
||||||
return
|
return
|
||||||
|
|
@ -109,10 +109,10 @@ local function setTileProperties(tileset, tileIndex, props)
|
||||||
log("Set " .. count .. " properties")
|
log("Set " .. count .. " properties")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function showPropertyEditor(existingProps)
|
local function show_property_editor()
|
||||||
log("showPropertyEditor() called")
|
log("show_property_editor() called")
|
||||||
|
|
||||||
local tileset, tileIndex = getSelectedTile()
|
local tileset, tile_index = get_selected_tile()
|
||||||
|
|
||||||
if not tileset then
|
if not tileset then
|
||||||
log("No tileset selected, showing alert")
|
log("No tileset selected, showing alert")
|
||||||
|
|
@ -121,131 +121,164 @@ local function showPropertyEditor(existingProps)
|
||||||
end
|
end
|
||||||
|
|
||||||
log("Getting properties for tile")
|
log("Getting properties for tile")
|
||||||
local properties = existingProps or getTileProperties(tileset, tileIndex)
|
local properties = get_tile_properties(tileset, tile_index)
|
||||||
|
|
||||||
local dlg = Dialog("Tile Properties - Tile #" .. tileIndex)
|
local function build_dialog()
|
||||||
|
local dlg = Dialog("Tile Properties - Tile #" .. tile_index)
|
||||||
|
|
||||||
dlg:label{ text="Properties:" }
|
for i, prop in ipairs(properties) do
|
||||||
|
local id_prefix = "prop_" .. i .. "_"
|
||||||
|
local prop_value = prop
|
||||||
|
|
||||||
for i, prop in ipairs(properties) do
|
dlg:separator{ id = id_prefix .. "sep" }
|
||||||
dlg:separator()
|
dlg:newrow()
|
||||||
dlg:entry{
|
|
||||||
id = "key_" .. i,
|
|
||||||
label = "Name:",
|
|
||||||
text = prop.key
|
|
||||||
}
|
|
||||||
dlg:combobox{
|
|
||||||
id = "type_" .. i,
|
|
||||||
label = "Type:",
|
|
||||||
option = prop.type,
|
|
||||||
options = { "boolean", "number", "string" },
|
|
||||||
onchange = function()
|
|
||||||
for j = 1, #properties do
|
|
||||||
properties[j].key = dlg.data["key_" .. j] or properties[j].key
|
|
||||||
local newType = dlg.data["type_" .. j] or properties[j].type
|
|
||||||
local oldType = properties[j].type
|
|
||||||
|
|
||||||
if newType ~= oldType then
|
|
||||||
if newType == "boolean" then
|
|
||||||
properties[j].value = false
|
|
||||||
elseif newType == "number" then
|
|
||||||
properties[j].value = 0
|
|
||||||
else -- string
|
|
||||||
properties[j].value = ""
|
|
||||||
end
|
|
||||||
else
|
|
||||||
properties[j].value = dlg.data["value_" .. j] or properties[j].value
|
|
||||||
end
|
|
||||||
|
|
||||||
properties[j].type = newType
|
|
||||||
end
|
|
||||||
dlg:close()
|
|
||||||
showPropertyEditor(properties)
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
if prop.type == "boolean" then
|
|
||||||
dlg:check{
|
|
||||||
id = "value_" .. i,
|
|
||||||
text = "",
|
|
||||||
selected = prop.value
|
|
||||||
}
|
|
||||||
elseif prop.type == "number" then
|
|
||||||
dlg:number{
|
|
||||||
id = "value_" .. i,
|
|
||||||
label = "Value:",
|
|
||||||
text = tostring(prop.value),
|
|
||||||
decimals = 0
|
|
||||||
}
|
|
||||||
else
|
|
||||||
dlg:entry{
|
dlg:entry{
|
||||||
id = "value_" .. i,
|
id = id_prefix .. "key",
|
||||||
label = "Value:",
|
label = "Name:",
|
||||||
text = tostring(prop.value)
|
text = prop_value.key
|
||||||
}
|
}
|
||||||
|
dlg:newrow()
|
||||||
|
|
||||||
|
dlg:combobox{
|
||||||
|
id = id_prefix .. "type",
|
||||||
|
label = "Type:",
|
||||||
|
option = prop_value.type,
|
||||||
|
options = { "boolean", "number", "string" },
|
||||||
|
onchange = function()
|
||||||
|
local new_type = dlg.data[id_prefix .. "type"]
|
||||||
|
if new_type ~= prop_value.type then
|
||||||
|
if new_type == "boolean" then
|
||||||
|
properties[i].value = false
|
||||||
|
elseif new_type == "number" then
|
||||||
|
properties[i].value = 0
|
||||||
|
else
|
||||||
|
properties[i].value = ""
|
||||||
|
end
|
||||||
|
properties[i].type = new_type
|
||||||
|
rebuild_from_dialog(dlg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
|
dlg:newrow()
|
||||||
|
|
||||||
|
if prop_value.type == "boolean" then
|
||||||
|
dlg:check{
|
||||||
|
id = id_prefix .. "value",
|
||||||
|
label = "Value:",
|
||||||
|
selected = prop_value.value
|
||||||
|
}
|
||||||
|
elseif prop_value.type == "number" then
|
||||||
|
dlg:number{
|
||||||
|
id = id_prefix .. "value",
|
||||||
|
label = "Value:",
|
||||||
|
text = tostring(prop_value.value),
|
||||||
|
decimals = 0
|
||||||
|
}
|
||||||
|
else
|
||||||
|
dlg:entry{
|
||||||
|
id = id_prefix .. "value",
|
||||||
|
label = "Value:",
|
||||||
|
text = tostring(prop_value.value)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
dlg:button{
|
||||||
|
id = id_prefix .. "delete",
|
||||||
|
text = "Delete",
|
||||||
|
onclick = function()
|
||||||
|
sync_from_dialog(dlg)
|
||||||
|
table.remove(properties, i)
|
||||||
|
rebuild_from_dialog(dlg)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
dlg:newrow()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
dlg:separator()
|
||||||
|
|
||||||
dlg:button{
|
dlg:button{
|
||||||
id = "delete_" .. i,
|
id = "add_btn",
|
||||||
text = "Delete",
|
text = "Add Property",
|
||||||
onclick = function()
|
onclick = function()
|
||||||
for j = 1, #properties do
|
sync_from_dialog(dlg)
|
||||||
properties[j].key = dlg.data["key_" .. j] or properties[j].key
|
table.insert(properties, {
|
||||||
properties[j].type = dlg.data["type_" .. j] or properties[j].type
|
key = "",
|
||||||
properties[j].value = dlg.data["value_" .. j] or properties[j].value
|
type = "string",
|
||||||
end
|
value = ""
|
||||||
table.remove(properties, i)
|
})
|
||||||
dlg:close()
|
rebuild_from_dialog(dlg)
|
||||||
showPropertyEditor(properties)
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dlg:button{
|
||||||
|
text = "Apply Changes",
|
||||||
|
onclick = function()
|
||||||
|
sync_from_dialog(dlg)
|
||||||
|
local new_props = {}
|
||||||
|
for _, prop in ipairs(properties) do
|
||||||
|
if prop.key and prop.key ~= "" then
|
||||||
|
table.insert(new_props, prop)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
set_tile_properties(tileset, tile_index, new_props)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
dlg:separator()
|
||||||
|
|
||||||
|
dlg:button{
|
||||||
|
text = "OK",
|
||||||
|
focus = true,
|
||||||
|
onclick = function()
|
||||||
|
sync_from_dialog(dlg)
|
||||||
|
local new_props = {}
|
||||||
|
for _, prop in ipairs(properties) do
|
||||||
|
if prop.key and prop.key ~= "" then
|
||||||
|
table.insert(new_props, prop)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
set_tile_properties(tileset, tile_index, new_props)
|
||||||
|
dlg:close()
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
dlg:button{ text = "Cancel" }
|
||||||
|
|
||||||
|
return dlg
|
||||||
end
|
end
|
||||||
|
|
||||||
dlg:separator()
|
function sync_from_dialog(dlg)
|
||||||
dlg:button{
|
log("sync_from_dialog() called")
|
||||||
text = "Add Property",
|
for i = 1, #properties do
|
||||||
onclick = function()
|
local id_prefix = "prop_" .. i .. "_"
|
||||||
for i = 1, #properties do
|
local data = dlg.data
|
||||||
properties[i].key = dlg.data["key_" .. i] or properties[i].key
|
|
||||||
properties[i].type = dlg.data["type_" .. i] or properties[i].type
|
log(" Property " .. i .. ":")
|
||||||
properties[i].value = dlg.data["value_" .. i] or properties[i].value
|
if data[id_prefix .. "key"] then
|
||||||
|
properties[i].key = data[id_prefix .. "key"]
|
||||||
|
log(" key = " .. tostring(properties[i].key))
|
||||||
end
|
end
|
||||||
table.insert(properties, {
|
if data[id_prefix .. "type"] then
|
||||||
key = "",
|
properties[i].type = data[id_prefix .. "type"]
|
||||||
type = "string",
|
log(" type = " .. tostring(properties[i].type))
|
||||||
value = ""
|
end
|
||||||
})
|
if data[id_prefix .. "value"] ~= nil then
|
||||||
dlg:close()
|
properties[i].value = data[id_prefix .. "value"]
|
||||||
showPropertyEditor(properties)
|
log(" value = " .. tostring(properties[i].value) .. " (type: " .. type(properties[i].value) .. ")")
|
||||||
end
|
else
|
||||||
}
|
log(" WARNING: value is nil in dialog data!")
|
||||||
|
|
||||||
dlg:separator()
|
|
||||||
dlg:button{
|
|
||||||
text = "Apply",
|
|
||||||
onclick = function()
|
|
||||||
local newProps = {}
|
|
||||||
for i = 1, #properties do
|
|
||||||
local key = dlg.data["key_" .. i]
|
|
||||||
local propType = dlg.data["type_" .. i]
|
|
||||||
local value = dlg.data["value_" .. i]
|
|
||||||
|
|
||||||
if key and key ~= "" then
|
|
||||||
table.insert(newProps, {
|
|
||||||
key = key,
|
|
||||||
type = propType,
|
|
||||||
value = value
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
setTileProperties(tileset, tileIndex, newProps)
|
|
||||||
dlg:close()
|
|
||||||
end
|
end
|
||||||
}
|
end
|
||||||
|
|
||||||
dlg:button{ text = "Cancel" }
|
function rebuild_from_dialog(old_dlg)
|
||||||
|
old_dlg:close()
|
||||||
|
local new_dlg = build_dialog()
|
||||||
|
new_dlg:show()
|
||||||
|
end
|
||||||
|
|
||||||
|
local dlg = build_dialog()
|
||||||
dlg:show()
|
dlg:show()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -255,16 +288,15 @@ function init(plugin)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- register in sprite menu
|
|
||||||
plugin:newCommand{
|
plugin:newCommand{
|
||||||
id = "TilePropertiesEditor",
|
id = "TilePropertiesEditor",
|
||||||
title = "Tile Properties",
|
title = "Tile Properties",
|
||||||
group = "sprite_properties",
|
group = "sprite_properties",
|
||||||
onenabled = function()
|
onenabled = function()
|
||||||
local tileset, tileIndex = getSelectedTile()
|
local tileset, tile_index = get_selected_tile()
|
||||||
return tileset ~= nil and tileIndex ~= nil
|
return tileset ~= nil and tile_index ~= nil
|
||||||
end,
|
end,
|
||||||
onclick = showPropertyEditor
|
onclick = show_property_editor
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue