project_files/HedgewarsMobile/Classes/MissionTrainingViewController.m
changeset 6084 e692c0348e74
parent 6083 72c882c0fd0f
child 6094 16b12a6417d1
equal deleted inserted replaced
6083:72c882c0fd0f 6084:e692c0348e74
    21 #import "MissionTrainingViewController.h"
    21 #import "MissionTrainingViewController.h"
    22 #import <QuartzCore/QuartzCore.h>
    22 #import <QuartzCore/QuartzCore.h>
    23 #import "GameInterfaceBridge.h"
    23 #import "GameInterfaceBridge.h"
    24 
    24 
    25 @implementation MissionTrainingViewController
    25 @implementation MissionTrainingViewController
    26 @synthesize listOfMissions, previewImage, tableView, descriptionLabel, missionFile;
    26 @synthesize listOfMissions, previewImage, tableView, descriptionLabel, missionName;
    27 
    27 
    28 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    28 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    29     return rotationManager(interfaceOrientation);
    29     return rotationManager(interfaceOrientation);
    30 }
    30 }
    31 
    31 
    32 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    32 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    33 -(void) viewDidLoad {
    33 -(void) viewDidLoad {
    34     srand(time(NULL));
       
    35 
       
    36     NSString *imgName = (IS_IPAD()) ? @"mediumBackground~ipad.png" : @"smallerBackground~iphone.png";
    34     NSString *imgName = (IS_IPAD()) ? @"mediumBackground~ipad.png" : @"smallerBackground~iphone.png";
    37     UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgName];
    35     UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgName];
    38     self.view.backgroundColor = [UIColor colorWithPatternImage:img];
    36     self.view.backgroundColor = [UIColor colorWithPatternImage:img];
    39     [img release];
    37     [img release];
    40     
    38     
    69 
    67 
    70     if (button.tag == 0) {
    68     if (button.tag == 0) {
    71         [AudioManagerController playBackSound];
    69         [AudioManagerController playBackSound];
    72         [[self parentViewController] dismissModalViewControllerAnimated:YES];
    70         [[self parentViewController] dismissModalViewControllerAnimated:YES];
    73     } else {
    71     } else {
    74 /*        GameInterfaceBridge *bridge = [[GameInterfaceBridge alloc] initWithController:self];
    72         GameInterfaceBridge *bridge = [[GameInterfaceBridge alloc] initWithController:self];
    75         [bridge startMissionGame:self.missionFile];
    73         [bridge startMissionGame:self.missionName];
    76         [bridge release];*/
    74         [bridge release];
    77     }
    75     }
    78 }
    76 }
    79 
    77 
    80 #pragma mark Table view data source
    78 #pragma mark Table view data source
    81 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    79 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
   103 }
   101 }
   104 
   102 
   105 #pragma mark -
   103 #pragma mark -
   106 #pragma mark Table view delegate
   104 #pragma mark Table view delegate
   107 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   105 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   108     NSString *missionName = [[self.listOfMissions objectAtIndex:[indexPath row]] stringByDeletingPathExtension];
   106     self.missionName = [[self.listOfMissions objectAtIndex:[indexPath row]] stringByDeletingPathExtension];
   109     NSString *filePath = [[NSString alloc] initWithFormat:@"%@/Missions/Training/%@@2x.png",GRAPHICS_DIRECTORY(),missionName];
   107     NSString *filePath = [[NSString alloc] initWithFormat:@"%@/Missions/Training/%@@2x.png",GRAPHICS_DIRECTORY(),self.missionName];
   110     UIImage *img = [[UIImage alloc] initWithContentsOfFile:filePath];
   108     UIImage *img = [[UIImage alloc] initWithContentsOfFile:filePath];
   111     [filePath release];
   109     [filePath release];
   112     [self.previewImage setImage:img];
   110     [self.previewImage setImage:img];
   113     [img release];
   111     [img release];
   114 
   112 
   122         if ([str hasPrefix:missionName]) {
   120         if ([str hasPrefix:missionName]) {
   123             NSArray *descriptionText = [str componentsSeparatedByString:@"\""];
   121             NSArray *descriptionText = [str componentsSeparatedByString:@"\""];
   124             self.descriptionLabel.text = [descriptionText objectAtIndex:1];
   122             self.descriptionLabel.text = [descriptionText objectAtIndex:1];
   125         }
   123         }
   126     }
   124     }
   127 
       
   128     NSString *missionPath = [[NSString alloc] initWithFormat:@"%@/%@.lua",TRAININGS_DIRECTORY(),missionName];
       
   129     self.missionFile = missionPath;
       
   130     [missionPath release];
       
   131 }
   125 }
   132 
   126 
   133 #pragma mark -
   127 #pragma mark -
   134 #pragma mark Memory management
   128 #pragma mark Memory management
   135 -(void) didReceiveMemoryWarning {
   129 -(void) didReceiveMemoryWarning {
   136     previewImage = nil;
   130     previewImage = nil;
   137     missionFile = nil;
   131     missionName = nil;
   138     [super didReceiveMemoryWarning];
   132     [super didReceiveMemoryWarning];
   139 }
   133 }
   140 
   134 
   141 -(void) viewDidUnload {
   135 -(void) viewDidUnload {
   142     self.listOfMissions = nil;
   136     self.listOfMissions = nil;
   143     self.previewImage = nil;
   137     self.previewImage = nil;
   144     self.tableView = nil;
   138     self.tableView = nil;
   145     self.descriptionLabel = nil;
   139     self.descriptionLabel = nil;
   146     self.missionFile = nil;
   140     self.missionName = nil;
   147     MSG_DIDUNLOAD();
   141     MSG_DIDUNLOAD();
   148     [super viewDidUnload];
   142     [super viewDidUnload];
   149 }
   143 }
   150 
   144 
   151 
   145 
   152 -(void) dealloc {
   146 -(void) dealloc {
   153     releaseAndNil(listOfMissions);
   147     releaseAndNil(listOfMissions);
   154     releaseAndNil(previewImage);
   148     releaseAndNil(previewImage);
   155     releaseAndNil(tableView);
   149     releaseAndNil(tableView);
   156     releaseAndNil(descriptionLabel);
   150     releaseAndNil(descriptionLabel);
   157     releaseAndNil(missionFile);
   151     releaseAndNil(missionName);
   158     [super dealloc];
   152     [super dealloc];
   159 }
   153 }
   160 
   154 
   161 
   155 
   162 @end
   156 @end