-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvisibilityGroupsDialog.lua
106 lines (99 loc) · 2.95 KB
/
visibilityGroupsDialog.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
-- This script helps the artist to hide or show arbitrary groups of layers
if app.activeSprite == nil then
print("Error: No active sprite")
return
end
local spr = app.activeSprite
-- Global groups:
if visibilityGroups == nil then
visibilityGroups = {}
for i=1,10 , 1 do
table.insert(visibilityGroups, {})
end
end
if groupNames == nil then
groupNames = {}
for i=1,10 , 1 do
table.insert(groupNames, {})
groupNames[i] = "No name"
end
end
local show = "O"
local hide = "-"
local buttonText = {show, show, show, show}
local dlg = Dialog("Visibility")
local radioIds = {"r1", "r2", "r3", "r4"}
local buttonIds = {"b1", "b2", "b3", "b4",}
function changeGroupName(index)
dlg:modify{ id=radioIds[index],
text=dlg.data.entry }
end
function setButtonText(index, showText)
dlg:modify{ id=buttonIds[index],
text=showText }
buttonText[index] = showText
end
function buttonShowState(index)
return buttonText[index] == show
end
-- Global last active visibility group
if activeVisibilityGroupIndex == nil then
activeVisibilityGroupIndex = 1
end
-- 1
for k=1, 4, 1 do
dlg:radio{ id=radioIds[k],
text=groupNames[k],
onclick=
function()
local selectedLayers = app.range.layers
activeVisibilityGroupIndex = k
if #selectedLayers == 0 then
print("Error: no selected layers. You must select layers on the editor first.")
return
end
visibilityGroups[k] = selectedLayers
local group = visibilityGroups[k]
for i=1, #group, 1 do
group[i].isVisible = true
end
setButtonText(k, show)
app.refresh()
end }
dlg:button{ id=buttonIds[k],
text=buttonText[k],
onclick=
function()
local group = visibilityGroups[k]
if group == nil then
print("Error: first you have to Set a Layer Group")
return
end
local groupStateShowed
if buttonText[k] == "O" then
groupStateShowed = true
buttonText[k] = hide
else
groupStateShowed = false
buttonText[k] = show
end
for i=1, #group, 1 do
if group[i] ~= nil then
group[i].isVisible = not groupStateShowed
end
end
setButtonText(k, buttonText[k])
app.refresh()
end }
dlg:newrow()
dlg:separator()
end
dlg:entry{ id="entry",
text="No Name",
onchange=function()
changeGroupName(activeVisibilityGroupIndex)
app.refresh()
end }
dlg:show{
wait=false
}