author | nemo |
Fri, 02 Sep 2011 19:06:05 -0400 | |
changeset 5744 | 746de1d303d2 |
parent 5208 | 878e551f0b4a |
child 5976 | 306cedbeb213 |
permissions | -rw-r--r-- |
4757 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
4976 | 3 |
* Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com> |
4757 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
17 |
* |
|
18 |
* File created on 30/12/2010. |
|
19 |
*/ |
|
20 |
||
21 |
||
22 |
#import "StatsPageViewController.h" |
|
23 |
#import "CommodityFunctions.h" |
|
24 |
||
25 |
@implementation StatsPageViewController |
|
4760 | 26 |
@synthesize statsArray; |
4757 | 27 |
|
28 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
29 |
return rotationManager(interfaceOrientation); |
|
30 |
} |
|
31 |
||
4766 | 32 |
-(void) viewDidLoad { |
33 |
if ([self.tableView respondsToSelector:@selector(setBackgroundView:)]) |
|
34 |
self.tableView.backgroundView = nil; |
|
35 |
||
36 |
NSString *imgName; |
|
37 |
if (IS_IPAD()) |
|
38 |
imgName = @"mediumBackground~ipad.png"; |
|
39 |
else |
|
40 |
imgName = @"smallerBackground~iphone.png"; |
|
41 |
||
42 |
if ([self.tableView respondsToSelector:@selector(setBackgroundView:)]) { |
|
43 |
UIImage *backgroundImage = [[UIImage alloc] initWithContentsOfFile:imgName]; |
|
44 |
UIImageView *background = [[UIImageView alloc] initWithImage:backgroundImage]; |
|
45 |
[backgroundImage release]; |
|
46 |
[self.tableView setBackgroundView:background]; |
|
47 |
[background release]; |
|
48 |
} else |
|
49 |
self.view.backgroundColor = [UIColor blackColor]; |
|
50 |
||
51 |
self.tableView.separatorColor = UICOLOR_HW_YELLOW_BODER; |
|
52 |
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
|
53 |
||
54 |
[super viewDidLoad]; |
|
55 |
} |
|
56 |
||
4757 | 57 |
#pragma mark - |
58 |
#pragma mark Table view data source |
|
59 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
4856 | 60 |
return 4; |
4757 | 61 |
} |
62 |
||
63 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
4856 | 64 |
if (section == 0 || section == 3) |
4760 | 65 |
return 1; |
4856 | 66 |
else if (section == 1) |
67 |
return [[self.statsArray objectAtIndex:0] count]; |
|
4757 | 68 |
else |
4856 | 69 |
return [self.statsArray count] - 2; |
4757 | 70 |
} |
71 |
||
72 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
73 |
static NSString *CellIdentifier0 = @"Cell0"; |
|
4760 | 74 |
NSInteger section = [indexPath section]; |
75 |
NSInteger row = [indexPath row]; |
|
4856 | 76 |
NSString *imgString = @""; |
4757 | 77 |
|
78 |
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
|
79 |
if (cell == nil) |
|
80 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease]; |
|
81 |
||
4856 | 82 |
if (section == 0) { // winning team |
83 |
imgString = @"StatsStar"; |
|
84 |
cell.textLabel.text = [self.statsArray objectAtIndex:1]; |
|
4766 | 85 |
cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT; |
4856 | 86 |
} else if (section == 1) { // teams ranking |
87 |
// color, # kills, teamname |
|
88 |
NSArray *info = [[[self.statsArray objectAtIndex:0] objectAtIndex:row] componentsSeparatedByString:@" "]; |
|
89 |
NSUInteger color = [[info objectAtIndex:0] intValue]; |
|
90 |
cell.textLabel.textColor = [UIColor colorWithRed:((color >> 16) & 0xFF)/255.0f |
|
91 |
green:((color >> 8) & 0xFF)/255.0f |
|
92 |
blue:(color & 0xFF)/255.0f |
|
93 |
alpha:1.0f]; |
|
94 |
cell.textLabel.text = [NSString stringWithFormat:@"%d. %@ (%@ kills)", row+1, [info objectAtIndex:2], [info objectAtIndex:1]]; |
|
4860 | 95 |
imgString = [NSString stringWithFormat:@"StatsMedal%d",row+1]; |
4856 | 96 |
} else if (section == 2) { // general info |
97 |
imgString = @"iconDamage"; |
|
98 |
cell.textLabel.text = [self.statsArray objectAtIndex:row + 2]; |
|
4766 | 99 |
cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT; |
4856 | 100 |
} else { // exit button |
4763
c228a4841e3f
unify stats display on ipad and non-ipad and on saved and normal games
koda
parents:
4760
diff
changeset
|
101 |
cell.textLabel.text = NSLocalizedString(@"Done",@""); |
4766 | 102 |
cell.textLabel.textColor = [UIColor whiteColor]; |
4856 | 103 |
cell.accessoryView = nil; |
104 |
cell.imageView.image = nil; |
|
4757 | 105 |
} |
4856 | 106 |
|
107 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.png",BTN_DIRECTORY(),imgString]]; |
|
108 |
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; |
|
109 |
cell.imageView.image = img; |
|
110 |
[img release]; |
|
111 |
cell.accessoryView = imgView; |
|
112 |
[imgView release]; |
|
113 |
||
114 |
cell.textLabel.textAlignment = UITextAlignmentCenter; |
|
4819 | 115 |
cell.textLabel.adjustsFontSizeToFitWidth = YES; |
4766 | 116 |
cell.backgroundColor = [UIColor blackColor]; |
117 |
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
|
4757 | 118 |
|
119 |
return cell; |
|
120 |
} |
|
121 |
||
4766 | 122 |
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { |
123 |
return 160; |
|
124 |
} |
|
125 |
||
126 |
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { |
|
127 |
if (section == 0) { |
|
128 |
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 160)]; |
|
129 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:@"smallerTitle.png"]; |
|
130 |
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; |
|
131 |
[img release]; |
|
132 |
imgView.center = CGPointMake(self.tableView.frame.size.height/2, 160/2); |
|
133 |
[header addSubview:imgView]; |
|
134 |
[imgView release]; |
|
135 |
||
136 |
return [header autorelease]; |
|
137 |
} else |
|
138 |
return nil; |
|
139 |
} |
|
140 |
||
4757 | 141 |
#pragma mark - |
142 |
#pragma mark Table view delegate |
|
143 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
4934 | 144 |
if ([indexPath section] == 3) { |
145 |
playSound(@"backSound"); |
|
4757 | 146 |
[self dismissModalViewControllerAnimated:YES]; |
4934 | 147 |
} |
4757 | 148 |
} |
149 |
||
150 |
#pragma mark - |
|
151 |
#pragma mark Memory management |
|
152 |
-(void) didReceiveMemoryWarning { |
|
153 |
// Releases the view if it doesn't have a superview. |
|
154 |
[super didReceiveMemoryWarning]; |
|
4760 | 155 |
self.statsArray = nil; |
4757 | 156 |
} |
157 |
||
158 |
-(void) dealloc { |
|
5208 | 159 |
releaseAndNil(statsArray); |
4757 | 160 |
[super dealloc]; |
161 |
} |
|
162 |
||
163 |
||
164 |
@end |
|
165 |