forked from TheFlyingMinotaur/CharacterCreatorRelease
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FireEmblemCharacterCreator.java
1290 lines (1151 loc) · 40.4 KB
/
FireEmblemCharacterCreator.java
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
package CharacterCreator;
/**
* FireEmblemCharacterCreator created by TheFlyingMinotaur
* Updated by Baconmaster120
* Additional art resources provided by Iscaneus
*/
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.colorchooser.AbstractColorChooserPanel;
import javax.swing.colorchooser.ColorSelectionModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
//import org.omg.CosNaming.NamingContextExtPackage.AddressHelper;
import CharacterCreator.ImagePanel;
import javax.swing.JLabel;
import java.awt.image.WritableRaster;
import java.awt.Font;
import java.awt.Graphics;
//import java.awt.GridLayout;
//import java.awt.Rectangle;
//import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import javax.swing.JSlider;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.AbstractAction;
import javax.swing.Action;
//import javax.swing.DebugGraphics;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JColorChooser;
public class FireEmblemCharacterCreator extends JFrame implements ChangeListener, ItemListener, ActionListener {
private static final long serialVersionUID = -7435578396712824308L;
BufferedImage portrait;
BufferedImage token;
BufferedImage hair;
BufferedImage hairb;
BufferedImage face;
BufferedImage accessory;
BufferedImage armor;
BufferedImage blankPortrait;
BufferedImage blankToken;
BufferedImage importedToken;
ImagePanel portraitPanel;
ImagePanel tokenPanel;
//This could probably be done WAY more efficiently
JLabel hairRect = new JLabel();
JLabel hairRectB = new JLabel();
JLabel hairRectD = new JLabel();
JLabel eyeRect = new JLabel();
JLabel eyeRectB = new JLabel();
JLabel eyeRectD = new JLabel();
JLabel skinRect = new JLabel();
JLabel skinRectB = new JLabel();
JLabel skinRectD = new JLabel();
JLabel metalRect = new JLabel();
JLabel metalRectB = new JLabel();
JLabel metalRectD = new JLabel();
JLabel trimRect = new JLabel();
JLabel trimRectB = new JLabel();
JLabel trimRectD = new JLabel();
JLabel clothRect = new JLabel();
JLabel clothRectB = new JLabel();
JLabel clothRectD = new JLabel();
JLabel leatherRect = new JLabel();
JLabel leatherRectB = new JLabel();
JLabel leatherRectD = new JLabel();
JLabel accessoryRect = new JLabel();
JLabel accessoryRectB = new JLabel();
JLabel accessoryRectD = new JLabel();
JTextField exportFileName = new JTextField();
ArrayList<JSlider> sliders = new ArrayList<JSlider>();
ArrayList<JComboBox<String>> boxes = new ArrayList<JComboBox<String>>();
Color skinColor = new Color(248,208,152,255);
Color hairColor = new Color(224,216,64,255);
Color eyeColor = new Color(64,50,25,255);
Color metalColor= new Color(100,100,100,255);
Color trimColor= new Color(247,173,82,255);
Color clothColor= new Color(82,82,115,255);
Color leatherColor= new Color(148,100,66,255);
Color accessoryColor = new Color(0,0,0,255);
Color outlineColor = new Color(0,0,0,255);
Color blankColor = new Color(0,0,0,0);
Color startCCColor = new Color(0,0,0,0);
Color newCCColor = new Color(0,0,0,0);
int hairXOffsetVal=0;
int hairYOffsetVal=0;
int faceXOffsetVal=0;
int faceYOffsetVal=0;
int armorXOffsetVal=0;
int armorYOffsetVal=0;
int accessoryXOffsetVal=0;
int accessoryYOffsetVal=0;
//SystemColorChooserPanel newChooser = new SystemColorChooserPanel();
//chooser.addChoosePanel(newChooser);
//Button strings
private static final String BTNEXPORT = "Export";
private static final String BTNHAIRCOLOR = "Hair Color";
private static final String BTNEYECOLOR = "Eye/Beard Color";
private static final String BTNSKINCOLOR = "Skin Color";
private static final String BTNMETALCOLOR = "Metal Color";
private static final String BTNTRIMCOLOR = "Trim Color";
private static final String BTNCLOTHCOLOR = "Cloth Color";
private static final String BTNLEATHERCOLOR = "Leather Color";
private static final String BTNACCESSORYCOLOR = "Accessory Color";
File folder;
File[] listOfFiles;
ArrayList<String> hairs = new ArrayList<String>();
ArrayList<String> faces = new ArrayList<String>();
ArrayList<String> armors = new ArrayList<String>();
ArrayList<String> accessories = new ArrayList<String>();
ArrayList<String> tokens = new ArrayList<String>();
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
FireEmblemCharacterCreator frame = new FireEmblemCharacterCreator();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
* @throws UnsupportedEncodingException
*/
public FireEmblemCharacterCreator() throws UnsupportedEncodingException {
String rawPath = FireEmblemCharacterCreator.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String path = URLDecoder.decode(rawPath, "UTF-8");
path = path.substring(0, path.lastIndexOf("/") + 1);
path = path.replaceAll("%20", " ");
folder = new File(path + "resources");
listOfFiles = folder.listFiles();
accessory = null;
try {
accessory = ImageIO.read(new File(path + "resources/Empty.png"));
} catch (IOException ex) {
}
hair = null;
try {
hair = ImageIO.read(new File(path + "resources/Empty.png"));
} catch (IOException ex) {
}
hairb = null;
try {
hairb = ImageIO.read(new File(path + "resources/Empty.png"));
} catch (IOException ex) {
}
face = null;
try {
face = ImageIO.read(new File(path + "resources/Empty.png"));
} catch (IOException ex) {
}
armor = null;
try {
armor = ImageIO.read(new File(path + "resources/Empty.png"));
} catch (IOException ex) {
}
portrait = null;
try {
portrait = ImageIO.read(new File(path + "resources/BlankPortrait.png"));
} catch (IOException ex) {
}
//System.out.println((portrait == null));
token = null;
try {
token = ImageIO.read(new File(path + "resources/BlankTok.png"));
} catch (IOException ex) {
}
blankPortrait = null;
try {
blankPortrait = ImageIO.read(new File(path + "resources/BlankPortrait.png"));
} catch (IOException ex) {
}
//System.out.println((portrait == null));
blankToken = null;
try {
blankToken = ImageIO.read(new File(path + "resources/BlankTok.png"));
} catch (IOException ex) {
}
importedToken = null;
try {
importedToken = ImageIO.read(new File(path + "resources/BlankTok.png"));
} catch (IOException ex) {
}
setFont(new Font("Calibri", Font.BOLD, 12));
setTitle("Fire Emblem Character Creator");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 925, 450); //was xx932x
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
//----------COLOR CHOOSER BUTTONS-----------------------------
JButton hairCCBtn = new JButton(BTNHAIRCOLOR);
hairCCBtn.setBounds(380,30,130,50);
hairCCBtn.addActionListener(this);
contentPane.add(hairCCBtn);
hairRectB.setBounds(380, 80, 40, 20);
hairRectB.setOpaque(true);
hairRectB.setBackground(hairColor.brighter());
contentPane.add(hairRectB);
hairRect.setBounds(420, 80, 50, 20);
hairRect.setOpaque(true);
hairRect.setBackground(hairColor);
contentPane.add(hairRect);
hairRectD.setBounds(470, 80, 40, 20);
hairRectD.setOpaque(true);
hairRectD.setBackground(hairColor.darker());
contentPane.add(hairRectD);
JButton eyeCCBtn = new JButton(BTNEYECOLOR);
eyeCCBtn.setBounds(510,30,130,50);
eyeCCBtn.addActionListener(this);
contentPane.add(eyeCCBtn);
//JLabel eyeRect = new JLabel();
eyeRectB.setBounds(510, 80, 40, 20);
eyeRectB.setOpaque(true);
eyeRectB.setBackground(eyeColor.brighter());
contentPane.add(eyeRectB);
eyeRect.setBounds(550, 80, 50, 20);
eyeRect.setOpaque(true);
eyeRect.setBackground(eyeColor);
contentPane.add(eyeRect);
eyeRectD.setBounds(600, 80, 40, 20);
eyeRectD.setOpaque(true);
eyeRectD.setBackground(eyeColor.darker());
contentPane.add(eyeRectD);
JButton skinCCBtn = new JButton(BTNSKINCOLOR);
skinCCBtn.setBounds(640,30,130,50);
skinCCBtn.addActionListener(this);
contentPane.add(skinCCBtn);
//JLabel skinRect = new JLabel();
skinRectB.setBounds(640, 80, 40, 20);
skinRectB.setOpaque(true);
skinRectB.setBackground(skinColor.brighter());
contentPane.add(skinRectB);
skinRect.setBounds(680, 80, 50, 20);
skinRect.setOpaque(true);
skinRect.setBackground(skinColor);
contentPane.add(skinRect);
skinRectD.setBounds(730, 80, 40, 20);
skinRectD.setOpaque(true);
skinRectD.setBackground(skinColor.darker());
contentPane.add(skinRectD);
JButton metalCCBtn = new JButton(BTNMETALCOLOR);
metalCCBtn.setBounds(380,100,130,50);
metalCCBtn.addActionListener(this);
contentPane.add(metalCCBtn);
//JLabel metalRect = new JLabel();
metalRectB.setBounds(380, 150, 40, 20);
metalRectB.setOpaque(true);
metalRectB.setBackground(metalColor.brighter());
contentPane.add(metalRectB);
metalRect.setBounds(420, 150, 50, 20);
metalRect.setOpaque(true);
metalRect.setBackground(metalColor);
contentPane.add(metalRect);
metalRectD.setBounds(470, 150, 40, 20);
metalRectD.setOpaque(true);
metalRectD.setBackground(metalColor.darker());
contentPane.add(metalRectD);
JButton trimCCBtn = new JButton(BTNTRIMCOLOR);
trimCCBtn.setBounds(510,100,130,50);
trimCCBtn.addActionListener(this);
contentPane.add(trimCCBtn);
//JLabel trimRect = new JLabel();
trimRectB.setBounds(510, 150, 40, 20);
trimRectB.setOpaque(true);
trimRectB.setBackground(trimColor.brighter());
contentPane.add(trimRectB);
trimRect.setBounds(550, 150, 50, 20);
trimRect.setOpaque(true);
trimRect.setBackground(trimColor);
contentPane.add(trimRect);
trimRectD.setBounds(600, 150, 40, 20);
trimRectD.setOpaque(true);
trimRectD.setBackground(trimColor.darker());
contentPane.add(trimRectD);
JButton clothCCBtn = new JButton(BTNCLOTHCOLOR);
clothCCBtn.setBounds(640,100,130,50);
clothCCBtn.addActionListener(this);
contentPane.add(clothCCBtn);
//JLabel clothRect = new JLabel();
clothRectB.setBounds(640, 150, 40, 20);
clothRectB.setOpaque(true);
clothRectB.setBackground(clothColor.brighter());
contentPane.add(clothRectB);
clothRect.setBounds(680, 150, 50, 20);
clothRect.setOpaque(true);
clothRect.setBackground(clothColor);
contentPane.add(clothRect);
clothRectD.setBounds(730, 150, 40, 20);
clothRectD.setOpaque(true);
clothRectD.setBackground(clothColor.darker());
contentPane.add(clothRectD);
JButton leatherCCBtn = new JButton(BTNLEATHERCOLOR);
leatherCCBtn.setBounds(770,100,130,50);
leatherCCBtn.addActionListener(this);
contentPane.add(leatherCCBtn);
//JLabel leatherRect = new JLabel();
leatherRectB.setBounds(770, 150, 40, 20);
leatherRectB.setOpaque(true);
leatherRectB.setBackground(leatherColor.brighter());
contentPane.add(leatherRectB);
leatherRect.setBounds(810, 150, 50, 20);
leatherRect.setOpaque(true);
leatherRect.setBackground(leatherColor);
contentPane.add(leatherRect);
leatherRectD.setBounds(860, 150, 40, 20);
leatherRectD.setOpaque(true);
leatherRectD.setBackground(leatherColor.darker());
contentPane.add(leatherRectD);
JButton accessoryCCBtn = new JButton(BTNACCESSORYCOLOR);
accessoryCCBtn.setBounds(770,30,130,50);
accessoryCCBtn.addActionListener(this);
contentPane.add(accessoryCCBtn);
//JLabel leatherRect = new JLabel();
accessoryRectB.setBounds(770, 80, 40, 20);
accessoryRectB.setOpaque(true);
accessoryRectB.setBackground(accessoryColor.brighter());
contentPane.add(accessoryRectB);
accessoryRect.setBounds(810, 80, 50, 20);
accessoryRect.setOpaque(true);
accessoryRect.setBackground(accessoryColor);
contentPane.add(accessoryRect);
accessoryRectD.setBounds(860, 80, 40, 20);
accessoryRectD.setOpaque(true);
accessoryRectD.setBackground(accessoryColor.darker());
contentPane.add(accessoryRectD);
//JColorChooser hairColorChooser = new JColorChooser();
//hairColorChooser.setSize(500,500);
//hairColorChooser.setVisible(true);
//hairColorChooser.setDefaultCloseOperation(EXIT_ON_CLOSE);
//PORTRAIT BOX
portraitPanel = new ImagePanel(path + "resources/BlankPortrait.png");
portraitPanel.setBounds(22, 10, 192, 192);
contentPane.add(portraitPanel);
//TOKEN BOX
tokenPanel = new ImagePanel(path + "resources/BlankTok.png");
tokenPanel.setBounds(224, 10, 128, 128);
contentPane.add(tokenPanel);
hairs.add("Empty.png");
faces.add("Empty.png");
armors.add("Empty.png");
accessories.add("Empty.png");
tokens.add("Emptytok.png");
System.out.println(listOfFiles.length);
for (int i = 0; i< listOfFiles.length; i++){
String filename = listOfFiles[i].getName();
if (filename.contains("Hair.png")){
hairs.add(filename);
}
else if(filename.contains("Face.png")){
faces.add(filename);
}
else if(filename.contains("Armor.png")){
armors.add(filename);
}
else if(filename.contains("Acc.png")) {
accessories.add(filename);
}
else if(filename.contains("Token.png")){
tokens.add(filename);
}
}
//ComboBox labels
JLabel lblHair = new JLabel("Hair");
lblHair.setFont(new Font("Calibri", Font.BOLD, 13));
lblHair.setBounds(41, 202, 131, 21);
contentPane.add(lblHair);
JLabel lblFace = new JLabel("Face");
lblFace.setFont(new Font("Calibri", Font.BOLD, 13));
lblFace.setBounds(231, 202, 131, 21);
contentPane.add(lblFace);
JLabel lblArmor = new JLabel("Armor");
lblArmor.setFont(new Font("Calibri", Font.BOLD, 13));
lblArmor.setBounds(421, 202, 131, 21);
contentPane.add(lblArmor);
JLabel lblAccessory = new JLabel("Accessory");
lblAccessory.setFont(new Font("Calibri", Font.BOLD, 13));
lblAccessory.setBounds(611, 202, 131, 21);
contentPane.add(lblAccessory);
//DROPBOXES
JComboBox<String> comboBox_hairs = new JComboBox<String>(hairs.toArray(new String[hairs.size()]));
comboBox_hairs.setBounds(40, 220, 131, 20);
comboBox_hairs.setMaximumRowCount(9);
contentPane.add(comboBox_hairs);
JComboBox<String> comboBox_faces = new JComboBox<String>(faces.toArray(new String[faces.size()]));
comboBox_faces.setBounds(230, 220, 131, 20);
comboBox_faces.setMaximumRowCount(9);
contentPane.add(comboBox_faces);
JComboBox<String> comboBox_armors = new JComboBox<String>(armors.toArray(new String[armors.size()]));
comboBox_armors.setBounds(420, 220, 131, 20);
comboBox_armors.setMaximumRowCount(9);
contentPane.add(comboBox_armors);
JComboBox<String> comboBox_accessories = new JComboBox<String>(accessories.toArray(new String[accessories.size()]));
comboBox_accessories.setBounds(610, 220, 131, 20);
comboBox_accessories.setMaximumRowCount(9);
contentPane.add(comboBox_accessories);
JComboBox<String> comboBox_tokens = new JComboBox<String>(tokens.toArray(new String[tokens.size()]));
comboBox_tokens.setBounds(230, 152, 131, 20);
comboBox_tokens.setMaximumRowCount(12);
contentPane.add(comboBox_tokens);
JLabel lblToken = new JLabel("Token");
lblToken.setFont(new Font("Calibri", Font.BOLD, 13));
lblToken.setBounds(224, 135, 46, 21);
contentPane.add(lblToken);
//---------XY OFFSET SLIDERS--------------------
JLabel lblXOffset = new JLabel("Y Offset");
lblXOffset.setFont(new Font("Calibri", Font.BOLD, 13));
lblXOffset.setBounds(40, 245, 46, 21);
contentPane.add(lblXOffset);
//NOTE! XOFFSET AND YOFFSET GOT SWITCHED FOR HAIR, MAYBE ALL
JSlider hairXOffset = new JSlider();
hairXOffset.setValue(0);
hairXOffset.setPaintTicks(true);
hairXOffset.setPaintLabels(true);
hairXOffset.setMajorTickSpacing(10);
hairXOffset.setMaximum(20);
hairXOffset.setMinimum(-20);
hairXOffset.setBounds(30, 265, 151, 38);
contentPane.add(hairXOffset);
JLabel lblYOffset = new JLabel("X Offset");
lblYOffset.setFont(new Font("Calibri", Font.BOLD, 13));
lblYOffset.setBounds(40, 310, 46, 21);
contentPane.add(lblYOffset);
JSlider hairYOffset = new JSlider();
hairYOffset.setValue(0);
hairYOffset.setPaintTicks(true);
hairYOffset.setPaintLabels(true);
hairYOffset.setMinimum(-20);
hairYOffset.setMaximum(20);
hairYOffset.setMajorTickSpacing(10);
hairYOffset.setBounds(30, 330, 151, 38);
contentPane.add(hairYOffset);
JLabel label_2 = new JLabel("Y Offset");
label_2.setFont(new Font("Calibri", Font.BOLD, 13));
label_2.setBounds(230, 245, 46, 21);
contentPane.add(label_2);
JSlider faceXOffset = new JSlider();
faceXOffset.setValue(0);
faceXOffset.setPaintTicks(true);
faceXOffset.setPaintLabels(true);
faceXOffset.setMinimum(-20);
faceXOffset.setMaximum(20);
faceXOffset.setMajorTickSpacing(10);
faceXOffset.setBounds(220, 265, 151, 38);
contentPane.add(faceXOffset);
JLabel label_5 = new JLabel("X Offset");
label_5.setFont(new Font("Calibri", Font.BOLD, 13));
label_5.setBounds(230, 310, 46, 21);
contentPane.add(label_5);
JSlider faceYOffset = new JSlider();
faceYOffset.setValue(0);
faceYOffset.setPaintTicks(true);
faceYOffset.setPaintLabels(true);
faceYOffset.setMinimum(-20);
faceYOffset.setMaximum(20);
faceYOffset.setMajorTickSpacing(10);
faceYOffset.setBounds(220, 330, 151, 38);
contentPane.add(faceYOffset);
JLabel label_8 = new JLabel("Y Offset");
label_8.setFont(new Font("Calibri", Font.BOLD, 13));
label_8.setBounds(420, 245, 46, 21);
contentPane.add(label_8);
JSlider armorXOffset = new JSlider();
armorXOffset.setValue(0);
armorXOffset.setPaintTicks(true);
armorXOffset.setPaintLabels(true);
armorXOffset.setMinimum(-20);
armorXOffset.setMaximum(20);
armorXOffset.setMajorTickSpacing(10);
armorXOffset.setBounds(410, 265, 151, 38);
contentPane.add(armorXOffset);
JLabel label_11 = new JLabel("X Offset");
label_11.setFont(new Font("Calibri", Font.BOLD, 13));
label_11.setBounds(420, 310, 46, 21);
contentPane.add(label_11);
JSlider armorYOffset = new JSlider();
armorYOffset.setValue(0);
armorYOffset.setPaintTicks(true);
armorYOffset.setPaintLabels(true);
armorYOffset.setMinimum(-20);
armorYOffset.setMaximum(20);
armorYOffset.setMajorTickSpacing(10);
armorYOffset.setBounds(410, 330, 151, 38);
contentPane.add(armorYOffset);
//Accessories
JLabel lblAccessoryYOffset = new JLabel("Y Offset");
lblAccessoryYOffset.setFont(new Font("Calibri", Font.BOLD, 13));
lblAccessoryYOffset.setBounds(610, 245, 46, 21);
contentPane.add(lblAccessoryYOffset);
JSlider accessoryXOffset = new JSlider();
accessoryXOffset.setValue(0);
accessoryXOffset.setPaintTicks(true);
accessoryXOffset.setPaintLabels(true);
accessoryXOffset.setMinimum(-20);
accessoryXOffset.setMaximum(20);
accessoryXOffset.setMajorTickSpacing(10);
accessoryXOffset.setBounds(600, 265, 151, 38);
contentPane.add(accessoryXOffset);
JLabel lblAccessoryXOffset = new JLabel("X Offset");
lblAccessoryXOffset.setFont(new Font("Calibri", Font.BOLD, 13));
lblAccessoryXOffset.setBounds(610, 310, 46, 21);
contentPane.add(lblAccessoryXOffset);
JSlider accessoryYOffset = new JSlider();
accessoryYOffset.setValue(0);
accessoryYOffset.setPaintTicks(true);
accessoryYOffset.setPaintLabels(true);
accessoryYOffset.setMinimum(-20);
accessoryYOffset.setMaximum(20);
accessoryYOffset.setMajorTickSpacing(10);
accessoryYOffset.setBounds(600, 330, 151, 38);
contentPane.add(accessoryYOffset);
JButton btnExport = new JButton(BTNEXPORT);
btnExport.setFont(new Font("Calibri", Font.BOLD, 13));
btnExport.setBounds(770, 265, 113, 38);
contentPane.add(btnExport);
JLabel lblFileName = new JLabel("File Name");
lblFileName.setFont(new Font("Calibri", Font.BOLD, 13));
lblFileName.setBounds(770, 202,113,21);
contentPane.add(lblFileName);
//JTextField exportFileName = new JTextField();
exportFileName.setBounds(770,220,113,21);
contentPane.add(exportFileName);
//--------LISTENERS--------------------
hairXOffset.addChangeListener(this);
hairYOffset.addChangeListener(this);
faceXOffset.addChangeListener(this);
faceYOffset.addChangeListener(this);
armorXOffset.addChangeListener(this);
armorYOffset.addChangeListener(this);
accessoryXOffset.addChangeListener(this);
accessoryYOffset.addChangeListener(this);
sliders.add(hairXOffset);
sliders.add(hairYOffset);
sliders.add(faceXOffset);
sliders.add(faceYOffset);
sliders.add(armorXOffset);
sliders.add(armorYOffset);
sliders.add(accessoryXOffset);
sliders.add(accessoryYOffset);
comboBox_hairs.addItemListener(this);
comboBox_faces.addItemListener(this);
comboBox_armors.addItemListener(this);
comboBox_accessories.addItemListener(this);
comboBox_tokens.addItemListener(this);
boxes.add(comboBox_hairs);
boxes.add(comboBox_faces);
boxes.add(comboBox_armors);
boxes.add(comboBox_tokens);
boxes.add(comboBox_accessories);
btnExport.addActionListener(this);
}
static BufferedImage deepCopy(BufferedImage bi) {
ColorModel cm = bi.getColorModel();
boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
WritableRaster raster = bi.copyData(null);
return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
}
void drawImages(){
portrait = deepCopy(blankPortrait);
token = new BufferedImage(128, 128, BufferedImage.TYPE_INT_ARGB);
Color pixel = null;
Color newPixel = null;
//Draw Hair_back
for(int i = 0; i<96; i++){
for(int j = 0; j<96; j++){
if (i-hairYOffsetVal <0 || i- hairYOffsetVal>95) continue;
if (j+hairXOffsetVal<0 || j+ hairXOffsetVal>95)continue;
pixel = new Color(hairb.getRGB(i-hairYOffsetVal, j+hairXOffsetVal),true);
if(pixel.getAlpha()==0){
continue;
}
newPixel = pixelParser(pixel);
//newPixel = pixel;
//System.out.println(newPixel.getRed());
//Image size x4
portrait.setRGB(i*2, j*2, newPixel.getRGB());
portrait.setRGB(i*2+1, j*2, newPixel.getRGB());
portrait.setRGB(i*2, j*2+1, newPixel.getRGB());
portrait.setRGB(i*2+1, j*2+1, newPixel.getRGB());
}
}
//Draw Armor
for(int i = 0; i<96; i++){
for(int j = 0; j<96; j++){
if (i-armorYOffsetVal <0 || i- armorYOffsetVal>95) continue;
if (j+armorXOffsetVal<0 || j+ armorXOffsetVal>95)continue;
pixel = new Color(armor.getRGB(i-armorYOffsetVal, j+armorXOffsetVal),true);
if(pixel.getAlpha()==0){
continue;
}
newPixel = pixelParser(pixel);
//newPixel = pixel;
portrait.setRGB(i*2, j*2, newPixel.getRGB());
portrait.setRGB(i*2+1, j*2, newPixel.getRGB());
portrait.setRGB(i*2, j*2+1, newPixel.getRGB());
portrait.setRGB(i*2+1, j*2+1, newPixel.getRGB());
}
}
//Draw face
for(int i = 0; i<96; i++){
for(int j = 0; j<96; j++){
if (i-faceYOffsetVal <0 || i- faceYOffsetVal>95) continue;
if (j+faceXOffsetVal<0 || j+ faceXOffsetVal>95)continue;
pixel = new Color(face.getRGB(i-faceYOffsetVal, j+faceXOffsetVal),true);
if(pixel.getAlpha()==0){
continue;
}
newPixel = facePixelParser(pixel);
//newPixel = pixel;
portrait.setRGB(i*2, j*2, newPixel.getRGB());
portrait.setRGB(i*2+1, j*2, newPixel.getRGB());
portrait.setRGB(i*2, j*2+1, newPixel.getRGB());
portrait.setRGB(i*2+1, j*2+1, newPixel.getRGB());
}
}
//Draw hair_front
for(int i = 0; i<96; i++){
for(int j = 0; j<96; j++){
if (i-hairYOffsetVal <0 || i- hairYOffsetVal>95) continue;
if (j+hairXOffsetVal<0 || j+ hairXOffsetVal>95)continue;
pixel = new Color(hair.getRGB(i-hairYOffsetVal, j+hairXOffsetVal),true);
newPixel = pixelParser(pixel);
if(pixel.getAlpha()==0){
continue;
}
//newPixel = pixel;
portrait.setRGB(i*2, j*2, newPixel.getRGB());
portrait.setRGB(i*2+1, j*2, newPixel.getRGB());
portrait.setRGB(i*2, j*2+1, newPixel.getRGB());
portrait.setRGB(i*2+1, j*2+1, newPixel.getRGB());
}
}
//Draw accessory
for(int i = 0; i<96; i++){
for(int j = 0; j<96; j++){
if (i-accessoryYOffsetVal <0 || i- accessoryYOffsetVal>95) continue;
if (j+accessoryXOffsetVal<0 || j+ accessoryXOffsetVal>95)continue;
pixel = new Color(accessory.getRGB(i-accessoryYOffsetVal, j+accessoryXOffsetVal),true);
newPixel = facePixelParser(pixel);
if(pixel.getAlpha()==0){
continue;
}
//newPixel = pixel;
portrait.setRGB(i*2, j*2, newPixel.getRGB());
portrait.setRGB(i*2+1, j*2, newPixel.getRGB());
portrait.setRGB(i*2, j*2+1, newPixel.getRGB());
portrait.setRGB(i*2+1, j*2+1, newPixel.getRGB());
}
}
//Draw Token
for(int i = 0; i<64; i++){
for(int j = 0; j<64; j++){
pixel = new Color(importedToken.getRGB(i, j),true);
if(pixel.getAlpha()==0){
continue;
}
newPixel = pixelParser(pixel);
//System.out.println(pixel.getRed() + " " + pixel.getGreen() + " " + pixel.getBlue());
//newPixel = pixel;
token.setRGB(i*2, j*2, newPixel.getRGB());
token.setRGB(i*2+1, j*2, newPixel.getRGB());
token.setRGB(i*2, j*2+1, newPixel.getRGB());
token.setRGB(i*2+1, j*2+1, newPixel.getRGB());
}
}
}
//RECOLORS EVERYTHING
//The included images all have red values corresponding to what they are.
//This is why eye and hair color match, because they share the same range of values (1-3)
//E.g. face color is 51, the lighter parts are 42, and darker parts are 60+, corresponding to case 4-8.
//Given that the max value is 25 (255), if the image eyes were changed to have red values above 210,
//they could be separated from the hair
//Alternatively, if the pixel could be confirmed as part of the hair or face, a simple if statement would fix it
Color pixelParser(Color pixel){
Color newPixel = null;
//double check this line
if(pixel.getAlpha() == 0){
newPixel = blankColor;
return newPixel;
}
int redIndex = pixel.getRed()/10;
//System.out.println(redIndex);
switch(redIndex){
case 0: newPixel = outlineColor;
break;
case 1: newPixel = hairColor.brighter();
break;
case 2: newPixel = hairColor;
break;
case 3: newPixel = hairColor.darker();
break;
case 4: newPixel = skinColor.brighter();
break;
case 5: newPixel = skinColor;
break;
case 6: newPixel = skinColor.darker();
break;
case 7: newPixel = skinColor.darker().darker();
break;
case 8: newPixel = skinColor.darker().darker().darker();
break;
case 9: newPixel = metalColor.brighter();
break;
case 10: newPixel = metalColor;
break;
case 11: newPixel = metalColor.darker();
break;
case 12: newPixel = trimColor.brighter();
break;
case 13: newPixel = trimColor;
break;
case 14: newPixel = trimColor.darker();
break;
case 15: newPixel = clothColor.brighter();
break;
case 16: newPixel = clothColor;
break;
case 17: newPixel = clothColor.darker();
break;
case 18: newPixel = leatherColor.brighter();
break;
case 19: newPixel = leatherColor;
break;
case 20: newPixel = leatherColor.darker();
break;
default: newPixel = Color.WHITE;
}
return newPixel;
}
Color facePixelParser(Color pixel){ //Currently used for face and accessory
Color newPixel = null;
//double check this line
if(pixel.getAlpha() == 0){
newPixel = blankColor;
return newPixel;
}
int redIndex = pixel.getRed()/10;
//System.out.println(redIndex);
switch(redIndex){
case 0: newPixel = outlineColor;
break;
case 1: newPixel = eyeColor.brighter();
break;
case 2: newPixel = eyeColor;
break;
case 3: newPixel = eyeColor.darker();
break;
case 4: newPixel = skinColor.brighter();
break;
case 5: newPixel = skinColor;
break;
case 6: newPixel = skinColor.darker();
break;
case 7: newPixel = skinColor.darker().darker();
break;
case 8: newPixel = skinColor.darker().darker().darker();
break;
case 9: newPixel = accessoryColor.brighter();
break;
case 10: newPixel = accessoryColor;
break;
case 11: newPixel = accessoryColor.darker();
break;
//12-20 shouldn't get used, but I'll keep them for now
case 12: newPixel = trimColor.brighter();
break;
case 13: newPixel = trimColor;
break;
case 14: newPixel = trimColor.darker();
break;
case 15: newPixel = clothColor.brighter();
break;
case 16: newPixel = clothColor;
break;
case 17: newPixel = clothColor.darker();
break;
case 18: newPixel = leatherColor.brighter();
break;
case 19: newPixel = leatherColor;
break;
case 20: newPixel = leatherColor.darker();
break;
default: newPixel = Color.WHITE;
}
return newPixel;
}
//If slider value changes, update image
public void stateChanged(ChangeEvent e){
JSlider src = (JSlider) e.getSource();
int index = sliders.indexOf(src);
int val = src.getValue();
//System.out.println(index);
switch(index){
case 0: //hair_X ------Should not be using id numbers. Too many potential problems when changed
hairXOffsetVal = val;
break;
case 1: //hair_Y
hairYOffsetVal = val;
break;
case 2:
faceXOffsetVal = val;
break;
case 3:
faceYOffsetVal = val;
break;
case 4:
armorXOffsetVal = val;
break;
case 5:
armorYOffsetVal = val;
break;
case 6:
accessoryXOffsetVal = val;
break;
case 7:
accessoryYOffsetVal = val;
break;
default:
System.out.println("Switch statement overran");
}
//System.out.println(src.getName() + " Val: " + val);
drawImages();
portraitPanel.setImage(portrait);
portraitPanel.repaint();
tokenPanel.setImage(token);
tokenPanel.repaint();
}
public void itemStateChanged(ItemEvent event){
try {
String rawPath = FireEmblemCharacterCreator.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String path = URLDecoder.decode(rawPath, "UTF-8");
path = path.substring(0, path.lastIndexOf("/") + 1);
path = path.replaceAll("%20", " ");
JComboBox<String> src = (JComboBox<String>)event.getSource();
String fileName = (String)src.getSelectedItem();
int menuNumber = boxes.indexOf(src);
switch(menuNumber){
case 0:
try {
hair = ImageIO.read(new File(path + "resources/" + fileName));
} catch (IOException ex) {
}
try {
String secondFileName = fileName.substring(0, fileName.length()-4);
hairb = ImageIO.read(new File(path + "resources/" + secondFileName + "b.png"));
} catch (IOException ex) {
}
break;
case 1:
try {
face = ImageIO.read(new File(path + "resources/" + fileName));
} catch (IOException ex) {
}
break;
case 2:
try {
armor = ImageIO.read(new File(path + "resources/" + fileName));
} catch (IOException ex) {
}
break;
case 3:
try {
importedToken = ImageIO.read(new File(path + "resources/" + fileName));
//System.out.println(src.getName() + " FileName: " + fileName);
} catch (IOException ex) {
}
break;
case 4:
try {
accessory = ImageIO.read(new File(path + "resources/" + fileName));