-
Notifications
You must be signed in to change notification settings - Fork 5
/
Layer2SpriteSheet.jsx
1764 lines (1520 loc) · 71 KB
/
Layer2SpriteSheet.jsx
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2007. Adobe Systems, Incorporated. All rights reserved.
// This script will export each layer in the document to a separate file.
// Written by Naoki Hada
// ZStrings and auto layout by Tom Ruark
/*
@@@BUILDINFO@@@ Export Layers to Sprite Sheet.jsx 1.0.0.16
*/
/*
// BEGIN__HARVEST_EXCEPTION_ZSTRING
<javascriptresource>
<name>$$$/JavaScripts/ExportLayersToSpriteSheet/Menu=Export Layers to Sprite Sheet...</name>
<category>layers</category>
<enableinfo>true</enableinfo>
<eventid>f42ac2d5-da04-47d5-9ece-62283ca65029</eventid>
<terminology><![CDATA[<< /Version 1
/Events <<
/f42ac2d5-da04-47d5-9ece-62283ca65029 [($$$/JavaScripts/ExportLayersToSpriteSheet/Action=Export Layers to Sprite Sheet) /noDirectParam <<
/message [($$$/Actions/Key/Message=Message) /char]
/destination [($$$/Actions/Key/Destination=Destination) /char]
/visibleOnly [($$$/Actions/Key/CompsObject/UseVisibility=Visibility) /boolean]
/format [($$$/Actions/Key/Format=Output Format) /integer]
/mode [($$$/Actions/Key/Mode=Packing Mode) /integer]
/reverse [($$$/Actions/Key/Reverse=Reverse Array) /boolean]
/pot [($$$/Actions/Key/POT=Power of Two) /boolean]
/rotate [($$$/Actions/Key/Rotate=Allow Rotation) /boolean]
/max_size [($$$/Actions/Key/MaxSize=Is Maximum Size) /boolean]
/pretty [($$$/Actions/Key/Pretty=Use Indentation) /boolean]
/hard_tabs [($$$/Actions/Key/HardTabs=Use Tabs) /boolean]
/indentation [($$$/Actions/Key/Indentation=Number of Spaces) /integer]
/width [($$$/Actions/Key/Width=Atlas Width) /char]
/height [($$$/Actions/Key/Height=Atlas Height) /char]
/padding [($$$/Actions/Key/Padding=Padding) /char]
/fileType [($$$/Actions/Key/FileType=File Type) /integer]
/icc [($$$/Actions/Key/PDFGenericFormat/KeepProfile=Keep Profile) /boolean]
/jpegQuality [($$$/Actions/Key/JPEGQuality=JPEG Quality) /char]
/psdMaxComp [($$$/Actions/Key/MaximizePSDCompatibility=maximize compatibility for Photoshop files) /boolean]
/tiffCompression [($$$/Actions/Key/TiffCompression=TIFF encoding) /char]
/tiffJpegQuality [($$$/Actions/Key/TIFFJPEGQuality=TIFF JPEG Quality) /char]
/pdfEncoding [($$$/Actions/Key/PDFEncoding=PDF encoding) /char]
/pdfJpegQuality [($$$/Actions/Key/PDFJPEGQuality=PDF JPEG Quality) /char]
/targaDepth [($$$/Actions/Key/Depth/TargaDepth=Targa depth) /char]
/bmpDepth [($$$/Actions/Key/Depth/BMPDepth=BMP depth) /char]
/png24Transparency [($$$/Actions/Key/Layer/PNG24PreserveTransparency=PNG 24 Preserve Transparency) /boolean]
/png24Interlaced [($$$/Actions/Key/Layer/PNG24Interlaced=PNG 24 Interlaced) /boolean]
/trim [($$$/Actions/Key/Trim=Trim the Layers) /boolean]
/png8Transparency [($$$/Actions/Key/Layer/PNG8PreserveTransparency=PNG 8 Preserve Transparency) /boolean]
/png8Interlaced [($$$/Actions/Key/Layer/PNG8Interlaced=PNG 8 Interlaced) /boolean]
>>]
>>
>> ]]></terminology>
</javascriptresource>
// END__HARVEST_EXCEPTION_ZSTRING
*/
// enable double clicking from the Macintosh Finder or the Windows Explorer
#target photoshop
var window = {};
#include "include/json2.js"
#include "include/texpack.js"
for (var p in window) this[p] = window[p];
delete window;
// debug level: 0-2 (0:disable, 1:break on error, 2:break at beginning)
// $.level = 0;
// debugger; // launch debugger on next line
// on localized builds we pull the $$$/Strings from a .dat file, see documentation for more details
$.localize = true;
//=================================================================
// Globals
//=================================================================
// UI strings to be localized
var strTitle = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Title=Export Layers to Sprite Sheet");
var strButtonRun = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Run=Run");
var strButtonCancel = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Cancel=Cancel");
var strHelpText = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Help=Please specify the format and location for saving each layer as a sprite sheet.");
var strLabelDestination = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Destination=Destination:");
var strLabelPadding = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Padding=Padding");
var strButtonBrowse = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Browse=&Browse...");
var strCheckboxVisibleOnly = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/VisibleOnly=&Visible Layers Only");
var strLabelPacking = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Packing=Packing:");
var strLabelFormat = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Format=Output Format:");
var strLabelTexture = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Texture=Texture:");
var strLabelHash = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Hash=Hash");
var strLabelArray = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Array=Array");
var strLabelReverse = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Reverse=Reverse Order");
var strLabelPretty = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Pretty=Add Indentation");
var strLabelAlgorithm = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Algorithm=Algorithm:");
var strddAlgorithm = localize( "$$$/locale_specific/JavaScripts/ExportLayersToSpriteSheet/DDAlgorithm=100" );
var strCheckboxPOT = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/POT=&Power of Two");
var strCheckboxMaxSize = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/MaxSize=&Is Maximum");
var strCheckboxRotate = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Rotate=&Allow Rotation");
var strLabelSpaces = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Spaces=Spaces");
var strLabelTabs = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Tabs=Tabs");
var strLabelTextureWidth = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/TextureWidth=Width");
var strLabelTextureHeight = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/TextureHeight=Height");
var stretTextureSize = localize( "$$$/locale_specific/JavaScripts/ExportLayersToSpriteSheet/ETTextureSize=50" );
var stretIndentation = localize( "$$$/locale_specific/JavaScripts/ExportLayersToSpriteSheet/ETIndentation=50" );
var strLabelFileType = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/FileType=File Type:");
var strCheckboxIncludeICCProfile = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/IncludeICC=&Include ICC Profile");
var strJPEGOptions = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/JPEGOptions=JPEG Options:");
var strLabelQuality = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Quality=Quality:");
var strPSDOptions = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/PSDOptions=PSD Options:");
var strCheckboxMaximizeCompatibility = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Maximize=&Maximize Compatibility");
var strTIFFOptions = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/TIFFOptions=TIFF Options:");
var strLabelImageCompression = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/ImageCompression=Image Compression:");
var strNone = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/None=None");
var strPDFOptions = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/PDFOptions=PDF Options:");
var strLabelEncoding = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Encoding=Encoding:");
var strTargaOptions = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/TargaOptions=Targa Options:");
var strLabelDepth = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Depth=Depth:");
var strRadiobutton16bit = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Bit16=16bit");
var strRadiobutton24bit = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Bit24=24bit");
var strRadiobutton32bit = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Bit32=32bit");
var strBMPOptions = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/BMPOptions=BMP Options:");
var strTitleSelectDestination = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/SelectDestination=Select Destination");
var strAlertSpecifyDestination = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/SpecifyDestination=Please specify destination.");
var strAlertDestinationNotExist = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/DestionationDoesNotExist=Destination does not exist.");
var strAlertDocumentMustBeOpened = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/OneDocument=There must be a document open to export!");
var strAlertDocumentMustBeSaved = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/SavedDocument=The document must be saved first!");
var strConfirmDocumentMustBeSaved = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/ShouldSavedDocument=Your document has unsaved changes. The changes will be automatically saved if you continue. Do you want to proceed?");
var strAlertNeedMultipleLayers = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/NoLayers=The document need to have multiple layers to export!");
var strAlertWasSuccessful = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Success= was successful.");
var strUnexpectedError = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Unexpected=Unexpected error");
var strMessage = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Message=Export Layers to Sprite Sheet action settings");
var stretQuality = localize( "$$$/locale_specific/JavaScripts/ExportLayersToSpriteSheet/ETQualityLength=30" );
var stretDestination = localize( "$$$/locale_specific/JavaScripts/ExportLayersToSpriteSheet/ETDestinationLength=160" );
var strddFileType = localize( "$$$/locale_specific/JavaScripts/ExportLayersToSpriteSheet/DDFileType=100" );
var strpnlOptions = localize( "$$$/locale_specific/JavaScripts/ExportLayersToSpriteSheet/PNLOptions=100" );
var strPNG8Options = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/PNG8Options=PNG-8 Options:");
var strCheckboxPNGTransparency = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Transparency=Transparency");
var strCheckboxPNGInterlaced = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Interlaced=Interlaced");
var strCheckboxTrim = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/Trim=Trim Layers");
var strPNG24Options = localize("$$$/JavaScripts/ExportLayersToSpriteSheet/PNG24Options=PNG-24 Options:");
// the drop down list indexes for file type
var bmpIndex = 0;
var jpegIndex = 1;
var pdfIndex = 2;
var psdIndex = 3;
var targaIndex = 4;
var tiffIndex = 5;
var png8Index = 6;
var png24Index = 7;
// the drop down list indexes for tiff compression
var compNoneIndex = 0;
var compLZWIndex = 1;
var compZIPIndex = 2;
var compJPEGIndex = 3;
// ok and cancel button
var runButtonID = 1;
var cancelButtonID = 2;
// namespace and prefix for storing XMP metadata
var XMPNamespace = "http://ns.texpack/json/1.0/";
var XMPPrefix = "json:";
///////////////////////////////////////////////////////////////////////////////
// Dispatch
///////////////////////////////////////////////////////////////////////////////
main();
///////////////////////////////////////////////////////////////////////////////
// Functions
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Function: main
// Usage: the core routine for this script
// Input: <none>
// Return: <none>
///////////////////////////////////////////////////////////////////////////////
function main() {
// there should one document already open
if ( app.documents.length <= 0 ) {
if ( DialogModes.NO != app.playbackDisplayDialogs ) {
alert( strAlertDocumentMustBeOpened );
}
return 'cancel'; // quit, returning 'cancel' (dont localize) makes the actions palette not record our script
}
// the active document must have a path
try {
var documentPath = Folder(app.activeDocument.fullName.parent).fsName;
} catch(err) {
if ( DialogModes.NO != app.playbackDisplayDialogs ) {
alert( strAlertDocumentMustBeSaved );
}
return 'cancel'; // quit, returning 'cancel' (dont localize) makes the actions palette not record our script
}
// ask to save unsaved changes
if (!app.activeDocument.saved) {
if (DialogModes.NO != app.playbackDisplayDialogs ? confirm(strConfirmDocumentMustBeSaved) : true) {
app.activeDocument.save(app.activeDocument.fullName);
} else {
return 'cancel'; // quit, returning 'cancel' (dont localize) makes the actions palette not record our script
}
}
// the document must have multiple layers
if ((app.activeDocument.layers.length <= 1) && (app.activeDocument.layerSets.length <= 0)) {
if ( DialogModes.NO != app.playbackDisplayDialogs ) {
alert( strAlertNeedMultipleLayers );
return 'cancel'; // quit, returning 'cancel' (dont localize) makes the actions palette not record our script
}
}
var documentName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
var exportInfo = new Object();
initExportInfo(exportInfo);
// update the export info with the metadata in the document
getMeta(exportInfo);
// see if I am getting descriptor parameters
descriptorToObject(exportInfo, app.playbackParameters, strMessage, postProcessExportInfo);
if ( DialogModes.ALL == app.playbackDisplayDialogs ) {
if (cancelButtonID == settingDialog(exportInfo, documentPath, documentName)) {
return 'cancel'; // quit, returning 'cancel' (dont localize) makes the actions palette not record our script
}
}
try {
var rememberMaximize;
var needMaximize = exportInfo.psdMaxComp ? QueryStateType.ALWAYS : QueryStateType.NEVER;
if ( exportInfo.fileType == psdIndex && app.preferences.maximizeCompatibility != needMaximize ) {
rememberMaximize = app.preferences.maximizeCompatibility;
app.preferences.maximizeCompatibility = needMaximize;
}
var originalDocument = app.activeDocument;
var duppedDocument = getDocumentCopy(originalDocument, true);
var frames = [];
// generate the frame information for each layer
generateFrames(duppedDocument, originalDocument, exportInfo, duppedDocument, frames);
duppedDocument.close(SaveOptions.DONOTSAVECHANGES);
// generate the output files
processFrames(frames, originalDocument, exportInfo);
app.activeDocument = originalDocument;
// update the document metadata with the new export info
addMeta(exportInfo);
app.activeDocument.save(app.activeDocument.fullName);
var d = objectToDescriptor(exportInfo, strMessage, preProcessExportInfo);
app.playbackParameters = d;
if ( rememberMaximize != undefined ) {
app.preferences.maximizeCompatibility = rememberMaximize;
}
if ( DialogModes.ALL == app.playbackDisplayDialogs ) {
alert(strTitle + strAlertWasSuccessful);
}
app.playbackDisplayDialogs = DialogModes.ALL;
} catch (e) {
if ( DialogModes.NO != app.playbackDisplayDialogs ) {
alert(e);
}
return 'cancel'; // quit, returning 'cancel' (dont localize) makes the actions palette not record our script
}
}
///////////////////////////////////////////////////////////////////////////////
// Function: settingDialog
// Usage: pop the ui and get user settings
// Input: exportInfo object containing our parameters, the document's path,
// the document's name
// Return: on ok, the dialog info is set to the exportInfo object
///////////////////////////////////////////////////////////////////////////////
function settingDialog(exportInfo, documentPath, documentName) {
dlgMain = new Window("dialog", strTitle);
// match our dialog background color to the host application
var brush = dlgMain.graphics.newBrush (dlgMain.graphics.BrushType.THEME_COLOR, "appDialogBackground");
dlgMain.graphics.backgroundColor = brush;
dlgMain.graphics.disabledBackgroundColor = dlgMain.graphics.backgroundColor;
dlgMain.orientation = 'column';
dlgMain.alignChildren = 'left';
// -- top of the dialog, first line
dlgMain.add("statictext", undefined, strLabelDestination);
// -- two groups, one for left and one for right ok, cancel
dlgMain.grpTop = dlgMain.add("group");
dlgMain.grpTop.orientation = 'row';
dlgMain.grpTop.alignChildren = 'top';
dlgMain.grpTop.alignment = 'fill';
// -- group top left
dlgMain.grpTopLeft = dlgMain.grpTop.add("group");
dlgMain.grpTopLeft.orientation = 'column';
dlgMain.grpTopLeft.alignChildren = 'left';
dlgMain.grpTopLeft.alignment = 'fill';
// -- the second line in the dialog
dlgMain.grpSecondLine = dlgMain.grpTopLeft.add("group");
dlgMain.grpSecondLine.orientation = 'row';
dlgMain.grpSecondLine.alignChildren = 'center';
dlgMain.etDestination = dlgMain.grpSecondLine.add("edittext", undefined, makeRelativePath(exportInfo.destination.toString(), documentPath));
dlgMain.etDestination.preferredSize.width = StrToIntWithDefault( stretDestination, 160 );
dlgMain.btnBrowse = dlgMain.grpSecondLine.add("button", undefined, strButtonBrowse);
dlgMain.btnBrowse.onClick = function() {
var defaultDestination = makeAbsolutePath(dlgMain.etDestination.text, documentPath);
var defaultFile = new File(defaultDestination);
if (defaultFile.exists && defaultFile.length < 0) {
defaultDestination = documentPath + '/' + documentName;
defaultFile = new File(defaultDestination);
}
var selFile = defaultFile.saveDlg(strTitleSelectDestination);
if (selFile != null) {
var selPath = makeRelativePath(selFile.fsName, documentPath);
dlgMain.etDestination.text = selPath.replace(/\.[^\.]+$/, '');
}
dlgMain.defaultElement.active = true;
}
// -- the fifth line in the dialog
dlgMain.grpFifthLine = dlgMain.grpTopLeft.add("group");
dlgMain.grpFifthLine.orientation = 'row';
dlgMain.grpFifthLine.alignChildren = 'fill';
dlgMain.cbVisible = dlgMain.grpFifthLine.add("checkbox", undefined, strCheckboxVisibleOnly);
dlgMain.cbVisible.value = exportInfo.visibleOnly;
dlgMain.cbTrim = dlgMain.grpFifthLine.add("checkbox", undefined, strCheckboxTrim.toString());
dlgMain.cbTrim.value = exportInfo.trim;
// -- the sixth line is the panel
dlgMain.pnlPacking = dlgMain.grpTopLeft.add("panel", undefined, strLabelPacking);
dlgMain.pnlPacking.alignment = 'fill';
dlgMain.grpAlgorithm = dlgMain.pnlPacking.add("group");
dlgMain.grpAlgorithm.orientation = 'row';
dlgMain.grpAlgorithm.alignChildren = 'middle';
dlgMain.grpAlgorithm.alignment = 'fill';
dlgMain.grpAlgorithm.add("statictext", undefined, strLabelAlgorithm);
dlgMain.ddAlgorithm = dlgMain.grpAlgorithm.add("dropdownlist");
dlgMain.ddAlgorithm.preferredSize.width = StrToIntWithDefault( strddAlgorithm, 100 );
dlgMain.ddAlgorithm.alignment = 'left';
for (var i = 0; i < MaxRects.Modes.length; i++) {
dlgMain.ddAlgorithm.add("item", MaxRects.Modes[i]);
}
dlgMain.ddAlgorithm.items[exportInfo.mode].selected = true;
dlgMain.pnlFormat = dlgMain.pnlPacking.add("panel", undefined, strLabelFormat);
dlgMain.pnlFormat.alignment = 'fill';
dlgMain.grpPretty = dlgMain.pnlFormat.add("group");
dlgMain.grpPretty.orientation = 'row';
dlgMain.grpPretty.alignChildren = 'middle';
dlgMain.grpPretty.alignment = 'fill';
dlgMain.cbPretty = dlgMain.grpPretty.add("checkbox", undefined, strLabelPretty);
dlgMain.cbPretty.value = exportInfo.pretty;
dlgMain.cbPretty.hard_tabs = exportInfo.hard_tabs;
dlgMain.rbTabs = dlgMain.grpPretty.add("radiobutton", undefined, strLabelTabs);
dlgMain.rbTabs.value = dlgMain.cbPretty.hard_tabs;
dlgMain.rbSpaces = dlgMain.grpPretty.add("radiobutton", undefined, strLabelSpaces);
dlgMain.rbSpaces.value = !dlgMain.cbPretty.hard_tabs;
dlgMain.etIndentation = dlgMain.grpPretty.add("edittext", undefined, exportInfo.indentation.toString());
dlgMain.etIndentation.preferredSize.width = StrToIntWithDefault( stretIndentation, 50 );
if (exportInfo.pretty) {
dlgMain.rbTabs.enabled = true;
dlgMain.rbSpaces.enabled = true;
dlgMain.etIndentation.enabled = !dlgMain.cbPretty.hard_tabs;
} else {
dlgMain.rbTabs.enabled = false;
dlgMain.rbSpaces.enabled = false;
dlgMain.etIndentation.enabled = false;
}
dlgMain.cbPretty.onClick = function() {
if (this.value) {
dlgMain.rbTabs.enabled = true;
dlgMain.rbTabs.value = this.hard_tabs;
dlgMain.rbSpaces.enabled = true;
dlgMain.rbSpaces.value = !this.hard_tabs;
dlgMain.etIndentation.enabled = !this.hard_tabs;
} else {
dlgMain.rbTabs.enabled = false;
dlgMain.rbSpaces.enabled = false;
dlgMain.etIndentation.enabled = false;
}
}
dlgMain.rbTabs.onClick = function() {
dlgMain.etIndentation.enabled = false;
dlgMain.cbPretty.hard_tabs = true;
}
dlgMain.rbSpaces.onClick = function() {
dlgMain.etIndentation.enabled = true;
dlgMain.cbPretty.hard_tabs = false;
}
dlgMain.grpFormat = dlgMain.pnlFormat.add("group");
dlgMain.grpFormat.orientation = 'row';
dlgMain.grpFormat.alignChildren = 'middle';
dlgMain.grpFormat.alignment = 'fill';
dlgMain.rbHash = dlgMain.grpFormat.add("radiobutton", undefined, strLabelHash);
dlgMain.rbArray = dlgMain.grpFormat.add("radiobutton", undefined, strLabelArray);
dlgMain.cbReverse = dlgMain.grpFormat.add("checkbox", undefined, strLabelReverse);
dlgMain.cbReverse.value = exportInfo.reverse;
switch (exportInfo.format) {
case 0:
dlgMain.rbHash.value = true;
dlgMain.cbReverse.enabled = false;
break;
case 1:
dlgMain.rbArray.value = true;
dlgMain.cbReverse.enabled = true;
break;
}
dlgMain.rbArray.onClick = function() {
dlgMain.cbReverse.enabled = true;
}
dlgMain.rbHash.onClick = function() {
dlgMain.cbReverse.enabled = false;
}
dlgMain.pnlTexture = dlgMain.pnlPacking.add("panel", undefined, strLabelTexture);
dlgMain.pnlTexture.alignment = 'fill';
dlgMain.grpTextureSize = dlgMain.pnlTexture.add("group");
dlgMain.grpTextureSize.orientation = 'row';
dlgMain.grpTextureSize.alignChildren = 'middle';
dlgMain.grpTextureSize.alignment = 'fill';
dlgMain.grpTextureSize.add("statictext", undefined, strLabelTextureWidth);
dlgMain.etTextureWidth = dlgMain.grpTextureSize.add("edittext", undefined, exportInfo.width.toString());
dlgMain.etTextureWidth.preferredSize.width = StrToIntWithDefault( stretTextureSize, 50 );
dlgMain.grpTextureSize.add("statictext", undefined, strLabelTextureHeight);
dlgMain.etTextureHeight = dlgMain.grpTextureSize.add("edittext", undefined, exportInfo.height.toString());
dlgMain.etTextureHeight.preferredSize.width = StrToIntWithDefault( stretTextureSize, 50 );
dlgMain.grpTextureSize.add("statictext", undefined, strLabelPadding);
dlgMain.etPadding = dlgMain.grpTextureSize.add("edittext", undefined, exportInfo.padding.toString());
dlgMain.etPadding.preferredSize.width = StrToIntWithDefault( stretTextureSize, 50 );
dlgMain.grpTextureOptions = dlgMain.pnlTexture.add("group");
dlgMain.grpTextureOptions.orientation = 'row';
dlgMain.grpTextureOptions.alignChildren = 'middle';
dlgMain.grpTextureOptions.alignment = 'fill';
dlgMain.cbPOT = dlgMain.grpTextureOptions.add("checkbox", undefined, strCheckboxPOT);
dlgMain.cbPOT.value = exportInfo.pot;
dlgMain.cbMaxSize = dlgMain.grpTextureOptions.add("checkbox", undefined, strCheckboxMaxSize);
dlgMain.cbMaxSize.value = exportInfo.max_size;
dlgMain.cbRotate = dlgMain.grpTextureOptions.add("checkbox", undefined, strCheckboxRotate);
dlgMain.cbRotate.value = exportInfo.rotate;
// -- the sixth line is the panel
dlgMain.pnlFileType = dlgMain.grpTopLeft.add("panel", undefined, strLabelFileType);
dlgMain.pnlFileType.alignment = 'fill';
// -- now a dropdown list
dlgMain.ddFileType = dlgMain.pnlFileType.add("dropdownlist");
dlgMain.ddFileType.preferredSize.width = StrToIntWithDefault( strddFileType, 100 );
dlgMain.ddFileType.alignment = 'left';
dlgMain.ddFileType.add("item", "BMP");
dlgMain.ddFileType.add("item", "JPEG");
dlgMain.ddFileType.add("item", "PDF");
dlgMain.ddFileType.add("item", "PSD");
dlgMain.ddFileType.add("item", "Targa");
dlgMain.ddFileType.add("item", "TIFF");
dlgMain.ddFileType.add("item", "PNG-8");
dlgMain.ddFileType.add("item", "PNG-24");
dlgMain.ddFileType.onChange = function() {
hideAllFileTypePanel();
switch(this.selection.index) {
case bmpIndex:
dlgMain.pnlFileType.pnlOptions.text = strBMPOptions;
dlgMain.pnlFileType.pnlOptions.grpBMPOptions.show();
break;
case jpegIndex:
dlgMain.pnlFileType.pnlOptions.text = strJPEGOptions;
dlgMain.pnlFileType.pnlOptions.grpJPEGOptions.show();
break;
case tiffIndex:
dlgMain.pnlFileType.pnlOptions.text = strTIFFOptions;
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.show();
break;
case pdfIndex:
dlgMain.pnlFileType.pnlOptions.text = strPDFOptions;
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.show();
break;
case targaIndex:
dlgMain.pnlFileType.pnlOptions.text = strTargaOptions;
dlgMain.pnlFileType.pnlOptions.grpTargaOptions.show();
break;
case png8Index:
dlgMain.pnlFileType.pnlOptions.text = strPNG8Options;
dlgMain.pnlFileType.pnlOptions.grpPNG8Options.show();
break;
case png24Index:
dlgMain.pnlFileType.pnlOptions.text = strPNG24Options;
dlgMain.pnlFileType.pnlOptions.grpPNG24Options.show();
break;
case psdIndex:
default:
dlgMain.pnlFileType.pnlOptions.text = strPSDOptions;
dlgMain.pnlFileType.pnlOptions.grpPSDOptions.show();
break;
}
}
dlgMain.ddFileType.items[exportInfo.fileType].selected = true;
// -- now after all the radio buttons
dlgMain.cbIcc = dlgMain.pnlFileType.add("checkbox", undefined, strCheckboxIncludeICCProfile);
dlgMain.cbIcc.value = exportInfo.icc;
dlgMain.cbIcc.alignment = 'left';
// -- now the options panel that changes
dlgMain.pnlFileType.pnlOptions = dlgMain.pnlFileType.add("panel", undefined, "Options");
dlgMain.pnlFileType.pnlOptions.alignment = 'fill';
dlgMain.pnlFileType.pnlOptions.orientation = 'stack';
dlgMain.pnlFileType.pnlOptions.preferredSize.height = StrToIntWithDefault( strpnlOptions, 100 );
// PSD options
dlgMain.pnlFileType.pnlOptions.grpPSDOptions = dlgMain.pnlFileType.pnlOptions.add("group");
dlgMain.pnlFileType.pnlOptions.grpPSDOptions.cbMax = dlgMain.pnlFileType.pnlOptions.grpPSDOptions.add("checkbox", undefined, strCheckboxMaximizeCompatibility);
dlgMain.pnlFileType.pnlOptions.grpPSDOptions.cbMax.value = exportInfo.psdMaxComp;
dlgMain.pnlFileType.pnlOptions.grpPSDOptions.visible = (exportInfo.fileType == psdIndex);
// PNG8 options
dlgMain.pnlFileType.pnlOptions.grpPNG8Options = dlgMain.pnlFileType.pnlOptions.add("group");
dlgMain.pnlFileType.pnlOptions.grpPNG8Options.png8Trans = dlgMain.pnlFileType.pnlOptions.grpPNG8Options.add("checkbox", undefined, strCheckboxPNGTransparency.toString());
dlgMain.pnlFileType.pnlOptions.grpPNG8Options.png8Inter = dlgMain.pnlFileType.pnlOptions.grpPNG8Options.add("checkbox", undefined, strCheckboxPNGInterlaced.toString());
dlgMain.pnlFileType.pnlOptions.grpPNG8Options.png8Trans.value = exportInfo.png8Transparency;
dlgMain.pnlFileType.pnlOptions.grpPNG8Options.png8Inter.value = exportInfo.png8Interlaced;
dlgMain.pnlFileType.pnlOptions.grpPNG8Options.visible = (exportInfo.fileType == png8Index);
// PNG24 options
dlgMain.pnlFileType.pnlOptions.grpPNG24Options = dlgMain.pnlFileType.pnlOptions.add("group");
dlgMain.pnlFileType.pnlOptions.grpPNG24Options.png24Trans = dlgMain.pnlFileType.pnlOptions.grpPNG24Options.add("checkbox", undefined, strCheckboxPNGTransparency.toString());
dlgMain.pnlFileType.pnlOptions.grpPNG24Options.png24Inter = dlgMain.pnlFileType.pnlOptions.grpPNG24Options.add("checkbox", undefined, strCheckboxPNGInterlaced.toString());
dlgMain.pnlFileType.pnlOptions.grpPNG24Options.png24Trans.value = exportInfo.png24Transparency;
dlgMain.pnlFileType.pnlOptions.grpPNG24Options.png24Inter.value = exportInfo.png24Interlaced;
dlgMain.pnlFileType.pnlOptions.grpPNG24Options.visible = (exportInfo.fileType == png24Index);
// JPEG options
dlgMain.pnlFileType.pnlOptions.grpJPEGOptions = dlgMain.pnlFileType.pnlOptions.add("group");
dlgMain.pnlFileType.pnlOptions.grpJPEGOptions.add("statictext", undefined, strLabelQuality);
dlgMain.pnlFileType.pnlOptions.grpJPEGOptions.etQuality = dlgMain.pnlFileType.pnlOptions.grpJPEGOptions.add("edittext", undefined, exportInfo.jpegQuality.toString());
dlgMain.pnlFileType.pnlOptions.grpJPEGOptions.etQuality.preferredSize.width = StrToIntWithDefault( stretQuality, 30 );
dlgMain.pnlFileType.pnlOptions.grpJPEGOptions.visible = (exportInfo.fileType == jpegIndex);
// TIFF options
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions = dlgMain.pnlFileType.pnlOptions.add("group");
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.orientation = 'column';
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.visible = (exportInfo.fileType == tiffIndex);
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpCompression = dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.add("group");
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpCompression.alignment = 'left';
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpCompression.add("statictext", undefined, strLabelImageCompression);
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpCompression.ddCompression = dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpCompression.add("dropdownlist");
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpCompression.ddCompression.add("item", strNone);
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpCompression.ddCompression.add("item", "LZW");
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpCompression.ddCompression.add("item", "ZIP");
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpCompression.ddCompression.add("item", "JPEG");
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpCompression.ddCompression.onChange = function() {
if (this.selection.index == compJPEGIndex) {
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpQuality.stQuality.enabled = true;
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpQuality.etQuality.enabled = true;
} else {
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpQuality.stQuality.enabled = false;
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpQuality.etQuality.enabled = false;
}
}
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpQuality = dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.add("group");
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpQuality.alignment = 'left';
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpQuality.stQuality = dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpQuality.add("statictext", undefined, strLabelQuality);
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpQuality.etQuality = dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpQuality.add("edittext", undefined, exportInfo.tiffJpegQuality.toString());
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpQuality.etQuality.preferredSize.width = StrToIntWithDefault( stretQuality, 30 );
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpQuality.etQuality.graphics.disabledBackgroundColor = brush;
var index;
switch (exportInfo.tiffCompression) {
case TIFFEncoding.NONE: index = compNoneIndex; break;
case TIFFEncoding.TIFFLZW: index = compLZWIndex; break;
case TIFFEncoding.TIFFZIP: index = compZIPIndex; break;
case TIFFEncoding.JPEG: index = compJPEGIndex; break;
default: index = compNoneIndex; break;
}
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpCompression.ddCompression.items[index].selected = true;
if (TIFFEncoding.JPEG != exportInfo.tiffCompression) { // if not JPEG
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpQuality.stQuality.enabled = false;
dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpQuality.etQuality.enabled = false;
}
// PDF options
dlgMain.pnlFileType.pnlOptions.grpPDFOptions = dlgMain.pnlFileType.pnlOptions.add("group");
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.orientation = 'column';
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.visible = (exportInfo.fileType == pdfIndex);
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpCompression = dlgMain.pnlFileType.pnlOptions.grpPDFOptions.add("group");
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpCompression.alignment = 'left';
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpCompression.add("statictext", undefined, strLabelEncoding);
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpCompression.rbZip = dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpCompression.add("radiobutton", undefined, "ZIP");
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpCompression.rbZip.onClick = function() {
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpQuality.stQuality.enabled = false;
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpQuality.etQuality.enabled = false;
}
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpCompression.rbJpeg = dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpCompression.add("radiobutton", undefined, "JPEG");
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpCompression.rbJpeg.onClick = function() {
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpQuality.stQuality.enabled = true;
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpQuality.etQuality.enabled = true;
}
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpQuality = dlgMain.pnlFileType.pnlOptions.grpPDFOptions.add("group");
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpQuality.alignment = 'left';
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpQuality.stQuality = dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpQuality.add("statictext", undefined, strLabelQuality);
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpQuality.etQuality = dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpQuality.add("edittext", undefined, exportInfo.pdfJpegQuality.toString());
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpQuality.etQuality.preferredSize.width = StrToIntWithDefault( stretQuality, 30 );
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpQuality.etQuality.graphics.disabledBackgroundColor = brush;
switch (exportInfo.pdfEncoding) {
case PDFEncoding.PDFZIP:
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpCompression.rbZip.value = true; break;
case PDFEncoding.JPEG:
default:
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpCompression.rbJpeg.value = true; break;
}
if (PDFEncoding.JPEG != exportInfo.pdfEncoding) {
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpQuality.stQuality.enabled = false;
dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpQuality.etQuality.enabled = false;
}
// Targa options
dlgMain.pnlFileType.pnlOptions.grpTargaOptions = dlgMain.pnlFileType.pnlOptions.add("group");
dlgMain.pnlFileType.pnlOptions.grpTargaOptions.add("statictext", undefined, strLabelDepth);
dlgMain.pnlFileType.pnlOptions.grpTargaOptions.visible = (exportInfo.fileType == targaIndex);
dlgMain.pnlFileType.pnlOptions.grpTargaOptions.rb16bit = dlgMain.pnlFileType.pnlOptions.grpTargaOptions.add( "radiobutton", undefined, strRadiobutton16bit);
dlgMain.pnlFileType.pnlOptions.grpTargaOptions.rb24bit = dlgMain.pnlFileType.pnlOptions.grpTargaOptions.add( "radiobutton", undefined, strRadiobutton24bit);
dlgMain.pnlFileType.pnlOptions.grpTargaOptions.rb32bit = dlgMain.pnlFileType.pnlOptions.grpTargaOptions.add( "radiobutton", undefined, strRadiobutton32bit);
switch (exportInfo.targaDepth) {
case TargaBitsPerPixels.SIXTEEN: dlgMain.pnlFileType.pnlOptions.grpTargaOptions.rb16bit.value = true; break;
case TargaBitsPerPixels.TWENTYFOUR: dlgMain.pnlFileType.pnlOptions.grpTargaOptions.rb24bit.value = true; break;
case TargaBitsPerPixels.THIRTYTWO: dlgMain.pnlFileType.pnlOptions.grpTargaOptions.rb32bit.value = true; break;
default: dlgMain.pnlFileType.pnlOptions.grpTargaOptions.rb24bit.value = true; break;
}
// BMP options
dlgMain.pnlFileType.pnlOptions.grpBMPOptions = dlgMain.pnlFileType.pnlOptions.add("group");
dlgMain.pnlFileType.pnlOptions.grpBMPOptions.add("statictext", undefined, strLabelDepth);
dlgMain.pnlFileType.pnlOptions.grpBMPOptions.visible = (exportInfo.fileType == bmpIndex);
dlgMain.pnlFileType.pnlOptions.grpBMPOptions.rb16bit = dlgMain.pnlFileType.pnlOptions.grpBMPOptions.add( "radiobutton", undefined, strRadiobutton16bit);
dlgMain.pnlFileType.pnlOptions.grpBMPOptions.rb24bit = dlgMain.pnlFileType.pnlOptions.grpBMPOptions.add( "radiobutton", undefined, strRadiobutton24bit);
dlgMain.pnlFileType.pnlOptions.grpBMPOptions.rb32bit = dlgMain.pnlFileType.pnlOptions.grpBMPOptions.add( "radiobutton", undefined, strRadiobutton32bit);
switch (exportInfo.bmpDepth) {
case BMPDepthType.SIXTEEN: dlgMain.pnlFileType.pnlOptions.grpBMPOptions.rb16bit.value = true; break;
case BMPDepthType.TWENTYFOUR:dlgMain.pnlFileType.pnlOptions.grpBMPOptions.rb24bit.value = true; break;
case BMPDepthType.THIRTYTWO: dlgMain.pnlFileType.pnlOptions.grpBMPOptions.rb32bit.value = true; break;
default: dlgMain.pnlFileType.pnlOptions.grpBMPOptions.rb24bit.value = true; break;
}
// the right side of the dialog, the ok and cancel buttons
dlgMain.grpTopRight = dlgMain.grpTop.add("group");
dlgMain.grpTopRight.orientation = 'column';
dlgMain.grpTopRight.alignChildren = 'fill';
dlgMain.btnRun = dlgMain.grpTopRight.add("button", undefined, strButtonRun );
dlgMain.btnRun.onClick = function() {
// check if the setting is properly
var destination = dlgMain.etDestination.text;
if (destination.length == 0) {
alert(strAlertSpecifyDestination);
return;
}
destination = makeAbsolutePath(destination, documentPath);
var folder = destination.substr(0, destination.lastIndexOf('/')) + '/';
if (folder.length > 0) {
var testFolder = new Folder(folder);
if (!testFolder.exists) {
alert(strAlertDestinationNotExist);
return;
}
}
dlgMain.close(runButtonID);
}
dlgMain.btnCancel = dlgMain.grpTopRight.add("button", undefined, strButtonCancel );
dlgMain.btnCancel.onClick = function() {
dlgMain.close(cancelButtonID);
}
dlgMain.defaultElement = dlgMain.btnRun;
dlgMain.cancelElement = dlgMain.btnCancel;
// the bottom of the dialog
dlgMain.grpBottom = dlgMain.add("group");
dlgMain.grpBottom.orientation = 'column';
dlgMain.grpBottom.alignChildren = 'left';
dlgMain.grpBottom.alignment = 'fill';
dlgMain.pnlHelp = dlgMain.grpBottom.add("panel");
dlgMain.pnlHelp.alignment = 'fill';
dlgMain.etHelp = dlgMain.pnlHelp.add("statictext", undefined, strHelpText, {multiline:true});
dlgMain.etHelp.alignment = 'fill';
dlgMain.onShow = function() {
dlgMain.ddFileType.onChange();
}
// give the hosting app the focus before showing the dialog
app.bringToFront();
dlgMain.center();
var result = dlgMain.show();
if (cancelButtonID == result) {
return result; // close to quit
}
// get setting from dialog
exportInfo.destination = makeAbsolutePath(dlgMain.etDestination.text, documentPath);
exportInfo.visibleOnly = dlgMain.cbVisible.value;
if (dlgMain.rbHash.value) {
exportInfo.format = 0;
} else if (dlgMain.rbArray.value) {
exportInfo.format = 1;
}
exportInfo.mode = dlgMain.ddAlgorithm.selection.index;
exportInfo.reverse = dlgMain.cbReverse.value;
exportInfo.pot = dlgMain.cbPOT.value;
exportInfo.rotate = dlgMain.cbRotate.value;
exportInfo.max_size = dlgMain.cbMaxSize.value;
exportInfo.pretty = dlgMain.cbPretty.value;
exportInfo.hard_tabs = dlgMain.cbPretty.hard_tabs;
exportInfo.indentation = dlgMain.etIndentation.text;
exportInfo.width = dlgMain.etTextureWidth.text;
exportInfo.height = dlgMain.etTextureHeight.text;
exportInfo.padding = dlgMain.etPadding.text;
exportInfo.fileType = dlgMain.ddFileType.selection.index;
exportInfo.icc = dlgMain.cbIcc.value;
exportInfo.jpegQuality = dlgMain.pnlFileType.pnlOptions.grpJPEGOptions.etQuality.text;
exportInfo.psdMaxComp = dlgMain.pnlFileType.pnlOptions.grpPSDOptions.cbMax.value;
index = dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpCompression.ddCompression.selection.index;
if (index == compNoneIndex) {
exportInfo.tiffCompression = TIFFEncoding.NONE;
}
if (index == compLZWIndex) {
exportInfo.tiffCompression = TIFFEncoding.TIFFLZW;
}
if (index == compZIPIndex) {
exportInfo.tiffCompression = TIFFEncoding.TIFFZIP;
}
if (index == compJPEGIndex) {
exportInfo.tiffCompression = TIFFEncoding.JPEG;
}
exportInfo.tiffJpegQuality = dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpQuality.etQuality.text;
if (dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpCompression.rbZip.value) {
exportInfo.pdfEncoding = PDFEncoding.PDFZIP;
}
if (dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpCompression.rbJpeg.value) {
exportInfo.pdfEncoding = PDFEncoding.JPEG;
}
exportInfo.pdfJpegQuality = dlgMain.pnlFileType.pnlOptions.grpPDFOptions.grpQuality.etQuality.text;
if (dlgMain.pnlFileType.pnlOptions.grpTargaOptions.rb16bit.value) {
exportInfo.targaDepth = TargaBitsPerPixels.SIXTEEN;
}
if (dlgMain.pnlFileType.pnlOptions.grpTargaOptions.rb24bit.value) {
exportInfo.targaDepth = TargaBitsPerPixels.TWENTYFOUR;
}
if (dlgMain.pnlFileType.pnlOptions.grpTargaOptions.rb32bit.value) {
exportInfo.targaDepth = TargaBitsPerPixels.THIRTYTWO;
}
if (dlgMain.pnlFileType.pnlOptions.grpBMPOptions.rb16bit.value) {
exportInfo.bmpDepth = BMPDepthType.SIXTEEN;
}
if (dlgMain.pnlFileType.pnlOptions.grpBMPOptions.rb24bit.value) {
exportInfo.bmpDepth = BMPDepthType.TWENTYFOUR;
}
if (dlgMain.pnlFileType.pnlOptions.grpBMPOptions.rb32bit.value) {
exportInfo.bmpDepth = BMPDepthType.THIRTYTWO;
}
if (typeof dlgMain.cbTrim.value !== "undefined") {
exportInfo.trim = dlgMain.cbTrim.value;
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
// Function: getDocumentCopy
// Usage: duplicate the document and optionally make all layers invisible
// Input: reference to the original document,
// whether the layers visibility should be set to invisible
// Return: a referencde to the duplicated copy
///////////////////////////////////////////////////////////////////////////////
function getDocumentCopy(ducumentRef, invisible) {
app.activeDocument = ducumentRef;
var duppedDocument = app.activeDocument.duplicate();
duppedDocument.activeLayer = duppedDocument.layers[duppedDocument.layers.length-1]; // for removing
if (invisible) {
setInvisibleAllArtLayers(duppedDocument);
}
return duppedDocument;
}
///////////////////////////////////////////////////////////////////////////////
// Function: processFrames
// Usage: create and save the pack files from the frames according to the
// exporting info
// Input: JavaScript array with the frames to process,
// reference to the original document,
// export info object containing more information
// Return: <node>, all the packets are created and saved to the destination
// files
///////////////////////////////////////////////////////////////////////////////
function processFrames(frames, orgObj, exportInfo) {
var results = packFrames(frames, exportInfo);
for (var r = 0; r < results.length; r++) {
var duppedDocument = getDocumentCopy(orgObj, true);
var result = results[r];
var sprites = result.sprites;
var framesPack;
if (exportInfo.format == 0) {
framesPack = {};
} else {
framesPack = [];
}
for (var i = 0; i < frames.length; i++) {
var frame = frames[i];
for (var j = 0; j < sprites.length; j++) {
var sprite = sprites[j];
if (frame.name == sprite.name) {
for (var k in sprite) {
frame[k] = sprite[k];
}
if (exportInfo.format == 0) {
framesPack[frame.name] = frame;
delete frame.name;
} else {
framesPack.push(frame);
}
duppedDocument.artLayers[sprite.name].visible = true;
}
}
}
removeAllInvisible(duppedDocument);
result.sprites = framesPack;
if (exportInfo.reverse && exportInfo.format == 1) {
result.sprites.reverse();
}
var outputFileName;
if (exportInfo.pretty) {
outputFileName = JSON.stringify(result, null, exportInfo.hard_tabs ? '\t' : parseInt(exportInfo.indentation));
} else {
outputFileName = JSON.stringify(result);
}
if (results.length > 1) {
saveTxt(outputFileName, exportInfo, r + 1);
} else {
saveTxt(outputFileName, exportInfo);
}
duppedDocument.resizeCanvas(result.width, result.height, AnchorPosition.TOPLEFT);
for (var i = 0; i < duppedDocument.artLayers.length; i++) {
var layer = duppedDocument.artLayers[i];
var layerName = layer.name;
var rect;
if (exportInfo.format == 0) {
for (var j in framesPack) {
if (j == layerName) {
rect = framesPack[j];
}
}
} else {
for (var j = 0; j < framesPack.length; j++) {
if (framesPack[j].name == layerName) {
rect = framesPack[j];
}
}
}
if (!rect) {
continue;
}
if (rect.rotated) {
if (!rect.trimmed) {
var bounds = layer.bounds;
var left = bounds[0];
var top = bounds[1];
var right = bounds[2];
var bottom = bounds[3];
var newLeft = rect.sourceH - (top + rect.width);
var newTop = left;
layer.translate(-left, -top)
layer.rotate(90, AnchorPosition.TOPLEFT);
layer.translate(bottom - top, 0);
layer.translate(newLeft, newTop);
} else {
layer.translate(-rect.offsetX, -rect.offsetY);
layer.rotate(90, AnchorPosition.TOPLEFT);
layer.translate(rect.height, 0);
}
} else {
if (rect.trimmed) {