// // LevelList.m // Awars III // // Created by 桐谷 諭史 on 2015/08/31. // Copyright (c) 2015年 Killery. All rights reserved. // #import "LevelList.h" @implementation LevelList -(void)awakeFromNib{ [levelListTV1 setTarget:self]; [levelListTV1 setAction:@selector(clickLL1:)]; [levelListTV2 setTarget:self]; [levelListTV2 setAction:@selector(clickLL2:)]; } -(id)init{ levelTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(EventLoop:) userInfo:nil repeats:YES ]; levelListMA1 = [NSMutableArray new]; levelListMA2 = [NSMutableArray new]; levelListMA3 = [NSMutableArray new]; [self initLevelTitleList]; return self; } -(void)EventLoop:(NSTimer*)time{ if(SCinputEndFlag){ [self initLevelTitleList]; SCinputEndFlag = false; } if([levelListMA1 count] > 0 && LL1row >=0){ SC[LL1row+1].name = [[[levelListMA1 objectAtIndex:LL1row] valueForKey:@"name"] retain]; SC[LL1row+1].iName = [[[levelListMA1 objectAtIndex:LL1row] valueForKey:@"img"] retain]; } if([levelListMA2 count] >0 && LL2row >= 0){ NSString *string1 = [[[levelListMA2 objectAtIndex:LL2row] valueForKeyPath:@"name"] retain]; NSString *string2 = [[[levelListMA2 objectAtIndex:LL2row] valueForKeyPath:@"op"] retain]; NSString *string3 = [[[levelListMA2 objectAtIndex:LL2row] valueForKeyPath:@"ed"] retain]; NSString *string4 = [[[levelListMA2 objectAtIndex:LL2row] valueForKeyPath:@"map"] retain]; [SC[LL1row+1].sName replaceObjectAtIndex:LL2row withObject:string1]; [SC[LL1row+1].nameSceneStart replaceObjectAtIndex:LL2row withObject:string2]; [SC[LL1row+1].nameSceneEnd replaceObjectAtIndex:LL2row withObject:string3]; [SC[LL1row+1].nameMAP replaceObjectAtIndex:LL2row withObject:string4]; } } -(void)initLevelTitleList{ [self willChangeValueForKey:@"levelListMA1"]; [levelListMA1 removeAllObjects]; [self didChangeValueForKey:@"levelListMA1"]; for(int i = 1;i <= SCarray;i++){ NSMutableDictionary* dict = [NSMutableDictionary new]; NSString *string = SC[i].iName; [dict setValue:[NSString stringWithFormat:@"%@", SC[i].name] forKey:@"name"]; [dict setValue:[NSString stringWithFormat:@"%@", string] forKey:@"img"]; [self willChangeValueForKey:@"levelListMA1"]; [levelListMA1 addObject:dict]; [self didChangeValueForKey:@"levelListMA1"]; } NSString *directoryPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent]; [[NSFileManager defaultManager] changeCurrentDirectoryPath:directoryPath]; NSArray *Farray; NSString *filePath = @"Map"; Farray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:filePath error:nil]; fileNumb = (int)[Farray count]; for (int i = 1; i < fileNumb;i++) { MF[i].fileName = [[Farray objectAtIndex:i] retain]; } [self willChangeValueForKey:@"levelListMA3"]; [levelListMA3 removeAllObjects]; [self didChangeValueForKey:@"levelListMA3"]; for(int i = 1; i < fileNumb;i++){ NSMutableDictionary* dict = [NSMutableDictionary new]; [dict setValue:[NSString stringWithFormat:@"%@", MF[i].fileName] forKey:@"name"]; [self willChangeValueForKey:@"levelListMA3"]; [levelListMA3 addObject:dict]; [self didChangeValueForKey:@"levelListMA3"]; } } -(void)clickLL1:(id)sender{ LL1row = (int)[levelListTV1 clickedRow]; [self willChangeValueForKey:@"levelListMA2"]; [levelListMA2 removeAllObjects]; [self didChangeValueForKey:@"levelListMA2"]; if([levelListTV1 clickedRow] >= 0){ for(int i = 0;i < [SC[LL1row+1].nameMAP count];i++){ NSMutableDictionary* dict = [NSMutableDictionary new]; [dict setValue:[NSString stringWithFormat:@"%@",[SC[LL1row+1].sName objectAtIndex:i]] forKey:@"name"]; [dict setValue:[NSString stringWithFormat:@"%@",[SC[LL1row+1].nameSceneStart objectAtIndex:i]] forKey:@"op"]; [dict setValue:[NSString stringWithFormat:@"%@",[SC[LL1row+1].nameSceneEnd objectAtIndex:i]] forKey:@"ed"]; [dict setValue:[NSString stringWithFormat:@"%@",[SC[LL1row+1].nameMAP objectAtIndex:i]] forKey:@"map"]; [self willChangeValueForKey:@"levelListMA2"]; [levelListMA2 addObject:dict]; [self didChangeValueForKey:@"levelListMA2"]; } } } -(void)clickLL2:(id)sender{ LL2row = (int)[levelListTV2 clickedRow]; } -(IBAction)levelEditor:(id)sender{ [levelWindow makeKeyAndOrderFront:nil]; } -(IBAction)ins1:(id)sender{ if(1){ NSMutableDictionary *dict = [NSMutableDictionary new]; if([levelListMA1 count] == 0){ [self SCinsert:LL1row]; SC[1].name = [@"新規タイトル" retain]; [dict setValue:[NSString stringWithFormat:@"%@", SC[1].name] forKey:@"name"]; [self willChangeValueForKey:@"levelListMA1"]; [levelListMA1 addObject:dict]; [self didChangeValueForKey:@"levelListMA1"]; [levelListAC1 setSelectionIndex:999]; }else if(LL1row == -1){ [self SCinsert:(int)[levelListMA1 count]+1]; SC[[levelListMA1 count]+1].name = [@"新規タイトル" retain]; [dict setValue:[NSString stringWithFormat:@"%@", SC[[levelListMA1 count]+1].name] forKey:@"name"]; [self willChangeValueForKey:@"levelListMA1"]; [levelListMA1 addObject:dict]; [self didChangeValueForKey:@"levelListMA1"]; [levelListAC1 setSelectionIndex:999]; }else if(LL1row > 0){ [self SCinsert:LL1row+1]; SC[LL1row+1].name = [@"新規タイトル" retain]; [dict setValue:[NSString stringWithFormat:@"%@", SC[LL1row+1].name] forKey:@"name"]; [self willChangeValueForKey:@"levelListMA1"]; [levelListMA1 insertObject:dict atIndex:LL1row]; [self didChangeValueForKey:@"levelListMA1"]; [levelListAC1 setSelectionIndex:999]; }else{ [self SCinsert:LL1row+1]; SC[LL1row+1].name = [@"新規タイトル" retain]; [dict setValue:[NSString stringWithFormat:@"%@", SC[LL1row+1].name] forKey:@"name"]; [self willChangeValueForKey:@"levelListMA1"]; [levelListMA1 insertObject:dict atIndex:LL1row]; [self didChangeValueForKey:@"levelListMA1"]; [levelListAC1 setSelectionIndex:999]; } } } void insertSC(SCENARIO *ptr, SCENARIO *last, int val) { for(SCENARIO *dst = last; --dst >= ptr; ){ *(dst + 1) = *dst; // 要素をひとつ後ろにずらす } ptr->name = [@"新規タイトル" retain]; ptr->nameSceneStart = NULL; ptr->nameSceneEnd = NULL; ptr->nameMAP = NULL; //NSLog(@"%p,%p",SC, ptr); } -(void)SCinsert:(int)row{ insertSC(&SC[row], &SC[SCarray+1], row);// [2] の位置に 2 を挿入。最後の 5 は破棄 SCarray++; } void deleteSC(SCENARIO *ptr, SCENARIO *last) { while ( ++ptr < last ) *(ptr - 1) = *ptr;// 要素をひとつ前にずらす } -(void)SCdelete:(int)row{ deleteSC(&SC[row], &SC[SCarray+1]);// [2] の要素を削除。最後の 5 はそのまま SCarray--; } -(IBAction)del1:(id)sender{ SCENARIO SCNULL[0]; if(1){ if([levelListMA1 count] == 0){ return; }else if(LL1row == -1){ if([levelListMA1 count] > 1) [self SCdelete:(int)[levelListMA1 count]]; else [self SCdelete:LL1row+1]; [self willChangeValueForKey:@"levelListMA1"]; [levelListMA1 removeObjectAtIndex:[levelListMA1 count]-1]; [self didChangeValueForKey:@"levelListMA1"]; [levelListAC1 setSelectionIndex:999]; }else if(LL1row > 0){ [self SCdelete:LL1row+1]; [self willChangeValueForKey:@"levelListMA1"]; [levelListMA1 removeObjectAtIndex:LL1row]; [self didChangeValueForKey:@"levelListMA1"]; [levelListAC1 setSelectionIndex:999]; }else{ [self SCdelete:LL1row]; [self willChangeValueForKey:@"levelListMA1"]; [levelListMA1 removeObjectAtIndex:LL1row]; [self didChangeValueForKey:@"levelListMA1"]; [levelListAC1 setSelectionIndex:999]; } } LL1row = -1; } -(IBAction)ins2:(id)sender{ if(1){ NSMutableDictionary *dict = [NSMutableDictionary new]; if([levelListMA2 count] == 0){ SC[LL1row+1].sName = [NSMutableArray new]; SC[LL1row+1].nameSceneStart = [NSMutableArray new]; SC[LL1row+1].nameSceneEnd = [NSMutableArray new]; SC[LL1row+1].nameMAP = [NSMutableArray new]; NSString *howCouldYou = [@"NULL" retain]; [SC[LL1row+1].sName addObject:howCouldYou]; [SC[LL1row+1].nameSceneStart addObject:howCouldYou]; [SC[LL1row+1].nameSceneEnd addObject:howCouldYou]; [SC[LL1row+1].nameMAP addObject:howCouldYou]; [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"name"]; [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"op"]; [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"ed"]; [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"map"]; [self willChangeValueForKey:@"levelListMA2"]; [levelListMA2 addObject:dict]; [self didChangeValueForKey:@"levelListMA2"]; [levelListAC2 setSelectionIndex:999]; }else if(LL2row == -1){ NSString *just = [@"NULL" retain]; [SC[LL1row+1].sName addObject:just]; [SC[LL1row+1].nameSceneStart addObject:just]; [SC[LL1row+1].nameSceneEnd addObject:just]; [SC[LL1row+1].nameMAP addObject:just]; [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"name"]; [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"op"]; [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"ed"]; [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"map"]; [self willChangeValueForKey:@"levelListMA2"]; [levelListMA2 addObject:dict]; [self didChangeValueForKey:@"levelListMA2"]; [levelListAC2 setSelectionIndex:999]; }else if(LL2row > 0){ NSString *just = [@"NULL" retain]; [SC[LL1row+1].sName insertObject:just atIndex:LL2row]; [SC[LL1row+1].nameSceneStart insertObject:just atIndex:LL2row]; [SC[LL1row+1].nameSceneEnd insertObject:just atIndex:LL2row]; [SC[LL1row+1].nameMAP insertObject:just atIndex:LL2row]; [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"name"]; [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"op"]; [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"ed"]; [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"map"]; [self willChangeValueForKey:@"levelListMA2"]; [levelListMA2 insertObject:dict atIndex:LL2row]; [self didChangeValueForKey:@"levelListMA2"]; [levelListAC2 setSelectionIndex:999]; }else{ NSString *just = [@"NULL" retain]; [SC[LL1row+1].sName insertObject:just atIndex:LL2row]; [SC[LL1row+1].nameSceneStart insertObject:just atIndex:LL2row]; [SC[LL1row+1].nameSceneEnd insertObject:just atIndex:LL2row]; [SC[LL1row+1].nameMAP insertObject:just atIndex:LL2row]; [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"name"]; [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"op"]; [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"ed"]; [dict setValue:[NSString stringWithFormat:@"NULL"] forKey:@"map"]; [self willChangeValueForKey:@"levelListMA2"]; [levelListMA2 insertObject:dict atIndex:LL2row]; [self didChangeValueForKey:@"levelListMA2"]; [levelListAC2 setSelectionIndex:999]; } } } -(IBAction)del2:(id)sender{ SCENARIO SCNULL[0]; if(1){ if([levelListMA2 count] == 0){ return; }else if(LL2row == -1){ if([levelListMA2 count] > 1) { [SC[[levelListMA2 count]].sName removeObjectAtIndex:[levelListMA2 count]-1]; [SC[[levelListMA2 count]].nameSceneStart removeObjectAtIndex:[levelListMA2 count]-1]; [SC[[levelListMA2 count]].nameSceneEnd removeObjectAtIndex:[levelListMA2 count]-1]; [SC[[levelListMA2 count]].nameMAP removeObjectAtIndex:[levelListMA2 count]-1]; } else{ [SC[1].sName removeObjectAtIndex:[levelListMA2 count]-1]; [SC[1].nameSceneStart removeObjectAtIndex:[levelListMA2 count]-1]; [SC[1].nameSceneEnd removeObjectAtIndex:[levelListMA2 count]-1]; [SC[1].nameMAP removeObjectAtIndex:[levelListMA2 count]-1]; } [self willChangeValueForKey:@"levelListMA2"]; [levelListMA2 removeObjectAtIndex:[levelListMA2 count]-1]; [self didChangeValueForKey:@"levelListMA2"]; [levelListAC2 setSelectionIndex:999]; }else if(LL2row > 0){ //SC[LL1row+1] = SCNULL[0]; [SC[LL1row+1].sName removeObjectAtIndex:LL2row]; [SC[LL1row+1].nameSceneStart removeObjectAtIndex:LL2row]; [SC[LL1row+1].nameSceneEnd removeObjectAtIndex:LL2row]; [SC[LL1row+1].nameMAP removeObjectAtIndex:LL2row]; [self willChangeValueForKey:@"levelListMA2"]; [levelListMA2 removeObjectAtIndex:LL2row]; [self didChangeValueForKey:@"levelListMA2"]; [levelListAC2 setSelectionIndex:999]; }else{ //SC[LL1row+1] = SCNULL[0]; [SC[LL1row+1].sName removeObjectAtIndex:LL2row]; [SC[LL1row+1].nameSceneStart removeObjectAtIndex:LL2row]; [SC[LL1row+1].nameSceneEnd removeObjectAtIndex:LL2row]; [SC[LL1row+1].nameMAP removeObjectAtIndex:LL2row]; [self willChangeValueForKey:@"levelListMA2"]; [levelListMA2 removeObjectAtIndex:LL2row]; [self didChangeValueForKey:@"levelListMA2"]; [levelListAC2 setSelectionIndex:999]; } } LL2row = -1; } -(IBAction)submit:(id)sender{ NSString *directoryPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent]; [[NSFileManager defaultManager] changeCurrentDirectoryPath:directoryPath]; NSString *pathDATA = @"data/Scenario/preset.txt"; NSString *pathFOLDER = @"data/Scenario/img"; NSString *fileData = @""; for(int i = 1;i <= SCarray;i++){ if(i > 1) fileData = [fileData stringByAppendingString:@"\n"]; fileData = [fileData stringByAppendingFormat:@"###%@###%@\n", SC[i].name, SC[i].iName]; for(int k = 0;k < [SC[i].sName count];k++){ if(k > 0) fileData = [fileData stringByAppendingString:@"\n"]; fileData = [fileData stringByAppendingFormat:@"%@##%@##%@##%@", [SC[i].sName objectAtIndex:k], [SC[i].nameSceneStart objectAtIndex:k], [SC[i].nameSceneEnd objectAtIndex:k], [SC[i].nameMAP objectAtIndex:k]]; } } [fileData writeToFile:pathDATA atomically:YES encoding:NSUTF8StringEncoding error:nil]; [levelWindow close]; } @end