OSDN Git Service

CPU射程操作バグ改善
[awarsiii/AwarsIV.git] / Awars III / ScenarioEditor.m
1 //
2 //  ScenarioEditor.m
3 //  Awars III
4 //
5 //  Created by Killery on 2013/01/28.
6 //  Copyright (c) 2013年 Killery. All rights reserved.
7 //
8
9 #import "ScenarioEditor.h"
10 #import "StandView.h"
11 #import "EventView.h"
12 #import "FieldScene.h"
13
14 @implementation ScenarioEditor
15
16 -(void)awakeFromNib{
17     [textListTV setTarget:self];
18     [textListTV setAction:@selector(ClickTL:)];
19     [lineListTV setTarget:self];
20     [lineListTV setAction:@selector(ClickLL:)];
21     [lineListTV setDoubleAction:@selector(DoubleClickLL:)];
22     
23     [standListTV setTarget:self];
24     [standListTV setAction:@selector(ClickSTAND:)];
25     [standListTV setDoubleAction:@selector(DoubleClickSTAND:)];
26     
27     [baseListTV setTarget:self];
28     [baseListTV setAction:@selector(ClickBASE:)];
29     [baseListTV setDoubleAction:@selector(DoubleClickBASE:)];
30     
31     [layerListTV setTarget:self];
32     [layerListTV setAction:@selector(ClickLAYER:)];
33     [layerListTV setDoubleAction:@selector(DoubleClickLAYER:)];
34     
35     standListMA = [NSMutableArray new];
36     baseListMA = [NSMutableArray new];
37     layerListMA = [NSMutableArray new];
38     //textListMA = [NSMutableArray new];
39     //lineListMA = [NSMutableArray new];
40     
41     [SETV1 setTarget:self];
42     [SETV1 setAction:@selector(ClickSETV1:)];
43     [SETV2 setTarget:self];
44     [SETV2 setAction:@selector(ClickSETV2:)];
45     [SETV3 setTarget:self];
46     [SETV3 setAction:@selector(ClickSETV3:)];
47     
48     SEMA1 = [NSMutableArray new];
49     SEMA2 = [NSMutableArray new];
50     SEMA3 = [NSMutableArray new];
51     
52     
53     [TV1 setTarget:self];
54     [TV1 setAction:@selector(TV1sgl:)];
55     
56     MA1 = [NSMutableArray new];
57     
58     [TV2 setTarget:self];
59     [TV2 setAction:@selector(TV2sgl:)];
60     
61     MA2 = [NSMutableArray new];
62     
63     
64     
65     
66     [SETV setTarget:self];
67     [SETV setAction:@selector(ClickSETV:)];
68     
69     SEMA = [NSMutableArray new];
70     
71     deletedName = [NSMutableArray new];
72     baseListDC = @{@"1":baseListMA};
73 }
74
75 -(id)init{
76     
77     if(self){
78     
79         time = [NSTimer
80              scheduledTimerWithTimeInterval:0.1
81              target:self selector:@selector(EventLoop2:)
82              userInfo:nil repeats:YES
83             ];
84         
85         testScenarioEditor = self;
86         
87         //[SEstandWindow setH
88         
89         textListMA = [NSMutableArray new];
90         lineListMA = [NSMutableArray new];
91         
92         StringText *stringText = [[StringText alloc] init];
93         
94         for(int i = 0;i<255;i++){
95             [stringText AddString:&TX[i].S :0];
96         }
97         
98         for(int i = 0;i <TEXTMAX;i++){
99             TX[i].fileName = NULL;
100             TXCPY[i].fileName = NULL;
101         }
102         
103         OMFGflag = true;
104         [self initText];
105         [self addLineList];
106         [self initFileDirectory];
107         [self loadStandData];
108         [self loadData];
109         Irow = -1;
110         IBrow = -1;
111         IBLrow = -1;
112         st = -1;
113         [textListAC setSelectionIndex:9999];
114         
115         I = Itop;
116         while(I){
117         
118             BASE *b = I->B;
119             BASE *bTop = b;
120             
121             while (b) {
122                 
123                 LAYER *lTop = b->L;
124                 while (b->L) {
125                     
126                     b->L->visibleInstant = b->L->visible;
127                     
128                     b->L = b->L->next;
129                 }b->L = lTop;
130                 
131                 
132                 b = b->next;
133             }
134             
135             b = bTop;
136             
137             I = I->next;
138         }I = Itop;
139         
140         SEMArow = -1;
141         
142         TXCPYcpy = true;
143         
144         [SEstandWindow close];
145     }
146     return self;
147 }
148
149
150
151 -(void)ClickSETV:(id)sender{
152     [self willChangeValueForKey:@"SEMA1"];
153     [SEMA1 removeAllObjects];
154     [self didChangeValueForKey:@"SEMA1"];
155     [self willChangeValueForKey:@"SEMA2"];
156     [SEMA2 removeAllObjects];
157     [self didChangeValueForKey:@"SEMA2"];
158     [self willChangeValueForKey:@"SEMA3"];
159     [SEMA3 removeAllObjects];
160     [self didChangeValueForKey:@"SEMA3"];
161     [SEIV setImage:NULL];
162     SEMA1row = -1;
163     SEMA2row = -1;
164     SEMA3row = -1;
165     
166     SEMArow = [SETV clickedRow];
167     
168     TX[st].S = STRtop[st];
169     for(int i = 0;i < sl;i++){
170         TX[st].S = TX[st].S->next;
171     }
172     
173     if(SEMArow < 0){
174         TX[st].S = STRtop[st];
175         return;
176     }
177     SItop = TX[st].S->i;
178     for(int i = 0;i < SEMArow;i++){
179         TX[st].S->i = TX[st].S->i->next;
180     }
181     
182     I = Itop;
183     while(I){
184         NSMutableDictionary *dict = [NSMutableDictionary new];
185         
186         [dict setValue:[NSString stringWithFormat:@"%@", I->name] forKey:@"name"];
187         
188         
189         [self willChangeValueForKey:@"SEMA1"];
190         [SEMA1 addObject:dict];
191         [self didChangeValueForKey:@"SEMA1"];
192         
193         I = I->next;
194     }I = Itop;
195     
196     if(TX[st].S->i){
197         
198         if(TX[st].S->i->SEMA1row-1 < 0){
199             [SEAC1 setSelectionIndex:9999];
200             [SEAC2 setSelectionIndex:9999];
201             [SEAC3 setSelectionIndex:9999];
202             TX[st].S->i = SItop;
203             TX[st].S = STRtop[st];
204             return;
205         }
206         
207         
208     }else{
209         [SEAC1 setSelectionIndex:9999];
210         [SEAC2 setSelectionIndex:9999];
211         [SEAC3 setSelectionIndex:9999];
212         TX[st].S->i = SItop;
213         TX[st].S = STRtop[st];
214         return;
215         
216     }
217     
218     I = Itop;
219     for(int i = 0;i < TX[st].S->i->SEMA1row-1;i++){
220         I = I->next;
221     }
222     
223     
224     BASE *b = I->B;
225     BASE *bTop = b;
226     
227     while(b){
228         NSMutableDictionary *dict = [NSMutableDictionary new];
229         
230         [dict setValue:[NSString stringWithFormat:@"%@", b->name] forKey:@"name"];
231         
232         
233         [self willChangeValueForKey:@"SEMA2"];
234         [SEMA2 addObject:dict];
235         [self didChangeValueForKey:@"SEMA2"];
236         
237         b = b->next;
238     }
239     b = bTop;
240     
241     I = Itop;
242     
243     if(TX[st].S->i){
244         
245     if(TX[st].S->i->SEMA2row-1 < 0){
246         [SEAC1 setSelectionIndex:9999];
247         [SEAC2 setSelectionIndex:9999];
248         [SEAC3 setSelectionIndex:9999];
249         TX[st].S->i = SItop;
250         TX[st].S = STRtop[st];
251         return;
252     }
253     
254     }else{
255         [SEAC1 setSelectionIndex:9999];
256         [SEAC2 setSelectionIndex:9999];
257         [SEAC3 setSelectionIndex:9999];
258         TX[st].S->i = SItop;
259         TX[st].S = STRtop[st];
260         return;
261     
262     
263     }
264     I = Itop;
265     for(int i = 0;i < TX[st].S->i->SEMA1row-1;i++){
266         I = I->next;
267     }
268     
269
270     for(int i = 0;i < TX[st].S->i->SEMA2row-1;i++){
271         b = b->next;
272     }
273     
274     LAYER *lTop = b->L;
275     if(!TX[st].S->i->SEMA3flag) TX[st].S->i->SEMA3flag = calloc(999, sizeof(int));
276     int i0 = 0;
277     while(b->L){
278         NSMutableDictionary *dict = [NSMutableDictionary new];
279         
280         int value = *(TX[st].S->i->SEMA3flag + i0) - 1;
281         //おまんちん
282         if(value < 0) value = 0;
283         
284         [dict setValue:[NSString stringWithFormat:@"%@", b->L->name] forKey:@"name"];
285         [dict setValue:[NSString stringWithFormat:@"%d", value] forKey:@"v"];
286         
287         [self willChangeValueForKey:@"SEMA3"];
288         [SEMA3 addObject:dict];
289         [self didChangeValueForKey:@"SEMA3"];
290         
291         b->L->visibleInstant = value;
292         
293         i0++;
294         b->L = b->L->next;
295     }
296     b->L = lTop;
297     
298     b = bTop;
299     I = Itop;
300     
301     if(TX[st].S->i){
302         [SEAC1 setSelectionIndex:TX[st].S->i->SEMA1row-1];
303         [SEAC2 setSelectionIndex:TX[st].S->i->SEMA2row-1];
304         SEMA1row = TX[st].S->i->SEMA1row-1;
305         SEMA2row = TX[st].S->i->SEMA2row-1;
306         //[SEstandTF setStringValue:[NSString stringWithFormat:@"x:%d y:%d", TX[st].S->i->standX, TX[st].S->i->standY]];
307         [SEstandTFx setStringValue:[NSString stringWithFormat:@"%d", TX[st].S->i->standX]];
308         [SEstandTFy setStringValue:[NSString stringWithFormat:@"%d", TX[st].S->i->standY]];
309     }else{
310         [SEAC1 setSelectionIndex:9999];
311         [SEAC2 setSelectionIndex:9999];
312     }
313     
314     SEMA3row = -1;
315     [SEAC3 setSelectionIndex:9999];
316     
317     TX[st].S->i = SItop;
318     TX[st].S = STRtop[st];
319 }
320
321 -(void)ClickSETV1:(id)sender{
322     SEMA1row = [SETV1 clickedRow];
323     SEMA2row = -1;
324     SEMA3row = -1;
325     
326     TX[st].S = STRtop[st];
327     for(int i = 0;i < sl;i++){
328         TX[st].S = TX[st].S->next;
329     }
330     
331     if(SEMArow < 0){
332         TX[st].S = STRtop[st];
333         return;
334     }
335     SItop = TX[st].S->i;
336     for(int i = 0;i < SEMArow;i++){
337         TX[st].S->i = TX[st].S->i->next;
338     }
339     
340     TX[st].S->i->SEMA1row = (int)SEMA1row + 1;
341     
342
343     
344     [self willChangeValueForKey:@"SEMA2"];
345     [SEMA2 removeAllObjects];
346     [self didChangeValueForKey:@"SEMA2"];
347     [self willChangeValueForKey:@"SEMA3"];
348     [SEMA3 removeAllObjects];
349     [self didChangeValueForKey:@"SEMA3"];
350     
351     I = Itop;
352     
353     if(SEMA1row < 0){
354         
355         
356         TX[st].S->i = SItop;
357         
358         TX[st].S = STRtop[st];
359         return;
360     }
361     
362     for(int i = 0;i < SEMA1row;i++){
363         I = I->next;
364     }
365     
366     if(!I) {
367         I = Itop;
368         TX[st].S->i = SItop;
369         
370         TX[st].S = STRtop[st];
371         
372         return;
373     }
374     
375     b = I->B;
376     
377     bool first = false;
378     BASE *bTop = b;
379     LAYER *lTop = NULL;
380     while(b){
381         NSMutableDictionary *dict2 = [NSMutableDictionary new];
382         [dict2 setValue:[NSString stringWithFormat:@"%@", b->name]  forKeyPath:@"name"];
383         
384         [self willChangeValueForKey:@"SEMA2"];
385         [SEMA2 addObject:dict2];
386         [self didChangeValueForKey:@"SEMA2"];
387         
388         lTop = b->L;
389         int i0 = 0;
390         TX[st].S->i->SEMA3flag = calloc(999, sizeof(int));
391         while(b->L && !first){
392             NSMutableDictionary *dict2 = [NSMutableDictionary new];
393             [dict2 setValue:[NSString stringWithFormat:@"%@", b->L->name]  forKeyPath:@"name"];
394             [dict2 setValue:[NSString stringWithFormat:@"%d", b->L->visible] forKeyPath:@"v"];
395             
396             b->L->visibleInstant = true;
397             *(TX[st].S->i->SEMA3flag+i0) = b->L->visible;
398             
399             
400             [self willChangeValueForKey:@"SEMA3"];
401             [SEMA3 addObject:dict2];
402             [self didChangeValueForKey:@"SEMA3"];
403             
404             b->L = b->L->next;
405             i0++;
406         }
407         b->L = lTop;
408         first = true;
409         
410         b = b->next;
411     }
412     
413     
414     TX[st].S->i = SItop;
415     
416     TX[st].S = STRtop[st];
417     
418     b = bTop;
419     
420     I = Itop;
421     
422     [SEAC2 setSelectionIndex:9999];
423     [SEAC3 setSelectionIndex:9999];
424 }
425
426 -(void)ClickSETV2:(id)sender{
427     SEMA2row = [SETV2 clickedRow];
428     SEMA3row = -1;
429     
430     TX[st].S = STRtop[st];
431     for(int i = 0;i < sl;i++){
432         TX[st].S = TX[st].S->next;
433     }
434     
435     if(SEMArow < 0){
436         TX[st].S = STRtop[st];
437         return;
438     }
439     SItop = TX[st].S->i;
440     for(int i = 0;i < SEMArow;i++){
441         TX[st].S->i = TX[st].S->i->next;
442     }
443     
444     TX[st].S->i->SEMA2row = (int)SEMA2row + 1;
445     
446     
447     [self willChangeValueForKey:@"SEMA3"];
448     [SEMA3 removeAllObjects];
449     [self didChangeValueForKey:@"SEMA3"];
450     
451     if(SEMA1row < 0){
452         
453         TX[st].S->i = SItop;
454         
455         TX[st].S = STRtop[st];
456         return;
457     }
458     
459     
460     I = Itop;
461     for(int i = 0;i < SEMA1row;i++){
462         I = I->next;
463     }
464     
465     BASE *b;
466     BASE *bTop;
467     
468     b = I->B;
469     bTop = b;
470     
471     for(int i = 0;i < SEMA2row;i++){
472         b = b->next;
473     }
474     
475     LAYER *lTop;
476     
477     int i0 = 0;
478     lTop = b->L;
479     TX[st].S->i->SEMA3flag = calloc(999, sizeof(int));
480     while(b->L){
481         NSMutableDictionary *dict2 = [NSMutableDictionary new];
482         [dict2 setValue:[NSString stringWithFormat:@"%@", b->L->name]  forKeyPath:@"name"];
483         [dict2 setValue:[NSString stringWithFormat:@"%d", b->L->visible] forKeyPath:@"v"];
484         //おまんちん
485         b->L->visibleInstant = b->L->visible;
486         
487         *(TX[st].S->i->SEMA3flag+i0) = b->L->visible;
488         
489         [self willChangeValueForKey:@"SEMA3"];
490         [SEMA3 addObject:dict2];
491         [self didChangeValueForKey:@"SEMA3"];
492         
493         b->L = b->L->next;
494         i0++;
495     }
496     b->L = lTop;
497     
498     
499     TX[st].S->i = SItop;
500     
501     TX[st].S = STRtop[st];
502     
503     b = bTop;
504     
505     I = Itop;
506     
507     [SEAC3 setSelectionIndex:9999];
508 }
509
510 -(void)ClickSETV3:(id)sender{
511     SEMA3row = [SETV3 clickedRow];
512 }
513
514 -(void)TV1sgl:(id)sender{
515     
516     static NSInteger postClicedrow;
517     postClicedrow = TVCrow1;
518     
519     
520     I = Itop;
521     
522     for(int i = 0;i < Irow;i++){
523         I = I->next;
524     }
525     
526     b = I->B;
527     
528     if(!b) return;
529     
530     TV1sglFlag = true;
531     TV2sglFlag = false;
532     
533     TVCrow1 = [TV1 clickedRow];
534     TVCrow2 = [TV2 clickedRow];
535     
536     [self willChangeValueForKey:@"MA2"];
537     [MA2 removeAllObjects];
538     [self didChangeValueForKey:@"MA2"];
539     
540     BASE *bTop = b;
541     
542     b = bTop;
543     for (int i = 0;i < TVCrow1;i++) {
544         b = b->next;
545     }
546     if(TVCrow1 >= 0 && b){
547         
548         
549         LAYER *lTop = b->L;
550         while(b->L){
551             NSMutableDictionary *dict2 = [NSMutableDictionary new];
552             [dict2 setValue:[NSString stringWithFormat:@"%@", b->L->name]  forKeyPath:@"name"];
553             [dict2 setValue:[NSString stringWithFormat:@"%d", b->L->z] forKeyPath:@"z"];
554             [dict2 setValue:[NSString stringWithFormat:@"%d", b->L->visible] forKeyPath:@"v"];
555             [dict2 setValue:b->L->img forKey:@"img"];
556             
557             [self willChangeValueForKey:@"MA2"];
558             [MA2 addObject:dict2];
559             [self didChangeValueForKey:@"MA2"];
560             
561             b->L = b->L->next;
562         }
563         b->L = lTop;
564     }
565     b = bTop;
566     
567     
568     I = Itop;
569     if(TVCrow1 != postClicedrow) layerLoadOver = true;
570 }
571
572 -(void)TV2sgl:(id)sender{
573     
574     TVCrow2 = [TV2 clickedRow];
575     //if(!b->L) return;
576     
577     TV2sglFlag = true;
578     TV1sglFlag = false;
579     
580 }
581
582 -(void)DoubleClickSTAND:(id)sender{
583     if(Irow < 0) return;
584     
585     if(![standListMA[Irow] valueForKey:@"file"])
586         return;
587     if([[standListMA[Irow] valueForKey:@"file"] isEqualToString:@""])
588         return;
589     if([[standListMA[Irow] valueForKey:@"file"] isEqualToString:@"(null)"])
590         return;
591     [self initLineBaseLayer];
592     IBrow = -1;
593     IBLrow = -1;
594     [baseListAC setSelectionIndex:9999];
595     [layerListAC setSelectionIndex:9999];
596     
597     [self saveStandData];
598     [self saveData];
599     [self loadStandData];
600     [self loadData];
601     [self initMA1MA2];
602     [standEditorPanel makeKeyAndOrderFront:nil];
603 }
604
605 -(void)ClickSTAND:(id)sender{
606     Irow = (int)[standListTV clickedRow];
607 }
608
609 -(void)DoubleClickBASE:(id)sender{
610     /*
611     IBrow = -1;
612     [baseListAC setSelectionIndex:9999];
613     [baseListAC setSelectionIndex:-1];
614      */
615 }
616
617 -(void)ClickBASE:(id)sender{
618     /*
619     IBrow = (int)[baseListTV clickedRow];
620     [layerListAC setSelectionIndex:9999];
621     IBLrow = -1;
622     if(IBrow >= 0){
623         I = Itop;
624         for (int i = 0;i < Irow;i++) {
625             I = I->next;
626         }
627     
628         IBtop = I->B;
629         for (int i = 0;i < IBrow;i++) {
630             I->B = I->B->next;
631         }
632         if(I->B){
633             [NSIV setImage:I->B->img];
634             I->B->z = [[[baseListMA objectAtIndex:IBrow] valueForKeyPath:@"pref"] intValue];
635             I->B->name = [[baseListMA objectAtIndex:IBrow] valueForKeyPath:@"name"];
636         }
637     
638         I->B = IBtop;
639         I = Itop;
640     
641
642     }
643     
644     [self initLineLayer];
645      */
646 }
647
648 -(void)DoubleClickLAYER:(id)sender{
649     /*
650     IBLrow = -1;
651     [layerListAC setSelectionIndex:9999];
652     [layerListAC setSelectionIndex:-1];
653      */
654 }
655
656 -(void)ClickLAYER:(id)sender{
657     /*
658     IBLrow = (int)[layerListTV clickedRow];
659     
660     
661     if(IBLrow >=0){
662         Itop = I;
663         for (int i = 0;i < Irow;i++) {
664             I = I->next;
665         }
666         
667         IBtop = I->B;
668         for (int i = 0;i < IBrow;i++) {
669             I->B = I->B->next;
670         }
671         
672         IBLtop = I->B->L;
673         for (int i = 0;i < IBLrow;i++) {
674             I->B->L = I->B->L->next;
675         }
676         
677         int oops = 0;
678         oops = [[layerListMA objectAtIndex:IBLrow] valueForKeyPath:@"visible"];
679         oops = oops>>4 & 0xf;
680         if(oops == 1){
681             
682             
683         }else{
684             if(oops == 3 || oops == 14){
685                 oops = -1;
686             }else{
687                 oops = 0;
688             }
689         }
690         I->B->L->visible = oops;
691         I->B->L->z = [[[layerListMA objectAtIndex:IBLrow] valueForKeyPath:@"pref"] intValue];
692         I->B->L->name = [[layerListMA objectAtIndex:IBLrow] valueForKeyPath:@"name"];
693         
694         [NSIV2 setImage:I->B->L->img];
695         I->B->L = IBLtop;
696         
697         
698         I->B = IBtop;
699         
700         
701         I = Itop;
702     }
703     
704     
705     
706     
707     
708     IBLrow = (int)[layerListTV clickedRow];
709     
710     if(IBLrow >= 0){
711         Itop = I;
712         if(!Itop) return;
713         for (int i = 0;i < Irow;i++) {
714             I = I->next;
715         }
716         
717         IBtop = I->B;
718         for (int i = 0;i < IBrow;i++) {
719             I->B = I->B->next;
720         }
721         
722         if(I->B){
723             IBLtop = I->B->L;
724             for (int i = 0;i < IBLrow;i++) {
725                 I->B->L = I->B->L->next;
726             }
727             
728             if(I->B->L){
729             int oops = 0;
730             oops = [[layerListMA objectAtIndex:IBLrow] valueForKeyPath:@"visible"];
731             oops = oops>>4 & 0xf;
732             if(oops == 1){
733             
734             
735             }else{
736                 if(oops == 3 || oops == 14){
737                     oops = -1;
738                 }else{
739                     oops = 0;
740                 }
741             }
742             I->B->L->visible = oops;
743             
744             I->B->L->z = [[[layerListMA objectAtIndex:IBLrow] valueForKeyPath:@"pref"] intValue];
745             I->B->L->name = [[layerListMA objectAtIndex:IBLrow] valueForKeyPath:@"name"];
746             
747             }
748             
749             if(I->B->L){
750                 [NSIV2 setImage:I->B->L->img];
751             }
752             
753             I->B->L = IBLtop;
754             
755         }
756         I->B = IBtop;
757         I = Itop;
758     }*/
759 }
760
761 -(void)DoubleClickLL:(id)sender{
762     LLrow = -1;
763     [lineListAC setSelectionIndex:9999];
764     [lineListAC setSelectionIndex:-1];
765     
766 }
767
768 -(void)ClickTL:(id)sender{
769     
770     
771     st = [textListTV selectedRow];
772     
773     if(st < 0){
774         [self willChangeValueForKey:@"lineListMA"];
775         [lineListMA removeAllObjects];
776         [self didChangeValueForKey:@"lineListMA"];
777         
778         
779         [Dname setStringValue:@""];
780         [Dstring setStringValue:@""];
781         [dialogName setStringValue:@""];
782         [dialogString setStringValue:@""];
783         [dialogImage setImage:NULL];
784         return;
785     }
786     
787     if(st >= 0){
788     [self willChangeValueForKey:@"lineListMA"];
789     [lineListMA removeAllObjects];
790     [self didChangeValueForKey:@"lineListMA"];
791     OMFGflag = true;
792         
793     STRtop[st] = TX[st].S;
794         
795         if(TX[st].S != NULL){
796         [Dname setStringValue:TX[st].S->name];
797         [Dstring setStringValue:TX[st].S->string];
798         [dialogName setStringValue:TX[st].S->name];
799         [dialogString setStringValue:TX[st].S->string];
800         [dialogImage setImage:TX[st].S->img];
801     while(TX[st].S != NULL){
802         NSMutableDictionary* dict = [NSMutableDictionary new];
803         
804         [dict setValue:[NSString stringWithFormat:@"%@:%@", TX[st].S->name, TX[st].S->string] forKey:@"name"];
805         [self willChangeValueForKey:@"lineListMA"];
806         [lineListMA addObject:dict];
807         [self didChangeValueForKey:@"lineListMA"];
808         [lineListAC setSelectionIndex:sl];
809         
810         TX[st].S = TX[st].S->next;
811     }
812         }
813         TX[st].S = STRtop[st];
814     }
815 }
816 -(void)ClickLL:(id)sender{
817     
818     sl = [lineListTV selectedRow];
819     
820     if(st < 0) return;
821     
822     LLrow = (int)[lineListTV selectedRow];
823     
824     STRtop[st] = TX[st].S;
825     
826     for(int k = 0;k < LLrow;k++) {
827         if(TX[st].S->next != NULL) TX[st].S = TX[st].S->next;
828     }
829     
830     [Dname setStringValue:TX[st].S->name];
831     if([[TX[st].S->string substringWithRange:NSMakeRange([TX[st].S->string length]-1, 1)] isEqualToString:@"\n"]){
832         [Dstring setStringValue:[NSString stringWithFormat:@"%@", [TX[st].S->string substringToIndex:[TX[st].S->string length]-1 ]]];
833     }else{
834         [Dstring setStringValue:[NSString stringWithFormat:@"%@", TX[st].S->string]];
835     }
836     
837     //NSLog(@"[%@]", [TX[st].S->string substringWithRange:NSMakeRange([TX[st].S->string length]-1, 1)]);
838     
839     [dialogName setStringValue:TX[st].S->name];
840     [dialogString setStringValue:TX[st].S->string];
841     [dialogImage setImage:TX[st].S->img];
842     TX[st].S = STRtop[st];
843     OMFGflag = false;
844 }
845
846 -(IBAction)SEstandXsubmit:(id)sender{
847     
848     if(SEMArow < 0)
849         return;
850     
851     TX[st].S = STRtop[st];
852     for(int i = 0;i < sl;i++){
853         TX[st].S = TX[st].S->next;
854     }
855     SItop = TX[st].S->i;
856     for(int i = 0;i < SEMArow;i++){
857         TX[st].S->i = TX[st].S->i->next;
858     }
859     TX[st].S->i->standX = [SEstandTFx intValue];
860     
861     TX[st].S->i = SItop;
862     TX[st].S = STRtop[st];
863     
864
865 }
866 -(IBAction)SEstandYsubmit:(id)sender{
867
868     if(SEMArow < 0)
869         return;
870     
871     TX[st].S = STRtop[st];
872     for(int i = 0;i < sl;i++){
873         TX[st].S = TX[st].S->next;
874     }
875     SItop = TX[st].S->i;
876     for(int i = 0;i < SEMArow;i++){
877         TX[st].S->i = TX[st].S->i->next;
878     }
879     TX[st].S->i->standY = [SEstandTFy intValue];
880     
881     TX[st].S->i = SItop;
882     TX[st].S = STRtop[st];
883     
884     [SEstandTFx intValue];
885 }
886
887 -(void)EventLoop2:(NSTimer *)timer{
888     
889     if(SEstandImgST)
890         [SESTIV setImage:SEstandImgST];
891     
892     if(standEditorFlag){
893     I = Itop;
894     
895     for(int i = 0;i < Irow;i++){
896         I = I->next;
897     }
898     
899     if(!I) {
900         I = Itop;
901         return;
902     }
903     
904     
905     b = I->B;
906     
907     BASE *bTop = b;
908     
909     for (int i = 0; i < TVCrow1; i++) {
910         b = b->next;
911     }
912     
913     if(TVCrow1 == -1) TVCrow2 = -1;
914     if(TVCrow1 >= 0 && b && [MA1 count] > 0){
915         int value = [[[MA1 objectAtIndex:TVCrow1] valueForKeyPath:@"z"] intValue];
916         b->z = value;
917         
918         NSString *value2 = [[MA1 objectAtIndex:TVCrow1] valueForKeyPath:@"name"];
919         b->name = [value2 retain];
920         
921         b->img = [IV1 image];
922         
923     }
924     if(TVCrow2 == -1) {b = bTop; return;}
925     
926     LAYER *lTop;
927     if(b) lTop = b->L;
928     for (int i = 0; i < TVCrow2; i++) {
929         b->L = b->L->next;
930     }
931     
932     
933     
934     if(b)
935         if(!layerLoadOver)
936             if(TVCrow2 >= 0 && b->L && [MA2 count] > 0){
937                 
938                 NSString *value = [[MA2 objectAtIndex:TVCrow2] valueForKeyPath:@"name"];
939                 b->L->name = [value retain];
940                 
941                 int value2 = [[[MA2 objectAtIndex:TVCrow2] valueForKeyPath:@"z"] intValue];
942                 b->L->z = value2;
943                 
944                 int flag = [[[MA2 objectAtIndex:TVCrow2] valueForKeyPath:@"v"] intValue];
945                 //flag = flag>>4 & 0xf;
946                 
947                 
948                 b->L->img = [IV2 image];
949                 
950                 if(flag > 0){
951                     
952                     b->L->visible = true;
953                 }
954                 else{
955                     
956                     b->L->visible = false;
957                 }
958                 
959             }
960     
961     if(b) b->L = lTop;
962     
963     b = bTop;
964     
965     I->B = b;
966     
967     I = Itop;
968     layerLoadOver = false;
969     }
970     
971     STRtop[st] = STRtop[st];
972     
973     if(SEMArow < 0){
974         [self willChangeValueForKey:@"SEMA1"];
975         [SEMA1 removeAllObjects];
976         [self didChangeValueForKey:@"SEMA1"];
977         [self willChangeValueForKey:@"SEMA2"];
978         [SEMA2 removeAllObjects];
979         [self didChangeValueForKey:@"SEMA2"];
980         [self willChangeValueForKey:@"SEMA3"];
981         [SEMA3 removeAllObjects];
982         [self didChangeValueForKey:@"SEMA3"];
983         
984         [SEIV setImage:nil];
985         SEMA1row = -1;
986         SEMA2row = -1;
987         SEMA3row = -1;
988         
989         return;
990         
991     }else{
992         STRtop[st] = STRtop[st];
993     }
994     
995     if(standChoiceFlag){
996         STRtop[st] = STRtop[st];
997         
998         TX[st].S = STRtop[st];
999         for(int i = 0;i < sl;i++){
1000             TX[st].S = TX[st].S->next;
1001         }
1002         
1003         
1004         if(SEMArow < 0){
1005             TX[st].S = STRtop[st];
1006             return;
1007         }
1008         
1009         SItop = TX[st].S->i;
1010         for(int i = 0;i < SEMArow;i++){
1011             TX[st].S->i = TX[st].S->i->next;
1012         }
1013             
1014         if(SEMArow >= 0){
1015         if(TX[st].S->i){
1016             TX[st].S->i->SEMA1row = (int)SEMA1row + 1;
1017             TX[st].S->i->SEMA2row = (int)SEMA2row + 1;
1018         }
1019         
1020         }
1021         
1022         
1023         I = Itop;
1024         
1025         for(int i = 0;i < SEMA1row;i++){
1026             I = I->next;
1027         
1028         }
1029         if(!I) {
1030             I = Itop;
1031             TX[st].S->i = SItop;
1032             TX[st].S = STRtop[st];
1033             return;
1034         }
1035         
1036         
1037         b = I->B;
1038         
1039         BASE *bTop = b;
1040         
1041         for (int i = 0; i < SEMA2row; i++) {
1042             b = b->next;
1043         }
1044         
1045        
1046         LAYER *lTop = b->L;
1047             int i0 = 0;
1048         while(b->L){
1049         //おまんちん
1050             if(i0 == SEMA3row && TX[st].S->i->SEMA3flag){
1051             b->L->visibleInstant = [[SEMA3[SEMA3row] valueForKey:@"v"] intValue];
1052                 *(TX[st].S->i->SEMA3flag+i0) = [[SEMA3[SEMA3row] valueForKey:@"v"] intValue]+1;
1053             }
1054             b->L = b->L->next;
1055             i0++;
1056         }
1057         b->L = lTop;
1058         
1059         
1060     
1061         
1062         b = bTop;
1063         
1064         
1065         
1066         I = Itop;
1067             
1068             
1069         
1070         
1071         TX[st].S->i = SItop;
1072         TX[st].S = STRtop[st];
1073         
1074         [self standImage];
1075     }
1076     STRtop[st] = STRtop[st];
1077 }
1078
1079 -(void)standImage{
1080     
1081     SEIV.image = SEstandImg;
1082 }
1083
1084 -(void)saveDataStand{
1085     
1086     NSString *directoryPath;
1087     
1088     directoryPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
1089     [[NSFileManager defaultManager] changeCurrentDirectoryPath:directoryPath];
1090     /*
1091     int std = 1;
1092     int Bcnt = 1;
1093     int Lcnt = 1;
1094     I = Itop;
1095     while (I) {
1096         NSString *fdata = @"data/StandList/STD";
1097         fdata = [fdata stringByAppendingFormat:@"%d.txt", std];
1098    
1099         NSString *Sdata = @"data/StandList/img/S";
1100         Sdata = [Sdata stringByAppendingFormat:@"%d", std];
1101         
1102         NSString *fileData = @"";
1103         
1104         fileData = [[fileData stringByAppendingString:[NSString stringWithFormat:@"%@", I->name]] stringByAppendingString:@"\n"];
1105         I->B = IBtop;
1106         while (I->B) {
1107             NSString *Bdata = [Sdata stringByAppendingFormat:@"B%d", Bcnt];
1108             
1109             fileData = [[fileData stringByAppendingString:[NSString stringWithFormat:@"----"]] stringByAppendingString:@"\n"];
1110             fileData = [[fileData stringByAppendingString:[NSString stringWithFormat:@"%@", I->B->name]] stringByAppendingString:@","];
1111             fileData = [[fileData stringByAppendingString:[NSString stringWithFormat:@"%d", I->B->x]] stringByAppendingString:@","];
1112             fileData = [[fileData stringByAppendingString:[NSString stringWithFormat:@"%d", I->B->y]] stringByAppendingString:@","];
1113             fileData = [[fileData stringByAppendingString:[NSString stringWithFormat:@"%d", I->B->z]] stringByAppendingString:@"\n"];
1114             
1115             I->B->L = IBLtop;
1116             while (I->B->L) {
1117                 
1118                 NSString *Ldata = [Bdata stringByAppendingFormat:@"L%d", Lcnt];
1119                 
1120                 fileData = [[fileData stringByAppendingString:[NSString stringWithFormat:@"%@", I->B->L->name]] stringByAppendingString:@","];
1121                 fileData = [[fileData stringByAppendingString:[NSString stringWithFormat:@"%d", I->B->L->x]] stringByAppendingString:@","];
1122                 fileData = [[fileData stringByAppendingString:[NSString stringWithFormat:@"%d", I->B->L->y]] stringByAppendingString:@","];
1123                 fileData = [[fileData stringByAppendingString:[NSString stringWithFormat:@"%d", I->B->L->z]] stringByAppendingString:@"\n"];
1124                 
1125                 NSData *f2IMGdata = [I->B->L->img TIFFRepresentation];
1126                 NSBitmapImageRep *brep = [NSBitmapImageRep imageRepWithData:f2IMGdata];
1127                 f2IMGdata = [brep representationUsingType:NSPNGFileType properties:nil];
1128                 
1129                 [f2IMGdata writeToFile:Ldata atomically:YES];
1130                 Lcnt++;
1131                 I->B->L = I->B->L->next;
1132             }I->B->L = IBLtop;
1133             
1134             NSData *fIMGdata = [I->B->img TIFFRepresentation];
1135             NSBitmapImageRep *brep = [NSBitmapImageRep imageRepWithData:fIMGdata];
1136             fIMGdata = [brep representationUsingType:NSPNGFileType properties:nil];
1137             
1138             [fIMGdata writeToFile:Bdata atomically:YES];
1139             Bcnt++;
1140             I->B = I->B->next;
1141         }I->B = IBtop;
1142    
1143         [fileData writeToFile:fdata atomically:YES encoding:NSUTF8StringEncoding error:nil];
1144         
1145         std++;
1146         I = I->next;
1147     }I = Itop;
1148      */
1149 }
1150
1151
1152 -(void)initFileDirectory{
1153     NSString *directoryPath;
1154     
1155     directoryPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
1156     [[NSFileManager defaultManager] changeCurrentDirectoryPath:directoryPath];
1157     /*
1158     char *cwd;
1159     cwd = getcwd(NULL, 0);
1160     
1161     ///// S1B1L1 の用に記述する
1162     ///// STD1 の用にデータファイルはなる
1163     ///// 立ち絵名前
1164     ///// ----
1165     ///// ベース名前 ベースxy 優先度
1166     ///// レイヤー名前 レイヤーxy 優先度 可視
1167     ///// レイヤー名前 レイヤーxy 優先度 可視
1168     ///// レイヤー名前 レイヤーxy 優先度 可視
1169     ///// ----
1170     ///// ベース名前 ベースxy 優先度
1171     ///// レイヤー名前 レイヤーxy 優先度 可視
1172     ///// レイヤー名前 レイヤーxy 優先度 可視
1173     ///// レイヤー名前 レイヤーxy 優先度 可視
1174     ///// レイヤー名前 レイヤーxy 優先度 可視
1175     ///// ----
1176
1177     NSData *InitialData = [NSData dataWithContentsOfFile:@"data/StandList/preset.txt"];
1178     NSString *pathSL = @"data/StandList/img";
1179     NSString *pathDATA2 = @"data/StandList/preset.txt";
1180     NSString *pathSLP = @"data/StandList/preset.txt";
1181     NSString *fileData = nil;
1182     
1183     if(!InitialData){
1184         [[NSFileManager defaultManager] createDirectoryAtPath:pathSL withIntermediateDirectories:YES attributes:nil error:nil];
1185         [[NSFileManager defaultManager] createFileAtPath:pathDATA2 contents:nil attributes:nil];
1186         
1187         [[NSFileManager defaultManager] createFileAtPath:pathSLP contents:nil attributes:nil];
1188     }
1189     
1190     
1191     
1192     I = calloc(1, sizeof(STAND));
1193     I->B = calloc(1, sizeof(BASE));
1194     I->B->L = calloc(1, sizeof(LAYER));
1195     Itop = I;
1196     for (int i = 0;i < 9999;i++) {
1197         NSString *fdata = @"data/StandList/STD";
1198         fdata = [fdata stringByAppendingFormat:@"%d.txt",i+1];
1199         fileData = [NSString stringWithContentsOfFile:fdata encoding:NSUTF8StringEncoding error:nil];
1200         IBtop = I->B;
1201         IBLtop = I->B->L;
1202         if(i > 0) {
1203             I->next = calloc(1, sizeof(STAND));
1204             I = I->next;
1205         }
1206         if(!fileData)
1207             break;
1208         fileDataArray = [fileData componentsSeparatedByString:@"\n"];
1209         I->name = [[fileDataArray objectAtIndex:0] retain];
1210         NSString *imagePath = @"data/StandList/img/S";
1211         imagePath = [imagePath stringByAppendingFormat:@"%d", i+1];
1212         
1213         bool initialStrFlag = false;
1214         int Bcnt = 1;
1215         int Lcnt = 1;
1216         for(int k= 2;k < [fileDataArray count];k++){
1217             NSString *str = [fileDataArray objectAtIndex:k];
1218             NSRange rangeSearch;
1219             NSArray *rangeArray;
1220             NSString *imagePathB = [imagePath stringByAppendingFormat:@"B%d", Bcnt];
1221             rangeArray = [str componentsSeparatedByString:@","];
1222             rangeSearch = [str rangeOfString:@"----"];
1223             
1224             if(!initialStrFlag){
1225                 I->B = calloc(1, sizeof(BASE));
1226                 I->B->name = [[rangeArray objectAtIndex:0] retain];
1227                 I->B->x = [[rangeArray objectAtIndex:1] intValue];
1228                 I->B->y = [[rangeArray objectAtIndex:2] intValue];
1229                 I->B->z = [[rangeArray objectAtIndex:3] intValue];
1230                 NSData *imgData = [NSData dataWithContentsOfFile:imagePathB];
1231                 if(imgData) I->B->img = [[NSImage alloc] initWithData:[[NSFileHandle fileHandleForReadingAtPath:imagePathB] readDataToEndOfFile]];
1232                 
1233                 initialStrFlag = true;
1234             }else{
1235             
1236                 if(rangeSearch.location != NSNotFound){
1237                     I->B->next = calloc(1, sizeof(BASE));
1238                     I->B = I->B->next;
1239                     initialStrFlag = false;
1240                     Bcnt++;
1241                 }else if([rangeArray count] > 2){
1242                     NSString *imagePathL = [imagePathB stringByAppendingFormat:@"L%d", Lcnt];
1243                     I->B->L = calloc(1, sizeof(LAYER));
1244                     
1245                     I->B->L->name = [[rangeArray objectAtIndex:0] intValue];
1246                     I->B->L->x = [[rangeArray objectAtIndex:1] intValue];
1247                     I->B->L->y = [[rangeArray objectAtIndex:2] intValue];
1248                     I->B->L->z = [[rangeArray objectAtIndex:3] intValue];
1249                     NSData *imgData = [NSData dataWithContentsOfFile:imagePathL];
1250                     if(imgData) I->B->L->img = [[NSImage alloc] initWithData:[[NSFileHandle fileHandleForReadingAtPath:imagePathL] readDataToEndOfFile]];
1251                     
1252                     I->B->L->next = calloc(1, sizeof(LAYER));
1253                     I->B->L = I->B->L->next;
1254                     Lcnt++;
1255                 }
1256                 I->B->L = IBLtop;
1257             }
1258         }
1259         I->B = IBtop;
1260     }
1261  I = Itop;
1262      */
1263 }
1264
1265
1266 -(IBAction)stringData:(id)sender{
1267     OMFGflag = false;
1268 }
1269
1270 -(void)submitLineList{
1271     
1272     if(LLrow == -1){
1273         [Dname setStringValue:@""];
1274         [Dstring setStringValue:@""];
1275         [dialogName setStringValue:@""];
1276         [dialogString setStringValue:@""];
1277         [dialogImage setImage:NULL];
1278     
1279         return;
1280     }
1281     
1282     
1283     TX[st].S = STRtop[st];
1284     
1285     if (st >= 0) {
1286         if(TX[st].S != NULL){
1287             for(int k = 0;k < LLrow ;k++) {
1288                 TX[st].S = TX[st].S->next;
1289             }
1290             
1291         TX[st].S->name = [[Dname stringValue] retain];
1292         TX[st].S->string = [[Dstring stringValue] retain];
1293         
1294         [dialogName setStringValue:TX[st].S->name];
1295         [dialogString setStringValue:TX[st].S->string];
1296         [dialogImage setImage:TX[st].S->img];
1297             
1298         [lineListAC setValue:[NSString stringWithFormat:@"%@:%@", TX[st].S->name, TX[st].S->string] forKeyPath:@"selection.name"];
1299             
1300         }
1301     }
1302     
1303     TX[st].S = STRtop[st];
1304      
1305 }
1306
1307
1308 -(void)initText{
1309     NSString *directoryPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
1310     [[NSFileManager defaultManager] changeCurrentDirectoryPath:directoryPath];
1311
1312
1313     NSData *InitialData = [NSData dataWithContentsOfFile:@"data/StringList/preset.txt"];
1314     NSString *pathFOLDER = @"data/StringList";
1315
1316     if(!InitialData){
1317         [[NSFileManager defaultManager] createDirectoryAtPath:pathFOLDER withIntermediateDirectories:YES attributes:nil error:nil];
1318     }
1319     
1320     NSArray *Farray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:pathFOLDER error:nil];
1321
1322     NSMutableArray *MA = [NSMutableArray new];
1323     for (int i = 0;i < [Farray count];i++) {
1324         if([[Farray objectAtIndex:i] isEqualToString:@"img"])
1325             continue;
1326         else if([[Farray objectAtIndex:i] isEqualToString:@"preset.txt"])
1327             continue;
1328         else if([[Farray objectAtIndex:i] isEqualToString:@".DS_Store"])
1329             continue;
1330     
1331         [MA addObject:[Farray objectAtIndex:i]];
1332         textNumb++;
1333
1334     }
1335     
1336     for (int i = 0; i < textNumb;i++) {
1337         TX[i].fileName = [[MA objectAtIndex:i] retain];
1338             //NSLog(@"%@", TX[i].fileName);
1339     }
1340     
1341     for(int i = 0; i< textNumb;i++){
1342         
1343
1344         NSMutableDictionary* dict = [NSMutableDictionary new];
1345         
1346         if(1){
1347             [dict setValue:[NSString stringWithFormat:@"%@", TX[i].fileName] forKey:@"name"];
1348             [self willChangeValueForKey:@"textListMA"];
1349             [textListMA addObject:dict];
1350             [self didChangeValueForKey:@"textListMA"];
1351         }
1352     }
1353     [textListAC setSelectionIndex:9999];
1354     ///NSLog(@"%@", textListMA);
1355 }
1356
1357
1358 -(void)addLineList{
1359     
1360     st = [textListTV selectedRow];
1361     NSArray *fileDataArray;
1362     for(int i = 0;i < textNumb;i++){
1363     NSString *tfD = @"data/StringList/"; 
1364     tfD = [tfD stringByAppendingFormat:@"%@", TX[i].fileName];
1365     NSString *textFileData = [NSString stringWithContentsOfFile:tfD encoding:NSUTF8StringEncoding error:nil];
1366     fileDataArray = [textFileData componentsSeparatedByString:@"\n"];
1367         siCnt = 0;
1368         STRtop[i] = TX[i].S;
1369         SItop = NULL;
1370     for(int j = 0;j<[fileDataArray count];j++){
1371         NSString *str = [fileDataArray objectAtIndex:j];
1372         NSRange range = NSMakeRange(2, str.length - 2);
1373         NSRange rangeSearch;
1374         NSRange rangeSearch2;
1375         NSRange rangeSearch3;
1376         NSArray *rangeArray;
1377         NSRange rangeSearch4;
1378         NSArray *rangeArray2;
1379         NSRange rangeSearch5;
1380         NSArray *rangeArray3;
1381         bool commentSwitch = false;
1382         rangeSearch = [str rangeOfString:@"##"];
1383         rangeSearch2 = [str rangeOfString:@"####"];
1384         rangeSearch3 = [str rangeOfString:@"##" options:NSBackwardsSearch];
1385         rangeArray = [str componentsSeparatedByString:@"##"];
1386         rangeArray2 = [str componentsSeparatedByString:@"%%"];
1387         rangeSearch4 = [str rangeOfString:@"%%"];
1388         rangeSearch5 = [str rangeOfString:@"$$"];
1389         rangeArray3 = [str componentsSeparatedByString:@"$$"];
1390         
1391         if (rangeSearch2.location != NSNotFound) {commentSwitch = true;
1392             
1393         }else if (rangeSearch.location != NSNotFound) {commentSwitch = false;
1394             TX[st].S->index++;
1395             StringText *stringText = [[StringText alloc] init];
1396             
1397             [stringText AddString:&TX[i].S :TX[i].S->index];
1398             //TX[i].S->next->iNameWall =TX[i].S->iNameWall;
1399             //TX[i].S->next->imgWall = TX[i].S->imgWall;
1400             //TX[i].S->next->wallFadeOut = TX[i].S->wallFadeOut;
1401             //TX[i].S->next->iNameStand =TX[i].S->iNameStand;
1402             //TX[i].S->next->imgStand = TX[i].S->imgStand;
1403             //TX[i].S->next->standPossition =TX[i].S->standPossition;
1404             
1405             if(SItop) TX[i].S->i = SItop;
1406             SItop = NULL;
1407             siCnt = 0;
1408             TX[i].S = TX[i].S->next;
1409             TX[i].S->name = [[str substringWithRange:range] retain];
1410             TX[i].S->name = [[rangeArray objectAtIndex:1] retain];
1411             TX[i].S->string = @"";
1412             if(rangeSearch3.location != NSNotFound && [rangeArray count] > 2){
1413                 
1414                 TX[i].S->iName = [[rangeArray objectAtIndex:2] retain];
1415                 TX[i].S->img = [NSImage imageNamed:TX[i].S->iName];
1416                 
1417                 NSString *iPath = @"data/StringList/img/";
1418                 iPath = [iPath stringByAppendingString:TX[i].S->iName];
1419                 NSData *iData = [NSData dataWithContentsOfFile:iPath];
1420                 if(iData){
1421                     NSImage *iImg = [[NSImage alloc] initWithContentsOfFile:iPath];
1422                     TX[i].S->img = iImg;
1423                 }
1424             }
1425         }else if(rangeSearch4.location != NSNotFound){
1426             TX[i].S->iNameWall = [[str substringWithRange:range] retain];
1427             TX[i].S->iNameWall = [[rangeArray2 objectAtIndex:1] retain];
1428             TX[i].S->iNameWallSort = [[rangeArray2 objectAtIndex:2] retain];
1429             TX[i].S->imgWall = [NSImage imageNamed:TX[i].S->iNameWall];
1430             
1431             TX[i].S->wallChanged = true;
1432             
1433             
1434             NSString *iPath = @"data/StringList/img/";
1435             iPath = [iPath stringByAppendingString:TX[i].S->iNameWall];
1436             NSData *iData = [NSData dataWithContentsOfFile:iPath];
1437             if(iData){
1438                 NSImage *iImg = [[NSImage alloc] initWithContentsOfFile:iPath];
1439                 TX[i].S->imgWall = iImg;
1440             }
1441             if(rangeSearch4.location != NSNotFound && [rangeArray2 count] > 2){
1442                 
1443                 if ([[rangeArray2 objectAtIndex:2] isEqualToString:@"FI"]) {
1444                    TX[i].S->wallFadeIn = true;
1445                 }else if([[rangeArray2 objectAtIndex:2] isEqualToString:@"FO"]){
1446                     TX[i].S->wallFadeOut = true;
1447                 }else if([[rangeArray2 objectAtIndex:2] isEqualToString:@"FIO"]){
1448                     TX[i].S->wallFadeIn = true;
1449                     TX[i].S->wallFadeOut = true;
1450                 }
1451             }
1452             
1453         }else if(rangeSearch5.location != NSNotFound){
1454
1455             if([rangeArray3 count] >= 5){
1456                 
1457                 if(siCnt == 0){
1458                     TX[i].S->i = calloc(1, sizeof(STANDIMAGE));
1459                     SItop = TX[i].S->i;
1460                 }else if(siCnt > 0){
1461                     TX[i].S->i->next = calloc(1, sizeof(STANDIMAGE));
1462                     if(siCnt == 1) SItop = TX[i].S->i;
1463                     TX[i].S->i = TX[i].S->i->next;
1464                 }
1465                 NSArray *sArray = [[rangeArray3 objectAtIndex:1] componentsSeparatedByString:@"["];
1466                 NSArray *sArray2 = [sArray[1] componentsSeparatedByString:@","];
1467                 
1468                 TX[i].S->i->name = [sArray[0] retain];
1469                 TX[i].S->i->standX = [sArray2[0] intValue];
1470                 TX[i].S->i->standY = [sArray2[1] intValue];
1471                 TX[i].S->i->SEMA1row = [[rangeArray3 objectAtIndex:2] intValue] + 1;
1472                 TX[i].S->i->SEMA2row = [[rangeArray3 objectAtIndex:3] intValue] + 1;
1473                 
1474                 if(TX[i].S->i->SEMA1row < 0){
1475                     TX[i].S->i->SEMA1row = 0;
1476                 }
1477                 if(TX[i].S->i->SEMA2row < 0){
1478                     TX[i].S->i->SEMA1row = 0;
1479                 }
1480                 
1481                 if(![[rangeArray3 objectAtIndex:4] isEqualToString:@""]){
1482                 NSArray *sArray3 = [[rangeArray3 objectAtIndex:4] componentsSeparatedByString:@","];
1483                 TX[i].S->i->SEMA3flag = calloc(999, sizeof(int));
1484                 int i0 = 0;
1485                 for (NSString *ary in sArray3) {
1486                     *(TX[i].S->i->SEMA3flag + i0) = [ary intValue] + 1;
1487                     NSLog(@"SEMA3[%d]%d", i0, *(TX[i].S->i->SEMA3flag + i0));
1488                     i0++;
1489                 }//おまんちん
1490                 }
1491             }
1492             siCnt++;
1493         }else if(!commentSwitch){
1494             TX[i].S->string = [[TX[i].S->string stringByAppendingString:str] retain];
1495             
1496             if([fileDataArray count] > 1 && [fileDataArray count] > j){
1497             NSString *str2 = [fileDataArray objectAtIndex:j];
1498             NSRange rangeSearchA = [str2 rangeOfString:@"##"];
1499             NSRange rangeSearchB = [str2 rangeOfString:@"%%"];
1500             NSRange rangeSearchC = [str2 rangeOfString:@"$$"];
1501             if (rangeSearchA.location == NSNotFound && rangeSearchB.location == NSNotFound && rangeSearchC.location == NSNotFound)
1502                 TX[i].S->string = [[TX[i].S->string stringByAppendingString:@"\n"] retain];
1503             }
1504         }
1505     }
1506         STRtop[i] = STRtop[i]->next;
1507         TX[i].S = STRtop[i];
1508     }
1509     
1510     /*
1511     NSLog(@"fN:%@\nNM:%@\nST:%@", TX[3].fileName, TX[3].S->name, TX[3].S->string);
1512     TX[3].S = TX[3].S->next;
1513     NSLog(@"fN:%@\nNM:%@\nST:%@", TX[3].fileName, TX[3].S->name, TX[3].S->string);
1514     TX[3].S = TX[3].S->next;
1515     NSLog(@"fN:%@\nNM:%@\nST:%@", TX[3].fileName, TX[3].S->name, TX[3].S->string);
1516     */
1517     
1518     
1519     
1520 }
1521
1522
1523 -(IBAction)titleBtn:(id)sender{
1524     
1525     [scenarioEditorWindow close];
1526     [titleWindow makeKeyAndOrderFront:nil];
1527 }
1528
1529 -(IBAction)insertLine:(id)sender{
1530     
1531     NSMutableDictionary *dict = [NSMutableDictionary new];
1532     [dict setValue:[NSString stringWithFormat:@"oops"] forKey:@"name"];
1533     
1534     STRtop[st] = TX[st].S;
1535     
1536     if(LLrow < 0){
1537         TX[st].S = STRtop[st];
1538         if([lineListMA count] == 0){
1539             TX[st].S = calloc(1, sizeof(STRING));
1540             //INIT 処理
1541             TX[st].S->name = @"";
1542             TX[st].S->string = @"";
1543             TX[st].S->next = NULL;
1544             STRtop[st] = TX[st].S;
1545         }else{
1546             while(TX[st].S->next) TX[st].S = TX[st].S->next;
1547             TX[st].S->next = calloc(1, sizeof(STRING));
1548             TX[st].S = TX[st].S->next;
1549             //INIT 処理
1550             TX[st].S->name = @"";
1551             TX[st].S->string = @"";
1552             TX[st].S->next = NULL;
1553             TX[st].S = STRtop[st];
1554         }
1555         
1556         [dict setValue:[NSString stringWithFormat:@":"] forKey:@"name"];
1557         
1558         [self willChangeValueForKey:@"lineListMA"];
1559         [lineListMA insertObject:dict atIndex:[lineListMA count]];
1560         [self didChangeValueForKey:@"lineListMA"];
1561         [lineListAC setSelectionIndex:9999];
1562         LLrow = -1;
1563     }else{
1564         TX[st].S = STRtop[st];
1565         if([lineListMA count] == 0){
1566             TX[st].S = calloc(1, sizeof(STRING));
1567             //INIT 処理
1568             TX[st].S->name = @"";
1569             TX[st].S->string = @"";
1570             TX[st].S->next = NULL;
1571             STRtop[st] = TX[st].S;
1572         }else if(LLrow > 0){
1573             for (int i = 0; i < LLrow-1;i++)
1574                 TX[st].S = TX[st].S->next;
1575             STRING *tmp = calloc(1, sizeof(STRING));
1576             *tmp = *TX[st].S->next;
1577             TX[st].S->next = calloc(1, sizeof(STRING));
1578             TX[st].S->next->next = tmp;
1579             TX[st].S->next->name = @"";
1580             TX[st].S->next->string = @"";
1581             TX[st].S = TX[st].S->next;
1582             TX[st].S = STRtop[st];
1583         }else{
1584             STRING *tmp = calloc(1, sizeof(STRING));
1585             tmp->next = TX[st].S;
1586             // INIT 処理[self InitAttack:tmp];
1587             tmp->name = @"";
1588             tmp->string = @"";
1589             STRtop[st] = tmp;
1590             TX[st].S = STRtop[st];
1591         }
1592         
1593         [dict setValue:[NSString stringWithFormat:@":"] forKey:@"name"];
1594         
1595         [self willChangeValueForKey:@"lineListMA"];
1596         [lineListMA insertObject:dict atIndex:LLrow];
1597         [self didChangeValueForKey:@"lineListMA"];
1598         [lineListAC setSelectionIndex:LLrow];
1599     }
1600     
1601     [Dname setStringValue:TX[st].S->name];
1602     [Dstring setStringValue:TX[st].S->string];
1603     [dialogName setStringValue:TX[st].S->name];
1604     [dialogString setStringValue:TX[st].S->string];
1605     [dialogImage setImage:TX[st].S->img];
1606     
1607     TX[st].S = STRtop[st];
1608 }
1609 -(IBAction)removeLine:(id)sender{
1610     
1611     STRtop[st] = TX[st].S;
1612     
1613     if(LLrow == -1){
1614         LLrow = (int)[lineListMA count] - 1;
1615     }
1616     
1617     if([lineListMA count] > 0){
1618         
1619         if(LLrow == 0){
1620             TX[st].S = STRtop[st];
1621             TX[st].S = TX[st].S->next;
1622             STRtop[st] = TX[st].S;
1623         }else if(LLrow == [lineListMA count] - 1){
1624             TX[st].S = STRtop[st];
1625             while(TX[st].S->next->next){
1626                 TX[st].S = TX[st].S->next;
1627             }
1628             TX[st].S->next = NULL;
1629         }else{
1630             TX[st].S = STRtop[st];
1631             for (int i = 0; i < LLrow - 1;i++)
1632                 TX[st].S = TX[st].S->next;
1633            TX[st].S->next = TX[st].S->next->next;
1634         }
1635         
1636         [self willChangeValueForKey:@"lineListMA"];
1637         [lineListMA removeObjectAtIndex:LLrow];
1638         [self didChangeValueForKey:@"lineListMA"];
1639         [lineListAC setSelectionIndex:LLrow-1];
1640         if(LLrow < 0) [lineListAC setSelectionIndex:[lineListMA count]-1];
1641         if(LLrow == 0) [lineListAC setSelectionIndex:0];
1642         if(LLrow > 0) {
1643             LLrow--;
1644             [Dname setStringValue:TX[st].S->name];
1645             [Dstring setStringValue:TX[st].S->string];
1646             [dialogName setStringValue:TX[st].S->name];
1647             [dialogString setStringValue:TX[st].S->string];
1648             [dialogImage setImage:TX[st].S->img];
1649         }
1650         
1651         if(TX[st].S){
1652             if(TX[st].S->name) [Dname setStringValue:TX[st].S->name];
1653                 else [Dname setStringValue:@""];
1654             }
1655         if(TX[st].S){
1656             if(TX[st].S->string) [Dstring setStringValue:TX[st].S->string];
1657             else [Dstring setStringValue:@""];
1658         }
1659         
1660         if(TX[st].S){
1661             if(TX[st].S->name) [dialogName setStringValue:TX[st].S->name];
1662             else [dialogName setStringValue:@""];
1663         }
1664         
1665         if(TX[st].S){
1666             if(TX[st].S->string) [dialogString setStringValue:TX[st].S->string];
1667             else [dialogString setStringValue:@""];
1668         }
1669         
1670         if(TX[st].S)
1671             [dialogImage setImage:TX[st].S->img];
1672     }
1673     TX[st].S = STRtop[st];
1674     
1675
1676 }
1677
1678 -(void)saveLineDataFnc{
1679     NSString *directoryPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
1680     [[NSFileManager defaultManager] changeCurrentDirectoryPath:directoryPath];
1681     
1682     NSString *saveDataPath = @"data/StringList/";
1683     
1684     saveDataPath = [saveDataPath stringByAppendingFormat:@"%@", TX[st].fileName];
1685     
1686     NSString *fileData = @"";
1687     
1688     
1689     STRtop[st] = TX[st].S;
1690     if(st < 0) return;
1691     if(!TX[st].S) return;
1692     if(TX[st].S->string == NULL) return;
1693     //if(TX[st].S->next != NULL) return;
1694     do {
1695         fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"##"]];
1696         fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"%@", TX[st].S->name]];
1697         if(TX[st].S->iName != NULL) {
1698             fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"##"]];
1699             fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"%@", TX[st].S->iName]];
1700         }
1701         fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"\n"]];
1702         
1703         fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"%@", TX[st].S->string]];
1704         
1705         NSString *omfgBR = @"";
1706         if([TX[st].S->string length] > 0){
1707         omfgBR = [TX[st].S->string substringFromIndex:[TX[st].S->string length]-1];
1708         }
1709         if(![omfgBR isEqualToString:@"\n"]){
1710             fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"\n"]];
1711         }
1712         
1713         SItop = TX[st].S->i;
1714         while(TX[st].S->i) {
1715             fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"$$"]];
1716             fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"%@[%d,%d]", TX[st].S->i->name, TX[st].S->i->standX, TX[st].S->i->standY]];
1717             fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"$$"]];
1718             fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"%d", TX[st].S->i->SEMA1row - 1]];
1719             fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"$$"]];
1720             fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"%d", TX[st].S->i->SEMA2row - 1]];
1721             fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"$$"]];
1722             
1723             I = Itop;
1724             
1725             for(int i = 0;i < SEMA1row;i++){
1726                 I = I->next;
1727             }
1728             
1729             BASE *b = I->B;
1730             BASE *bTop = b;
1731             
1732             for(int i = 0;i < SEMA2row;i++){
1733                 b = b->next;
1734             }
1735             
1736             LAYER *lTop = b->L;
1737             if(TX[st].S->i->SEMA3flag)
1738                 for(int i = 0;*(TX[st].S->i->SEMA3flag + i) > 0;i++){
1739                 if(i > 0)
1740                     fileData = [fileData stringByAppendingString:@","];
1741                 fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"%d", *(TX[st].S->i->SEMA3flag + i)-1]];
1742                 
1743             }b->L = lTop;
1744             
1745             b = bTop;
1746             
1747             I = Itop;
1748             
1749             
1750             fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"\n"]];
1751             
1752             TX[st].S->i = TX[st].S->i->next;
1753         }TX[st].S->i = SItop;
1754         
1755         if(TX[st].S->imgWall != NULL) {
1756             fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"%%%%"]];
1757             fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"%@", TX[st].S->iNameWall]];
1758             if (TX[st].S->wallFadeIn && TX[st].S->wallFadeOut) {
1759                 fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"%%%%"]];
1760                 fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"FIO"]];
1761             }
1762             else if(TX[st].S->wallFadeIn) {
1763                 fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"%%%%"]];
1764                 fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"FI"]];
1765             }
1766             else if(TX[st].S->wallFadeOut) {
1767                 fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"%%%%"]];
1768                 fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"FO"]];
1769             }else{
1770                 fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"%%%%"]];
1771                 fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"NULL"]];
1772             }
1773             if(TX[st].S->iNameWallSort){
1774                 fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"%%%%"]];
1775                 fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"%@",TX[st].S->iNameWallSort]];
1776             }
1777             fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"\n"]];
1778             if(TX[st].S->img){
1779                 NSString *path = @"data/StringList/img/";
1780                 NSData *data = [TX[st].S->img TIFFRepresentation];
1781                 NSBitmapImageRep *brep = [NSBitmapImageRep imageRepWithData:data];
1782                 data = [brep representationUsingType:NSPNGFileType properties:nil];
1783                 
1784                 path = [path stringByAppendingString:TX[st].S->iName];
1785                 
1786                 [data writeToFile:path atomically:YES];
1787             }if(TX[st].S->imgWall){
1788                 NSString *path = @"data/StringList/img/";
1789                 NSData *data = [TX[st].S->imgWall TIFFRepresentation];
1790                 NSBitmapImageRep *brep = [NSBitmapImageRep imageRepWithData:data];
1791                 data = [brep representationUsingType:NSPNGFileType properties:nil];
1792                 
1793                 path = [path stringByAppendingString:TX[st].S->iNameWall];
1794                 
1795                 [data writeToFile:path atomically:YES];
1796             }
1797
1798         }
1799         
1800         TX[st].S = TX[st].S->next;
1801     }while(TX[st].S != NULL);
1802     
1803     [fileData writeToFile:saveDataPath atomically:YES encoding:NSUTF8StringEncoding error:nil];
1804     
1805     
1806     TX[st].S = STRtop[st];
1807 }
1808
1809 -(IBAction)saveLineData:(id)sender{
1810     
1811                     
1812     [self saveLineDataFnc];
1813 }
1814
1815 -(IBAction)detailBtn:(id)sender{
1816     
1817     if(st<0)
1818         return;
1819     if(sl<0)
1820         return;
1821     
1822     for(int i = 0;i < sl;i++){
1823         TX[st].S = TX[st].S->next;
1824     }
1825     
1826     
1827     [IVface setImage:TX[st].S->img];
1828     [IVwall setImage:TX[st].S->imgWall];
1829     
1830     if(TX[st].S->iName)
1831         [TFface setStringValue:TX[st].S->iName];
1832     else
1833         [TFface setStringValue:@""];
1834
1835     if(TX[st].S->iNameWall)
1836         [TFwall setStringValue:TX[st].S->iNameWall];
1837     else
1838         [TFwall setStringValue:@""];
1839
1840
1841     [SEstandTFx setStringValue:[NSString stringWithFormat:@"0"]];
1842     [SEstandTFy setStringValue:[NSString stringWithFormat:@"0"]];
1843     
1844     //NSLog(@"[%@]",[TFface stringValue]);
1845     
1846     [FIbtn setState:TX[st].S->wallFadeIn];
1847     [FObtn setState:TX[st].S->wallFadeOut];
1848     
1849     if(TX[st].S->i){
1850     SEMA1row = TX[st].S->i->SEMA1row - 1;
1851     SEMA2row = TX[st].S->i->SEMA2row - 1;
1852     }else{
1853         SEMA1row = - 1;
1854         SEMA2row = - 1;
1855     }
1856     SEMA3row = -1;
1857     [self initSEstand];
1858     
1859
1860     [self willChangeValueForKey:@"SEMA"];
1861     [SEMA removeAllObjects];
1862     [self didChangeValueForKey:@"SEMA"];
1863     
1864     
1865     
1866     SItop = TX[st].S->i;
1867     while (TX[st].S->i) {
1868         NSMutableDictionary *dict = [NSMutableDictionary new];
1869         
1870         [dict setValue:[NSString stringWithFormat:@"%@", TX[st].S->i->name] forKey:@"name"];
1871         
1872         [self willChangeValueForKey:@"SEMA"];
1873         [SEMA addObject:dict];
1874         [self didChangeValueForKey:@"SEMA"];
1875         
1876         TX[st].S->i = TX[st].S->i->next;
1877     }TX[st].S->i = SItop;
1878     
1879     SEMArow = -1;
1880     [SEAC setSelectionIndex:9999];
1881     
1882     TX[st].S = STRtop[st];
1883     
1884     if(SEMA1row < 0)
1885         [SEAC1 setSelectionIndex:9999];
1886     else
1887         [SEAC1 setSelectionIndex:SEMA1row];
1888     if(SEMA2row < 0)
1889         [SEAC2 setSelectionIndex:9999];
1890     else
1891         [SEAC2 setSelectionIndex:SEMA2row];
1892     [SEAC3 setSelectionIndex:9999];
1893     
1894     STRtop[st] = STRtop[st];
1895     standChoiceFlag = true;
1896     
1897     [detailWindow makeKeyAndOrderFront:nil];
1898 }
1899
1900 -(IBAction)standBtn:(id)sender{
1901     
1902     [self loadStandData];
1903     [self loadData];
1904     
1905     Irow = -1;
1906     
1907     standEditorFlag = true;
1908     
1909     [standPanel makeKeyAndOrderFront:nil];
1910 }
1911
1912 -(IBAction)backStand:(id)sender{
1913     [self saveStandData];
1914     [self saveData];
1915     [self loadStandData];
1916     [self loadData];
1917     
1918     standEditorFlag = false;
1919     
1920     [standPanel close];
1921     [scenarioEditorWindow makeKeyAndOrderFront:nil];
1922 }
1923
1924
1925 -(IBAction)submitStand:(id)sender{
1926     [standEditorPanel close];
1927     //[self saveDataStand];
1928     [self saveStandData];
1929     [self loadStandData];
1930     TVCrow1 = -1;
1931     TVCrow2 = -1;
1932     [standPanel makeKeyAndOrderFront:nil];
1933 }
1934
1935
1936 -(IBAction)insertLineStand:(id)sender{
1937     NSMutableDictionary *dict = [NSMutableDictionary new];
1938     [dict setValue:[NSString stringWithFormat:@"新規立ち絵"] forKey:@"name"];
1939     /*
1940     Itop = I;
1941     
1942     if(Irow < 0){
1943         I = Itop;
1944         if([standListMA count] == 0){
1945             I = calloc(1, sizeof(STAND));
1946             //INIT 処理
1947             I->B = NULL;
1948             I->registerNum = 0;
1949             I->index = 0;
1950             I->name = [@"新規立ち絵" retain];
1951             I->next = NULL;
1952             Itop = I;
1953         }else{
1954             while(I->next) I = I->next;
1955             I->next = calloc(1, sizeof(STAND));
1956             I = I->next;
1957             //INIT 処理
1958             I->B = NULL;
1959             I->registerNum = 0;
1960             I->name = [@"新規立ち絵" retain];
1961             I->next = NULL;
1962             I = Itop;
1963         }
1964         
1965
1966         
1967         [self willChangeValueForKey:@"standListMA"];
1968         [standListMA insertObject:dict atIndex:[standListMA count]];
1969         [self didChangeValueForKey:@"standListMA"];
1970         [standListAC setSelectionIndex:9999];
1971         Irow = -1;
1972         Inumb++;
1973     }else{
1974         I = Itop;
1975         if([standListMA count] == 0){
1976             I = calloc(1, sizeof(STAND));
1977             //INIT 処理
1978             I->B = NULL;
1979             I->registerNum = 0;
1980             I->name = [@"新規立ち絵" retain];
1981             I->next = NULL;
1982             Itop = I;
1983         }else if(Irow > 0){
1984             for (int i = 0; i < Irow-1;i++)
1985             I = I->next;
1986             STAND *tmp = calloc(1, sizeof(STAND));
1987             *tmp = *I->next;
1988             I->next = calloc(1, sizeof(STAND));
1989             I->next->next = tmp;
1990             I = I->next;
1991             //INIT 処理
1992             I->B = NULL;
1993             I->registerNum = 0;
1994             I->name = [@"新規立ち絵" retain];
1995             I = Itop;
1996         }else{
1997             STAND *tmp = calloc(1, sizeof(STAND));
1998             tmp->next = I;
1999             // INIT 処理[self InitAttack:tmp];
2000             tmp->B = NULL;
2001             tmp->registerNum = 0;
2002             tmp->name = [@"新規立ち絵" retain];
2003             Itop = tmp;
2004             I = Itop;
2005         }
2006         
2007
2008         
2009         [self willChangeValueForKey:@"standListMA"];
2010         [standListMA insertObject:dict atIndex:Irow];
2011         [self didChangeValueForKey:@"standListMA"];
2012         [standListAC setSelectionIndex:Irow];
2013         Inumb++;
2014     }
2015     
2016     [self saveDataStand];
2017     I = Itop;
2018     [self initLineBaseLayer];
2019     */
2020     
2021     
2022     I = Itop;
2023     
2024     if(1){
2025         NSMutableDictionary *dict = [NSMutableDictionary new];
2026         if([standListMA count] == 0){
2027             
2028             Itop = calloc(1, sizeof(STAND));
2029             I = Itop;
2030             I->name = [@"新規立ち絵" retain];
2031             I->B = NULL;
2032             [dict setValue:[NSString stringWithFormat:@"%@", I->name] forKey:@"name"];
2033             
2034             [self willChangeValueForKey:@"standListMA"];
2035             [standListMA insertObject:dict atIndex:[standListMA count]];
2036             [self didChangeValueForKey:@"standListMA"];
2037             [standListAC setSelectionIndex:999];
2038         }else if(Irow == -1){
2039             while (I->next) {
2040                 I = I->next;
2041             }
2042             I->next = calloc(1, sizeof(STAND));
2043             I= I->next;
2044             I->name = [@"新規立ち絵" retain];
2045             I->B = NULL;
2046             [dict setValue:[NSString stringWithFormat:@"%@", I->name] forKey:@"name"];
2047             
2048             [self willChangeValueForKey:@"standListMA"];
2049             [standListMA insertObject:dict atIndex:[standListMA count]];
2050             [self didChangeValueForKey:@"standListMA"];
2051             [standListAC setSelectionIndex:999];
2052             
2053         }else if(Irow > 0){
2054             for (int i = 0; i < Irow-1; i++) {
2055                 I = I->next;
2056             }
2057             STAND *tmp = (STAND*)malloc(sizeof(STAND));
2058             tmp = I->next;
2059             I->next = (STAND*)malloc(sizeof(STAND));
2060             I->next->next = tmp;
2061             I = I->next;
2062             I->name = [@"新規立ち絵" retain];
2063             I->B = NULL;
2064             [dict setValue:[NSString stringWithFormat:@"%@", I->name] forKey:@"name"];
2065             [self willChangeValueForKey:@"standListMA"];
2066             [standListMA insertObject:dict atIndex:Irow];
2067             [self didChangeValueForKey:@"standListMA"];
2068             [standListAC setSelectionIndex:999];
2069             
2070         }else{
2071             Itop = I;
2072             STAND tmp;
2073             tmp = *I;
2074             I->name = [@"新規立ち絵" retain];
2075             I->B = NULL;
2076             I->next = calloc(1, sizeof(STAND));
2077             I = I->next;
2078             *I = tmp;
2079             //b->L = NULL;
2080             I = Itop;
2081             [dict setValue:[NSString stringWithFormat:@"%@", I->name] forKey:@"name"];
2082             
2083             [self willChangeValueForKey:@"standListMA"];
2084             [standListMA insertObject:dict atIndex:Irow];
2085             [self didChangeValueForKey:@"standListMA"];
2086             [standListAC setSelectionIndex:999];
2087         }
2088
2089         I = Itop;
2090         Inumb++;
2091     }
2092     
2093     I = Itop;
2094     
2095     [self saveStandData];
2096     [self saveData];
2097     [self loadStandData];
2098     [self loadData];
2099     //[self initLineBaseLayer];
2100     
2101 }
2102 -(IBAction)removeLineStand:(id)sender{
2103
2104     /*
2105     Itop = I;
2106     
2107     if(Irow == -1){
2108         Irow = (int)[standListMA count] - 1;
2109     }
2110     
2111     if([standListMA count] > 0){
2112         
2113         if(Irow == 0){
2114             I = Itop;
2115             I = I->next;
2116             Itop = I;
2117         }else if(Irow == [standListMA count] - 1){
2118             I = Itop;
2119             while(I->next->next){
2120                 I = I->next;
2121             }
2122             I->next = NULL;
2123         }else{
2124             I = Itop;
2125             for (int i = 0; i < Irow - 1;i++)
2126                 I = I->next;
2127             I->next = I->next->next;
2128         }
2129         
2130         [self willChangeValueForKey:@"standListMA"];
2131         [standListMA removeObjectAtIndex:Irow];
2132         [self didChangeValueForKey:@"standListMA"];
2133         [standListAC setSelectionIndex:Irow-1];
2134         if(Irow < 0) [standListAC setSelectionIndex:[standListMA count]-1];
2135         if(Irow == 0) [standListAC setSelectionIndex:0];
2136         if(Irow > 0) Irow--;
2137         Inumb--;
2138     }
2139     I = Itop;
2140     */
2141     
2142     NSString *directoryPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
2143     [[NSFileManager defaultManager] changeCurrentDirectoryPath:directoryPath];
2144     
2145     NSString *path = @"data/Scenario/";
2146     
2147     I = Itop;
2148     
2149     if(1){
2150         if([standListMA count] == 0){
2151             return;
2152         }else if(Irow == -1){
2153             for(int i = 0;i < [standListMA count]-1;i++){
2154
2155                 if(i == [standListMA count] - 2)
2156                     break;
2157                 
2158                 
2159                 I = I->next;
2160             }
2161             if([standListMA count] > 1) {
2162                 path = [path stringByAppendingFormat:@"%@",I->next->fName];
2163                 
2164                 
2165                 [[NSFileManager defaultManager] removeItemAtPath:path error:nil];
2166                 I->next = NULL;
2167             }
2168             else {
2169                 path = [path stringByAppendingFormat:@"%@",Itop->fName];
2170                 
2171                 [[NSFileManager defaultManager] removeItemAtPath:path error:nil];
2172                 Itop = NULL;
2173                 
2174             }
2175             [self willChangeValueForKey:@"standListMA"];
2176             [standListMA removeObjectAtIndex:[standListMA count]-1];
2177             [self didChangeValueForKey:@"standListMA"];
2178             [standListAC setSelectionIndex:999];
2179             
2180         }else if(Irow > 0){
2181             for (int i = 0; i < Irow-1; i++) {
2182                 
2183                 I = I->next;
2184             }
2185
2186             path = [path stringByAppendingFormat:@"%@",I->next->fName];
2187             
2188             [[NSFileManager defaultManager] removeItemAtPath:path error:nil];
2189             
2190             I->next = I->next->next;
2191             
2192             [self willChangeValueForKey:@"standListMA"];
2193             [standListMA removeObjectAtIndex:Irow];
2194             [self didChangeValueForKey:@"standListMA"];
2195             [standListAC setSelectionIndex:999];
2196             
2197         }else{
2198             path = [path stringByAppendingFormat:@"%@",Itop->fName];
2199             
2200             [[NSFileManager defaultManager] removeItemAtPath:path error:nil];
2201             
2202             Itop = I->next;
2203             I = Itop;
2204             [self willChangeValueForKey:@"standListMA"];
2205             [standListMA removeObjectAtIndex:Irow];
2206             [self didChangeValueForKey:@"standListMA"];
2207             [standListAC setSelectionIndex:999];
2208         }
2209         
2210         I = Itop;
2211     }
2212     Inumb--;
2213     Irow = -1;
2214     
2215     [self saveStandData];
2216     [self saveData];
2217     [self loadStandData];
2218     [self loadData];
2219    // [self initMA1MA2];
2220 }
2221
2222
2223
2224 -(IBAction)insertLineBase:(id)sender{
2225     /*
2226     NSMutableDictionary *dict = [NSMutableDictionary new];
2227     [dict setValue:[NSString stringWithFormat:@"新規ベース"] forKey:@"name"];
2228     
2229     I = Itop;
2230     for (int i = 0; i < Irow; i++) {
2231         I = I->next;
2232     }
2233     
2234     
2235     IBtop = I->B;
2236     
2237     if(IBrow < 0){
2238         I->B = IBtop;
2239         if([baseListMA count] == 0){
2240             I->B = calloc(1, sizeof(BASE));
2241             //INIT 処理
2242             I->B->L = NULL;
2243             I->registerNum++;
2244             I->B->index = 0;
2245             I->B->name = [@"新規ベース" retain];
2246             I->B->z = 100;
2247             I->B->img = nil;
2248             I->B->next = NULL;
2249             IBtop = I->B;
2250         }else{
2251             while(I->B->next) I->B = I->B->next;
2252             I->B->next = calloc(1, sizeof(BASE));
2253             I->B = I->B->next;
2254             //INIT 処理
2255             I->B->L = NULL;
2256             I->registerNum++;
2257             I->B->name = [@"新規ベース" retain];
2258             I->B->z = 100;
2259             I->B->img = nil;
2260             I->B->next = NULL;
2261             I->B = IBtop;
2262         }
2263         
2264         [dict setValue:[NSString stringWithFormat:@"%d", I->B->z] forKey:@"pref"];
2265         
2266         [self willChangeValueForKey:@"baseListMA"];
2267         [baseListMA insertObject:dict atIndex:[baseListMA count]];
2268         [self didChangeValueForKey:@"baseListMA"];
2269         [baseListAC setSelectionIndex:9999];
2270         IBrow = -1;
2271     }else{
2272         I->B = IBtop;
2273         if([baseListMA count] == 0){
2274             I->B = calloc(1, sizeof(BASE));
2275             //INIT 処理
2276             I->B->L = NULL;
2277             I->registerNum++;
2278             I->B->name = [@"新規ベース" retain];
2279             I->B->z = 100;
2280             I->B->img = nil;
2281             I->B->next = NULL;
2282             IBtop = I->B;
2283         }else if(IBrow > 0){
2284             for (int i = 0; i < IBrow-1;i++)
2285                 I->B = I->B->next;
2286             BASE *tmp = calloc(1, sizeof(BASE));
2287             *tmp = *I->B->next;
2288             I->B->next = calloc(1, sizeof(BASE));
2289             I->B->next->next = tmp;
2290             I->B = I->B->next;
2291             //INIT 処理
2292             I->B->L = NULL;
2293             I->registerNum++;
2294             I->B->img = nil;
2295             I->B->name = [@"新規ベース" retain];
2296             I->B->z = 100;
2297             I->B = IBtop;
2298         }else{
2299             BASE *tmp = calloc(1, sizeof(BASE));
2300             tmp->next = I->B;
2301             // INIT 処理[self InitAttack:tmp];
2302             tmp->L = NULL;
2303             I->registerNum++;
2304             tmp->name = [@"新規ベース" retain];
2305             tmp->z = 100;
2306             tmp->img = nil;
2307             IBtop = tmp;
2308             I->B = IBtop;
2309         }
2310         
2311         [dict setValue:[NSString stringWithFormat:@"%d", I->B->z] forKey:@"pref"];
2312         
2313         [self willChangeValueForKey:@"baseListMA"];
2314         [baseListMA insertObject:dict atIndex:IBrow];
2315         [self didChangeValueForKey:@"baseListMA"];
2316         [baseListAC setSelectionIndex:IBrow];
2317     }
2318     
2319     
2320     I = Itop;
2321      */
2322 }
2323
2324 -(IBAction)removeLineBase:(id)sender{
2325     /*
2326     if(IBrow == -1){
2327         IBrow = (int)[baseListMA count] - 1;
2328     }
2329     
2330     Itop = I;
2331     for (int i = 0; i < Irow; i++) {
2332         I = I->next;
2333     }
2334     
2335     IBtop = I->B;
2336     if([baseListMA count] > 0){
2337         
2338         if(IBrow == 0){
2339             I->B = IBtop;
2340             I->B = I->B->next;
2341             I->registerNum--;
2342             IBtop = I->B;
2343         }else if(IBrow == [baseListMA count] - 1){
2344             I->B = IBtop;
2345             while(I->B->next->next){
2346                 I->B = I->B->next;
2347             }
2348             I->registerNum--;
2349             I->B->next = NULL;
2350         }else{
2351             I->B = IBtop;
2352             for (int i = 0; i < IBrow - 1;i++)
2353                 I->B = I->B->next;
2354             I->B->next = I->B->next->next;
2355             I->registerNum--;
2356         }
2357         
2358         [self willChangeValueForKey:@"baseListMA"];
2359         [baseListMA removeObjectAtIndex:IBrow];
2360         [self didChangeValueForKey:@"baseListMA"];
2361         [baseListAC setSelectionIndex:IBrow-1];
2362         if(IBrow < 0) [baseListAC setSelectionIndex:[baseListMA count]-1];
2363         if(IBrow == 0) [baseListAC setSelectionIndex:0];
2364         if(IBrow > 0) IBrow--;
2365     }
2366     I->B = IBtop;
2367     
2368     I = Itop;
2369
2370     
2371     [self initLineLayer];
2372     */
2373 }
2374
2375 -(void)initLineBaseLayer{
2376     /*
2377     [self willChangeValueForKey:@"baseListMA"];
2378     [baseListMA removeAllObjects];
2379     [self didChangeValueForKey:@"baseListMA"];
2380     
2381     [self willChangeValueForKey:@"layerListMA"];
2382     [layerListMA removeAllObjects];
2383     [self didChangeValueForKey:@"layerListMA"];
2384     
2385     Itop = I;
2386     for (int i = 0; i < Irow; i++) {
2387         I = I->next;
2388     }
2389     IBtop = I->B;
2390     while (I->B) {
2391         NSMutableDictionary *dict = [NSMutableDictionary new];
2392         [dict setValue:[NSString stringWithFormat:@"%@", I->B->name] forKey:@"name"];
2393         [dict setValue:[NSString stringWithFormat:@"%d", I->B->z] forKey:@"pref"];
2394         
2395         [self willChangeValueForKey:@"baseListMA"];
2396         [baseListMA addObject:dict];
2397         [self didChangeValueForKey:@"baseListMA"];
2398         I->B = I->B->next;
2399     }I->B = IBtop;
2400     I = Itop;
2401     
2402     */
2403 }
2404
2405 -(void)initLineLayer{
2406     /*
2407     [self willChangeValueForKey:@"layerListMA"];
2408     [layerListMA removeAllObjects];
2409     [self didChangeValueForKey:@"layerListMA"];
2410     
2411     if(IBrow < 0) return;
2412     
2413     Itop = I;
2414     for (int i = 0; i < Irow; i++) {
2415         I = I->next;
2416     }
2417     
2418     IBtop = I->B;
2419     for (int i = 0; i < IBrow; i++) {
2420         I->B = I->B->next;
2421     }
2422     
2423     if(!I->B) return;
2424     
2425     IBLtop = I->B->L;
2426     while (I->B->L) {
2427         NSMutableDictionary *dict = [NSMutableDictionary new];
2428         [dict setValue:[NSString stringWithFormat:@"%@", I->B->L->name] forKey:@"name"];
2429         [dict setValue:[NSString stringWithFormat:@"%d", I->B->L->z] forKey:@"pref"];
2430         [dict setValue:[NSString stringWithFormat:@"%d", I->B->L->visible] forKey:@"visible"];
2431         
2432         [self willChangeValueForKey:@"layerListMA"];
2433         [layerListMA addObject:dict];
2434         [self didChangeValueForKey:@"layerListMA"];
2435         I->B->L = I->B->L->next;
2436     }
2437     
2438     I->B->L = IBLtop;
2439     I->B = IBtop;
2440     I = Itop;
2441     I = Itop;
2442      */
2443 }
2444
2445
2446 -(IBAction)insertLineLayer:(id)sender{
2447     /*
2448     if(IBrow < 0) return;
2449     
2450     
2451     NSMutableDictionary *dict = [NSMutableDictionary new];
2452     [dict setValue:[NSString stringWithFormat:@"新規レイヤー"] forKey:@"name"];
2453     I = Itop;
2454     for (int i = 0; i < Irow; i++) {
2455         I = I->next;
2456     }
2457     
2458     IBtop = I->B;
2459     for (int i = 0; i < IBrow; i++) {
2460         I->B = I->B->next;
2461     }
2462     
2463     
2464     IBLtop = I->B->L;
2465     
2466     if(IBLrow < 0){
2467         I->B->L = IBLtop;
2468         if([layerListMA count] == 0){
2469             I->B->L = calloc(1, sizeof(LAYER));
2470             //INIT 処理
2471             I->registerNum++;
2472             I->B->L->index = 0;
2473             I->B->L->z = 225;
2474             I->B->L->name = [@"新規レイヤー" retain];
2475             I->B->L->next = NULL;
2476             IBLtop = I->B->L;
2477         }else{
2478             while(I->B->L->next) I->B->L = I->B->L->next;
2479             I->B->L->next = calloc(1, sizeof(LAYER));
2480             I->B->L = I->B->L->next;
2481             //INIT 処理
2482             I->registerNum++;
2483             I->B->L->z = 225;
2484             I->B->L->name = [@"新規レイヤー" retain];
2485             I->B->L->next = NULL;
2486             I->B->L = IBLtop;
2487         }
2488         
2489         [dict setValue:[NSString stringWithFormat:@"%d", I->B->L->z] forKey:@"pref"];
2490         
2491         [self willChangeValueForKey:@"layerListMA"];
2492         [layerListMA insertObject:dict atIndex:[layerListMA count]];
2493         [self didChangeValueForKey:@"layerListMA"];
2494         [layerListAC setSelectionIndex:9999];
2495         IBLrow = -1;
2496     }else{
2497         I->B->L = IBLtop;
2498         if([layerListMA count] == 0){
2499             I->B->L = calloc(1, sizeof(LAYER));
2500             //INIT 処理
2501             I->registerNum++;
2502             I->B->L->z = 225;
2503             I->B->L->name = [@"新規レイヤー" retain];
2504             I->B->L->next = NULL;
2505             IBLtop = I->B->L;
2506         }else if(IBLrow > 0){
2507             for (int i = 0; i < IBLrow-1;i++)
2508                 I->B->L = I->B->L->next;
2509             LAYER *tmp = calloc(1, sizeof(LAYER));
2510             *tmp = *I->B->L->next;
2511             I->B->L->next = calloc(1, sizeof(LAYER));
2512             I->B->L->next->next = tmp;
2513             I->B->L = I->B->L->next;
2514             //INIT 処理
2515             I->registerNum++;
2516             I->B->L->z = 225;
2517             I->B->L->name = [@"新規レイヤー" retain];
2518             I->B->L = IBLtop;
2519         }else{
2520             LAYER *tmp = calloc(1, sizeof(LAYER));
2521             tmp->next = I->B->L;
2522             // INIT 処理[self InitAttack:tmp];
2523             I->registerNum++;
2524             tmp->z = 225;
2525             tmp->name = [@"新規レイヤー" retain];
2526             IBLtop = tmp;
2527             I->B->L = IBLtop;
2528         }
2529         
2530         [dict setValue:[NSString stringWithFormat:@"%d", I->B->L->z] forKey:@"pref"];
2531         
2532         [self willChangeValueForKey:@"layerListMA"];
2533         [layerListMA insertObject:dict atIndex:IBLrow];
2534         [self didChangeValueForKey:@"layerListMA"];
2535         [layerListAC setSelectionIndex:IBLrow];
2536     }
2537     
2538     I->B = IBtop;
2539     I = Itop;
2540     */
2541 }
2542
2543 -(IBAction)removeLineLayer:(id)sender{
2544     /*
2545     if(IBrow < 0) return;
2546     
2547     
2548     if(IBLrow == -1){
2549         IBLrow = (int)[layerListMA count] - 1;
2550     }
2551     
2552     Itop = I;
2553     for (int i = 0; i < Irow; i++) {
2554         I = I->next;
2555     }
2556     
2557     IBtop = I->B;
2558     for (int i = 0; i < IBrow; i++) {
2559         I->B = I->B->next;
2560     }
2561     
2562     IBLtop = I->B->L;
2563     if([layerListMA count] > 0){
2564         
2565         if(IBLrow == 0){
2566             I->B->L = IBLtop;
2567             I->B->L = I->B->L->next;
2568             I->registerNum--;
2569             IBLtop = I->B->L;
2570         }else if(IBLrow == [layerListMA count] - 1){
2571             I->B->L = IBLtop;
2572             while(I->B->L->next->next){
2573                 I->B->L = I->B->L->next;
2574             }
2575             I->registerNum--;
2576             I->B->L->next = NULL;
2577         }else{
2578             I->B->L = IBLtop;
2579             for (int i = 0; i < IBLrow - 1;i++)
2580                 I->B->L = I->B->L->next;
2581             I->B->L->next = I->B->L->next->next;
2582             I->registerNum--;
2583         }
2584         
2585         [self willChangeValueForKey:@"layerListMA"];
2586         [layerListMA removeObjectAtIndex:IBLrow];
2587         [self didChangeValueForKey:@"layerListMA"];
2588         [layerListAC setSelectionIndex:IBrow-1];
2589         if(IBLrow < 0) [layerListAC setSelectionIndex:[layerListMA count]-1];
2590         if(IBLrow == 0) [layerListAC setSelectionIndex:0];
2591         if(IBLrow > 0) IBLrow--;
2592     }
2593     I->B->L = IBLtop;
2594     
2595     I->B = IBtop;
2596     
2597     I = Itop;
2598 */
2599 }
2600
2601
2602
2603
2604 -(IBAction)detailClose:(id)sender{
2605
2606     TX[st].S = STRtop[st];
2607     for(int i = 0;i < sl;i++){
2608         TX[st].S = TX[st].S->next;
2609     }
2610     
2611     SItop = TX[st].S->i;
2612     while(TX[st].S->i){
2613     
2614     TX[st].S->img = [[IVface image] retain];
2615     TX[st].S->imgWall = [[IVwall image] retain];
2616     
2617     if(SEMA1row < 0 || SEMA2row < 0){
2618         TX[st].S->i->imgStand = NULL;
2619     }else{
2620         //TX[st].S->i->imgStand = [[SEIV image] retain];
2621     }
2622     if([TFface stringValue]) TX[st].S->iName = [[TFface stringValue] retain];
2623     if([TFwall stringValue]) TX[st].S->iNameWall = [[TFwall stringValue] retain];
2624
2625     
2626     NSString *directoryPath;
2627     
2628     directoryPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
2629     [[NSFileManager defaultManager] changeCurrentDirectoryPath:directoryPath];
2630     
2631     TX[st].S->wallFadeIn = [FIbtn state];
2632     TX[st].S->wallFadeOut = [FObtn state];
2633     
2634     if(SEMA1row < 0){
2635         TX[st].S->i = SItop;
2636         TX[st].S = STRtop[st];
2637         [self linefix];
2638         [self saveLineDataFnc];
2639         standChoiceFlag = false;
2640         [detailWindow close];
2641         return;
2642     }
2643     if(SEMA2row < 0){
2644         TX[st].S->i = SItop;
2645         TX[st].S = STRtop[st];
2646         [self linefix];
2647         [self saveLineDataFnc];
2648         standChoiceFlag = false;
2649         [detailWindow close];
2650         return;
2651     }
2652         
2653         TX[st].S->i = TX[st].S->i->next;
2654     }
2655     TX[st].S->i = SItop;
2656     
2657     TX[st].S = STRtop[st];
2658  
2659     standChoiceFlag = false;
2660     [self linefix];
2661     
2662     [self saveLineDataFnc];
2663     
2664     [detailWindow close];
2665 }
2666
2667
2668 -(IBAction)addTextList:(id)sender{
2669     
2670     NSMutableDictionary *dict = [NSMutableDictionary new];
2671     [dict setValue:[NSString stringWithFormat:@"新規ファイル%ld",[textListMA count]] forKey:@"name"];
2672     
2673     [self willChangeValueForKey:@"textListMA"];
2674     [textListMA addObject:dict];
2675     [self didChangeValueForKey:@"textListMA"];
2676     
2677     TX[st].fileName = [[NSString stringWithFormat:@"新規ファイル%ld", [textListMA count]-1] retain];
2678 }
2679 -(IBAction)removeTextList:(id)sender{
2680     
2681     NSString *directoryPath;
2682     
2683     directoryPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
2684     [[NSFileManager defaultManager] changeCurrentDirectoryPath:directoryPath];
2685     
2686     NSString *path = @"data/StringList/";
2687     
2688     path = [path stringByAppendingString:TX[st].fileName];
2689     
2690     [[NSFileManager defaultManager] removeItemAtPath:path error:nil];
2691     
2692     TX[st].fileName = NULL;
2693     TX[st].S = NULL;
2694     
2695     [self willChangeValueForKey:@"textListMA"];
2696     [textListAC setSelectionIndex:st];
2697     [textListAC setValue:@"Deleted" forKey:@"name"];
2698     [self didChangeValueForKey:@"textListMA"];
2699     
2700 }
2701
2702
2703
2704
2705 -(IBAction)insert1:(id)sender{
2706     
2707     
2708     I = Itop;
2709     
2710     for(int i = 0;i < Irow;i++){
2711         I = I->next;
2712     }
2713     
2714     b = I->B;
2715     
2716     BASE *bTop = b;
2717     
2718     if(1){
2719         NSMutableDictionary *dict = [NSMutableDictionary new];
2720         if([MA1 count] == 0){
2721             
2722             bTop = calloc(1, sizeof(BASE));
2723             b = bTop;
2724             b->name = [@"新キャラ" retain];
2725             b->postName = NULL;
2726             b->z = 100;
2727             b->L = NULL;
2728             [dict setValue:[NSString stringWithFormat:@"%@", b->name] forKey:@"name"];
2729             [dict setValue:[NSString stringWithFormat:@"%d", b->z] forKey:@"z"];
2730             
2731             [self willChangeValueForKey:@"MA1"];
2732             [MA1 insertObject:dict atIndex:[MA1 count]];
2733             [self didChangeValueForKey:@"MA1"];
2734             [AC1 setSelectionIndex:999];
2735         }else if(TVCrow1 == -1){
2736             while (b->next) {
2737                 b = b->next;
2738             }
2739             b->next = calloc(1, sizeof(BASE));
2740             b = b->next;
2741             b->name = [@"新キャラ" retain];
2742             b->postName = NULL;
2743             b->z = 100;
2744             b->L = NULL;
2745             [dict setValue:[NSString stringWithFormat:@"%@", b->name] forKey:@"name"];
2746             [dict setValue:[NSString stringWithFormat:@"%d", b->z] forKey:@"z"];
2747             
2748             [self willChangeValueForKey:@"MA1"];
2749             [MA1 insertObject:dict atIndex:[MA1 count]];
2750             [self didChangeValueForKey:@"MA1"];
2751             [AC1 setSelectionIndex:999];
2752             
2753         }else if(TVCrow1 > 0){
2754             for (int i = 0; i < TVCrow1-1; i++) {
2755                 
2756                 b = b->next;
2757             }
2758             BASE *tmp = (BASE*)malloc(sizeof(BASE));
2759             tmp = b->next;
2760             b->next = (BASE*)malloc(sizeof(BASE));
2761             b->next->next = tmp;
2762             b = b->next;
2763             b->name = [@"新キャラ" retain];
2764             b->postName = NULL;
2765             b->z = 100;
2766             b->L = NULL;
2767             [dict setValue:[NSString stringWithFormat:@"%@", b->name] forKey:@"name"];
2768             [dict setValue:[NSString stringWithFormat:@"%d", b->z] forKey:@"z"];
2769             
2770             [self willChangeValueForKey:@"MA1"];
2771             [MA1 insertObject:dict atIndex:TVCrow1];
2772             [self didChangeValueForKey:@"MA1"];
2773             [AC1 setSelectionIndex:999];
2774             
2775         }else{
2776             bTop = b;
2777             BASE tmp;
2778             tmp = *b;
2779             //LAYER *tmp2 = (LAYER*)malloc(sizeof(LAYER));
2780             b->name = [@"新キャラ" retain];
2781             b->postName = NULL;
2782             b->z = 100;
2783             b->L = NULL;
2784             b->next = calloc(1, sizeof(BASE));
2785             b = b->next;
2786             *b = tmp;
2787             //b->L = NULL;
2788             b = bTop;
2789             [dict setValue:[NSString stringWithFormat:@"%@", b->name] forKey:@"name"];
2790             [dict setValue:[NSString stringWithFormat:@"%d", b->z] forKey:@"z"];
2791             
2792             [self willChangeValueForKey:@"MA1"];
2793             [MA1 insertObject:dict atIndex:TVCrow1];
2794             [self didChangeValueForKey:@"MA1"];
2795             [AC1 setSelectionIndex:999];
2796         }
2797         
2798         b = bTop;
2799         I->B = b;
2800         I = Itop;
2801     }
2802     I = Itop;
2803 }
2804
2805 -(IBAction)insert2:(id)sender{
2806     
2807     I = Itop;
2808     
2809     for(int i = 0;i < Irow;i++){
2810         I = I->next;
2811     }
2812     
2813     b = I->B;
2814     
2815     if(!b || TVCrow1 == -1) return;
2816     
2817     BASE *bTop = b;
2818     for(int i = 0;i < TVCrow1;i++){
2819         b = b->next;
2820     }
2821     LAYER *blTop = b->L;
2822     /*
2823      for(int i = 0;i < TVCrow2;i++){
2824      b->L = b->L->next;
2825      }
2826      */
2827     LAYER *l = b->L;
2828     blTop = l;
2829     
2830     if(TVCrow1 == -1) return;
2831     
2832     if(1){
2833         NSMutableDictionary *dict = [NSMutableDictionary new];
2834         if([MA2 count] == 0){
2835             
2836             blTop = calloc(1, sizeof(LAYER));
2837             l = blTop;
2838             l->name = [@"新規レイヤー" retain];
2839             l->postName = NULL;
2840             l->z = 150;
2841             
2842             [dict setValue:[NSString stringWithFormat:@"%@", l->name] forKey:@"name"];
2843             [dict setValue:[NSString stringWithFormat:@"%d", l->z] forKey:@"z"];
2844             
2845             [self willChangeValueForKey:@"MA2"];
2846             [MA2 insertObject:dict atIndex:[MA2 count]];
2847             [self didChangeValueForKey:@"MA2"];
2848             [AC2 setSelectionIndex:999];
2849         }else if(TVCrow2 == -1){
2850             while (l->next) {
2851                 l = l->next;
2852             }
2853             l->next = calloc(1, sizeof(LAYER));
2854             l = l->next;
2855             l->name = [@"新規レイヤー" retain];
2856             l->postName = NULL;
2857             l->z = 150;
2858             
2859             [dict setValue:[NSString stringWithFormat:@"%@", l->name] forKey:@"name"];
2860             [dict setValue:[NSString stringWithFormat:@"%d", l->z] forKey:@"z"];
2861             
2862             [self willChangeValueForKey:@"MA2"];
2863             [MA2 insertObject:dict atIndex:[MA2 count]];
2864             [self didChangeValueForKey:@"MA2"];
2865             [AC2 setSelectionIndex:999];
2866             
2867         }else if(TVCrow2 > 0){
2868             for (int i = 0; i < TVCrow2-1; i++) {
2869                 
2870                 l = l->next;
2871             }
2872             LAYER *tmp = (LAYER*)malloc(sizeof(LAYER));
2873             tmp = l->next;
2874             l->next = (LAYER*)malloc(sizeof(LAYER));
2875             l->next->next = tmp;
2876             l = l->next;
2877             l->name = [@"新規レイヤー" retain];
2878             l->postName = NULL;
2879             l->z = 150;
2880             [dict setValue:[NSString stringWithFormat:@"%@", l->name] forKey:@"name"];
2881             [dict setValue:[NSString stringWithFormat:@"%d", l->z] forKey:@"z"];
2882             
2883             [self willChangeValueForKey:@"MA2"];
2884             [MA2 insertObject:dict atIndex:TVCrow2];
2885             [self didChangeValueForKey:@"MA2"];
2886             [AC2 setSelectionIndex:999];
2887             
2888         }else{
2889             blTop = l;
2890             LAYER tmp = *l;
2891             l->next = calloc(1, sizeof(LAYER));
2892             l->name = [@"新規レイヤー" retain];
2893             l->postName = NULL;
2894             l->z = 150;
2895             l = l->next;
2896             *l = tmp;
2897             l = blTop;
2898             [dict setValue:[NSString stringWithFormat:@"%@", l->name] forKey:@"name"];
2899             [dict setValue:[NSString stringWithFormat:@"%d", l->z] forKey:@"z"];
2900             
2901             [self willChangeValueForKey:@"MA2"];
2902             [MA2 insertObject:dict atIndex:TVCrow2];
2903             [self didChangeValueForKey:@"MA2"];
2904             [AC2 setSelectionIndex:999];
2905         }
2906         
2907         
2908         l = blTop;
2909         b->L = l;
2910         b = bTop;
2911         I->B = b;
2912         I = Itop;
2913     }
2914
2915     
2916     
2917     
2918
2919 }
2920
2921 -(IBAction)remove1:(id)sender{
2922     int cnt = 0;
2923     int coun = 0;
2924     
2925     I = Itop;
2926     
2927     for(int i = 0;i < Irow;i++){
2928         I = I->next;
2929     }
2930     
2931     b = I->B;
2932     
2933     BASE *bbTop = b;
2934     while(b){
2935         if(coun >= TVCrow1)
2936             break;
2937         cnt++;
2938         
2939         
2940         LAYER *llTop = b->L;
2941         while(b->L){cnt++;
2942             
2943             b->L = b->L->next;
2944         }b->L = llTop;
2945         
2946         b = b->next;
2947         coun++;
2948     }b = bbTop;
2949     
2950     if(TVCrow1 == -1){
2951         for (int i = 0; i < [MA1 count]-1; i++){
2952             cnt++;
2953             if(i >= [MA1 count]-1) break;
2954             LAYER *llTop = b->L;
2955             while(b->L){
2956                 cnt++;
2957                 b->L = b->L->next;
2958             }b->L = llTop;
2959             b = b->next;
2960         }b = bbTop;
2961     }
2962     
2963     BASE *bTop = b;
2964     
2965     
2966     if(1){
2967         if([MA1 count] == 0){
2968             return;
2969         }else if(TVCrow1 == -1){
2970             for(int i = 0;i < [MA1 count]-1;i++){
2971                 if(i == [MA1 count]- 2){
2972                     cnt++;
2973                     [deletedName addObject:[b->next->name stringByAppendingFormat:@"%d", cnt]];
2974                 }
2975                 if(i == [MA1 count] - 2)
2976                     break;
2977                 b = b->next;
2978             }
2979             if([MA1 count] > 1) {
2980                 b->next = NULL;
2981             }
2982             else {
2983                 cnt++;
2984                 [deletedName addObject:[b->name stringByAppendingFormat:@"%d", cnt]];
2985                 bTop = NULL;
2986                 
2987             }
2988             [self willChangeValueForKey:@"MA1"];
2989             [MA1 removeObjectAtIndex:[MA1 count]-1];
2990             [self didChangeValueForKey:@"MA1"];
2991             [AC1 setSelectionIndex:999];
2992             
2993             [self willChangeValueForKey:@"MA2"];
2994             [MA2 removeAllObjects];
2995             [self didChangeValueForKey:@"MA2"];
2996             [AC2 setSelectionIndex:999];
2997             
2998         }else if(TVCrow1 > 0){
2999             for (int i = 0; i < TVCrow1-1; i++) {
3000                 
3001                 b = b->next;
3002             }
3003             cnt ++;
3004             [deletedName addObject:[b->next->name stringByAppendingFormat:@"%d", cnt]];
3005             b->next = b->next->next;
3006             
3007             [self willChangeValueForKey:@"MA1"];
3008             [MA1 removeObjectAtIndex:TVCrow1];
3009             [self didChangeValueForKey:@"MA1"];
3010             [AC1 setSelectionIndex:999];
3011             
3012             [self willChangeValueForKey:@"MA2"];
3013             [MA2 removeAllObjects];
3014             [self didChangeValueForKey:@"MA2"];
3015             [AC2 setSelectionIndex:999];
3016             
3017         }else{
3018             cnt ++;
3019             [deletedName addObject:[bTop->name stringByAppendingFormat:@"%d", cnt]];
3020             bTop = b->next;
3021             b = bTop;
3022             [self willChangeValueForKey:@"MA1"];
3023             [MA1 removeObjectAtIndex:TVCrow1];
3024             [self didChangeValueForKey:@"MA1"];
3025             [AC1 setSelectionIndex:999];
3026             
3027             [self willChangeValueForKey:@"MA2"];
3028             [MA2 removeAllObjects];
3029             [self didChangeValueForKey:@"MA2"];
3030             [AC2 setSelectionIndex:999];
3031         }
3032         
3033         
3034         b = bTop;
3035         I->B = b;
3036         I = Itop;
3037     }
3038     
3039     
3040     
3041     
3042     
3043     
3044     
3045     
3046     
3047
3048 }
3049
3050 -(IBAction)remove2:(id)sender{
3051     int cnt = 0;
3052     int coun = 0;
3053     
3054     I = Itop;
3055     
3056     for(int i = 0;i < Irow;i++){
3057         I = I->next;
3058     }
3059     
3060     b = I->B;
3061     
3062     BASE *bbTop = b;
3063     while(b){
3064         if(coun >= TVCrow1)
3065             break;
3066         cnt++;
3067         
3068         LAYER *llTop = b->L;
3069         while(b->L){cnt++;
3070             
3071             b->L = b->L->next;
3072         }b->L = llTop;
3073         
3074         b = b->next;
3075         coun++;
3076     }b = bbTop;
3077     
3078     
3079     if(TVCrow1 == -1){
3080         while(b){
3081             cnt++;
3082             LAYER *llTop = b->L;
3083             while(b->L){cnt++;
3084                 
3085                 b->L = b->L->next;
3086             }b->L = llTop;
3087             b = b->next;
3088         }b = bbTop;
3089     }
3090     
3091     BASE *bTop = b;
3092     for(int i = 0;i < TVCrow1;i++){
3093         b = b->next;
3094     }
3095     
3096     LAYER *blTop = b->L;
3097     /*
3098      for(int i = 0;i < TVCrow2;i++){
3099      b->L = b->L->next;
3100      }
3101      */
3102     LAYER *l = b->L;
3103     blTop = l;
3104     
3105     if(1){
3106         if([MA2 count] == 0){
3107             return;
3108         }else if(TVCrow2 == -1){
3109             for(int i = 0;i < [MA2 count]-1;i++){
3110                 cnt++;
3111                 if(i == [MA2 count]-2){
3112                     cnt ++;
3113                     cnt ++;
3114                     [deletedName addObject:[l->next->name stringByAppendingFormat:@"%d", cnt]];
3115                 }
3116                 if(i == [MA2 count] - 2)
3117                     break;
3118                 l = l->next;
3119             }
3120             if([MA2 count] > 1) {
3121                 l->next = NULL;
3122             }else{
3123                 cnt++;
3124                 cnt++;
3125                 [deletedName addObject:[l->name stringByAppendingFormat:@"%d", cnt]];
3126                 blTop = NULL;
3127             }
3128             [self willChangeValueForKey:@"MA2"];
3129             [MA2 removeObjectAtIndex:[MA2 count]-1];
3130             [self didChangeValueForKey:@"MA2"];
3131             [AC2 setSelectionIndex:999];
3132             
3133         }else if(TVCrow2 > 0){
3134             for (int i = 0; i < TVCrow2-1; i++) {
3135                 
3136                 l = l->next;
3137                 cnt++;
3138             }
3139             cnt += 3;
3140             [deletedName addObject:[l->next->name stringByAppendingFormat:@"%d", cnt]];
3141             l->next = l->next->next;
3142             
3143             [self willChangeValueForKey:@"MA2"];
3144             [MA2 removeObjectAtIndex:TVCrow2];
3145             [self didChangeValueForKey:@"MA2"];
3146             [AC2 setSelectionIndex:999];
3147             
3148         }else{
3149             cnt += 2;
3150             [deletedName addObject:[blTop->name stringByAppendingFormat:@"%d", cnt]];
3151             blTop = l->next;
3152             l = blTop;
3153             [self willChangeValueForKey:@"MA2"];
3154             [MA2 removeObjectAtIndex:TVCrow2];
3155             [self didChangeValueForKey:@"MA2"];
3156             [AC2 setSelectionIndex:999];
3157         }
3158         
3159         l = blTop;
3160         b->L = l;
3161         
3162     }
3163     
3164     I->B = b;
3165     b = bTop;
3166     I = Itop;
3167 }
3168
3169 -(IBAction)saveBtn:(id)sender{
3170     [self saveData];
3171 }
3172
3173 -(void)saveData{
3174     
3175     NSString *directoryPath;
3176     
3177     directoryPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
3178     [[NSFileManager defaultManager] changeCurrentDirectoryPath:directoryPath];
3179     
3180     
3181     NSString *fdata = @"data/Scenario/";
3182     NSString *direct = @"data/Scenario/";
3183     
3184     /*
3185     [[NSFileManager defaultManager] createDirectoryAtPath:direct
3186                               withIntermediateDirectories:YES
3187                                                attributes:nil
3188                                                     error:nil];
3189     */
3190     NSString *fileData = @"";
3191     for(int i = 0;i < [deletedName count];i++){
3192         
3193         NSString *dlPath = @"data/Scenario/img/";
3194         dlPath = [dlPath  stringByAppendingFormat:@"%@", [deletedName objectAtIndex:i]];
3195         [[NSFileManager defaultManager] removeItemAtPath:dlPath error:nil];
3196         
3197     }
3198     deletedName = [NSMutableArray new];
3199     
3200     
3201     Standcount = 0;
3202     
3203     I = Itop;
3204     for(int i = 0;i < Irow;i++){
3205         b = I->B;
3206         BASE *btop = I->B;
3207         while (b) {
3208             LAYER *ltop = b->L;
3209             while (b->L) {
3210                 Standcount++;
3211                 b->L = b->L->next;
3212             }b->L = ltop;
3213             b = b->next;
3214         }b = btop;
3215         
3216         I = I->next;
3217     }
3218     
3219     if(!I) return;
3220     
3221     
3222     if(I){
3223         
3224         if(!I->fName) return;
3225         if([I->fName isEqualToString:@""]) return;
3226         
3227         fdata = [fdata stringByAppendingFormat:@"%@", I->fName];
3228          b = I->B;
3229     
3230         
3231         if(!b) return;
3232         BASE *bTop = b;
3233         if(b)
3234             while(b){Standcount++;
3235                 fileData = [[fileData stringByAppendingString:[NSString stringWithFormat:@"%@,%d, %d, %d"
3236                                                                , b->name, b->z, b->x, b->y]]
3237                             stringByAppendingString:@"\n"];
3238                 
3239                 NSData *f2Data = [b->img TIFFRepresentation];
3240                 NSBitmapImageRep *brep = [NSBitmapImageRep imageRepWithData:f2Data];
3241                 f2Data = [brep representationUsingType:NSPNGFileType properties:nil];
3242                 
3243                 NSString *dlPath = @"data/Scenario/img/";
3244                 dlPath = [dlPath  stringByAppendingFormat:@"%@#%d", b->postName, Standcount];
3245                 
3246                 [[NSFileManager defaultManager] removeItemAtPath:dlPath error:nil];
3247                 
3248                 NSString *bcPath = @"data/Scenario/img/";
3249                 bcPath = [bcPath stringByAppendingFormat:@"%@#%d", b->name, Standcount];
3250                 
3251                 [f2Data writeToFile:bcPath atomically:YES];
3252                 
3253                 b->postName = b->name;
3254                 fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"####\n"]];
3255                 LAYER *lTop = NULL;
3256                 if(b) lTop = b->L;
3257                 if(b) if(b->L)
3258                     while(b->L){Standcount++;
3259                         fileData = [[fileData stringByAppendingString:[NSString stringWithFormat:@"%@,%d,%d, %d, %d"
3260                                                                        , b->L->name, b->L->z, b->L->visible, b->L->x, b->L->y]] stringByAppendingString:@"\n"];
3261                         
3262                         NSData *f2Data = [b->L->img TIFFRepresentation];
3263                         NSBitmapImageRep *brep = [NSBitmapImageRep imageRepWithData:f2Data];
3264                         f2Data = [brep representationUsingType:NSPNGFileType properties:nil];
3265                         
3266                         NSString *dlPath = @"data/Scenario/img/";
3267                         dlPath = [dlPath  stringByAppendingFormat:@"%@#%d", b->L->postName, Standcount];
3268                         
3269                         [[NSFileManager defaultManager] removeItemAtPath:dlPath error:nil];
3270                         
3271                         NSString *bcPath = @"data/Scenario/img/";
3272                         bcPath = [bcPath stringByAppendingFormat:@"%@#%d", b->L->name, Standcount];
3273                         
3274                         [f2Data writeToFile:bcPath atomically:YES];
3275                         
3276                         
3277                         b->L->postName = b->L->name;
3278                         b->L = b->L->next;
3279                     }
3280                 b->L = lTop;
3281                 fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"$$$$\n"]];
3282                 
3283                 b = b->next;
3284             }
3285         b = bTop;
3286         I->B = b;
3287
3288     }
3289     I = Itop;
3290     
3291     [fileData writeToFile:fdata atomically:YES encoding:NSUTF8StringEncoding error:nil];
3292     
3293     Standcount = 0;
3294     I = Itop;
3295     while(I){
3296     if(!I->fName) return;
3297     if([I->fName isEqualToString:@""]) return;
3298     
3299     fdata = [@"data/Scenario/" retain];
3300         
3301     fileData = [@"" retain];
3302         
3303     fdata = [fdata stringByAppendingFormat:@"%@", I->fName];
3304
3305     b = I->B;
3306     if(!b) return;
3307     BASE *bTop = b;
3308     if(b)
3309         while(b){Standcount++;
3310             fileData = [[fileData stringByAppendingString:[NSString stringWithFormat:@"%@,%d, %d, %d"
3311                                                            , b->name, b->z, b->x, b->y]]
3312                         stringByAppendingString:@"\n"];
3313             
3314             NSData *f2Data = [b->img TIFFRepresentation];
3315             NSBitmapImageRep *brep = [NSBitmapImageRep imageRepWithData:f2Data];
3316             f2Data = [brep representationUsingType:NSPNGFileType properties:nil];
3317             
3318             NSString *dlPath = @"data/Scenario/img/";
3319             dlPath = [dlPath  stringByAppendingFormat:@"%@#%d", b->postName, Standcount];
3320             
3321             [[NSFileManager defaultManager] removeItemAtPath:dlPath error:nil];
3322             
3323             NSString *bcPath = @"data/Scenario/img/";
3324             bcPath = [bcPath stringByAppendingFormat:@"%@#%d", b->name, Standcount];
3325             
3326             [f2Data writeToFile:bcPath atomically:YES];
3327             
3328             b->postName = b->name;
3329             fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"####\n"]];
3330             LAYER *lTop = NULL;
3331             if(b) lTop = b->L;
3332             if(b) if(b->L)
3333                 while(b->L){Standcount++;
3334                     fileData = [[fileData stringByAppendingString:[NSString stringWithFormat:@"%@,%d,%d, %d, %d"
3335                                                                    , b->L->name, b->L->z, b->L->visible, b->L->x, b->L->y]] stringByAppendingString:@"\n"];
3336                     
3337                     NSData *f2Data = [b->L->img TIFFRepresentation];
3338                     NSBitmapImageRep *brep = [NSBitmapImageRep imageRepWithData:f2Data];
3339                     f2Data = [brep representationUsingType:NSPNGFileType properties:nil];
3340                     
3341                     NSString *dlPath = @"data/Scenario/img/";
3342                     dlPath = [dlPath  stringByAppendingFormat:@"%@#%d", b->L->postName, Standcount];
3343                     
3344                     [[NSFileManager defaultManager] removeItemAtPath:dlPath error:nil];
3345                     
3346                     NSString *bcPath = @"data/Scenario/img/";
3347                     bcPath = [bcPath stringByAppendingFormat:@"%@#%d", b->L->name, Standcount];
3348                     
3349                     [f2Data writeToFile:bcPath atomically:YES];
3350                     
3351                     
3352                     b->L->postName = b->L->name;
3353                     b->L = b->L->next;
3354                 }
3355             b->L = lTop;
3356             fileData = [fileData stringByAppendingString:[NSString stringWithFormat:@"$$$$\n"]];
3357             
3358             b = b->next;
3359         }
3360         b = bTop;
3361         I->B = b;
3362         
3363         [fileData writeToFile:fdata atomically:YES encoding:NSUTF8StringEncoding error:nil];
3364
3365         
3366         I = I->next;
3367     }
3368     I = Itop;
3369     
3370     Standcount = 0;
3371 }
3372
3373 -(void)saveStandData{
3374     
3375     
3376     
3377     I = Itop;
3378     for (int i = 0;i < Inumb && I && [standListMA count] > 0;i++) {
3379         I->name = [standListMA[i] valueForKey:@"name"];
3380         I->fName = [standListMA[i] valueForKey:@"file"];
3381         I = I->next;
3382     }I = Itop;
3383     
3384     
3385     
3386     
3387     
3388     
3389     
3390     
3391     
3392     NSString *directoryPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
3393     [[NSFileManager defaultManager] changeCurrentDirectoryPath:directoryPath];
3394
3395     NSString *pathI = @"data/Scenario/preset2.txt";
3396     NSString *string = @"";
3397     I = Itop;
3398     for (int i = 0;i < Inumb;i++) {
3399         string = [string stringByAppendingFormat:@"%@,%@", I->name, I->fName];
3400         string = [string stringByAppendingFormat:@"\n"];
3401         I = I->next;
3402     }I = Itop;
3403     
3404     [string writeToFile:pathI atomically:YES encoding:NSUTF8StringEncoding error:nil];
3405
3406 }
3407
3408 -(void)loadStandData{
3409     
3410     NSString *directoryPath;
3411     
3412     directoryPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
3413     [[NSFileManager defaultManager] changeCurrentDirectoryPath:directoryPath];
3414     
3415     NSArray *fileDataArrayFirst;
3416     NSString *fileData = @"";
3417     
3418     NSString *pathI = @"data/Scenario/preset2.txt";
3419     NSString *pathID = @"data/Scenario/";
3420     
3421     I = NULL;
3422     Itop = NULL;
3423     
3424     if(![[NSFileManager defaultManager] fileExistsAtPath:pathI]){
3425         [[NSFileManager defaultManager] createFileAtPath:pathI contents:nil attributes:nil];
3426     }
3427     
3428     
3429     NSArray *IList = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:pathID error:nil];
3430     Inumb = 0;
3431     /*
3432     for(NSString *path in IList){
3433         
3434         if([path isEqualToString:@".DS_Store"]){
3435             continue;
3436         }
3437         
3438         if([path isEqualToString:@"preset.txt"]){
3439             continue;
3440         }
3441         
3442         if([path isEqualToString:@"preset2.txt"]){
3443             continue;
3444         }
3445         
3446         if([path isEqualToString:@"img"]){
3447             continue;
3448         }
3449         
3450         static int eTopFlag = 0;
3451         
3452         if(eTopFlag == 0){
3453             I = calloc(1, sizeof(STAND));
3454             Itop = I;
3455             eTopFlag = 1;
3456         }else{
3457             if(eTopFlag == 1){
3458                 eTopFlag = 2;
3459                 Itop = I;
3460             }
3461             I->next = calloc(1, sizeof(STAND));
3462             I = I->next;
3463         }
3464         Inumb++;
3465         
3466     }
3467     I = Itop;
3468     */
3469     
3470     
3471     
3472     fileData = [NSString stringWithContentsOfFile:pathI encoding:NSUTF8StringEncoding error:nil];
3473     fileDataArrayFirst = [fileData componentsSeparatedByString:@"\n"];
3474
3475     I = NULL;
3476     for(int i = 0;i < [fileDataArrayFirst count] - 1;i++){
3477         
3478         if(i == 0){
3479             I = calloc(1, sizeof(STAND));
3480             Itop = I;
3481         }else if(i > 0){
3482             I->next = calloc(1, sizeof(STAND));
3483             if(i == 1)
3484                 Itop = I;
3485             I = I->next;
3486         }
3487         Inumb++;
3488     }I = Itop;
3489     if([fileDataArrayFirst[0] isEqualToString:@""])
3490         return;
3491     I = Itop;
3492     int lolfix = 0;
3493     for(int i = 0;i < Inumb && I;i++){
3494         NSArray *firstArray = [[fileDataArrayFirst[i] componentsSeparatedByString:@","] retain];
3495         
3496         if([firstArray count] > 1){
3497             I->name = [firstArray[0] retain];
3498             I->fName = [firstArray[1] retain];
3499         }
3500         
3501         I = I->next;
3502     }
3503     I = Itop;
3504
3505     I = Itop;
3506     
3507     [self willChangeValueForKey:@"standListMA"];
3508     [standListMA removeAllObjects];
3509     [self didChangeValueForKey:@"standListMA"];
3510     while(I){
3511     if(1){
3512         NSMutableDictionary *dict = [NSMutableDictionary new];
3513     
3514         [dict setValue:[NSString stringWithFormat:@"%@", I->name] forKey:@"name"];
3515         [dict setValue:[NSString stringWithFormat:@"%@", I->fName] forKey:@"file"];
3516         
3517         [self willChangeValueForKey:@"standListMA"];
3518         [standListMA addObject:dict];
3519         [self didChangeValueForKey:@"standListMA"];
3520     }
3521         I = I->next;
3522     }
3523     I = Itop;
3524     
3525     [standListAC setSelectionIndex:9999];
3526 }
3527
3528 -(void)loadData{
3529     
3530     
3531     NSString *directoryPath;
3532     
3533     directoryPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
3534     [[NSFileManager defaultManager] changeCurrentDirectoryPath:directoryPath];
3535     
3536     NSArray *fileDataArrayFirst;
3537     NSString *fileData = @"";
3538     
3539     NSString *pathI = @"data/Scenario/preset2.txt";
3540     
3541     NSArray *fileDataArray;
3542     
3543     if(!I) return;
3544     
3545     
3546     Standcount = 0;
3547     I = Itop;
3548     while(I){
3549         b = I->B;
3550         BASE *bTop = b;
3551         LAYER *lTop = NULL;
3552         NSString *pathID = @"data/Scenario/";
3553         
3554         pathID = [pathID stringByAppendingFormat:@"%@", I->fName];
3555         
3556         if(![[NSFileManager defaultManager] fileExistsAtPath:pathID]){
3557             I = I->next;
3558             continue;
3559         }
3560         
3561         fileData = [NSString stringWithContentsOfFile:pathID encoding:NSUTF8StringEncoding error:nil];
3562         fileDataArray = [fileData componentsSeparatedByString:@"\n"];
3563         
3564         
3565
3566     for(int i = 0;i < [fileDataArray count]-1;i++){
3567         NSString *str = [fileDataArray objectAtIndex:i];
3568         NSRange rangeSearch;
3569         NSRange rangeSearch2;
3570         NSArray *rangeArray;
3571         NSArray *rangeArray2;
3572         static bool firstFlag = true;
3573         static bool nextIsBASEflag = true;
3574         static bool nextIsLAYERflag = false;
3575         rangeSearch = [str rangeOfString:@"####"];
3576         rangeSearch2 = [str rangeOfString:@"$$$$"];
3577         rangeArray = [str componentsSeparatedByString:@","];
3578         
3579         if (rangeSearch.location != NSNotFound){
3580             
3581             nextIsLAYERflag = true;
3582             nextIsBASEflag = false;
3583             lTop = NULL;
3584         }else if(rangeSearch2.location != NSNotFound){
3585             nextIsLAYERflag = false;
3586             nextIsBASEflag = true;
3587             b->L = lTop;
3588         }else if(nextIsBASEflag && !nextIsLAYERflag){Standcount++;
3589             
3590             if(firstFlag){
3591                 bTop = calloc(1, sizeof(BASE));
3592                 b = bTop;
3593                 b->name = [[rangeArray objectAtIndex:0] retain];
3594                 b->postName = b->name;
3595                 b->z = [[rangeArray objectAtIndex:1] intValue];
3596                 b->x = [[rangeArray objectAtIndex:2] intValue];
3597                 b->y = [[rangeArray objectAtIndex:3] intValue];
3598                 b->next = NULL;
3599                 b->L = NULL;
3600                 NSString *iPath = @"data/Scenario/img/";
3601                 iPath = [iPath stringByAppendingFormat:@"%@#%d", b->name, Standcount];
3602                 NSData *iData = [NSData dataWithContentsOfFile:iPath];
3603                 if(iData){
3604                     NSImage *iImg = [[NSImage alloc] initWithContentsOfFile:iPath];
3605                     b->img = iImg;
3606                 }
3607                 
3608                 firstFlag = false;
3609             }else{
3610                 b->next = calloc(1, sizeof(BASE));
3611                 b = b->next;
3612                 b->name = [[rangeArray objectAtIndex:0] retain];
3613                 b->postName = b->name;
3614                 b->z = [[rangeArray objectAtIndex:1] intValue];
3615                 b->x = [[rangeArray objectAtIndex:2] intValue];
3616                 b->y = [[rangeArray objectAtIndex:3] intValue];
3617                 b->next = NULL;
3618                 b->L = NULL;
3619                 NSString *iPath = @"data/Scenario/img/";
3620                 iPath = [iPath stringByAppendingFormat:@"%@#%d", b->name, Standcount];
3621                 NSData *iData = [NSData dataWithContentsOfFile:iPath];
3622                 if(iData){
3623                     NSImage *iImg = [[NSImage alloc] initWithContentsOfFile:iPath];
3624                     b->img = iImg;
3625                 }
3626             }
3627             
3628         }else if(!nextIsBASEflag && nextIsLAYERflag){Standcount++;
3629             
3630             if(!b->L){
3631                 b->L = calloc(1, sizeof(LAYER));
3632                 lTop = b->L;
3633                 b->L->name = [[rangeArray objectAtIndex:0] retain];
3634                 b->L->postName = b->L->name;
3635                 b->L->z = [[rangeArray objectAtIndex:1] intValue];
3636                 b->L->visible = [[rangeArray objectAtIndex:2] intValue];
3637                 b->L->x = [[rangeArray objectAtIndex:3] intValue];
3638                 b->L->y = [[rangeArray objectAtIndex:4] intValue];
3639                 b->L->next = NULL;
3640                 NSString *iPath = @"data/Scenario/img/";
3641                 iPath = [iPath stringByAppendingFormat:@"%@#%d", b->L->name, Standcount];
3642                 NSData *iData = [NSData dataWithContentsOfFile:iPath];
3643                 if(iData){
3644                     NSImage *iImg = [[NSImage alloc] initWithContentsOfFile:iPath];
3645                     b->L->img = iImg;
3646                 }
3647                 
3648             }else{
3649                 b->L->next = calloc(1, sizeof(LAYER));
3650                 b->L = b->L->next;
3651                 b->L->name = [[rangeArray objectAtIndex:0] retain];
3652                 b->L->postName = b->L->name;
3653                 b->L->z = [[rangeArray objectAtIndex:1] intValue];
3654                 b->L->visible = [[rangeArray objectAtIndex:2] intValue];
3655                 b->L->x = [[rangeArray objectAtIndex:3] intValue];
3656                 b->L->y = [[rangeArray objectAtIndex:4] intValue];
3657                 b->L->next = NULL;
3658                 NSString *iPath = @"data/Scenario/img/";
3659                 iPath = [iPath stringByAppendingFormat:@"%@#%d", b->L->name, Standcount];
3660                 NSData *iData = [NSData dataWithContentsOfFile:iPath];
3661                 if(iData){
3662                     NSImage *iImg = [[NSImage alloc] initWithContentsOfFile:iPath];
3663                     b->L->img = iImg;
3664                 }
3665             }
3666             
3667         }else{
3668             
3669         }
3670         
3671         if(i+1 == [fileDataArray count]-1){
3672             firstFlag = true;
3673             nextIsBASEflag = true;
3674             nextIsLAYERflag = false;
3675         }
3676     }
3677     b = bTop;
3678         I->B = b;
3679         I = I->next;
3680     }  I = Itop;
3681     Standcount = 0;
3682     
3683 }
3684
3685 -(void)initMA1MA2{
3686
3687     I = Itop;
3688     
3689     for(int i = 0;i < Irow;i++){
3690         I = I->next;
3691     }
3692     
3693     if(!I) return;
3694     
3695     b = I->B;
3696     
3697     [self willChangeValueForKey:@"MA1"];
3698     [MA1 removeAllObjects];
3699     [self didChangeValueForKey:@"MA1"];
3700     [self willChangeValueForKey:@"MA2"];
3701     [MA2 removeAllObjects];
3702     [self didChangeValueForKey:@"MA2"];
3703     
3704     
3705     bool first = false;
3706     BASE *bTop = b;
3707     LAYER *lTop = NULL;
3708     while(b){
3709         NSMutableDictionary *dict2 = [NSMutableDictionary new];
3710         [dict2 setValue:[NSString stringWithFormat:@"%@", b->name]  forKeyPath:@"name"];
3711         [dict2 setValue:[NSString stringWithFormat:@"%d", b->z] forKeyPath:@"z"];
3712         [dict2 setValue:b->img forKey:@"img"];
3713         
3714         [self willChangeValueForKey:@"MA1"];
3715         [MA1 addObject:dict2];
3716         [self didChangeValueForKey:@"MA1"];
3717         
3718         lTop = b->L;
3719         while(b->L && !first){
3720             NSMutableDictionary *dict2 = [NSMutableDictionary new];
3721             [dict2 setValue:[NSString stringWithFormat:@"%@", b->L->name]  forKeyPath:@"name"];
3722             [dict2 setValue:[NSString stringWithFormat:@"%d", b->L->z] forKeyPath:@"z"];
3723             [dict2 setValue:[NSString stringWithFormat:@"%d", b->L->visible] forKeyPath:@"v"];
3724             [dict2 setValue:b->L->img forKey:@"img"];
3725             
3726             [self willChangeValueForKey:@"MA2"];
3727             [MA2 addObject:dict2];
3728             [self didChangeValueForKey:@"MA2"];
3729             
3730             b->L = b->L->next;
3731         }
3732         b->L = lTop;
3733         first = true;
3734         
3735         b = b->next;
3736     }
3737     b = bTop;
3738     
3739 I = Itop;
3740
3741
3742 }
3743
3744 -(void)initSEstand{
3745
3746     
3747     [self willChangeValueForKey:@"SEMA1"];
3748     [SEMA1 removeAllObjects];
3749     [self didChangeValueForKey:@"SEMA1"];
3750     
3751     I = Itop;
3752     for(int i = 0;i < Inumb;i++){
3753         NSMutableDictionary *dict = [NSMutableDictionary new];
3754         [dict setValue:[NSString stringWithFormat:@"%@", I->name]  forKeyPath:@"name"];
3755         
3756         [self willChangeValueForKey:@"SEMA1"];
3757         [SEMA1 addObject:dict];
3758         [self didChangeValueForKey:@"SEMA1"];
3759     
3760         I = I->next;
3761     }
3762     
3763     
3764     
3765     
3766     I = Itop;
3767     
3768     if(SEMA1row < 0){
3769         [SEAC1 setSelectionIndex:9999];
3770         [SEAC2 setSelectionIndex:9999];
3771         [SEAC3 setSelectionIndex:9999];
3772         return;
3773     }
3774     
3775     for(int i = 0;i < SEMA1row;i++){
3776         I = I->next;
3777     }
3778     
3779     if(!I) return;
3780     
3781     b = I->B;
3782     
3783     [self willChangeValueForKey:@"SEMA2"];
3784     [SEMA2 removeAllObjects];
3785     [self didChangeValueForKey:@"SEMA2"];
3786     [self willChangeValueForKey:@"SEMA3"];
3787     [SEMA3 removeAllObjects];
3788     [self didChangeValueForKey:@"SEMA3"];
3789     
3790     
3791     bool first = false;
3792     BASE *bTop = b;
3793     LAYER *lTop = NULL;
3794     while(b){
3795         NSMutableDictionary *dict2 = [NSMutableDictionary new];
3796         [dict2 setValue:[NSString stringWithFormat:@"%@", b->name]  forKeyPath:@"name"];
3797         
3798         [self willChangeValueForKey:@"SEMA2"];
3799         [SEMA2 addObject:dict2];
3800         [self didChangeValueForKey:@"SEMA2"];
3801         
3802         lTop = b->L;
3803         int i0 = 0;
3804         while(b->L && !first){
3805             NSMutableDictionary *dict2 = [NSMutableDictionary new];
3806             [dict2 setValue:[NSString stringWithFormat:@"%@", b->L->name]  forKeyPath:@"name"];
3807             if(TX[st].S->i->SEMA3flag) {
3808                 [dict2 setValue:[NSString stringWithFormat:@"%d", *(TX[st].S->i->SEMA3flag + i0) - 1 ] forKeyPath:@"v"];
3809                 b->L->visibleInstant = *(TX[st].S->i->SEMA3flag + i0) - 1;
3810             }else [dict2 setValue:[NSString stringWithFormat:@"%d", b->L->visibleInstant] forKeyPath:@"v"];
3811             
3812             [self willChangeValueForKey:@"SEMA3"];
3813             [SEMA3 addObject:dict2];
3814             [self didChangeValueForKey:@"SEMA3"];
3815             
3816             b->L = b->L->next;
3817             i0++;
3818         }
3819         b->L = lTop;
3820         first = true;
3821         
3822         b = b->next;
3823     }
3824     b = bTop;
3825     
3826     I = Itop;
3827
3828
3829
3830
3831
3832 }
3833
3834
3835
3836
3837
3838
3839 -(IBAction)SEstand:(id)sender{
3840
3841     TX[st].S = STRtop[st];
3842     for(int i = 0;i < sl;i++){
3843         TX[st].S = TX[st].S->next;
3844     }
3845     
3846     SItop = TX[st].S->i;
3847     for(int i = 0;i < SEMArow;i++){
3848         TX[st].S->i = TX[st].S->i->next;
3849     }
3850     
3851     TX[st].S->i->imgStand = [SEIV image];
3852     TX[st].S->i->name = [[SEMA[SEMArow] valueForKey:@"name"] retain];
3853     
3854     TX[st].S->i = SItop;
3855     
3856     TX[st].S = STRtop[st];
3857     [SEstandViewTestWindow makeKeyAndOrderFront:nil];
3858 }
3859
3860
3861
3862 -(IBAction)SEstandSubmit:(id)sender{
3863     
3864     
3865     TX[st].S = STRtop[st];
3866     for(int i = 0;i < sl;i++){
3867         TX[st].S = TX[st].S->next;
3868     }
3869     SItop = TX[st].S->i;
3870     for(int i = 0;i < SEMArow;i++){
3871         TX[st].S->i = TX[st].S->i->next;
3872     }
3873     [SEstandTFx setStringValue:[NSString stringWithFormat:@"%d", TX[st].S->i->standX]];
3874     [SEstandTFy setStringValue:[NSString stringWithFormat:@"%d", TX[st].S->i->standY]];
3875     
3876     TX[st].S->i = SItop;
3877     TX[st].S = STRtop[st];
3878     [SEstandViewTestWindow close];
3879 }
3880
3881
3882
3883 -(IBAction)SEstandSEclear:(id)sender{
3884
3885     if(![SEstandTF0 stringValue]){
3886         return;
3887     }else if([[SEstandTF0 stringValue] isEqualToString:@""]){
3888         return;
3889     }else if([[SEstandTF0 stringValue] isEqualToString:@"(null)"]){
3890         return;
3891     }
3892     
3893     NSArray *SECHK = [[SEMA[SEMArow] valueForKey:@"name"] componentsSeparatedByString:@"new"];
3894     if([SECHK count] >= 2){
3895         return;
3896     }
3897     
3898     
3899     int theMA = -1;
3900     for(int i = 0;i < [SEMA count];i++){theMA++;
3901         if([[SEMA[i] valueForKey:@"name"] isEqualToString:[SEstandTF0 stringValue]])
3902             break;
3903     }
3904     if(theMA < 0)
3905         return;
3906     
3907     TX[st].S = STRtop[st];
3908     for(int i = 0;i < sl;i++){
3909         TX[st].S = TX[st].S->next;
3910     }
3911     
3912     si = TX[st].S->i;
3913     SItop = si;
3914     for(int i = 0;i < theMA;i++) {
3915         si = si->next;
3916     }
3917     
3918     NSArray *siArray = [si->name componentsSeparatedByString:@"(clear)"];
3919     
3920     if([siArray count] < 2) {
3921         [self willChangeValueForKey:@"SEMA"];
3922         [SEMA[theMA] setValue:[NSString stringWithFormat:@"%@(clear)", si->name] forKey:@"name"];
3923         [self didChangeValueForKey:@"SEMA"];
3924         
3925         si->name = [[si->name stringByAppendingFormat:@"(clear)"] retain];
3926         
3927         
3928     }else if([siArray count] >= 2) {
3929             [self willChangeValueForKey:@"SEMA"];
3930             [SEMA[theMA] setValue:[NSString stringWithFormat:@"%@", si->name] forKey:@"name"];
3931             [self didChangeValueForKey:@"SEMA"];
3932         
3933         si->name = [[si->name substringToIndex:[si->name length] - [@"(clear)" length]] retain];
3934     }
3935     
3936     si = SItop;
3937     TX[st].S->i = si;
3938     TX[st].S = STRtop[st];
3939     
3940     [self linefix];
3941     
3942 }
3943 -(IBAction)SEstandSEadd:(id)sender{
3944     
3945     if(![SEstandTF0 stringValue]){
3946         return;
3947     }else if([[SEstandTF0 stringValue] isEqualToString:@""]){
3948         return;
3949     }else if([[SEstandTF0 stringValue] isEqualToString:@"(null)"]){
3950         return;
3951     }else if([[SEstandTF0 stringValue] isEqualToString:@"(new)"]){
3952         return;
3953     }else if([[SEstandTF0 stringValue] isEqualToString:@"(clear)"]){
3954         return;
3955     }
3956     
3957     if(SEMArow >= 0){
3958     NSArray *SECHK = [[SEMA[SEMArow] valueForKey:@"name"] componentsSeparatedByString:@"claer"];
3959     if([SECHK count] >= 2){
3960         return;
3961     }
3962     }
3963     
3964     
3965     for(int i = 0;i < [SEMA count];i++){
3966         if([[SEMA[i] valueForKey:@"name"] isEqualToString:[SEstandTF0 stringValue]])
3967             return;
3968         if([[SEMA[i] valueForKey:@"name"] isEqualToString:[NSString stringWithFormat:@"%@(new)", [SEstandTF0 stringValue]]])
3969             return;
3970         if([[SEMA[i] valueForKey:@"name"] isEqualToString:[NSString stringWithFormat:@"%@(clear)", [SEstandTF0 stringValue]]])
3971             return;
3972     }
3973     
3974     TX[st].S = STRtop[st];
3975     for(int i = 0;i < sl;i++){
3976         TX[st].S = TX[st].S->next;
3977     }
3978     
3979     si = TX[st].S->i;
3980     SItop = si;
3981     if(1){
3982         NSMutableDictionary *dict = [NSMutableDictionary new];
3983         if([SEMA count] == 0){
3984             
3985             SItop = calloc(1, sizeof(STANDIMAGE));
3986             si = SItop;
3987             si->name = [[NSString stringWithFormat:@"%@", [SEstandTF0 stringValue]] retain];
3988             STANDADDSTRING = si->name;
3989             STANDADD = si;
3990             si->SEMA1row = -1;
3991             si->SEMA2row = -1;
3992             
3993             [dict setValue:[NSString stringWithFormat:@"%@", [SEstandTF0 stringValue]] forKey:@"name"];
3994             [TX[st].SIarray insertObject:[NSString stringWithFormat:@"%@", [SEstandTF0 stringValue]] atIndex:[SEMA count]];
3995             
3996             [self willChangeValueForKey:@"SEMA"];
3997             [SEMA insertObject:dict atIndex:[SEMA count]];
3998             [self didChangeValueForKey:@"SEMA"];
3999             [SEAC setSelectionIndex:999];
4000             SEMArow = -1;
4001         }else if(SEMArow == -1){
4002             while (si->next) {
4003                 si = si->next;
4004             }
4005             si->next = calloc(1, sizeof(BASE));
4006             si = si->next;
4007             si->name = [[NSString stringWithFormat:@"%@", [SEstandTF0 stringValue]] retain];
4008             STANDADDSTRING = si->name;
4009             STANDADD = si;
4010             si->SEMA1row = -1;
4011             si->SEMA2row = -1;
4012             
4013             [dict setValue:[NSString stringWithFormat:@"%@", [SEstandTF0 stringValue]] forKey:@"name"];
4014             [TX[st].SIarray insertObject:[NSString stringWithFormat:@"%@", [SEstandTF0 stringValue]] atIndex:[SEMA count]];
4015             
4016             
4017             [self willChangeValueForKey:@"SEMA"];
4018             [SEMA insertObject:dict atIndex:[SEMA count]];
4019             [self didChangeValueForKey:@"SEMA"];
4020             [SEAC setSelectionIndex:999];
4021             SEMArow = -1;
4022         }else if(SEMArow > 0){
4023             for (int i = 0; i < TVCrow1-1; i++) {
4024                 
4025                 b = b->next;
4026             }
4027             STANDIMAGE *tmp = (STANDIMAGE*)malloc(sizeof(STANDIMAGE));
4028             tmp = si->next;
4029             si->next = (STANDIMAGE*)malloc(sizeof(STANDIMAGE));
4030             si->next->next = tmp;
4031             si = si->next;
4032             si->name = [[NSString stringWithFormat:@"%@", [SEstandTF0 stringValue]] retain];
4033             STANDADDSTRING = si->name;
4034             STANDADD = si;
4035             si->SEMA1row = -1;
4036             si->SEMA2row = -1;
4037
4038             [dict setValue:[NSString stringWithFormat:@"%@", [SEstandTF0 stringValue]] forKey:@"name"];
4039             [TX[st].SIarray insertObject:[NSString stringWithFormat:@"%@", [SEstandTF0 stringValue]] atIndex:SEMArow];
4040             
4041             
4042             [self willChangeValueForKey:@"SEMA"];
4043             [SEMA insertObject:dict atIndex:SEMArow];
4044             [self didChangeValueForKey:@"SEMA"];
4045             [SEAC setSelectionIndex:999];
4046             SEMArow = -1;
4047         }else{
4048             SItop = si;
4049             STANDIMAGE tmp;
4050             tmp = *si;
4051             si->name = [[NSString stringWithFormat:@"%@", [SEstandTF0 stringValue]] retain];
4052             STANDADDSTRING = si->name;
4053             STANDADD = &tmp;
4054             si->SEMA1row = -1;
4055             si->SEMA2row = -1;
4056             si->next = calloc(1, sizeof(STANDIMAGE));
4057             si = si->next;
4058             *si = tmp;
4059             si = SItop;
4060             [dict setValue:[NSString stringWithFormat:@"%@", [SEstandTF0 stringValue]] forKey:@"name"];
4061             [TX[st].SIarray insertObject:[NSString stringWithFormat:@"%@", [SEstandTF0 stringValue]] atIndex:SEMArow];
4062             
4063             [self willChangeValueForKey:@"SEMA"];
4064             [SEMA insertObject:dict atIndex:SEMArow];
4065             [self didChangeValueForKey:@"SEMA"];
4066             [SEAC setSelectionIndex:999];
4067             SEMArow = -1;
4068         }
4069         
4070     }si = SItop;
4071
4072     TX[st].S->i = si;
4073
4074     [self linefix];
4075 }
4076
4077 -(void)linefix2{
4078 //おまんちん
4079     
4080     TX[st].S = STRtop[st];
4081     
4082     
4083     TX[st].S = STRtop[st];
4084     for(int i = 0;i < sl;i++){
4085         TX[st].S = TX[st].S->next;
4086     }
4087     
4088     SItop = TX[st].S->i;
4089     for(int i = 0;i < SEMArow;i++){
4090         TX[st].S->i = TX[st].S->i->next;
4091     }
4092     STANDIMAGE *zOMG = TX[st].S->i;
4093
4094     TX[st].S->i = SItop;
4095     
4096     if(TX[st].S){
4097         
4098         STRING *OMFG = TX[st].S->next;
4099         STRING *OMFGGE = OMFG;
4100         
4101         while(OMFG){
4102         
4103             STANDIMAGE *OMFGcrnt0 = OMFG->i;
4104             int OMFGcnt = 0;
4105             for(int i = 0;OMFG->i;i++){
4106                 OMFGcnt++;
4107                 OMFG->i = OMFG->i->next;
4108             }OMFG->i = OMFGcrnt0;
4109             
4110             
4111             STANDIMAGE *LOL = OMFG->i;
4112             int MatchCnt = 0;
4113             while(OMFG->i){
4114                 NSArray *hiThere = [zOMG->name componentsSeparatedByString:@"(new)"];
4115                 NSArray *helloMan = [OMFG->i->name componentsSeparatedByString:@"(clear)"];
4116                 STANDIMAGE *OMFGcrnt = OMFG->i;
4117                 if([hiThere[0] isEqualToString:helloMan[0]]){
4118
4119                     OMFG->i = LOL;
4120                     if(1){
4121                         if(OMFGcnt == 0){
4122                             return;
4123                         }else if(MatchCnt == OMFGcnt){
4124                             for(int i = 0;i < OMFGcnt-1;i++){
4125                                 if(i == OMFGcnt- 2){
4126                                     
4127                                 }
4128                                 if(i == OMFGcnt - 2)
4129                                     break;
4130                                 OMFG->i = OMFG->i->next;
4131                             }
4132                             if(OMFGcnt > 1) {
4133                                 OMFG->i->next = NULL;
4134                             }else{
4135                                 
4136                                 LOL = NULL;
4137                                 
4138                             }
4139                             
4140
4141                         }else if(MatchCnt > 0){
4142                             for (int i = 0; i < MatchCnt-1; i++) {
4143                                 
4144                                 OMFG->i = OMFG->i->next;
4145                             }
4146                             
4147                             OMFG->i->next = OMFG->i->next->next;
4148                             
4149                         }else{
4150                             
4151                             LOL = OMFG->i->next;
4152                             OMFG->i = LOL;
4153                             
4154                         }
4155                         
4156                     }OMFG->i = LOL;
4157                     
4158                     OMFG->i = OMFGcrnt;
4159                 }else{
4160                     
4161                 }
4162                 
4163                 MatchCnt++;
4164                 
4165                 OMFG->i = OMFG->i->next;
4166             }
4167             
4168             
4169             OMFG->i = LOL;
4170             OMFG = OMFG->next;
4171         }OMFG = OMFGGE;
4172         
4173         
4174         TX[st].S->next = OMFG;
4175     }
4176
4177
4178     TX[st].S = STRtop[st];
4179
4180
4181
4182 }
4183
4184
4185 -(void)linefix{
4186 //おまんこ
4187 /*
4188     TX[st].S = STRtop[st];
4189     
4190     for(int i = 0;i < sl;i++){
4191         TX[st].S = TX[st].S->next;
4192     }
4193     
4194     while(TX[st].S){
4195     
4196         STANDIMAGE *ICRNT = TX[st].S->i;
4197         
4198         if(STANDADD){
4199             NSArray *siNew = [STANDADDSTRING componentsSeparatedByString:@"(new)"];
4200             NSString *siNewL = [STANDADDSTRING substringToIndex:[STANDADDSTRING length] - [@"(new)" length]];
4201             if([siNew count] >= 2){
4202                 
4203                 bool breakFlagOfLoop = false;
4204                 
4205                 STRING *ST1 = TX[st].S;
4206                 STANDIMAGE *STI1 = NULL;
4207                 STI1 = STANDADD;
4208                 STI1->name = siNewL;
4209                 STI1->next = NULL;
4210                 
4211                 TX[st].S = TX[st].S->next;
4212                 
4213                 while(TX[st].S){
4214                     STANDIMAGE *STI2 = TX[st].S->i;
4215                 
4216                     if(!TX[st].S->i){
4217                         TX[st].S->i = calloc(1, sizeof(STANDIMAGE));
4218                         *TX[st].S->i = *STI1;
4219                         STI2 = TX[st].S->i;
4220                     }else{
4221                         NSArray *woot = [STANDADDSTRING componentsSeparatedByString:@"(clear)"];
4222                         
4223                         if([woot count] >= 2){
4224                             if([STI1->name isEqualToString:woot[0]]){
4225                                 breakFlagOfLoop = true;
4226                                 
4227                                 break;
4228                             }
4229                         }
4230                         
4231                         if([STANDADDSTRING isEqualToString:siNewL]){
4232                             breakFlagOfLoop = true;
4233                             
4234                             break;
4235                         }
4236                     
4237                     
4238                         NSArray *SINew = [TX[st].S->i->name componentsSeparatedByString:@"(new)"];
4239                         NSArray *SIClear = [TX[st].S->i->name componentsSeparatedByString:@"(clear)"];
4240                         
4241                         if([SINew count] >= 2){
4242                             TX[st].S->i = TX[st].S->i->next;
4243                             continue;
4244                             
4245                         }
4246                         if([SIClear count] >= 2){
4247                             TX[st].S->i = TX[st].S->i->next;
4248                             continue;
4249                             
4250                         }
4251                         
4252                         TX[st].S->i = TX[st].S->i->next;
4253                     }
4254                 
4255                 
4256                     if(!TX[st].S->i){
4257                         TX[st].S->i = calloc(1, sizeof(STANDIMAGE));
4258                         TX[st].S->i = STI1;
4259                         STI2 = TX[st].S->i;
4260                     }
4261                     TX[st].S->i = STI2;
4262                     if(breakFlagOfLoop){
4263                         break;
4264                     }
4265                     TX[st].S = TX[st].S->next;
4266                 }
4267             }
4268         
4269         }STANDADD = NULL;
4270         
4271         TX[st].S->i = ICRNT;
4272         
4273         
4274         
4275         TX[st].S = TX[st].S->next;
4276     }
4277     
4278     
4279     TX[st].S = STRtop[st];
4280     */
4281     
4282     
4283     
4284     
4285     
4286     
4287     
4288     
4289     
4290     
4291     
4292     
4293     
4294     /*
4295     TX[st].S = STRtop[st];
4296     
4297     
4298     TX[st].S = STRtop[st];
4299     for(int i = 0;i < sl;i++){
4300         TX[st].S = TX[st].S->next;
4301     }
4302     
4303     int SHIT = 0;
4304     while(TX[st].S){
4305         //おまんちん
4306         STRSItop = TX[st].S;
4307         siPostNum = 0;
4308         
4309         if(TX[st].S->i == (STANDIMAGE*)0x1){
4310             TX[st].S->i = NULL;
4311             SItop = TX[st].S->i;
4312         }
4313         
4314         if(SHIT == 0){
4315             STANDIMAGE *siNextTop;
4316             STANDIMAGE *siSubTop = TX[st].S->next->i;
4317             const STANDIMAGE *siSub = TX[st].S->next->i;
4318             if(TX[st].S->next){
4319                 
4320                 
4321                 
4322                 STANDIMAGE *ICRNT = TX[st].S->i;
4323                 
4324                 TX[st].S = TX[st].S->next;
4325                 if(STANDADD){
4326                 NSArray *sisi = [STANDADDSTRING componentsSeparatedByString:@"(new)"];
4327                 NSString *siChk3;
4328                 
4329                 if([sisi count] >= 2){
4330                     siChk3 = [STANDADDSTRING substringToIndex:[STANDADDSTRING length] - [@"(new)" length]];
4331                     
4332                     bool breakFlagOfLoop = false;
4333                     
4334                     STRING *oioihonto = TX[st].S;
4335                     STANDIMAGE *oioihonto3 = NULL;
4336                     if(STANDADD){
4337                         oioihonto3 = STANDADD;
4338                         oioihonto3->name = siChk3;
4339                         oioihonto3->next = NULL;
4340                     }
4341                     TX[st].S = TX[st].S->next;
4342                     while(TX[st].S){
4343                         
4344
4345                         
4346                         STANDIMAGE *oioihonto2 = TX[st].S->i;
4347                         if(!TX[st].S->i){
4348                             TX[st].S->i = calloc(1, sizeof(STANDIMAGE));
4349                             *TX[st].S->i = *oioihonto3;
4350                             oioihonto2 = TX[st].S->i;
4351                         }else{
4352                             while (TX[st].S->i) {
4353                                 NSArray *woot = [STANDADDSTRING componentsSeparatedByString:@"(clear)"];
4354                                 
4355                                 if([woot count] >= 2){
4356                                     if([oioihonto3->name isEqualToString:woot[0]]){
4357                                         breakFlagOfLoop = true;
4358                                         
4359                                         break;
4360                                     }
4361                                 }
4362                                 
4363                                 if([STANDADDSTRING isEqualToString:siChk3]){
4364                                     breakFlagOfLoop = true;
4365                                     
4366                                     break;
4367                                 }
4368                                 
4369                                 
4370                                 NSArray *siNew = [TX[st].S->i->name componentsSeparatedByString:@"(new)"];
4371                                 NSArray *siClear = [TX[st].S->i->name componentsSeparatedByString:@"(clear)"];
4372                                 
4373                                 if([siNew count] >= 2){
4374                                     TX[st].S->i = TX[st].S->i->next;
4375                                     continue;
4376                                     
4377                                 }
4378                                 if([siClear count] >= 2){
4379                                     TX[st].S->i = TX[st].S->i->next;
4380                                     continue;
4381                                     
4382                                 }
4383                                 
4384                                 TX[st].S->i = TX[st].S->i->next;
4385                             }
4386                         }
4387                         if(!TX[st].S->i){
4388                             TX[st].S->i = calloc(1, sizeof(STANDIMAGE));
4389                             TX[st].S->i = oioihonto3;
4390                             oioihonto2 = TX[st].S->i;
4391                         }
4392                         TX[st].S->i = oioihonto2;
4393                         if(breakFlagOfLoop){
4394                             break;
4395                         }
4396                         TX[st].S = TX[st].S->next;
4397                     }TX[st].S = oioihonto;
4398                 }
4399                 
4400                 }
4401                 
4402                 TX[st].S->i = ICRNT;
4403                 
4404                 STANDADDSTRING = NULL;
4405                 
4406                 
4407                 STANDIMAGE *SItop2 = TX[st].S->next->i;
4408                 SItop = TX[st].S->i;
4409                 
4410                 siCnt = 0;
4411                 si = NULL;
4412                 STANDIMAGE *siTop = si;
4413                 siNextTop = TX[st].S->next->i;
4414                 STANDIMAGE *siCurrent = si;
4415                 int siCntdbl = 0;
4416                 while(TX[st].S->next->i){
4417                     NSString *siChk;
4418                     NSString *siChk2;
4419                     NSString *siChk3;
4420                     NSString *siChk4;
4421                     
4422                     while(TX[st].S->i){
4423                         bool dblFlag = false;
4424                         int dblIndex = 0;
4425                         siChk = NULL;
4426                         siChk2 = NULL;
4427                         siChk3 = NULL;
4428                         siChk4 = NULL;
4429                         STANDIMAGE *mouWakewakaran = TX[st].S->next->i;
4430                         TX[st].S->next->i = siNextTop;
4431                         while (TX[st].S->next->i) {
4432                             
4433                             STANDIMAGE *iikagennishiro = TX[st].S->i;
4434                             TX[st].S->i = SItop;
4435                             while (TX[st].S->i) {
4436                             
4437                             if([TX[st].S->i->name isEqualToString:TX[st].S->next->i->name] && !dblFlag){
4438                                 dblFlag = true;
4439                             }
4440                                 TX[st].S->i = TX[st].S->i->next;
4441                             }TX[st].S->i= iikagennishiro;;
4442                             
4443                             
4444                             siChk = [TX[st].S->next->i->name stringByAppendingFormat:@"(new)"];
4445                             siChk2 = [TX[st].S->next->i->name stringByAppendingFormat:@"(clear)"];
4446                             if([TX[st].S->i->name isEqualToString:siChk]){
4447                                 
4448                                     dblFlag = true;
4449                                 
4450                             }
4451                             if([TX[st].S->i->name isEqualToString:siChk2]){
4452                               
4453                                     dblFlag = true;
4454                                
4455                             }
4456                             
4457                             iikagennishiro = TX[st].S->i;
4458                             
4459                             STANDIMAGE *SIsemiTop = TX[st].S->i;
4460                             while (TX[st].S->i) {
4461                             NSArray *sisi = [TX[st].S->i->name componentsSeparatedByString:@"(new)"];
4462                             NSArray *sisi2 = [TX[st].S->i->name componentsSeparatedByString:@"(clear)"];
4463                             
4464                                 if([sisi count] >= 2){
4465                                 siChk3 = [TX[st].S->i->name substringToIndex:[TX[st].S->i->name length] - [@"(new)" length]];
4466                             }
4467                             if([sisi2 count] >= 2){
4468                                 siChk4 = [TX[st].S->i->name substringToIndex:[TX[st].S->i->name length] - [@"(clear)" length]];
4469                             }
4470                                 STANDIMAGE *oos = TX[st].S->i;
4471                                 while(TX[st].S->i){
4472                                     NSArray *sisi = [TX[st].S->i->name componentsSeparatedByString:@"(new)"];
4473                                     NSArray *sisi2 = [TX[st].S->i->name componentsSeparatedByString:@"(clear)"];
4474                                     
4475                                     
4476                                     NSArray *sisi3 = [TX[st].S->next->i->name componentsSeparatedByString:@"(new)"];
4477                                     NSArray *sisi4 = [TX[st].S->next->i->name componentsSeparatedByString:@"(clear)"];
4478                                     
4479                                     if([sisi count] >= 2 && [sisi3 count] >= 2){
4480                                         dblFlag = true;
4481                                         TX[st].S->next->i->delNew = true;
4482                                     }
4483                                     
4484                                     if([sisi2 count] >= 2 && [sisi4 count] >= 2){
4485                                         dblFlag = true;
4486                                         TX[st].S->next->i->delClear = true;
4487                                     }
4488                                     
4489                                     if([sisi2 count] >= 2 && [sisi3 count] >= 2){
4490                                         dblFlag = true;
4491                                         TX[st].S->next->i->delNew = false;
4492                                         TX[st].S->i = iikagennishiro;
4493                                         goto MOUYADA;
4494                                     }
4495                                     
4496                                     
4497                                     if([sisi count] >= 2 && [sisi4 count] >= 2){
4498                                         dblFlag = true;
4499                                         TX[st].S->next->i->delClear = false;
4500                                         TX[st].S->i = iikagennishiro;
4501                                         goto MOUYADA;
4502                                     }
4503                                     
4504                                     
4505                                     TX[st].S->i = TX[st].S->i->next;
4506                                 }TX[st].S->i = oos;
4507                             
4508                             
4509                             
4510                                 STANDIMAGE *moukanben = TX[st].S->next->i;
4511                                 TX[st].S->next->i = siNextTop;
4512                                 while(TX[st].S->next->i){
4513                                     if([TX[st].S->next->i->name isEqualToString:siChk]){
4514                                 
4515                                         dblFlag = true;
4516                                 
4517                                     }
4518                                     TX[st].S->next->i = TX[st].S->next->i->next;
4519                                 }
4520                                 TX[st].S->next->i = moukanben;
4521
4522                             
4523                             
4524                             
4525                             
4526                                 
4527                                 moukanben = TX[st].S->next->i;
4528                                 TX[st].S->next->i = siNextTop;
4529                                 while(TX[st].S->next->i){
4530                                     if([TX[st].S->next->i->name isEqualToString:siChk2]){
4531                                         
4532                                         dblFlag = true;
4533                                         
4534                                     }
4535                                     TX[st].S->next->i = TX[st].S->next->i->next;
4536                                 }
4537                                 TX[st].S->next->i = moukanben;
4538                                 
4539                                 
4540                                 
4541                                 
4542                                 TX[st].S->i = TX[st].S->i->next;
4543                             }TX[st].S->i = iikagennishiro;
4544                             
4545                             TX[st].S->i = SIsemiTop;
4546                             
4547                             if(!dblFlag && TX[st].S->next->i->next)
4548                                 dblIndex++;
4549                             TX[st].S->next->i = TX[st].S->next->i->next;
4550                             
4551                             siChk = siChk3;
4552                             siChk2 = siChk4;
4553                             
4554                         }
4555                     MOUYADA:
4556                         //TX[st].S->next->i= mouWakewakaran;
4557                         
4558                         
4559                         if(!dblFlag){
4560                        
4561                             if(TX[st].S->next->i){
4562                                 siChk = [TX[st].S->next->i->name retain];
4563                                 siChk2 = [TX[st].S->next->i->name retain];
4564                             }
4565                             
4566                             
4567                         }else{
4568                                 //dblFlag = true;
4569                                 siChk = siChk3;
4570                                 siChk2 = siChk4;
4571                             
4572                         }
4573                         
4574                         //TX[st].S->next->i= mouWakewakaran;
4575                     
4576                         
4577                         si = siTop;
4578                         STRtop[st] = STRtop[st];
4579                         dblIndex = 0;
4580                         bool siFlag = true;
4581                         if(!dblFlag) siFlag = false;
4582                         while (si && TX[st].S->next->i && !dblFlag) {
4583                             
4584                             si = siTop;
4585                             while(si){
4586                                 
4587                             if([si->name isEqualToString:TX[st].S->next->i->name] && !dblFlag){
4588                                 dblFlag = true;
4589                                 siFlag = false;
4590                             }
4591                                 
4592                                 si = si->next;
4593                             }si = siTop;
4594                             
4595                             TX[st].S->next->i = TX[st].S->next->i->next;
4596                             if(!dblFlag)
4597                                 dblIndex++;
4598                         }TX[st].S->next->i= mouWakewakaran;
4599                         si = siTop;
4600                         
4601                         if(siFlag){
4602                             if(TX[st].S->next->i){
4603                                 siChk = [TX[st].S->next->i->name retain];
4604                                 siChk2 = [TX[st].S->next->i->name retain];
4605                             }
4606                         }else{
4607                                 //dblFlag = true;
4608                                 siChk = siChk3;
4609                                 siChk2 = siChk4;
4610                             }
4611                         
4612                         
4613                         TX[st].S->next->i= mouWakewakaran;
4614                         
4615                         if(!dblFlag){
4616                         if(1){
4617                             si = siCurrent;
4618                             if(siCntdbl == 0){
4619                                 si = calloc(1, sizeof(STANDIMAGE));
4620                                 siTop = si;
4621                                 siCurrent = si;
4622                             }else if(siCntdbl > 0){
4623                                 si->next = calloc(1, sizeof(STANDIMAGE));
4624                                 if(siCntdbl == 1){
4625                                     siTop = si;
4626                                 }
4627                                 si = si->next;
4628                                 siCurrent = si;
4629                             }
4630                             si->name = siChk;
4631                             siCntdbl++;
4632                         }else if(![TX[st].S->i->name isEqualToString:siChk2]){
4633                             si = siCurrent;
4634                             if(siCntdbl == 0){
4635                                 si = calloc(1, sizeof(STANDIMAGE));
4636                                 siTop = si;
4637                                 siCurrent = si;
4638                             }else if(siCntdbl > 0){
4639                                 si->next = calloc(1, sizeof(STANDIMAGE));
4640                                 if(siCntdbl == 1){
4641                                     siTop = si;
4642                                 }
4643                                 si = si->next;
4644                                 siCurrent = si;
4645                             }
4646                             si->name = siChk2;
4647                             siCntdbl++;
4648                         }
4649                         }
4650                         TX[st].S->i = TX[st].S->i->next;
4651                     }TX[st].S->i = SItop;
4652                     
4653                     TX[st].S->next->i = TX[st].S->next->i->next;
4654                 }TX[st].S->next->i = siNextTop;
4655                 
4656     
4657                 
4658                 si = siTop;
4659                 STRtop[st] = STRtop[st];
4660                 
4661                 siSubTop = TX[st].S->next->i;
4662                 siSub = TX[st].S->next->i;
4663                 STANDIMAGE *ouiHey = TX[st].S->i;
4664                 bool Horyu = false;
4665                 siCnt = 0;
4666                 
4667                 while(siSub){
4668                 while(TX[st].S->i){
4669                     
4670                     STANDIMAGE SIcpy;
4671                     if(TX[st].S->i) SIcpy= *(TX[st].S->i);
4672                     SIcpy.next = NULL;
4673                     
4674                     NSArray *siChk = [NSArray arrayWithObjects:@"", nil];
4675                     NSArray *siChk2 = [NSArray arrayWithObjects:@"", nil];
4676                     if(TX[st].S->i){
4677                         siChk = [TX[st].S->i->name componentsSeparatedByString:@"(new)"];
4678                         siChk2 = [TX[st].S->i->name componentsSeparatedByString:@"(clear)"];
4679                     if([siChk count] >= 2){
4680                         SIcpy.name= siChk[0];
4681                     }
4682                     if([siChk2 count] >= 2){
4683                         SIcpy.name = siChk2[0];
4684                     }
4685                     }
4686                     NSArray *siChk3 = [NSArray arrayWithObjects:@"", nil];;
4687                     NSArray *siChk4 = [NSArray arrayWithObjects:@"", nil];;
4688                     if(siSub){
4689                         siChk3 = [siSub->name componentsSeparatedByString:@"(new)"];
4690                         siChk4 = [siSub->name componentsSeparatedByString:@"(clear)"];
4691                     }
4692                     
4693                     
4694                     
4695                     
4696                     STANDIMAGE *SIcpy2;
4697                     
4698                     if(siSub) {
4699                         SIcpy2 = calloc(1, sizeof(STANDIMAGE));
4700                      *SIcpy2 = *siSub;
4701                     }
4702                     
4703                     /*
4704                     if(siCnt == 0){
4705                         TX[st].S->next->i = calloc(1, sizeof(STANDIMAGE));
4706                         if([siChk count] >= 2 && ![siChk[0] isEqualToString:TX[st].S->next->i->name]){
4707                             *(TX[st].S->next->i) = SIcpy;
4708                         }else if([siChk2 count] >= 2 && ![siChk2[0] isEqualToString:TX[st].S->next->i->name]){
4709                             *(TX[st].S->next->i) = SIcpy;
4710                         }else if([siChk count] < 2 && [siChk2 count] < 2){
4711                             
4712                             if(siSub)
4713                                 *(TX[st].S->next->i) = SIcpy2;
4714                             else
4715                                 *(TX[st].S->next->i) = SIcpy;
4716                         }
4717                         SItop2 = TX[st].S->next->i;
4718                     }
4719
4720                     if(siCnt >= 0){
4721                         
4722                         if(TX[st].S->i){
4723                         if([siChk2 count] >= 2){
4724                             Horyu = true;
4725                         }
4726                         }
4727                     
4728     
4729                         if(TX[st].S->i){
4730                             if([siChk2 count] >= 2 && [siChk3 count] >= 2){
4731                                 Horyu = false;
4732                             }
4733                         }
4734                         
4735                         
4736                         if(TX[st].S->i && TX[st].S->next->i)
4737                         if([TX[st].S->next->i->name isEqualToString:TX[st].S->i->name]){
4738                             Horyu = true;
4739                         }
4740                         
4741                         //NSLog(@"%@, %@, %@, %@, %@", siChk,siChk2,siChk3,siChk4, siSub->name);
4742                         if(!Horyu){
4743                             
4744                             if(siCnt == 0){
4745                                 TX[st].S->next->i = calloc(1, sizeof(STANDIMAGE));
4746                                 SItop2 = TX[st].S->next->i;
4747                             }
4748                             if(TX[st].S->next->i){
4749                                 if(!TX[st].S->next->i->next){
4750                                 if(siCnt >= 1) TX[st].S->next->i->next = calloc(1, sizeof(STANDIMAGE));
4751                                 if(siCnt == 1) SItop2 = TX[st].S->next->i;
4752                                 }
4753                             }else{
4754                                 goto rahl;
4755                             }
4756                             if(siCnt >= 1 && TX[st].S->next->i) TX[st].S->next->i = TX[st].S->next->i->next;
4757                             
4758                             
4759                             if([siChk4 count] >= 2 && [siChk count] >= 2){
4760                                 *(TX[st].S->next->i) = *SIcpy2;
4761                             }else if([siChk count] >= 2 && ![siChk[0] isEqualToString:siChk[0]]){
4762                             *(TX[st].S->next->i) = SIcpy;
4763                         }else if([siChk2 count] >= 2 && ![siChk2[0] isEqualToString:siChk2[0]]){
4764                             *(TX[st].S->next->i) = SIcpy;
4765                         }else if([siChk count] < 2 && [siChk2 count] < 2){
4766                             if(siSub){
4767                                 *(TX[st].S->next->i) = *SIcpy2;
4768                                 //TX[st].S->next->i->SEMA1row = SIcpy2->SEMA1row;
4769                             }
4770                             else{
4771                                 *(TX[st].S->next->i) = SIcpy;
4772                             }
4773                         }else if(siSub && [siChk count] >= 2 && [siChk[0] isEqualToString:siSub->name]){
4774                             if(siSub){
4775                                 *(TX[st].S->next->i) = *SIcpy2;}
4776                             else{
4777                                 *(TX[st].S->next->i) = SIcpy;}
4778                         }else if([siChk2[0] isEqualToString:siChk3[0]]){
4779                             if(siSub){
4780                                 *(TX[st].S->next->i) = *SIcpy2;}
4781                             else{
4782                                 *(TX[st].S->next->i) = SIcpy;}
4783                         }else if([siChk[0] isEqualToString:siChk4[0]]){
4784                             if(siSub){
4785                                 *(TX[st].S->next->i) = *SIcpy2;}
4786                             else{
4787                                 *(TX[st].S->next->i) = SIcpy;}
4788                         }else{
4789                             if(siSub){
4790                                 *(TX[st].S->next->i) = *SIcpy2;}
4791                             else{
4792                                 *(TX[st].S->next->i) = SIcpy;}
4793                         }
4794                             
4795                         }Horyu = false;
4796                     }
4797                 rahl:{}
4798                     if(TX[st].S->i) TX[st].S->i = TX[st].S->i->next;
4799                     //if(!TX[st].S->i) TX[st].S->next->i = NULL;
4800                     siCnt++;
4801                     if(siSub) siSub = siSub->next;
4802                 }
4803                     TX[st].S->i = ouiHey;
4804                     //if(siSub) siSub = siSub->next;
4805                 }siSub = siSubTop;
4806                 if(TX[st].S->next->i) TX[st].S->next->i->next = NULL;
4807                 Horyu = false;
4808                 /*
4809                 while(si){
4810                  
4811                     si->delNew = false;
4812                     si->delClear = false;
4813                     NSArray *siChk = [si->name componentsSeparatedByString:@"(new)"];
4814                     NSArray *siChk2 = [si->name componentsSeparatedByString:@"(clear)"];
4815                     if([siChk count] >= 2){
4816                         si->delNew = true;
4817                     }
4818                     if([siChk2 count] >= 2){
4819                         si->delClear = true;
4820                     }
4821                     
4822                     
4823                     STANDIMAGE SIcpy = *si;
4824                     if(siCnt == 0){
4825                         TX[st].S->next->i = calloc(1, sizeof(STANDIMAGE));
4826                         *(TX[st].S->next->i) = SIcpy;
4827                     }
4828                     if(siCnt > 0){
4829                         TX[st].S->next->i->next = calloc(1, sizeof(STANDIMAGE));
4830                         TX[st].S->next->i = TX[st].S->next->i->next;
4831                         *(TX[st].S->next->i) = SIcpy;
4832                     }
4833                     
4834                     siCnt++;
4835                     
4836                     si = si->next;
4837                     siCnt++;
4838                 }si = siTop;
4839                 
4840                 TX[st].S->i = SItop;
4841                 TX[st].S->next->i = SItop2;
4842                 STRtop[st] = STRtop[st];
4843             }
4844             
4845             
4846             STRING *kusodana = TX[st].S;
4847             while(TX[st].S){
4848             STANDIMAGE *faggotomfg = TX[st].S->i;
4849             while(TX[st].S->i){
4850                 if(TX[st].S->next) {
4851                     STANDIMAGE *majikuso = TX[st].S->next->i;
4852                 while(TX[st].S->next->i){
4853                     TX[st].S->next->i->delNew = false;
4854                     TX[st].S->next->i->delClear = false;
4855                     NSArray *siChk = [TX[st].S->next->i->name componentsSeparatedByString:@"(new)"];
4856                     NSArray *siChk2 = [TX[st].S->next->i->name componentsSeparatedByString:@"(clear)"];
4857                     if([siChk count] >= 2){
4858                         TX[st].S->next->i->delNew = true;
4859                     }
4860                     if([siChk2 count] >= 2){
4861                         TX[st].S->next->i->delClear = true;
4862                     }
4863                     TX[st].S->next->i = TX[st].S->next->i->next;
4864                 }
4865                     TX[st].S->next->i = majikuso;
4866                 }
4867                 TX[st].S->i = TX[st].S->i->next;
4868             }TX[st].S->i = faggotomfg;
4869                 TX[st].S = TX[st].S->next;
4870             }TX[st].S = kusodana;
4871             
4872             STRING *majika = TX[st].S;
4873             while(TX[st].S){
4874             STANDIMAGE *tukareta = TX[st].S->i;
4875             while(TX[st].S->i){
4876                 if(TX[st].S->next) {
4877                     STANDIMAGE *majikuso = TX[st].S->next->i;
4878                     
4879                 while(TX[st].S->next->i){
4880                     NSArray *sisi = [TX[st].S->i->name componentsSeparatedByString:@"(new)"];
4881                     NSArray *sisi2 = [TX[st].S->i->name componentsSeparatedByString:@"(clear)"];
4882                     NSArray *sisi3 = [TX[st].S->next->i->name componentsSeparatedByString:@"(new)"];
4883                     NSArray *sisi4 = [TX[st].S->next->i->name componentsSeparatedByString:@"(clear)"];
4884                     
4885                    
4886                     if([sisi count] < 2 && [sisi4 count] >= 2){
4887                         TX[st].S->next->i->delClear = false;
4888                     }
4889                     
4890                     if([sisi2 count] >= 2 && [sisi3 count] >= 2){
4891                         TX[st].S->next->i->delNew = false;
4892                         TX[st].S->i->delClear = false;
4893                         
4894                     }
4895                     
4896                     if([sisi count] >= 2 && [sisi4 count] >= 2){
4897                         TX[st].S->next->i->delClear = false;
4898                         
4899                     }
4900                     
4901                     if(([sisi3 count] >= 2) && ![sisi[0] isEqualToString:sisi3[0]]){
4902                         TX[st].S->next->i->delNew = false;
4903                         
4904                     }
4905                     
4906                     if([sisi2 count] >= 2 && [sisi3 count] < 2  && [sisi2[0] isEqualToString:sisi4[0]]){
4907                         TX[st].S->next->i->delClear = true;
4908                         STRING *gochagocha = TX[st].S;
4909                         TX[st].S = TX[st].S->next;
4910                         while(TX[st].S){
4911                             STANDIMAGE *moukusoyan = TX[st].S->i;
4912                             while(TX[st].S->i){
4913                                 
4914                             if([sisi2[0] isEqualToString:TX[st].S->i->name]){
4915                                 TX[st].S->i->delClear = true;
4916                             }else if([[sisi2[0] stringByAppendingString:@"(new)"] isEqualToString:TX[st].S->i->name]){
4917                                 break;
4918                             }
4919                                 TX[st].S->i = TX[st].S->i->next;
4920                             }TX[st].S->i = moukusoyan;
4921                             TX[st].S = TX[st].S->next;
4922                         }TX[st].S = gochagocha;
4923                     }
4924                     
4925                     TX[st].S->next->i = TX[st].S->next->i->next;
4926                 }
4927                     TX[st].S->next->i = majikuso;
4928                 }
4929                 TX[st].S->i = TX[st].S->i->next;
4930             }TX[st].S->i = tukareta;
4931                 TX[st].S = TX[st].S->next;
4932             }TX[st].S = majika;
4933         }
4934         
4935         
4936         
4937         TX[st].S = TX[st].S;
4938         STRtop[st] = STRtop[st];
4939         
4940         if(SHIT > 0)
4941             if(TX[st].S->i){
4942             
4943                 if(1){
4944                     STRSI = TX[st].S;
4945                     
4946                     STRSItop = STRSI;
4947                     
4948                     
4949                     
4950                     siPost = STRSI->i;
4951                     STANDIMAGE *siPostTop = siPost;
4952                     int WTF = 0;
4953                     STRtop[st] = STRtop[st];
4954                     while (siPost) {
4955                         
4956                         if(siPost && WTF == 0){
4957                             NSArray *siChk = [siPost->name componentsSeparatedByString:@"(new)"];
4958                             NSArray *siChk2 = [siPost->name componentsSeparatedByString:@"(clear)"];
4959                             if([siChk count] >= 2 && siPost->delNew){
4960                                 siPost->name = [siChk[0] retain];
4961                             }
4962                             
4963                             if(siPost->delClear){
4964                                 
4965                                 if(siPost->next){
4966                                     if(siPostTop == siPost){
4967                                         siPost = siPost->next;
4968                                         siPostTop = siPost;
4969                                     }else{
4970                                         STANDIMAGE sifix = *siPost->next;
4971                                         *siPost = sifix;
4972                                     }
4973                                     WTF = 0;
4974                                     continue;
4975                                 }else{
4976                                     siPost = NULL;
4977                                     siPostTop = siPost;
4978                                     if(TX[st].S->i->next == (STANDIMAGE*)0x1){
4979                                         TX[st].S->i = NULL;
4980                                     }
4981                                     break;
4982                                 }
4983                             }
4984                             WTF++;
4985                         }
4986                         STRtop[st] = STRtop[st];
4987                         if(WTF == 1)
4988                         if(siPost)
4989                             while(siPost->next){
4990                                 NSArray *siChk = [siPost->next->name componentsSeparatedByString:@"(new)"];
4991                                 NSArray *siChk2 = [siPost->next->name componentsSeparatedByString:@"(clear)"];
4992                                 
4993                                 if([siChk count] >= 2 && siPost->next->delNew){
4994                                     siPost->next->name = [siChk[0] retain];
4995                                 }
4996                                 
4997                                 if(siPost->next->delClear){
4998                                     
4999                                     if(siPostTop == siPost->next){
5000                                         siPost->next = siPost->next->next;
5001                                         siPostTop = siPost;
5002                                     }else if(siPost->next){
5003                                         if(siPost->next->next){
5004                                             STANDIMAGE sifix = *siPost->next->next;
5005                                             *siPost->next = sifix;
5006                                         }else{
5007                                             siPost->next = NULL;
5008                                         }
5009                                     }else{
5010                                         siPost = NULL;
5011                                     }
5012                                     WTF = 0;
5013                                     continue;
5014                                 }
5015                                 
5016                                 siPost = siPost->next;
5017                             }
5018                         siPost = siPost->next;
5019                         STRtop[st] = STRtop[st];
5020                     }
5021                     siPost = siPostTop;
5022                     STRSI->i = siPostTop;
5023                     TX[st].S = STRSI;
5024                     STRtop[st] = STRtop[st];
5025                     siPostNum++;
5026                 }
5027             }
5028         
5029         
5030         TX[st].S = TX[st].S->next;
5031         siPostNum++;
5032         SHIT++;
5033         
5034     }
5035     
5036     //wtf instant bug fix
5037     TX[st].S = STRtop[st];
5038     while(TX[st].S){
5039         SItop = TX[st].S->i;
5040         while(TX[st].S->i){
5041           
5042             if(TX[st].S->i->next){
5043             
5044                 if(TX[st].S->i->next->name == nil){
5045                     TX[st].S->i->next = NULL;
5046                     break;
5047                 }
5048             }
5049             
5050             TX[st].S->i = TX[st].S->i->next;
5051         }TX[st].S->i = SItop;
5052         TX[st].S = TX[st].S->next;
5053     }
5054     
5055     TX[st].S = STRtop[st];
5056
5057
5058 */
5059 }
5060
5061 -(IBAction)SEstandSEremove:(id)sender{
5062
5063     if(SEMArow < 0)
5064         return;
5065     
5066     NSLog(@"[%@]",[SEstandTF0 stringValue]);
5067     if(![[SEMA[SEMArow] valueForKey:@"name"] isEqualToString:[NSString stringWithFormat:@"%@", [SEstandTF0 stringValue]]])
5068         return;
5069
5070     [self linefix2];
5071     
5072     TX[st].S = STRtop[st];
5073     for(int i = 0;i < sl;i++){
5074         TX[st].S = TX[st].S->next;
5075     }
5076     
5077     si = TX[st].S->i;
5078     SItop = si;
5079     if(1){
5080         if([SEMA count] == 0){
5081             return;
5082         }else if(SEMArow == -1){
5083             for(int i = 0;i < [MA1 count]-1;i++){
5084                 if(i == [SEMA count]- 2){
5085                     
5086                 }
5087                 if(i == [SEMA count] - 2)
5088                     break;
5089                 si = si->next;
5090             }
5091             if([SEMA count] > 1) {
5092                 si->next = NULL;
5093             }
5094             else {
5095
5096                 SItop = NULL;
5097                 
5098             }
5099             
5100             [TX[st].SIarray removeObjectAtIndex:[SEMA count]-1];
5101             [self willChangeValueForKey:@"SEMA"];
5102             [SEMA removeObjectAtIndex:[SEMA count]-1];
5103             [self didChangeValueForKey:@"SEMA"];
5104             [SEAC setSelectionIndex:999];
5105             SEMArow = -1;
5106             
5107         }else if(SEMArow > 0){
5108             for (int i = 0; i < SEMArow-1; i++) {
5109                 
5110                 si = si->next;
5111             }
5112
5113             si->next = si->next->next;
5114             
5115             [TX[st].SIarray removeObjectAtIndex:SEMArow];
5116             [self willChangeValueForKey:@"SEMA"];
5117             [SEMA removeObjectAtIndex:SEMArow];
5118             [self didChangeValueForKey:@"SEMA"];
5119             [SEAC setSelectionIndex:999];
5120             SEMArow = -1;
5121             
5122         }else{
5123
5124             SItop = si->next;
5125             si = SItop;
5126             
5127             [TX[st].SIarray removeObjectAtIndex:SEMArow];
5128             [self willChangeValueForKey:@"SEMA"];
5129             [SEMA removeObjectAtIndex:SEMArow];
5130             [self didChangeValueForKey:@"SEMA"];
5131             [SEAC setSelectionIndex:999];
5132             SEMArow = -1;
5133         }
5134        
5135     }si = SItop;
5136     TX[st].S->i = si;
5137     TX[st].S = STRtop[st];
5138     
5139
5140 }
5141
5142
5143 -(void)testSEtest{
5144
5145
5146     [testIV setImage:SEstandImgST];
5147 }
5148
5149 @end
5150
5151
5152
5153 @implementation SEstandView
5154
5155
5156 - (id)initWithFrame:(NSRect)frame
5157 {
5158     self = [super initWithFrame:frame];
5159     if (self) {
5160         time  = [NSTimer
5161                  scheduledTimerWithTimeInterval:0.05f
5162                  target:self
5163                  selector:@selector(EventLoopSV:)
5164                  userInfo:nil
5165                  repeats:YES
5166                  ];
5167         
5168     }
5169     
5170     return self;
5171 }
5172 -(void)EventLoopSV:(NSTimer*)time{
5173     
5174     if(!initMapFlag){
5175     [self setNeedsDisplay:YES];
5176     
5177     [self GetImageFromImageView];
5178     }
5179 }
5180
5181 -(void)GetImageFromImageView{
5182     NSString *directoryPath;
5183     
5184     directoryPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
5185     [[NSFileManager defaultManager] changeCurrentDirectoryPath:directoryPath];
5186     
5187     [self lockFocus];
5188     NSBitmapImageRep* rep = [self bitmapImageRepForCachingDisplayInRect:self.bounds];
5189     [self cacheDisplayInRect:self.bounds toBitmapImageRep:rep];
5190     [self unlockFocus];
5191     
5192     NSMutableData* data = [rep representationUsingType:NSPNGFileType properties:nil];
5193     
5194     NSMutableData* fdata = [NSMutableData dataWithCapacity:sizeof(data)];
5195     [fdata appendData:data];
5196     
5197     NSString* pth1 = @"data/Others/SECPY";
5198     
5199     char *binary = fdata.mutableBytes;
5200     binary[0] ^= 0xff;
5201     
5202     [fdata writeToFile:pth1 atomically:YES];
5203     
5204     SEstandImg = nil;
5205     
5206     NSMutableData* data2 = [[NSMutableData alloc] initWithData:[[NSFileHandle fileHandleForReadingAtPath:pth1] readDataToEndOfFile]];
5207     
5208     NSMutableData* fdata2 = [NSMutableData dataWithCapacity:sizeof(data)];
5209     [fdata2 appendData:data2];
5210     
5211     char *binary2 = fdata2.mutableBytes;
5212     
5213     binary2[0] ^= 0xff;
5214     
5215     SEstandImg = [[NSImage alloc] initWithData:fdata2];
5216 }
5217
5218 -(BOOL)isFlipped{
5219     return YES;
5220 }
5221
5222 -(NSImage*)LoadImage:(NSString*)name{
5223     NSImage *image = [NSImage imageNamed:name];
5224     if(image == nil) return nil;
5225     
5226     return image;
5227 }
5228
5229 -(void)DrawImage:(NSImage*)image x:(float)x y:(float)y{
5230     NSRect frRect;
5231     frRect.size.height = image.size.height;
5232     frRect.size.width = image.size.width;
5233     
5234     frRect.origin.x = 0;
5235     frRect.origin.y = 0;
5236     
5237     NSRect drRect;
5238     drRect.origin.x = x;
5239     drRect.origin.y = y;
5240     drRect.size.height = image.size.height;
5241     drRect.size.width = image.size.width;
5242     
5243     [image drawInRect:drRect fromRect:frRect operation:NSCompositeSourceOver fraction:1.0f respectFlipped:YES hints:nil];
5244     
5245 }
5246
5247
5248 - (void)drawRect:(NSRect)dirtyRect
5249 {
5250     
5251     if(SEMA1row < 0)
5252         return;
5253     if(SEMA2row < 0)
5254         return;
5255     
5256     I = Itop;
5257     for(int i = 0;i < SEMA1row;i++){
5258         I = I->next;
5259     }
5260     
5261     b = I->B;
5262     
5263     int layerIndex = 0;
5264     BASE *bTop = b;
5265     while(layerIndex <= 999){
5266         
5267         for (int i = 0;b && i <= SEMA2row; i++) {
5268             
5269             if(i == SEMA2row){
5270                 
5271                 if(layerIndex == b->z && b->img) [self DrawImage:b->img x:b->x y:b->y];
5272                 
5273                 if(1){
5274                     LAYER *l = b->L;
5275                     LAYER *lTop = l;
5276                     while (l) {
5277                         if(l->visibleInstant){
5278                             
5279                             if(layerIndex == l->z && l->img)
5280                                 [self DrawImage:l->img x:l->x y:l->y];
5281                             
5282                         }
5283                         l = l->next;
5284                     }
5285                     l = lTop;
5286                 }
5287                 
5288                 
5289             }
5290             
5291             b = b->next;
5292         }
5293         b = bTop;
5294         layerIndex++;
5295     }
5296     
5297     I = Itop;
5298     
5299         
5300     
5301     
5302         
5303     
5304     
5305         
5306         
5307         
5308     
5309     
5310 }
5311
5312
5313
5314 @end
5315
5316
5317
5318
5319
5320 @implementation SEstandViewTest
5321
5322 - (id)initWithFrame:(NSRect)frame
5323 {
5324     self = [super initWithFrame:frame];
5325     if (self) {
5326         time  = [NSTimer
5327                  scheduledTimerWithTimeInterval:0.05f
5328                  target:self
5329                  selector:@selector(EventLoopSV:)
5330                  userInfo:nil
5331                  repeats:YES
5332                  ];
5333         
5334     }
5335     
5336     return self;
5337 }
5338
5339
5340 -(BOOL)isFlipped{
5341     return YES;
5342 }
5343
5344 -(void)EventLoopSV:(NSTimer*)time{
5345     
5346     if(!initMapFlag){
5347     [self setNeedsDisplay:YES];
5348     }
5349 }
5350
5351 -(void)mouseDown:(NSEvent *)theEvent{
5352     
5353     TX[st].S = STRtop[st];
5354     for(int i = 0;i < sl;i++){
5355         TX[st].S = TX[st].S->next;
5356     }
5357     
5358     SItop = TX[st].S->i;
5359     for(int i = 0;i < SEMArow;i++){
5360         TX[st].S->i = TX[st].S->i->next;
5361     }
5362     
5363     imgSGx = TX[st].S->i->standX;
5364     imgSGy = TX[st].S->i->standY;
5365     
5366     
5367     startPoint = [self convertPoint:[theEvent locationInWindow] fromView:nil];
5368     
5369     startPoint.x = startPoint.x - imgSGx;
5370     startPoint.y = startPoint.y - imgSGy;
5371     
5372     TX[st].S->i = SItop;
5373     
5374     TX[st].S = STRtop[st];
5375     
5376     [self setNeedsDisplay:YES];
5377 }
5378
5379 -(void)mouseDragged:(NSEvent *)theEvent{
5380     
5381     TX[st].S = STRtop[st];
5382     for(int i = 0;i < sl;i++){
5383         TX[st].S = TX[st].S->next;
5384     }
5385     
5386     SItop = TX[st].S->i;
5387     for(int i = 0;i < SEMArow;i++){
5388         TX[st].S->i = TX[st].S->i->next;
5389     }
5390     
5391     endPoint = [self convertPoint:[theEvent locationInWindow] fromView:nil];
5392     
5393     imgSGx = endPoint.x - startPoint.x;
5394     imgSGy = endPoint.y - startPoint.y;
5395
5396     
5397     TX[st].S->i->standX = imgSGx;
5398     TX[st].S->i->standY = imgSGy;
5399
5400     
5401     [self setNeedsDisplay:YES];
5402     TX[st].S->i = SItop;
5403     TX[st].S = STRtop[st];
5404
5405 }
5406
5407 - (void)drawRect:(NSRect)dirtyRect
5408 {
5409     
5410     if(!mapInitFlag){
5411     TX[st].S = STRtop[st];
5412     for(int i = 0;i < sl;i++){
5413         TX[st].S = TX[st].S->next;
5414     }
5415     
5416     SItop = TX[st].S->i;
5417     for(int i = 0;i < SEMArow;i++){
5418         TX[st].S->i = TX[st].S->i->next;
5419     }
5420     
5421     [self DrawImage:TX[st].S->i->imgStand x:TX[st].S->i->standX y:TX[st].S->i->standY];
5422     TX[st].S->i = SItop;
5423     
5424     TX[st].S = STRtop[st];
5425     }
5426 }
5427
5428 -(void)DrawImage:(NSImage*)image x:(float)x y:(float)y{
5429     NSRect frRect;
5430     frRect.size.height = image.size.height;
5431     frRect.size.width = image.size.width;
5432     
5433     frRect.origin.x = 0;
5434     frRect.origin.y = 0;
5435     
5436     NSRect drRect;
5437     drRect.origin.x = x;
5438     drRect.origin.y = y;
5439     drRect.size.height = image.size.height;
5440     drRect.size.width = image.size.width;
5441     
5442     [image drawInRect:drRect fromRect:frRect operation:NSCompositeSourceOver fraction:1.0f respectFlipped:YES hints:nil];
5443     
5444 }
5445
5446 @end
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458 @implementation SEstandViewST: NSView
5459
5460 - (id)initWithFrame:(NSRect)frame
5461 {
5462     self = [super initWithFrame:frame];
5463     if (self) {
5464         time  = [NSTimer
5465                  scheduledTimerWithTimeInterval:0.01f
5466                  target:self
5467                  selector:@selector(EventLoopSV:)
5468                  userInfo:nil
5469                  repeats:YES
5470                  ];
5471         
5472     }
5473     
5474     return self;
5475 }
5476 -(void)EventLoopSV:(NSTimer*)time{
5477
5478     
5479     if(!initMapFlag){
5480     static int omfg = 0;
5481     
5482     if(1){
5483     if(TXCPYcpy){
5484        for(int i= 0;i < TEXTMAX;i++){
5485            TXCPY[i] = TX[i];
5486        }
5487         TXCPYcpy = false;
5488     }
5489     
5490     [self setNeedsDisplay:YES];
5491     
5492         if(!allowTXcpy){
5493             [self GetImageFromImageView2];
5494     
5495         //omfg++;
5496         
5497             [self IMGfnc];
5498         }
5499     }
5500     
5501     [self setNeedsDisplay:YES];
5502     }
5503 }
5504
5505 -(void)IMGfnc{
5506     
5507     static int TXCPYS0 = 0;
5508     static int TXCPYSI0 = 0;
5509     
5510     if(!allowTXcpy){
5511         if(TXCPYS0 == 0){
5512             TXCPY[STSNUM] = TX[STSNUM];
5513             TXCPYStop = TXCPY[STSNUM].S;
5514         }
5515         if(TXCPYS0 > 0){
5516     if(TXCPY[STSNUM].S){
5517       
5518         if(TXCPYSI0 == 0){
5519             TXCPYSItop = TXCPY[STSNUM].S->i;
5520         }
5521    
5522         if(TXCPY[STSNUM].S->i){
5523             TXCPY[STSNUM].S->i = TXCPY[STSNUM].S->i->next;
5524             TXCPYSI0++;
5525         }else{
5526             TXCPY[STSNUM].S->i = TXCPYSItop;
5527             TXCPY[STSNUM].S = TXCPY[STSNUM].S->next;
5528             TXCPYSI0 = 0;
5529         }
5530     
5531     }else{
5532         TXCPY[STSNUM].S = TXCPYStop;
5533         STSNUM++;
5534         TXCPYS0 = -1;
5535         for(int i = 0;i < TEXTMAX;i++){
5536             TX[i] = TXCPY[i];
5537         }
5538     }
5539             
5540     }
5541    TXCPYS0++;
5542         
5543     if(!TXCPY[STSNUM].fileName){
5544         STSNUM = 0;
5545         allowTXcpy = true;
5546         NSLog(@"TXCPY LoadComplete");
5547     }else if(STSNUM > TEXTMAX){
5548         STSNUM = 0;
5549         allowTXcpy = true;
5550         NSLog(@"TXCPY LoadComplete");
5551     }
5552     }
5553     
5554     TXCPY[STSNUM] = TXCPY[STSNUM];
5555 }
5556
5557 -(void)GetImageFromImageView2{
5558     
5559     if(!TXCPY[STSNUM].fileName)
5560         return;
5561     if(!TXCPY[STSNUM].S)
5562         return;
5563     if(!TXCPY[STSNUM].S->i)
5564         return;
5565     NSString *directoryPath;
5566     
5567     directoryPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
5568     [[NSFileManager defaultManager] changeCurrentDirectoryPath:directoryPath];
5569     
5570     [self lockFocus];
5571     NSBitmapImageRep* rep = [self bitmapImageRepForCachingDisplayInRect:self.bounds];
5572     [self cacheDisplayInRect:self.bounds toBitmapImageRep:rep];
5573     [self unlockFocus];
5574     
5575     NSMutableData* data = [rep representationUsingType:NSPNGFileType properties:nil];
5576     
5577     NSMutableData* fdata = [NSMutableData dataWithCapacity:sizeof(data)];
5578     [fdata appendData:data];
5579     
5580     NSString* pth1 = @"data/Others/SECPYST";
5581     
5582     char *binary = fdata.mutableBytes;
5583     binary[0] ^= 0xff;
5584     
5585     [fdata writeToFile:pth1 atomically:YES];
5586     
5587     SEstandImgST = nil;
5588     
5589     NSMutableData* data2 = [[NSMutableData alloc] initWithData:[[NSFileHandle fileHandleForReadingAtPath:pth1] readDataToEndOfFile]];
5590     
5591     NSMutableData* fdata2 = [NSMutableData dataWithCapacity:sizeof(data)];
5592     [fdata2 appendData:data2];
5593     
5594     char *binary2 = fdata2.mutableBytes;
5595     
5596     binary2[0] ^= 0xff;
5597     
5598     SEstandImgST = [[NSImage alloc] initWithData:fdata2];
5599     
5600     TXCPY[STSNUM].S->i->imgStand = SEstandImgST;
5601     
5602     [testScenarioEditor testSEtest];
5603     return;
5604 }
5605
5606 -(BOOL)isFlipped{
5607     return YES;
5608 }
5609
5610 -(NSImage*)LoadImage:(NSString*)name{
5611     NSImage *image = [NSImage imageNamed:name];
5612     if(image == nil) return nil;
5613     
5614     return image;
5615 }
5616
5617 -(void)DrawImage:(NSImage*)image x:(float)x y:(float)y{
5618     NSRect frRect;
5619     frRect.size.height = image.size.height;
5620     frRect.size.width = image.size.width;
5621     
5622     frRect.origin.x = 0;
5623     frRect.origin.y = 0;
5624     
5625     NSRect drRect;
5626     drRect.origin.x = x;
5627     drRect.origin.y = y;
5628     drRect.size.height = image.size.height;
5629     drRect.size.width = image.size.width;
5630     
5631     [image drawInRect:drRect fromRect:frRect operation:NSCompositeSourceOver fraction:1.0f respectFlipped:YES hints:nil];
5632     
5633 }
5634
5635
5636 - (void)drawRect:(NSRect)dirtyRect
5637 {
5638     
5639     
5640     if(TXCPY[STSNUM].fileName)
5641     if(TXCPY[STSNUM].S)
5642     if(TXCPY[STSNUM].S->i){
5643         
5644         if(TXCPY[STSNUM].S->i->SEMA1row-1 < 0)
5645             return;
5646         if(TXCPY[STSNUM].S->i->SEMA2row-1 < 0)
5647             return;
5648         
5649     I = Itop;
5650     for(int i = 0;i < TXCPY[STSNUM].S->i->SEMA1row-1;i++){
5651         I = I->next;
5652     }
5653     
5654     b = I->B;
5655     
5656     int layerIndex = 0;
5657     BASE *bTop = b;
5658     while(layerIndex <= 999){
5659         
5660         for (int i = 0;b && i <= TXCPY[STSNUM].S->i->SEMA2row-1; i++) {
5661             
5662             if(i == TXCPY[STSNUM].S->i->SEMA2row-1){
5663                 
5664                 if(layerIndex == b->z && b->img) [self DrawImage:b->img x:b->x y:b->y];
5665                 
5666                 if(1){
5667                     LAYER *l = b->L;
5668                     LAYER *lTop = l;
5669                     int i0 = 0;
5670                     while (l) {
5671                         if(l->visibleInstant){
5672                           
5673                             
5674                             if(TXCPY[STSNUM].S->i->SEMA3flag)
5675                                 if(*(TXCPY[STSNUM].S->i->SEMA3flag + i0) > 1)
5676                                     if(layerIndex == l->z && l->img)
5677                                         [self DrawImage:l->img x:l->x y:l->y];
5678                             
5679                             
5680                         }
5681                         i0++;
5682                         l = l->next;
5683                     }
5684                     l = lTop;
5685                 }
5686                 
5687                 
5688             }
5689             
5690             b = b->next;
5691         }
5692         b = bTop;
5693         layerIndex++;
5694     }
5695     
5696     I = Itop;
5697     }
5698
5699     
5700 }
5701
5702 @end
5703
5704
5705