cocoaTouch/GameConfigViewController.m
changeset 3513 f589230fa21b
parent 3490 016b3172b645
equal deleted inserted replaced
3512:6a8b5f313190 3513:f589230fa21b
     9 #import "GameConfigViewController.h"
     9 #import "GameConfigViewController.h"
    10 #import "SDL_uikitappdelegate.h"
    10 #import "SDL_uikitappdelegate.h"
    11 #import "CommodityFunctions.h"
    11 #import "CommodityFunctions.h"
    12 #import "MapConfigViewController.h"
    12 #import "MapConfigViewController.h"
    13 #import "TeamConfigViewController.h"
    13 #import "TeamConfigViewController.h"
       
    14 #import "SchemeWeaponConfigViewController.h"
    14 
    15 
    15 @implementation GameConfigViewController
    16 @implementation GameConfigViewController
    16 
    17 
    17 
    18 
    18 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    19 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    29         case 1:
    30         case 1:
    30             [self performSelector:@selector(startGame)
    31             [self performSelector:@selector(startGame)
    31                        withObject:nil
    32                        withObject:nil
    32                        afterDelay:0.25];
    33                        afterDelay:0.25];
    33             break;
    34             break;
    34 
    35         default:
       
    36             break;
    35     }
    37     }
    36 }
    38 }
    37 
    39 
    38 -(IBAction) segmentPressed:(id) sender {
    40 -(IBAction) segmentPressed:(id) sender {
    39     UISegmentedControl *theSegment = (UISegmentedControl *)sender;
    41     UISegmentedControl *theSegment = (UISegmentedControl *)sender;
    41     switch (theSegment.selectedSegmentIndex) {
    43     switch (theSegment.selectedSegmentIndex) {
    42         case 0:
    44         case 0:
    43             // this init here is just aestetic as this controller was already set up in viewDidLoad
    45             // this init here is just aestetic as this controller was already set up in viewDidLoad
    44             if (mapConfigViewController == nil) {
    46             if (mapConfigViewController == nil) {
    45                 mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil];
    47                 mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil];
    46                 [mapConfigViewController viewWillAppear:NO];  
       
    47             }
    48             }
    48             activeController = mapConfigViewController;
    49             activeController = mapConfigViewController;
    49             break;
    50             break;
    50         case 1:
    51         case 1:
    51             if (teamConfigViewController == nil) {
    52             if (teamConfigViewController == nil) {
    52                 teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
    53                 teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
    53                 // this message is compulsory otherwise the team table won't be loaded at all
    54                 // this message is compulsory otherwise the table won't be loaded at all
    54                 [teamConfigViewController viewWillAppear:NO];  
       
    55             }
    55             }
    56             activeController = teamConfigViewController;
    56             activeController = teamConfigViewController;
    57             break;
    57             break;
    58         case 2:
    58         case 2:
    59             
    59             if (schemeWeaponConfigViewController == nil) {
    60             break;
    60                 schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
    61     }
    61             }
    62     
    62             activeController = schemeWeaponConfigViewController;
       
    63             break;
       
    64     }
       
    65     
       
    66     // this message is compulsory otherwise the table won't be loaded at all
       
    67     [activeController viewWillAppear:NO];      
    63     [self.view addSubview:activeController.view];
    68     [self.view addSubview:activeController.view];
    64 }
    69 }
    65 
    70 
    66 -(void) startGame {
    71 -(void) startGame {
    67     // don't start playing if the preview is in progress
    72     // don't start playing if the preview is in progress
   108     NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:mapConfigViewController.seedCommand,@"seed_command",
   113     NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:mapConfigViewController.seedCommand,@"seed_command",
   109                                                                       mapConfigViewController.templateFilterCommand,@"templatefilter_command",
   114                                                                       mapConfigViewController.templateFilterCommand,@"templatefilter_command",
   110                                                                       mapConfigViewController.mapGenCommand,@"mapgen_command",
   115                                                                       mapConfigViewController.mapGenCommand,@"mapgen_command",
   111                                                                       mapConfigViewController.mazeSizeCommand,@"mazesize_command",
   116                                                                       mapConfigViewController.mazeSizeCommand,@"mazesize_command",
   112                                                                       mapConfigViewController.themeCommand,@"theme_command",
   117                                                                       mapConfigViewController.themeCommand,@"theme_command",
   113                                                                       teamConfigViewController.listOfSelectedTeams,@"teams_list",nil];
   118                                                                       teamConfigViewController.listOfSelectedTeams,@"teams_list",
       
   119                                                                       schemeWeaponConfigViewController.selectedScheme,@"scheme",
       
   120                                                                       schemeWeaponConfigViewController.selectedWeapon,@"weapon",
       
   121                                                                       nil];
   114     [dict writeToFile:GAMECONFIG_FILE() atomically:YES];
   122     [dict writeToFile:GAMECONFIG_FILE() atomically:YES];
   115     [dict release];
   123     [dict release];
   116 
   124 
   117     // finally launch game and remove this controller
   125     // finally launch game and remove this controller
   118     [[self parentViewController] dismissModalViewControllerAnimated:YES];
   126     [[self parentViewController] dismissModalViewControllerAnimated:YES];
   119     [[SDLUIKitDelegate sharedAppDelegate] startSDLgame];
   127     [[SDLUIKitDelegate sharedAppDelegate] startSDLgame];
   120 }
   128 }
   121 
   129 
   122 -(void) viewDidLoad {
   130 -(void) viewDidLoad {
   123     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   131     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   124         mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPad" bundle:nil];
   132         if (mapConfigViewController == nil)
   125         teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStylePlain];
   133             mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPad" bundle:nil];
       
   134         if (teamConfigViewController == nil)
       
   135             teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStylePlain];
   126         teamConfigViewController.view.frame = CGRectMake(0, 224, 300, 500);
   136         teamConfigViewController.view.frame = CGRectMake(0, 224, 300, 500);
   127         teamConfigViewController.view.backgroundColor = [UIColor clearColor];
   137         teamConfigViewController.view.backgroundColor = [UIColor clearColor];
   128         [mapConfigViewController.view addSubview:teamConfigViewController.view];
   138         [mapConfigViewController.view addSubview:teamConfigViewController.view];
       
   139         if (schemeWeaponConfigViewController == nil)
       
   140             schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
       
   141         schemeWeaponConfigViewController.view.frame = CGRectMake(362, 224, 300, 500);
       
   142         schemeWeaponConfigViewController.view.backgroundColor = [UIColor clearColor];
       
   143         [mapConfigViewController.view addSubview:schemeWeaponConfigViewController.view];
   129     } else
   144     } else
   130         mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil];
   145         mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil];
   131     activeController = mapConfigViewController;
   146     activeController = mapConfigViewController;
   132     
   147     
   133     [self.view addSubview:mapConfigViewController.view];
   148     [self.view addSubview:mapConfigViewController.view];
   136 }
   151 }
   137 
   152 
   138 -(void) viewWillAppear:(BOOL)animated {
   153 -(void) viewWillAppear:(BOOL)animated {
   139     [mapConfigViewController viewWillAppear:animated];
   154     [mapConfigViewController viewWillAppear:animated];
   140     [teamConfigViewController viewWillAppear:animated];
   155     [teamConfigViewController viewWillAppear:animated];
       
   156     [schemeWeaponConfigViewController viewWillAppear:animated];
   141     // ADD other controllers here
   157     // ADD other controllers here
   142      
   158      
   143     [super viewWillAppear:animated];
   159     [super viewWillAppear:animated];
   144 }
   160 }
   145 
   161 
   146 -(void) viewDidAppear:(BOOL)animated {
   162 -(void) viewDidAppear:(BOOL)animated {
   147     [mapConfigViewController viewDidAppear:animated];
   163     [mapConfigViewController viewDidAppear:animated];
   148     [teamConfigViewController viewDidAppear:animated];
   164     [teamConfigViewController viewDidAppear:animated];
       
   165     [schemeWeaponConfigViewController viewDidAppear:animated];
   149     [super viewDidAppear:animated];
   166     [super viewDidAppear:animated];
   150 }
   167 }
   151 
   168 
   152 -(void) didReceiveMemoryWarning {
   169 -(void) didReceiveMemoryWarning {
   153     // Releases the view if it doesn't have a superview.
   170     // Releases the view if it doesn't have a superview.
   155     // Release any cached data, images, etc that aren't in use.
   172     // Release any cached data, images, etc that aren't in use.
   156     if (mapConfigViewController.view.superview == nil) 
   173     if (mapConfigViewController.view.superview == nil) 
   157         mapConfigViewController = nil;
   174         mapConfigViewController = nil;
   158     if (teamConfigViewController.view.superview == nil)
   175     if (teamConfigViewController.view.superview == nil)
   159         teamConfigViewController = nil;
   176         teamConfigViewController = nil;
       
   177     if (schemeWeaponConfigViewController.view.superview == nil)
       
   178         schemeWeaponConfigViewController = nil;
   160     activeController = nil;
   179     activeController = nil;
   161     MSG_MEMCLEAN();
   180     MSG_MEMCLEAN();
   162 }
   181 }
   163 
       
   164 
   182 
   165 -(void) viewDidUnload {
   183 -(void) viewDidUnload {
   166     activeController = nil;
   184     activeController = nil;
   167     mapConfigViewController = nil;
   185     mapConfigViewController = nil;
   168     teamConfigViewController = nil;
   186     teamConfigViewController = nil;
       
   187     schemeWeaponConfigViewController = nil;
   169     [super viewDidUnload];
   188     [super viewDidUnload];
   170     MSG_DIDUNLOAD();
   189     MSG_DIDUNLOAD();
   171 }
   190 }
   172 
       
   173 
   191 
   174 -(void) dealloc {
   192 -(void) dealloc {
   175     [activeController release];
   193     [activeController release];
   176     [mapConfigViewController release];
   194     [mapConfigViewController release];
   177     [teamConfigViewController release];
   195     [teamConfigViewController release];
       
   196     [schemeWeaponConfigViewController release];
   178     [super dealloc];
   197     [super dealloc];
   179 }
   198 }
   180 
   199 
   181 @end
   200 @end