forked from alpyre/Sevgi_Engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_editor.c
More file actions
1587 lines (1393 loc) · 58.5 KB
/
Copy pathimage_editor.c
File metadata and controls
1587 lines (1393 loc) · 58.5 KB
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
/******************************************************************************
* ImageEditor *
******************************************************************************/
///Defines
#define MODE_BLANK 0
#define MODE_BOBSHEET 1
#define MODE_SPRITEBANK 2
#define MUIM_ImageEditor_Load 0x80430601
#define MUIM_ImageEditor_Save 0x80430602
#define MUIM_ImageEditor_SaveAs 0x80430603
#define MUIM_ImageEditor_ChangeSpec 0x80430604
#define MUIM_ImageEditor_UpdateSpec 0x80430605
#define MUIM_ImageEditor_SelectHitBox 0x80430606
#define MUIM_ImageEditor_AddHitBox 0x80430607
#define MUIM_ImageEditor_RemoveHitBox 0x80430608
#define MUIM_ImageEditor_SpecUp 0x80430609
#define MUIM_ImageEditor_SpecDown 0x8043060A
#define UPDATE_H_OFFS 0x01
#define UPDATE_V_OFFS 0x02
#define UPDATE_HITBOX_X1 0x03
#define UPDATE_HITBOX_Y1 0x04
#define UPDATE_HITBOX_X2 0x05
#define UPDATE_HITBOX_Y2 0x06
///
///Includes
#include <stdio.h> // <-- For sprintf()
#include <string.h> // <-- For sprintf()
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/asl.h>
#include <proto/utility.h> // <-- Required for tag redirection
#include <libraries/mui.h>
#include <libraries/asl.h>
#include <proto/muimaster.h>
#include <clib/alib_protos.h> // <-- Required for DoSuperMethod()
#include <SDI_compiler.h> // Required for
#include <SDI_hook.h> // <-- multi platform
#include <SDI_stdarg.h> // compatibility
#include "dosupernew.h"
#include "utility.h"
#include "toolbar.h"
#include "integer_gadget.h"
#include "image_display.h"
#include "image_editor.h"
///
///Structs
struct cl_ObjTable
{
Object* load;
Object* save;
Object* saveas;
Object* undo;
Object* redo;
Object* file;
Object* scale;
Object* small;
Object* big;
Object* hitbox_small;
Object* display;
Object* image_group;
Object* img_num;
Object* img_up;
Object* img_down;
Object* width;
Object* height;
Object* h_offs;
Object* v_offs;
Object* hitbox_group;
Object* hitbox_lv;
Object* hitbox_x1;
Object* hitbox_y1;
Object* hitbox_x2;
Object* hitbox_y2;
Object* hitbox_add;
Object* hitbox_rem;
};
struct cl_Data
{
struct cl_ObjTable obj_table;
ULONG mode; //MODE_BOBSHEET or MODE_SPRITEBANK
struct Sheet* sheet;
BOOL edited;
};
struct cl_Msg
{
ULONG MethodID;
LONG value;
};
struct cl_UpdateMsg
{
ULONG MethodID;
ULONG update_mode;
LONG value;
};
///
///Globals
extern APTR g_MemoryPool;
extern struct FileRequester* g_FileReq;
extern Object* App;
extern struct MUI_CustomClass* MUIC_Integer;
extern struct MUI_CustomClass* MUIC_ImageDisplay;
extern struct Project {
STRPTR directory;
STRPTR settings_header;
STRPTR assets_header;
STRPTR palettes_header;
STRPTR data_drawer;
STRPTR assets_drawer;
ULONG screen_depth;
}g_Project;
///
///Protos
ULONG m_FillHitBoxList(struct IClass* cl, Object* obj);
///
///Hooks
/******************************************************************************
* Displays the hitbox item as its index on the list. *
******************************************************************************/
HOOKPROTO(hitbox_dispfunc, LONG, char **array, struct HitBox* p)
{
if (p) {
static UBYTE pos[8];
sprintf(pos, "%ld", (LONG)array[-1] + 1);
*array = pos;
}
return(0);
}
MakeStaticHook(hitbox_disphook, hitbox_dispfunc);
///
///checkFileType(file)
ULONG checkFileType(STRPTR file)
{
ULONG ret_val = MODE_BLANK;
BPTR fh = Open(file, MODE_OLDFILE);
UBYTE id[8];
if (fh) {
Read(fh, id, 8);
if (strncmp(id, "BOBSHEET", 8) == 0) {
ret_val = MODE_BOBSHEET;
}
else if (strncmp(id, "SPRBANK", 7) == 0) {
ret_val = MODE_SPRITEBANK;
}
Close(fh);
}
return ret_val;
}
///
///checkDataSizes(sheet)
/******************************************************************************
* Returns the recommended data size type for the image sheet. *
******************************************************************************/
UBYTE checkDataSizes(struct Sheet* sheet)
{
UBYTE type = 0;
ULONG i;
ULONG i_max = sheet->num_images;
BOOL small_sizes = TRUE;
BOOL big_sizes = FALSE;
BOOL has_hitboxes = FALSE;
BOOL small_hitboxes = TRUE;
struct HitBox* hb;
for (i = 0; i < i_max; i++) {
if (sheet->spec[i].width > 0xFF || sheet->spec[i].height > 0xFF) {
big_sizes = TRUE;
break;
}
if (small_sizes && (sheet->spec[i].h_offs > 127 || sheet->spec[i].h_offs < -128 ||
sheet->spec[i].v_offs > 127 || sheet->spec[i].h_offs < -128)) {
small_sizes = FALSE;
}
for (hb = (struct HitBox*) sheet->spec[i].hitboxes.mlh_Head; hb->node.mln_Succ; hb = (struct HitBox*)hb->node.mln_Succ) {
has_hitboxes = TRUE;
if (hb->x1 > 127 || hb->x1 < -128 || hb->x2 > 127 || hb->x2 < -128 || hb->y1 > 127 || hb->y1 < -128 || hb->y2 > 127 || hb->y2 < -128) {
small_hitboxes = FALSE;
}
}
}
if (big_sizes) {
type = 0x04;
}
else if (small_sizes) {
type = 0x02;
}
if (has_hitboxes) {
type |= 0x08;
if (small_hitboxes) {
type |= 0x10;
}
}
return type;
}
///
///copySheetILBM(old_sheet_file, ilbm_filename, new_dir)
/******************************************************************************
* If the sheet is "saved as" to a different directory, copy the BOBSheet's *
* ILBM file to the new directory alongside with it. *
******************************************************************************/
VOID copySheetILBM(STRPTR old_sheet_file, STRPTR ilbm_filename, STRPTR new_dir)
{
STRPTR old_dir = pathPart(old_sheet_file);
if (old_dir && strcmp(old_dir, new_dir)) {
STRPTR old_ILBM_path = makePath(old_dir, ilbm_filename, NULL);
if (old_ILBM_path) {
STRPTR new_ILBM_path = makePath(new_dir, ilbm_filename, NULL);
if (new_ILBM_path) {
if (Exists(old_ILBM_path)) {
CopyFile(old_ILBM_path, new_ILBM_path);
}
freeString(new_ILBM_path);
}
freeString(old_ILBM_path);
}
}
freeString(old_dir);
}
///
///findOnSaveList(save_list, index)
struct HitBox* findOnSaveList(struct MinList* save_list, UWORD index)
{
struct HitBox* hb;
for (hb = (struct HitBox*)save_list->mlh_Head; hb->node.mln_Succ; hb = (struct HitBox*)hb->node.mln_Succ){
if (hb->index == index) return hb;
}
return NULL;
}
///
///compareHitBoxes(save_list, hb1, hb2)
BOOL compareHitBoxes(struct MinList* save_list, struct HitBox* hb1, /*WARNING: must be a save list hitbox*/ struct HitBox* hb2)
{
if (hb2->next == 0xFFFE) return FALSE;
if (hb1->x1 != hb2->x1) return FALSE;
if (hb1->y1 != hb2->y1) return FALSE;
if (hb1->x2 != hb2->x2) return FALSE;
if (hb1->y2 != hb2->y2) return FALSE;
if (hb1->node.mln_Succ->mln_Succ) {
if (hb2->next == 0xFFFF) return FALSE;
else {
return compareHitBoxes(save_list, (struct HitBox*)hb1->node.mln_Succ, findOnSaveList(save_list, hb2->next));
}
}
else {
if (hb2->next == 0xFFFF) return TRUE;
else return FALSE;
}
return TRUE;
}
///
///createSaveHitBox(save_list, current_index, hitbox)
UWORD createSaveHitBox(struct MinList* save_list, UWORD* current_index, struct HitBox* hitbox)
{
UWORD ret_val = *current_index;
struct HitBox* hb_test;
struct HitBox* hb_new;
struct HitBox* hb_next;
if (hitbox->node.mln_Succ) {
for (hb_test = (struct HitBox*)save_list->mlh_Head; hb_test->node.mln_Succ; hb_test = (struct HitBox*)hb_test->node.mln_Succ) {
if (compareHitBoxes(save_list, hitbox, hb_test)) {
return hb_test->index;
}
}
if (hitbox->node.mln_Succ->mln_Succ)
hb_next = (struct HitBox*)hitbox->node.mln_Succ;
else
hb_next = NULL;
hb_new = newHitBox(hitbox->x1, hitbox->y1, hitbox->x2, hitbox->y2, *current_index, 0xFFFE);
if (hb_new) {
AddTail((struct List*)save_list, (struct Node*)hb_new);
*current_index = *current_index + 1;
if (hb_next)
hb_new->next = createSaveHitBox(save_list, current_index, hb_next);
else
hb_new->next = 0xFFFF;
}
return ret_val;
}
else
return 0xFFFF;
}
///
///saveHitBoxes(fh, sheet, type)
VOID saveHitBoxes(BPTR fh, struct Sheet* sheet, UBYTE type)
{
if (type & 0x08) {
ULONG i;
struct HitBox* hb_save;
struct HitBox* hb_next;
struct MinList save_list;
UWORD* index = AllocPooled(g_MemoryPool, sizeof(UWORD)* sheet->num_images);
UWORD num_hitboxes = 0;
if (index) {
NewList((struct List*)&save_list);
//populate the save list
for (i = 0; i < sheet->num_images; i++) {
index[i] = createSaveHitBox(&save_list, &num_hitboxes, (struct HitBox*)sheet->spec[i].hitboxes.mlh_Head);
}
Write(fh, &num_hitboxes, sizeof(UWORD));
Write(fh, index, sizeof(UWORD) * sheet->num_images);
if (type & 0x10) {
for (hb_save = (struct HitBox*)save_list.mlh_Head; hb_save->node.mln_Succ; hb_save = (struct HitBox*)hb_save->node.mln_Succ) {
struct HitBox_small {
BYTE x1, y1;
BYTE x2, y2;
UWORD next_hitbox;
}hb;
hb.x1 = hb_save->x1;
hb.y1 = hb_save->y1;
hb.x2 = hb_save->x2;
hb.y2 = hb_save->y2;
hb.next_hitbox = hb_save->next;
Write(fh, &hb, sizeof(hb));
}
}
else
{
for (hb_save = (struct HitBox*)save_list.mlh_Head; hb_save->node.mln_Succ; hb_save = (struct HitBox*)hb_save->node.mln_Succ) {
struct HitBox_big {
WORD x1, y1;
WORD x2, y2;
UWORD next_hitbox;
}hb;
hb.x1 = hb_save->x1;
hb.y1 = hb_save->y1;
hb.x2 = hb_save->x2;
hb.y2 = hb_save->y2;
hb.next_hitbox = hb_save->next;
Write(fh, &hb, sizeof(hb));
}
}
//Free the memory used
FreePooled(g_MemoryPool, index, sizeof(UWORD) * sheet->num_images);
for (hb_save = (struct HitBox*)save_list.mlh_Head; (hb_next = (struct HitBox*)hb_save->node.mln_Succ); hb_save = hb_next) {
deleteHitBox(hb_save);
}
}
}
}
///
//<DEFINE SUBCLASS METHODS HERE>
///m_Reset(cl, obj, msg)
ULONG m_Reset(struct IClass* cl, Object* obj, Msg msg)
{
struct cl_Data *data = INST_DATA(cl, obj);
if (data->sheet) {
freeSheet(data->sheet);
data->sheet = NULL;
data->mode = MODE_BLANK;
data->edited = FALSE;
DoMethod(data->obj_table.file, MUIM_Set, MUIA_Text_Contents, "");
DoMethod(data->obj_table.small, MUIM_NoNotifySet, MUIA_Selected, TRUE);
DoMethod(data->obj_table.big, MUIM_NoNotifySet, MUIA_Selected, FALSE);
DoMethod(data->obj_table.hitbox_small, MUIM_Set, MUIA_Disabled, TRUE);
DoMethod(data->obj_table.hitbox_small, MUIM_Set, MUIA_Selected, TRUE);
DoMethod(data->obj_table.display, MUIM_Set, MUIA_ImageDisplay_Sheet, NULL);
DoMethod(data->obj_table.img_num, MUIM_NoNotifySet, MUIA_Integer_Value, 0);
DoMethod(data->obj_table.width, MUIM_Set, MUIA_Integer_Value, 0);
DoMethod(data->obj_table.height, MUIM_Set, MUIA_Integer_Value, 0);
DoMethod(data->obj_table.h_offs, MUIM_NoNotifySet, MUIA_Integer_Value, 0);
DoMethod(data->obj_table.v_offs, MUIM_NoNotifySet, MUIA_Integer_Value, 0);
DoMethod(data->obj_table.hitbox_lv, MUIM_List_Clear);
DoMethod(data->obj_table.hitbox_x1, MUIM_NoNotifySet, MUIA_Integer_Value, 0);
DoMethod(data->obj_table.hitbox_y1, MUIM_NoNotifySet, MUIA_Integer_Value, 0);
DoMethod(data->obj_table.hitbox_x2, MUIM_NoNotifySet, MUIA_Integer_Value, 0);
DoMethod(data->obj_table.hitbox_y2, MUIM_NoNotifySet, MUIA_Integer_Value, 0);
DoMethod(data->obj_table.image_group, MUIM_Set, MUIA_Disabled, TRUE);
DoMethod(data->obj_table.hitbox_group, MUIM_Set, MUIA_Disabled, TRUE);
DoMethod(data->obj_table.hitbox_add, MUIM_Set, MUIA_Disabled, TRUE);
DoMethod(data->obj_table.hitbox_rem, MUIM_Set, MUIA_Disabled, TRUE);
DoMethod(data->obj_table.save, MUIM_Set, MUIA_Disabled, TRUE);
DoMethod(data->obj_table.saveas, MUIM_Set, MUIA_Disabled, TRUE);
}
return 0;
}
///
///m_SetSheet(cl, obj, sheet, mode, filename)
ULONG m_SetSheet(struct IClass* cl, Object* obj, struct Sheet* sheet, ULONG mode, STRPTR filename)
{
struct cl_Data *data = INST_DATA(cl, obj);
data->sheet = sheet;
data->mode = mode;
DoMethod(data->obj_table.file, MUIM_Set, MUIA_Text_Contents, filename);
DoMethod(data->obj_table.small, MUIM_Set, MUIA_Selected, sheet->type & 0x02);
DoMethod(data->obj_table.big, MUIM_Set, MUIA_Selected, sheet->type & 0x04);
DoMethod(data->obj_table.hitbox_small, MUIM_Set, MUIA_Disabled, sheet->type &0x08 ? FALSE : TRUE);
DoMethod(data->obj_table.hitbox_small, MUIM_Set, MUIA_Selected, sheet->type &0x08 ? sheet->type & 0x10 : TRUE);
DoMethod(data->obj_table.display, MUIM_Set, MUIA_ImageDisplay_Sheet, sheet->image);
DoMethod(data->obj_table.display, MUIM_Set, MUIA_ImageDisplay_ImageSpec, &sheet->spec[0]);
DoMethod(data->obj_table.img_num, MUIM_NoNotifySet, MUIA_Integer_Value, 0);
DoMethod(data->obj_table.img_num, MUIM_Set, MUIA_Integer_Max, sheet->num_images - 1);
DoMethod(data->obj_table.width, MUIM_Set, MUIA_Integer_Value, sheet->spec[0].width);
DoMethod(data->obj_table.height, MUIM_Set, MUIA_Integer_Value, sheet->spec[0].height);
DoMethod(data->obj_table.h_offs, MUIM_NoNotifySet, MUIA_Integer_Value, sheet->spec[0].h_offs);
DoMethod(data->obj_table.v_offs, MUIM_NoNotifySet, MUIA_Integer_Value, sheet->spec[0].v_offs);
DoMethod(data->obj_table.hitbox_x1, MUIM_NoNotifySet, MUIA_Integer_Value, 0);
DoMethod(data->obj_table.hitbox_y1, MUIM_NoNotifySet, MUIA_Integer_Value, 0);
DoMethod(data->obj_table.hitbox_x2, MUIM_NoNotifySet, MUIA_Integer_Value, 0);
DoMethod(data->obj_table.hitbox_y2, MUIM_NoNotifySet, MUIA_Integer_Value, 0);
DoMethod(data->obj_table.image_group, MUIM_Set, MUIA_Disabled, FALSE);
if (mode == MODE_BOBSHEET) {
DoMethod(data->obj_table.img_up, MUIM_Set, MUIA_Disabled, FALSE);
DoMethod(data->obj_table.img_down, MUIM_Set, MUIA_Disabled, FALSE);
}
else {
DoMethod(data->obj_table.img_up, MUIM_Set, MUIA_Disabled, TRUE);
DoMethod(data->obj_table.img_down, MUIM_Set, MUIA_Disabled, TRUE);
}
DoMethod(data->obj_table.hitbox_add, MUIM_Set, MUIA_Disabled, FALSE);
DoMethod(data->obj_table.saveas, MUIM_Set, MUIA_Disabled, FALSE);
m_FillHitBoxList(cl, obj);
return 0;
}
///
///m_LoadSheet(cl, obj, msg)
ULONG m_LoadSheet(struct IClass* cl, Object* obj, Msg msg)
{
struct cl_Data *data = INST_DATA(cl, obj);
STRPTR path;
struct Window* window;
get(obj, MUIA_Window_Window, &window);
DoMethod(obj, MUIM_Set, MUIA_Window_Sleep, TRUE);
if (data->edited) {
if (!MUI_Request(App, obj, NULL, "Sheet Editor", "*_Discard|_Cancel", "Discard the changes made on the current sheet?")) {
goto cancel;
}
}
if (MUI_AslRequestTags(g_FileReq, ASLFR_TitleText, "Load a BOBSheet or SpriteBank",
ASLFR_Window, window,
ASLFR_PositiveText, "Load",
ASLFR_DrawersOnly, FALSE,
ASLFR_DoSaveMode, FALSE,
ASLFR_DoPatterns, TRUE,
ASLFR_InitialPattern, "#?.(sht|spr)",
g_Project.data_drawer ? ASLFR_InitialDrawer : TAG_IGNORE, g_Project.data_drawer,
ASLFR_InitialFile, "",
TAG_END) && strlen(g_FileReq->fr_File)) {
// ASL requester resets the busy pointer so let's set it again
SetWindowPointer(window, WA_BusyPointer, TRUE, TAG_DONE);
path = makePath(g_FileReq->fr_Drawer, g_FileReq->fr_File, NULL);
if (path) {
struct Sheet* sheet = NULL;
ULONG mode = checkFileType(path);
switch (mode) {
case MODE_BOBSHEET:
sheet = loadBOBSheet(path);
break;
case MODE_SPRITEBANK:
sheet = loadSpriteBank(path);
break;
default:
MUI_Request(App, obj, NULL, "Sheet Editor", "*_Ok", "File is not a Sevgi Engine SpriteBank or BOBSheet!");
}
if (sheet) {
m_Reset(cl, obj, msg);
m_SetSheet(cl, obj, sheet, mode, g_FileReq->fr_File);
}
freeString(path);
}
}
cancel:
DoMethod(obj, MUIM_Set, MUIA_Window_Sleep, FALSE);
return 0;
}
///
///m_SaveSheet(cl, obj, msg)
ULONG m_SaveSheet(struct IClass* cl, Object* obj, Msg msg)
{
struct cl_Data *data = INST_DATA(cl, obj);
if (data->sheet) {
struct Window* window;
BPTR fh = NULL;
ULONG i;
//put user selected size type settings onto the sheet
ULONG small_sizes;
ULONG big_sizes;
ULONG small_hitbox_sizes;
UBYTE new_type = 0;
DoMethod(obj, MUIM_Set, MUIA_Window_Sleep, TRUE);
get(obj, MUIA_Window_Window, &window);
get(data->obj_table.small, MUIA_Selected, &small_sizes);
get(data->obj_table.big, MUIA_Selected, &big_sizes);
get(data->obj_table.hitbox_small, MUIA_Selected, &small_hitbox_sizes);
new_type = small_sizes ? 0x02 : (big_sizes ? 0x04 : 0x00);
if (data->sheet->num_hitboxes) new_type |= (small_hitbox_sizes ? 0x18 : 0x08);
data->sheet->type = new_type;
switch (data->mode) {
case MODE_BOBSHEET:
{
fh = Open(data->sheet->sheet_file, MODE_READWRITE);
if (fh) {
UBYTE type = data->sheet->type & 0x06; //Let's temporarily turn off bit 0
UBYTE hbx_type = data->sheet->type & 0x18;
UBYTE recommended_type = checkDataSizes(data->sheet);
UBYTE recommended_img_type = recommended_type & 0x06;
UBYTE recommended_hbx_type = recommended_type & 0x18;
if (type == 0x04) {
MUI_Request(App, obj, NULL, "Sheet Editor", "*_Ok", "This BOBSheet requires compiling the engine with BIG_IMAGE_SIZES!");
}
else if (type != recommended_img_type) {
if (recommended_img_type == 0x02) {
if (MUI_Request(App, obj, NULL, "Sheet Editor", "Use _small sizes|*Use _default sizes", "This BOBSheet uses small size offsets and can be saved using small data size.\nWhich also suggests compiling the engine with SMALL_IMAGE_SIZES.\nWould you want to save with small data sizes?")) {
type = recommended_img_type;
}
}
else {
if (MUI_Request(App, obj, NULL, "Sheet Editor", "Continue|*_Cancel", "This BOBSheet was created with %s size offsets.\nAfter the edits made it now requires %s data sizes.\nIf you click 'Continue' the sheet will be saved using %s data sizes.%s\n\nWhat would you want to do?",
(ULONG)(type == 0x02 ? "small" : "regular"), (ULONG)(recommended_img_type == 0x02 ? "small" : "regular"), (ULONG)(recommended_img_type == 0x02 ? "small" : "regular"), (ULONG)(recommended_img_type == 0x02 ? "\nThis will require compiling the engine with SMALL_IMAGE_SIZES for this sheet to work." : ""))) {
type = recommended_img_type;
}
else goto cancel;
}
}
else if (type == 0x02) {
MUI_Request(App, obj, NULL, "Sheet Editor", "*_Ok", "This BOBSheet requires compiling the engine with SMALL_IMAGE_SIZES!");
}
if (recommended_hbx_type & 0x8) {
if (hbx_type & 0x8) {
if (hbx_type != recommended_hbx_type) {
if (recommended_hbx_type == 0x18) {
//was big, now small
if (MUI_Request(App, obj, NULL, "Sheet Editor", "Use _small sizes|*Use _default sizes", "The hitboxes on this BOBSheet used to have big size offsets.\nAfter the edits made it now can be saved with small data sizes.\nWhich also suggests compiling the engine with SMALL_IMAGE_SIZES.\n\nWhat would you want to do?")) {
type |= recommended_hbx_type;
}
else {
type |= hbx_type;
}
}
else {
//was small, now big
if (MUI_Request(App, obj, NULL, "Sheet Editor", "Continue|*_Cancel", "The hitboxes on this BOBSheet used to have small size offsets.\nAfter the edits made it now requires big data sizes.\nIf you click 'Continue' the sheet will be saved using big data sizes.\nThis will require compiling the engine withOUT SMALL_IMAGE_SIZES for this sheet to work.\n\nWhat would you want to do?")) {
type |= recommended_hbx_type;
}
else goto cancel;
}
}
else {
type |= recommended_hbx_type;
}
}
else {
type |= recommended_hbx_type;
}
}
type |= 0x01; //This editor can only save BST_IRREGULAR sheets
Write(fh, "BOBSHEET", 8);
Write(fh, data->sheet->ilbm_file, strlen(data->sheet->ilbm_file) + 1);
Write(fh, &type, 1);
Write(fh, &data->sheet->num_images, 2);
switch (type & 0x06) {
case 0x02: //SMALL_SIZES
for (i = 0; i < data->sheet->num_images; i++) {
UBYTE width = data->sheet->spec[i].width;
UBYTE height = data->sheet->spec[i].height;
BYTE h_offs = data->sheet->spec[i].h_offs;
BYTE v_offs = data->sheet->spec[i].v_offs;
UBYTE word = data->sheet->spec[i].x / 16;
UWORD row = data->sheet->spec[i].y;
Write(fh, &width, sizeof(width));
Write(fh, &height, sizeof(height));
Write(fh, &h_offs, sizeof(h_offs));
Write(fh, &v_offs, sizeof(v_offs));
Write(fh, &word, sizeof(word));
Write(fh, &row, sizeof(row));
}
break;
case 0x04: //BIG_SIZES
for (i = 0; i < data->sheet->num_images; i++) {
UWORD width = data->sheet->spec[i].width;
UWORD height = data->sheet->spec[i].height;
WORD h_offs = data->sheet->spec[i].h_offs;
WORD v_offs = data->sheet->spec[i].v_offs;
UBYTE word = data->sheet->spec[i].x / 16;
UWORD row = data->sheet->spec[i].y;
Write(fh, &width, sizeof(width));
Write(fh, &height, sizeof(height));
Write(fh, &h_offs, sizeof(h_offs));
Write(fh, &v_offs, sizeof(v_offs));
Write(fh, &word, sizeof(word));
Write(fh, &row, sizeof(row));
}
break;
default:
for (i = 0; i < data->sheet->num_images; i++) {
UBYTE width = data->sheet->spec[i].width;
UBYTE height = data->sheet->spec[i].height;
WORD h_offs = data->sheet->spec[i].h_offs;
WORD v_offs = data->sheet->spec[i].v_offs;
UBYTE word = data->sheet->spec[i].x / 16;
UWORD row = data->sheet->spec[i].y;
Write(fh, &width, sizeof(width));
Write(fh, &height, sizeof(height));
Write(fh, &h_offs, sizeof(h_offs));
Write(fh, &v_offs, sizeof(v_offs));
Write(fh, &word, sizeof(word));
Write(fh, &row, sizeof(row));
}
}
saveHitBoxes(fh, data->sheet, type);
SetFileSize(fh, 0, OFFSET_CURRENT);
}
}
break;
case MODE_SPRITEBANK:
{
UBYTE type = data->sheet->type & 0x06;
UBYTE hbx_type = data->sheet->type & 0x18;
UBYTE* table = (UBYTE*)data->sheet->sprite_bank + 10;
ULONG table_size = type == 0x02 ? 8 : (type == 0x04 ? 12 : 10);
UBYTE* spr_data = table + (table_size * data->sheet->num_images) + 2;
UWORD spr_data_size = *(UWORD*)(spr_data - 2);
fh = Open(data->sheet->sheet_file, MODE_READWRITE);
if (fh) {
UBYTE recommended_type = checkDataSizes(data->sheet);
UBYTE recommended_img_type = recommended_type & 0x06;
UBYTE recommended_hbx_type = recommended_type & 0x18;
if (type == 0x04) {
MUI_Request(App, obj, NULL, "Sheet Editor", "*_Ok", "This spritebank requires compiling the engine with BIG_IMAGE_SIZES!");
}
else if (type != recommended_img_type) {
if (recommended_img_type == 0x02) {
if (MUI_Request(App, obj, NULL, "Sheet Editor", "Use _small sizes|*Use _default sizes", "This spritebank uses small size offsets and can be saved using small data size.\nWhich also suggests compiling the engine with SMALL_IMAGE_SIZES.\nWould you want to save with small data sizes?")) {
type = recommended_img_type;
}
}
else {
if (MUI_Request(App, obj, NULL, "Sheet Editor", "Continue|*_Cancel", "This spritebank was created with %s size offsets.\nAfter the edits made it now requires %s data sizes.\nIf you click 'Continue' the bank will be saved using %s data sizes.%s\n\nWhat would you want to do?",
(ULONG)(type == 0x02 ? "small" : "regular"), (ULONG)(recommended_img_type == 0x02 ? "small" : "regular"), (ULONG)(recommended_img_type == 0x02 ? "small" : "regular"), (ULONG)(recommended_img_type == 0x02 ? "\nThis will require compiling the engine with SMALL_IMAGE_SIZES for this spritebank to work." : ""))) {
type = recommended_img_type;
}
else goto cancel;
}
}
else if (type == 0x02) {
MUI_Request(App, obj, NULL, "Sheet Editor", "*_Ok", "This spritebank requires compiling the engine with SMALL_IMAGE_SIZES!");
}
if (recommended_hbx_type & 0x8) {
if (hbx_type & 0x8) {
if (hbx_type != recommended_hbx_type) {
if (recommended_hbx_type == 0x18) {
//was big, now small
if (MUI_Request(App, obj, NULL, "Sheet Editor", "Use _small sizes|*Use _default sizes", "The hitboxes on this BOBSheet used to have big size offsets.\nAfter the edits made it now can be saved with small data sizes.\nWhich also suggests compiling the engine with SMALL_IMAGE_SIZES.\n\nWhat would you want to do?")) {
type |= recommended_hbx_type;
}
else {
type |= hbx_type;
}
}
else {
//was small, now big
if (MUI_Request(App, obj, NULL, "Sheet Editor", "Continue|*_Cancel", "The hitboxes on this BOBSheet used to have small size offsets.\nAfter the edits made it now requires big data sizes.\nIf you click 'Continue' the sheet will be saved using big data sizes.\nThis will require compiling the engine withOUT SMALL_IMAGE_SIZES for this sheet to work.\n\nWhat would you want to do?")) {
type |= recommended_hbx_type;
}
else goto cancel;
}
}
else {
type |= recommended_hbx_type;
}
}
else {
type |= recommended_hbx_type;
}
}
Write(fh, "SPRBANK", 7);
Write(fh, &type, 1);
Write(fh, &data->sheet->num_images, 2);
switch (type & 0x06) {
case 0x02: //SMALL_SIZES
for (i = 0; i < data->sheet->num_images; i++) {
UBYTE width = data->sheet->spec[i].width;
UBYTE height = data->sheet->spec[i].height;
BYTE h_offs = data->sheet->spec[i].h_offs;
BYTE v_offs = data->sheet->spec[i].v_offs;
Write(fh, table + table_size * i, 4); // Writes offset, type and hsn
Write(fh, &width, sizeof(width));
Write(fh, &height, sizeof(height));
Write(fh, &h_offs, sizeof(h_offs));
Write(fh, &v_offs, sizeof(v_offs));
}
break;
case 0x04: //BIG_SIZES
for (i = 0; i < data->sheet->num_images; i++) {
UWORD width = data->sheet->spec[i].width;
UWORD height = data->sheet->spec[i].height;
WORD h_offs = data->sheet->spec[i].h_offs;
WORD v_offs = data->sheet->spec[i].v_offs;
Write(fh, table + table_size * i, 4); // Writes offset, type and hsn
Write(fh, &width, sizeof(width));
Write(fh, &height, sizeof(height));
Write(fh, &h_offs, sizeof(h_offs));
Write(fh, &v_offs, sizeof(v_offs));
}
break;
default:
for (i = 0; i < data->sheet->num_images; i++) {
UBYTE width = data->sheet->spec[i].width;
UBYTE height = data->sheet->spec[i].height;
WORD h_offs = data->sheet->spec[i].h_offs;
WORD v_offs = data->sheet->spec[i].v_offs;
Write(fh, table + table_size * i, 4); // Writes offset, type and hsn
Write(fh, &width, sizeof(width));
Write(fh, &height, sizeof(height));
Write(fh, &h_offs, sizeof(h_offs));
Write(fh, &v_offs, sizeof(v_offs));
}
}
// Write sprite data size
Write(fh, &spr_data_size, 2);
// Write sprite data
Write(fh, spr_data, spr_data_size);
saveHitBoxes(fh, data->sheet, type);
SetFileSize(fh, 0, OFFSET_CURRENT);
}
}
break;
}
data->edited = FALSE;
DoMethod(data->obj_table.save, MUIM_Set, MUIA_Disabled, TRUE);
cancel:
if (fh) Close(fh);
DoMethod(obj, MUIM_Set, MUIA_Window_Sleep, FALSE);
}
return 0;
}
///
///m_SaveSheetAs(cl, obj, msg)
ULONG m_SaveSheetAs(struct IClass* cl, Object* obj, Msg msg)
{
struct cl_Data *data = INST_DATA(cl, obj);
if (data->sheet) {
STRPTR path;
struct Window* window;
get(obj, MUIA_Window_Window, &window);
DoMethod(obj, MUIM_Set, MUIA_Window_Sleep, TRUE);
if (MUI_AslRequestTags(g_FileReq, ASLFR_TitleText, "Save BOBSheet or SpriteBank as",
ASLFR_Window, window,
ASLFR_PositiveText, "Save",
ASLFR_DrawersOnly, FALSE,
ASLFR_DoSaveMode, TRUE,
ASLFR_DoPatterns, TRUE,
ASLFR_InitialPattern, "#?.(sht|spr)",
g_Project.data_drawer ? ASLFR_InitialDrawer : TAG_IGNORE, g_Project.data_drawer,
ASLFR_InitialFile, FilePart(data->sheet->sheet_file),
TAG_END) && strlen(g_FileReq->fr_File)) {
// ASL requester resets the busy pointer so let's set it again
SetWindowPointer(window, WA_BusyPointer, TRUE, TAG_DONE);
path = makePath(g_FileReq->fr_Drawer, g_FileReq->fr_File, NULL);
if (path) {
if (Exists(path)) {
if (!MUI_Request(App, obj, NULL, "Image Editor", "*_Overwrite|_Cancel", "Sheet file already exists!")) {
freeString(path);
goto cancel;
}
}
if (data->mode == MODE_BOBSHEET) {
copySheetILBM(data->sheet->sheet_file, data->sheet->ilbm_file, g_FileReq->fr_Drawer);
}
freeString(data->sheet->sheet_file);
data->sheet->sheet_file = path;
m_SaveSheet(cl, obj, msg);
DoMethod(data->obj_table.file, MUIM_Set, MUIA_Text_Contents, g_FileReq->fr_File);
}
}
cancel:
DoMethod(obj, MUIM_Set, MUIA_Window_Sleep, FALSE);
}
return 0;
}
///
///m_ChangeSpec(cl, obj, msg)
ULONG m_ChangeSpec(struct IClass* cl, Object* obj, struct cl_Msg* msg)
{
struct cl_Data *data = INST_DATA(cl, obj);
if (data->sheet) {
struct ImageSpec* spec = &data->sheet->spec[msg->value];
DoMethod(data->obj_table.width, MUIM_Set, MUIA_Integer_Value, spec->width);
DoMethod(data->obj_table.height, MUIM_Set, MUIA_Integer_Value, spec->height);
DoMethod(data->obj_table.h_offs, MUIM_NoNotifySet, MUIA_Integer_Value, spec->h_offs);
DoMethod(data->obj_table.v_offs, MUIM_NoNotifySet, MUIA_Integer_Value, spec->v_offs);
m_FillHitBoxList(cl, obj);
DoMethod(data->obj_table.display, MUIM_Set, MUIA_ImageDisplay_ImageSpec, spec);
}
return 0;
}
///
///m_UpdateSpec(cl, obj, msg)
ULONG m_UpdateSpec(struct IClass* cl, Object* obj, struct cl_UpdateMsg* msg)
{
struct cl_Data *data = INST_DATA(cl, obj);
if (data->sheet) {
ULONG img_num;
struct HitBox* hb;
get(data->obj_table.img_num, MUIA_Integer_Value, &img_num);
DoMethod(data->obj_table.hitbox_lv, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &hb);
switch (msg->update_mode) {
case UPDATE_H_OFFS:
data->sheet->spec[img_num].h_offs = msg->value;
break;
case UPDATE_V_OFFS:
data->sheet->spec[img_num].v_offs = msg->value;
break;
case UPDATE_HITBOX_X1:
if (hb) hb->x1 = msg->value;
break;
case UPDATE_HITBOX_Y1:
if (hb) hb->y1 = msg->value;
break;
case UPDATE_HITBOX_X2:
if (hb) hb->x2 = msg->value;
break;
case UPDATE_HITBOX_Y2:
if (hb) hb->y2 = msg->value;
break;
}
if (data->edited == FALSE) {
data->edited = TRUE;
DoMethod(data->obj_table.save, MUIM_Set, MUIA_Disabled, FALSE);
}
DoMethod(data->obj_table.display, MUIM_ImageDisplay_Update);
}
return 0;
}
///
///m_SpecUp(cl, obj, msg)
/******************************************************************************
* Moves the selected image's spec up changing the order of the sheet. *
* WARNING: Only works on BOBSheets! *
******************************************************************************/
ULONG m_SpecUp(struct IClass* cl, Object* obj, Msg msg)
{
struct cl_Data *data = INST_DATA(cl, obj);
if (data->sheet && data->sheet->num_images > 1 && data->mode == MODE_BOBSHEET) {
ULONG img_num;
get(data->obj_table.img_num, MUIA_Integer_Value, &img_num);
if (img_num < data->sheet->num_images - 1) {
swapSpecs(&data->sheet->spec[img_num], &data->sheet->spec[img_num + 1]);
DoMethod(data->obj_table.img_num, MUIM_NoNotifySet, MUIA_Integer_Value, img_num + 1);
}
}
return 0;
}
///
///m_SpecDown(cl, obj, msg)
/******************************************************************************
* Moves the selected image's spec down changing the order of the sheet. *
* WARNING: Only works on BOBSheets! *
******************************************************************************/
ULONG m_SpecDown(struct IClass* cl, Object* obj, Msg msg)
{
struct cl_Data *data = INST_DATA(cl, obj);
if (data->sheet && data->sheet->num_images > 1 && data->mode == MODE_BOBSHEET) {
ULONG img_num;
get(data->obj_table.img_num, MUIA_Integer_Value, &img_num);
if (img_num > 0) {
swapSpecs(&data->sheet->spec[img_num], &data->sheet->spec[img_num - 1]);
DoMethod(data->obj_table.img_num, MUIM_NoNotifySet, MUIA_Integer_Value, img_num - 1);
}
}
return 0;
}
///
///m_FillHitBoxList(cl, obj)
ULONG m_FillHitBoxList(struct IClass* cl, Object* obj)
{
struct cl_Data *data = INST_DATA(cl, obj);
if (data->sheet) {
ULONG img_num;
ULONG i;
struct MinList* hbs;