author | koda |
Thu, 22 Sep 2011 15:30:40 +0200 | |
changeset 5992 | a311b8461ec9 |
parent 5982 | 283be2ca54a7 |
child 6000 | dbcebcd3d79f |
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]; |
|
5976
306cedbeb213
fixed several 'retina display' images and added a bunch more (though just from upscaling the normal ones; might be nice to have 'em redrawn at a real higher resolution)
koda
parents:
5208
diff
changeset
|
76 |
NSString *imgName = @""; |
5982
283be2ca54a7
mad several updates to the resource copying phase in the ios project file, changed paths of some images and added some smaller forts version
koda
parents:
5976
diff
changeset
|
77 |
NSString *imgPath = ICONS_DIRECTORY(); |
4757 | 78 |
|
79 |
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
|
80 |
if (cell == nil) |
|
81 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease]; |
|
82 |
||
4856 | 83 |
if (section == 0) { // winning team |
5976
306cedbeb213
fixed several 'retina display' images and added a bunch more (though just from upscaling the normal ones; might be nice to have 'em redrawn at a real higher resolution)
koda
parents:
5208
diff
changeset
|
84 |
imgName = @"star"; |
306cedbeb213
fixed several 'retina display' images and added a bunch more (though just from upscaling the normal ones; might be nice to have 'em redrawn at a real higher resolution)
koda
parents:
5208
diff
changeset
|
85 |
imgPath = [[NSBundle mainBundle] resourcePath]; |
4856 | 86 |
cell.textLabel.text = [self.statsArray objectAtIndex:1]; |
4766 | 87 |
cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT; |
4856 | 88 |
} else if (section == 1) { // teams ranking |
89 |
// color, # kills, teamname |
|
90 |
NSArray *info = [[[self.statsArray objectAtIndex:0] objectAtIndex:row] componentsSeparatedByString:@" "]; |
|
91 |
NSUInteger color = [[info objectAtIndex:0] intValue]; |
|
92 |
cell.textLabel.textColor = [UIColor colorWithRed:((color >> 16) & 0xFF)/255.0f |
|
93 |
green:((color >> 8) & 0xFF)/255.0f |
|
94 |
blue:(color & 0xFF)/255.0f |
|
95 |
alpha:1.0f]; |
|
96 |
cell.textLabel.text = [NSString stringWithFormat:@"%d. %@ (%@ kills)", row+1, [info objectAtIndex:2], [info objectAtIndex:1]]; |
|
5976
306cedbeb213
fixed several 'retina display' images and added a bunch more (though just from upscaling the normal ones; might be nice to have 'em redrawn at a real higher resolution)
koda
parents:
5208
diff
changeset
|
97 |
imgName = [NSString stringWithFormat:@"StatsMedal%d",row+1]; |
4856 | 98 |
} else if (section == 2) { // general info |
5976
306cedbeb213
fixed several 'retina display' images and added a bunch more (though just from upscaling the normal ones; might be nice to have 'em redrawn at a real higher resolution)
koda
parents:
5208
diff
changeset
|
99 |
imgName = @"iconDamage"; |
4856 | 100 |
cell.textLabel.text = [self.statsArray objectAtIndex:row + 2]; |
4766 | 101 |
cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT; |
4856 | 102 |
} else { // exit button |
4763
c228a4841e3f
unify stats display on ipad and non-ipad and on saved and normal games
koda
parents:
4760
diff
changeset
|
103 |
cell.textLabel.text = NSLocalizedString(@"Done",@""); |
4766 | 104 |
cell.textLabel.textColor = [UIColor whiteColor]; |
4856 | 105 |
cell.accessoryView = nil; |
106 |
cell.imageView.image = nil; |
|
4757 | 107 |
} |
4856 | 108 |
|
5976
306cedbeb213
fixed several 'retina display' images and added a bunch more (though just from upscaling the normal ones; might be nice to have 'em redrawn at a real higher resolution)
koda
parents:
5208
diff
changeset
|
109 |
NSString *imgString = [[NSString alloc] initWithFormat:@"%@/%@.png",imgPath,imgName]; |
306cedbeb213
fixed several 'retina display' images and added a bunch more (though just from upscaling the normal ones; might be nice to have 'em redrawn at a real higher resolution)
koda
parents:
5208
diff
changeset
|
110 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgString]; |
306cedbeb213
fixed several 'retina display' images and added a bunch more (though just from upscaling the normal ones; might be nice to have 'em redrawn at a real higher resolution)
koda
parents:
5208
diff
changeset
|
111 |
[imgString release]; |
4856 | 112 |
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; |
113 |
cell.imageView.image = img; |
|
114 |
[img release]; |
|
115 |
cell.accessoryView = imgView; |
|
116 |
[imgView release]; |
|
117 |
||
118 |
cell.textLabel.textAlignment = UITextAlignmentCenter; |
|
4819 | 119 |
cell.textLabel.adjustsFontSizeToFitWidth = YES; |
4766 | 120 |
cell.backgroundColor = [UIColor blackColor]; |
121 |
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
|
4757 | 122 |
|
123 |
return cell; |
|
124 |
} |
|
125 |
||
4766 | 126 |
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { |
127 |
return 160; |
|
128 |
} |
|
129 |
||
130 |
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { |
|
131 |
if (section == 0) { |
|
132 |
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 160)]; |
|
133 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:@"smallerTitle.png"]; |
|
134 |
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; |
|
135 |
[img release]; |
|
136 |
imgView.center = CGPointMake(self.tableView.frame.size.height/2, 160/2); |
|
137 |
[header addSubview:imgView]; |
|
138 |
[imgView release]; |
|
139 |
||
140 |
return [header autorelease]; |
|
141 |
} else |
|
142 |
return nil; |
|
143 |
} |
|
144 |
||
4757 | 145 |
#pragma mark - |
146 |
#pragma mark Table view delegate |
|
147 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
4934 | 148 |
if ([indexPath section] == 3) { |
149 |
playSound(@"backSound"); |
|
4757 | 150 |
[self dismissModalViewControllerAnimated:YES]; |
4934 | 151 |
} |
4757 | 152 |
} |
153 |
||
154 |
#pragma mark - |
|
155 |
#pragma mark Memory management |
|
156 |
-(void) didReceiveMemoryWarning { |
|
157 |
// Releases the view if it doesn't have a superview. |
|
158 |
[super didReceiveMemoryWarning]; |
|
4760 | 159 |
self.statsArray = nil; |
4757 | 160 |
} |
161 |
||
162 |
-(void) dealloc { |
|
5208 | 163 |
releaseAndNil(statsArray); |
4757 | 164 |
[super dealloc]; |
165 |
} |
|
166 |
||
167 |
||
168 |
@end |
|
169 |