OSDN Git Service

命中表示修正
[awarsiii/AwarsIV.git] / Awars III / LevelList.m
1 //
2 //  LevelList.m
3 //  Awars III
4 //
5 //  Created by 桐谷 諭史 on 2015/08/31.
6 //  Copyright (c) 2015年 Killery. All rights reserved.
7 //
8
9 #import "LevelList.h"
10
11 @implementation LevelList
12
13 -(void)awakeFromNib{
14     [levelListTV1 setTarget:self];
15     [levelListTV1 setAction:@selector(clickLL1:)];
16     
17     [levelListTV2 setTarget:self];
18     [levelListTV2 setAction:@selector(clickLL2:)];
19 }
20
21 -(id)init{
22     levelTimer  = [NSTimer
23              scheduledTimerWithTimeInterval:0.01
24              target:self
25              selector:@selector(EventLoop:)
26              userInfo:nil
27              repeats:YES
28              ];
29     levelListMA1 = [NSMutableArray new];
30     levelListMA2 = [NSMutableArray new];
31     levelListMA3 = [NSMutableArray new];
32     
33     [self initLevelTitleList];
34     
35     return self;
36 }
37
38 -(void)EventLoop:(NSTimer*)time{
39     
40     if(SCinputEndFlag){
41         [self initLevelTitleList];
42         SCinputEndFlag = false;
43     }
44     
45     
46     if([levelListMA1 count] > 0 && LL1row >=0){
47         SC[LL1row+1].name = [[[levelListMA1 objectAtIndex:LL1row] valueForKey:@"name"] retain];
48         SC[LL1row+1].iName = [[[levelListMA1 objectAtIndex:LL1row] valueForKey:@"img"] retain];
49     }
50     
51     if([levelListMA2 count] >0 && LL2row >= 0){
52         
53         NSString *string1 = [[[levelListMA2 objectAtIndex:LL2row] valueForKeyPath:@"name"] retain];
54         NSString *string2 = [[[levelListMA2 objectAtIndex:LL2row] valueForKeyPath:@"op"] retain];
55         NSString *string3 = [[[levelListMA2 objectAtIndex:LL2row] valueForKeyPath:@"ed"] retain];
56         NSString *string4 = [[[levelListMA2 objectAtIndex:LL2row] valueForKeyPath:@"map"] retain];
57         
58         
59         [SC[LL1row+1].sName replaceObjectAtIndex:LL2row withObject:string1];
60         [SC[LL1row+1].nameSceneStart replaceObjectAtIndex:LL2row withObject:string2];
61         [SC[LL1row+1].nameSceneEnd replaceObjectAtIndex:LL2row withObject:string3];
62         [SC[LL1row+1].nameMAP replaceObjectAtIndex:LL2row withObject:string4];
63         
64         
65     }
66     
67 }
68
69
70
71 -(void)initLevelTitleList{
72     
73     
74     [self willChangeValueForKey:@"levelListMA1"];
75     [levelListMA1 removeAllObjects];
76     [self didChangeValueForKey:@"levelListMA1"];
77     
78     for(int i = 1;i <= SCarray;i++){
79
80         NSMutableDictionary* dict = [NSMutableDictionary new];
81         
82         NSString *string = SC[i].iName;
83         
84             [dict setValue:[NSString stringWithFormat:@"%@", SC[i].name] forKey:@"name"];
85             [dict setValue:[NSString stringWithFormat:@"%@", string] forKey:@"img"];
86             
87             [self willChangeValueForKey:@"levelListMA1"];
88             [levelListMA1 addObject:dict];
89             [self didChangeValueForKey:@"levelListMA1"];
90         
91         
92     }
93     
94     
95     NSString *directoryPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
96     [[NSFileManager defaultManager] changeCurrentDirectoryPath:directoryPath];
97     
98     NSArray *Farray;
99     NSString *filePath = @"Map";
100     Farray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:filePath error:nil];
101     
102     fileNumb = (int)[Farray count];
103     for (int i = 1; i < fileNumb;i++) {
104         MF[i].fileName = [[Farray objectAtIndex:i] retain];
105     }
106     
107     [self willChangeValueForKey:@"levelListMA3"];
108     [levelListMA3 removeAllObjects];
109     [self didChangeValueForKey:@"levelListMA3"];
110     
111     for(int i = 1; i < fileNumb;i++){
112         NSMutableDictionary* dict = [NSMutableDictionary new];
113         
114         [dict setValue:[NSString stringWithFormat:@"%@", MF[i].fileName] forKey:@"name"];
115         [self willChangeValueForKey:@"levelListMA3"];
116         [levelListMA3 addObject:dict];
117         [self didChangeValueForKey:@"levelListMA3"];
118     }
119 }
120
121
122 -(void)clickLL1:(id)sender{
123     LL1row = (int)[levelListTV1 clickedRow];
124     
125     [self willChangeValueForKey:@"levelListMA2"];
126     [levelListMA2 removeAllObjects];
127     [self didChangeValueForKey:@"levelListMA2"];
128     
129     if([levelListTV1 clickedRow] >= 0){
130         
131         for(int i = 0;i < [SC[LL1row+1].nameMAP count];i++){
132             NSMutableDictionary* dict = [NSMutableDictionary new];
133             
134             [dict setValue:[NSString stringWithFormat:@"%@",[SC[LL1row+1].sName objectAtIndex:i]] forKey:@"name"];
135             [dict setValue:[NSString stringWithFormat:@"%@",[SC[LL1row+1].nameSceneStart objectAtIndex:i]] forKey:@"op"];
136             [dict setValue:[NSString stringWithFormat:@"%@",[SC[LL1row+1].nameSceneEnd objectAtIndex:i]] forKey:@"ed"];
137             [dict setValue:[NSString stringWithFormat:@"%@",[SC[LL1row+1].nameMAP objectAtIndex:i]] forKey:@"map"];
138             
139             [self willChangeValueForKey:@"levelListMA2"];
140             [levelListMA2 addObject:dict];
141             [self didChangeValueForKey:@"levelListMA2"];
142             
143         }
144         
145     }
146 }
147
148 -(void)clickLL2:(id)sender{
149     LL2row = (int)[levelListTV2 clickedRow];
150 }
151
152
153 -(IBAction)levelEditor:(id)sender{
154     [levelWindow makeKeyAndOrderFront:nil];
155     
156 }
157
158
159
160
161
162
163
164 -(IBAction)ins1:(id)sender{
165     
166     if(1){
167         NSMutableDictionary *dict = [NSMutableDictionary new];
168         if([levelListMA1 count] == 0){
169             [self SCinsert:LL1row];
170             SC[1].name = [@"新規タイトル" retain];
171             
172             [dict setValue:[NSString stringWithFormat:@"%@", SC[1].name] forKey:@"name"];
173             
174             [self willChangeValueForKey:@"levelListMA1"];
175             [levelListMA1 addObject:dict];
176             [self didChangeValueForKey:@"levelListMA1"];
177             [levelListAC1 setSelectionIndex:999];
178         }else if(LL1row == -1){
179             
180             [self SCinsert:(int)[levelListMA1 count]+1];
181             SC[[levelListMA1 count]+1].name = [@"新規タイトル" retain];
182             
183             [dict setValue:[NSString stringWithFormat:@"%@", SC[[levelListMA1 count]+1].name] forKey:@"name"];
184             
185             
186             [self willChangeValueForKey:@"levelListMA1"];
187             [levelListMA1 addObject:dict];
188             [self didChangeValueForKey:@"levelListMA1"];
189             [levelListAC1 setSelectionIndex:999];
190             
191         }else if(LL1row > 0){
192             
193             [self SCinsert:LL1row+1];
194             SC[LL1row+1].name = [@"新規タイトル" retain];
195             
196             [dict setValue:[NSString stringWithFormat:@"%@", SC[LL1row+1].name] forKey:@"name"];
197             
198             
199             [self willChangeValueForKey:@"levelListMA1"];
200             [levelListMA1 insertObject:dict atIndex:LL1row];
201             [self didChangeValueForKey:@"levelListMA1"];
202             [levelListAC1 setSelectionIndex:999];
203             
204         }else{
205             
206             
207             [self SCinsert:LL1row+1];
208             SC[LL1row+1].name = [@"新規タイトル" retain];
209             
210             [dict setValue:[NSString stringWithFormat:@"%@", SC[LL1row+1].name] forKey:@"name"];
211             
212             [self willChangeValueForKey:@"levelListMA1"];
213             [levelListMA1 insertObject:dict atIndex:LL1row];
214             [self didChangeValueForKey:@"levelListMA1"];
215             [levelListAC1 setSelectionIndex:999];
216         }
217         
218         
219         
220     }
221     
222 }
223
224 void insertSC(SCENARIO *ptr, SCENARIO *last, int val)
225 {
226     for(SCENARIO *dst = last; --dst >= ptr; ){
227         
228         *(dst + 1) = *dst;      // 要素をひとつ後ろにずらす
229     
230     }
231     
232     
233     ptr->name = [@"新規タイトル" retain];
234     ptr->nameSceneStart = NULL;
235     ptr->nameSceneEnd = NULL;
236     ptr->nameMAP = NULL;
237     
238     //NSLog(@"%p,%p",SC, ptr);
239     
240 }
241
242 -(void)SCinsert:(int)row{
243     
244     
245     insertSC(&SC[row], &SC[SCarray+1], row);// [2] の位置に 2 を挿入。最後の 5 は破棄
246     SCarray++;
247 }
248
249 void deleteSC(SCENARIO *ptr, SCENARIO *last)
250 {
251     while ( ++ptr < last )
252         *(ptr - 1) = *ptr;//  要素をひとつ前にずらす
253 }
254 -(void)SCdelete:(int)row{
255     
256     deleteSC(&SC[row], &SC[SCarray+1]);// [2] の要素を削除。最後の 5 はそのまま
257     SCarray--;
258 }
259
260
261 -(IBAction)del1:(id)sender{
262     SCENARIO SCNULL[0];
263     if(1){
264         if([levelListMA1 count] == 0){
265             return;
266         }else if(LL1row == -1){
267            
268             if([levelListMA1 count] > 1) [self SCdelete:(int)[levelListMA1 count]];
269             else [self SCdelete:LL1row+1];
270             
271             [self willChangeValueForKey:@"levelListMA1"];
272             [levelListMA1 removeObjectAtIndex:[levelListMA1 count]-1];
273             [self didChangeValueForKey:@"levelListMA1"];
274             [levelListAC1 setSelectionIndex:999];
275             
276         }else if(LL1row > 0){
277             [self SCdelete:LL1row+1];
278             
279             [self willChangeValueForKey:@"levelListMA1"];
280             [levelListMA1 removeObjectAtIndex:LL1row];
281             [self didChangeValueForKey:@"levelListMA1"];
282             [levelListAC1 setSelectionIndex:999];
283             
284         }else{
285             
286             [self SCdelete:LL1row];
287             
288             [self willChangeValueForKey:@"levelListMA1"];
289             [levelListMA1 removeObjectAtIndex:LL1row];
290             [self didChangeValueForKey:@"levelListMA1"];
291             [levelListAC1 setSelectionIndex:999];
292             
293         }
294         
295     }
296
297     LL1row = -1;
298 }
299
300 -(IBAction)ins2:(id)sender{
301
302     
303     if(1){
304         NSMutableDictionary *dict = [NSMutableDictionary new];
305         if([levelListMA2 count] == 0){
306             SC[LL1row+1].sName = [NSMutableArray new];
307             SC[LL1row+1].nameSceneStart = [NSMutableArray new];
308             SC[LL1row+1].nameSceneEnd = [NSMutableArray new];
309             SC[LL1row+1].nameMAP = [NSMutableArray new];
310             NSString *howCouldYou = [@"NULL" retain];
311             [SC[LL1row+1].sName addObject:howCouldYou];
312             [SC[LL1row+1].nameSceneStart addObject:howCouldYou];
313             [SC[LL1row+1].nameSceneEnd addObject:howCouldYou];
314             [SC[LL1row+1].nameMAP addObject:howCouldYou];
315             
316             [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"name"];
317             [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"op"];
318             [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"ed"];
319             [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"map"];
320             
321             [self willChangeValueForKey:@"levelListMA2"];
322             [levelListMA2 addObject:dict];
323             [self didChangeValueForKey:@"levelListMA2"];
324             [levelListAC2 setSelectionIndex:999];
325         }else if(LL2row == -1){
326             NSString *just = [@"NULL" retain];
327             [SC[LL1row+1].sName addObject:just];
328             [SC[LL1row+1].nameSceneStart addObject:just];
329             [SC[LL1row+1].nameSceneEnd addObject:just];
330             [SC[LL1row+1].nameMAP addObject:just];
331             
332             [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"name"];
333             [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"op"];
334             [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"ed"];
335             [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"map"];
336             
337             
338             [self willChangeValueForKey:@"levelListMA2"];
339             [levelListMA2 addObject:dict];
340             [self didChangeValueForKey:@"levelListMA2"];
341             [levelListAC2 setSelectionIndex:999];
342             
343         }else if(LL2row > 0){
344             NSString *just = [@"NULL" retain];
345             [SC[LL1row+1].sName insertObject:just atIndex:LL2row];
346             [SC[LL1row+1].nameSceneStart insertObject:just atIndex:LL2row];
347             [SC[LL1row+1].nameSceneEnd insertObject:just atIndex:LL2row];
348             [SC[LL1row+1].nameMAP insertObject:just atIndex:LL2row];
349             
350             [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"name"];
351             [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"op"];
352             [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"ed"];
353             [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"map"];
354             
355             
356             [self willChangeValueForKey:@"levelListMA2"];
357             [levelListMA2 insertObject:dict atIndex:LL2row];
358             [self didChangeValueForKey:@"levelListMA2"];
359             [levelListAC2 setSelectionIndex:999];
360             
361         }else{
362             NSString *just = [@"NULL" retain];
363             [SC[LL1row+1].sName insertObject:just atIndex:LL2row];
364             [SC[LL1row+1].nameSceneStart insertObject:just atIndex:LL2row];
365             [SC[LL1row+1].nameSceneEnd insertObject:just atIndex:LL2row];
366             [SC[LL1row+1].nameMAP insertObject:just atIndex:LL2row];
367             
368             [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"name"];
369             [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"op"];
370             [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"ed"];
371             [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"map"];
372             
373             [self willChangeValueForKey:@"levelListMA2"];
374             [levelListMA2 insertObject:dict atIndex:LL2row];
375             [self didChangeValueForKey:@"levelListMA2"];
376             [levelListAC2 setSelectionIndex:999];
377         }
378         
379         
380         
381     }
382 }
383 -(IBAction)del2:(id)sender{
384     SCENARIO SCNULL[0];
385     if(1){
386         if([levelListMA2 count] == 0){
387             return;
388         }else if(LL2row == -1){
389             
390             if([levelListMA2 count] > 1) {
391                 [SC[[levelListMA2 count]].sName removeObjectAtIndex:[levelListMA2 count]-1];
392                 [SC[[levelListMA2 count]].nameSceneStart removeObjectAtIndex:[levelListMA2 count]-1];
393                 [SC[[levelListMA2 count]].nameSceneEnd removeObjectAtIndex:[levelListMA2 count]-1];
394                 [SC[[levelListMA2 count]].nameMAP removeObjectAtIndex:[levelListMA2 count]-1];
395             
396             }
397             else{
398                 [SC[1].sName removeObjectAtIndex:[levelListMA2 count]-1];
399                 [SC[1].nameSceneStart removeObjectAtIndex:[levelListMA2 count]-1];
400                 [SC[1].nameSceneEnd removeObjectAtIndex:[levelListMA2 count]-1];
401                 [SC[1].nameMAP removeObjectAtIndex:[levelListMA2 count]-1];
402             }
403             [self willChangeValueForKey:@"levelListMA2"];
404             [levelListMA2 removeObjectAtIndex:[levelListMA2 count]-1];
405             [self didChangeValueForKey:@"levelListMA2"];
406             [levelListAC2 setSelectionIndex:999];
407             
408         }else if(LL2row > 0){
409             //SC[LL1row+1] = SCNULL[0];
410             
411             [SC[LL1row+1].sName removeObjectAtIndex:LL2row];
412             [SC[LL1row+1].nameSceneStart removeObjectAtIndex:LL2row];
413             [SC[LL1row+1].nameSceneEnd removeObjectAtIndex:LL2row];
414             [SC[LL1row+1].nameMAP removeObjectAtIndex:LL2row];
415             
416             [self willChangeValueForKey:@"levelListMA2"];
417             [levelListMA2 removeObjectAtIndex:LL2row];
418             [self didChangeValueForKey:@"levelListMA2"];
419             [levelListAC2 setSelectionIndex:999];
420             
421         }else{
422             
423             //SC[LL1row+1] = SCNULL[0];
424             
425             [SC[LL1row+1].sName removeObjectAtIndex:LL2row];
426             [SC[LL1row+1].nameSceneStart removeObjectAtIndex:LL2row];
427             [SC[LL1row+1].nameSceneEnd removeObjectAtIndex:LL2row];
428             [SC[LL1row+1].nameMAP removeObjectAtIndex:LL2row];
429             
430             
431             
432             [self willChangeValueForKey:@"levelListMA2"];
433             [levelListMA2 removeObjectAtIndex:LL2row];
434             [self didChangeValueForKey:@"levelListMA2"];
435             [levelListAC2 setSelectionIndex:999];
436             
437         }
438         
439     }
440     
441     LL2row = -1;
442 }
443
444
445
446
447
448
449
450
451
452 -(IBAction)submit:(id)sender{
453     
454     NSString *directoryPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
455     [[NSFileManager defaultManager] changeCurrentDirectoryPath:directoryPath];
456
457     NSString *pathDATA = @"data/Scenario/preset.txt";
458     NSString *pathFOLDER = @"data/Scenario/img";
459     
460     NSString *fileData = @"";
461     for(int i = 1;i <= SCarray;i++){
462         if(i > 1) fileData = [fileData stringByAppendingString:@"\n"];
463         fileData = [fileData stringByAppendingFormat:@"###%@###%@\n", SC[i].name, SC[i].iName];
464         for(int k = 0;k < [SC[i].sName count];k++){
465             if(k > 0) fileData = [fileData stringByAppendingString:@"\n"];
466             fileData = [fileData stringByAppendingFormat:@"%@##%@##%@##%@",
467                         [SC[i].sName objectAtIndex:k], [SC[i].nameSceneStart objectAtIndex:k],
468                         [SC[i].nameSceneEnd objectAtIndex:k], [SC[i].nameMAP objectAtIndex:k]];
469         }
470         
471     }
472     
473     [fileData writeToFile:pathDATA atomically:YES encoding:NSUTF8StringEncoding error:nil];
474     
475     [levelWindow close];
476 }
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499 @end