Skip to content

Commit 102a0c2

Browse files
committed
Added dialogs
1 parent 62b7ee0 commit 102a0c2

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

editor-script-atlas/atlas.editor_script

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,36 @@ local function get_atlas(opts)
2929
end
3030

3131

32+
local dialog = editor.ui.component(function(props)
33+
local name, set_name = editor.ui.use_state("")
34+
35+
return editor.ui.dialog({
36+
title= props.title,
37+
content = editor.ui.vertical({
38+
padding = editor.ui.PADDING_LARGE,
39+
children = {
40+
editor.ui.string_field({
41+
value = name,
42+
on_value_changed = set_name
43+
})
44+
}
45+
}),
46+
buttons = {
47+
editor.ui.dialog_button({
48+
text = "Cancel",
49+
cancel = true
50+
}),
51+
editor.ui.dialog_button({
52+
text = "Add",
53+
enabled = name ~= "",
54+
defualt = true,
55+
result = name
56+
}),
57+
}
58+
})
59+
end)
60+
61+
3262
local function update_atlas(atlas, new_images_string)
3363
-- Get the old atlas text then add our new string to the beginning.
3464
-- While the editor would add them to the end, it's a lot easier for
@@ -97,7 +127,12 @@ end
97127

98128

99129
local function add_images_as_animation(opts)
100-
local animation_start_string = "animations {\ id: \"" .. "anim_" .. os.date("%Y%m%d%H%M%S") .. "\"\n"
130+
local animation_name = editor.ui.show_dialog(dialog({ title = "Add images as animation" }))
131+
if animation_name == nil then
132+
return
133+
end
134+
135+
local animation_start_string = "animations {\ id: \"" .. animation_name .. "\"\n"
101136
local animation_end_string = " playback: PLAYBACK_LOOP_FORWARD\n fps: 60\n flip_horizontal: 0 \nflip_vertical: 0\n}\n"
102137
local images = image_strings(opts, 4)
103138

@@ -117,8 +152,13 @@ end
117152

118153

119154
local function add_images_to_new_atlas(opts)
155+
local atlas_name = editor.ui.show_dialog(dialog({ title = "Create a new atlas" }))
156+
if atlas_name == nil then
157+
return
158+
end
159+
120160
local base_path = path_segments(editor.get(opts.selection[1], "path"))
121-
local atlas = base_path .. "ATLAS" .. os.date("%Y%m%d%H%M%S") .. ".atlas"
161+
local atlas = base_path .. atlas_name .. ".atlas"
122162
local atlas_string = ""
123163
for _, id in pairs(opts.selection) do
124164
local path = editor.get(id, "path")

0 commit comments

Comments
 (0)