diff -r b4c31cea013e -r 222b8016c773 project_files/HedgewarsMobile/Classes/SupportViewController.m --- a/project_files/HedgewarsMobile/Classes/SupportViewController.m Thu Nov 04 18:19:28 2010 -0400 +++ b/project_files/HedgewarsMobile/Classes/SupportViewController.m Fri Nov 05 00:38:30 2010 +0100 @@ -23,30 +23,150 @@ #import "CommodityFunctions.h" @implementation SupportViewController +@synthesize waysToSupport; --(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { +-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return rotationManager(interfaceOrientation); } --(void) didReceiveMemoryWarning { - // Releases the view if it doesn't have a superview. +#pragma mark - +#pragma mark View lifecycle +-(void) viewDidLoad { + [super viewDidLoad]; + + NSArray *array = [[NSArray alloc] initWithObjects: + NSLocalizedString(@"Leave a positive review on iTunes!",@""), + NSLocalizedString(@"Join us on Facebook",@""), + NSLocalizedString(@"Follow on Twitter",@""), + NSLocalizedString(@"Visit website",@""), + nil]; + self.waysToSupport = array; + [array release]; + + self.tableView.rowHeight = 50; +} + +#pragma mark - +#pragma mark Table view data source +-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 2; +} + +-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + if (section == 0) + return 1; + else + return [self.waysToSupport count] - 1; +} + +-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + static NSString *CellIdentifier = @"Cell"; + NSInteger row = [indexPath row]; + NSInteger section = [indexPath section]; + + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; + if (cell == nil) + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; + + NSString *rowString = [self.waysToSupport objectAtIndex:(row + section)]; + cell.textLabel.text = rowString; + + if (section == 0) { + cell.textLabel.textAlignment = UITextAlignmentCenter; + cell.imageView.image = nil; + } else { + cell.textLabel.textAlignment = UITextAlignmentLeft; + NSString *imgString = nil; + switch (row) { + case 0: + imgString = @"fb.png"; + break; + case 1: + imgString = @"tw.png"; + break; + case 2: + imgString = @"Icon-Small.png"; + break; + default: + DLog(@"No way"); + break; + } + + UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgString]; + cell.imageView.image = img; + [img release]; + } + + return cell; +} + +#pragma mark - +#pragma mark Table view delegate +-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + NSString *urlString = nil; + if ([indexPath section] == 0) + urlString = @"http://itunes.apple.com/us/app/hedgewars/id391234866?affC=QQABAAAAHgAFasEiWjVwUGZOc3k1VGctQkRJazlacXhUclpBTVpiU2xteVdfUQ%3D%3D#&mt=8"; + else + switch ([indexPath row]) { + case 0: + urlString = @"http://www.facebook.com/Hedgewars"; + break; + case 1: + urlString = @"http://twitter.com/hedgewars"; + break; + case 2: + urlString = @"http://www.hedgewars.org"; + break; + default: + DLog(@"No way"); + break; + } + [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]]; +} + +-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger) section { + if (section == 1) { + UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 240)]; + UIImage *img = [[UIImage alloc] initWithContentsOfFile:@"surprise.png"]; + UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; + [img release]; + imgView.center = CGPointMake(self.tableView.frame.size.width/2, 120); + [footer addSubview:imgView]; + [imgView release]; + + UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 20)]; + label.textAlignment = UITextAlignmentCenter; + label.text = @" ♥ THANK YOU ♥ "; + label.backgroundColor = [UIColor clearColor]; + label.center = CGPointMake(self.tableView.frame.size.width/2, 250); + [footer addSubview:label]; + [label release]; + + return [footer autorelease]; + } else + return nil; +} + +-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { + // image height + label height + return 265; +} + +#pragma mark - +#pragma mark Memory management +-(void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; - // Release any cached data, images, etc that aren't in use. } -(void) viewDidUnload { + self.waysToSupport = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - // Release any retained subviews of the main view. - // e.g. self.myOutlet = nil; } -(void) dealloc { + [self.waysToSupport release]; [super dealloc]; } --(IBAction) buttonPressed:(id) sender { - NSString *reviewURL = @"http://itunes.apple.com/us/app/hedgewars/id391234866?affC=QQABAAAAHgAFasEiWjVwUGZOc3k1VGctQkRJazlacXhUclpBTVpiU2xteVdfUQ%3D%3D#&mt=8"; - [[UIApplication sharedApplication] openURL:[NSURL URLWithString:reviewURL]]; -} - @end